import React from "react"; import { Title, Card, Text, Flex, Badge, Box, RingProgress, Alert, } from "@mantine/core"; import { IconAlertTriangle } from "@tabler/icons-react"; import { TimeValue } from "@mantine/dates"; import { IconPencil, IconPlus, IconTrash } from "@tabler/icons-react"; import { ConfirmDialogButton } from "./ConfirmDialogButton"; import { NavigateButton } from "./NavigateButton"; import { Link, useFetcher } from "react-router"; import { useUserContext } from "./UserContext"; export interface OrderSetProps { orderSets: (Pick< OrderSet, | "id" | "name" | "scheduled" | "time" | "weekends" | "weekdays" | "orders" | "probability" > & { orders: Pick; punishment_pool_name: string; })[]; username: string; linkBack?: React.ReactNode; } export const OrderSets: React.FC = ({ orderSets, username, linkBack, }) => { const { username: current_user } = useUserContext(); const fetcher = useFetcher(); const handleDelete = React.useCallback( (id: number) => { fetcher.submit(null, { action: `/orders/${username}/${id}`, method: "DELETE", }); }, [fetcher], ); const [isMastodonSet, setIsMastodonSet] = React.useState(true); React.useEffect(() => { fetch(`/api/subs/${username}`) .then((response) => response.json()) .then((data) => { if (!data.mastodon_server || !data.mastodon_username) { setIsMastodonSet(false); } }); }, [username]); return ( <> Order Sets for {username} {linkBack ? linkBack : null} {orderSets.length > 0 && isMastodonSet ? null : ( } my="md" w="40rem" > {username} must authorize with a Mastodon account before orders can be issued. {username === current_user ? ( <>
Edit Profile ) : null}
)} {orderSets ? orderSets.map( ({ id, name, scheduled, orders, time, weekdays, weekends, probability, punishment_pool_name, }) => ( {name} {scheduled ? ( <> Scheduled: {time.split(",").map((time) => (
))}
{weekdays ? ( Weekdays ) : null} {weekends ? ( Weekends ) : null} {probability * 100}%} sections={[ { color: "cyan", value: probability * 100 }, ]} /> ) : null} Orders: {orders.length}
{punishment_pool_name ? `Punishments: ${punishment_pool_name}` : null}
handleDelete(id)} > Edit
), ) : null}
New ); };