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"; import { DonutChart } from "@mantine/charts"; const COLORS_ROTATION = [ "teal", "pink", "lime", "violet", "orange", "blue", "yellow", "grape", "green", "red", "cyan", "gray", ]; 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(() => { if (username) { fetch(`/api/subs/${username}`) .then((response) => response.json()) .then((data) => { if (!data.mastodon_server || !data.mastodon_username) { setIsMastodonSet(false); } }); } }, [username]); const [portalRef, setPortalRef] = React.useState(); 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}
)}
{ if (portalRef == null && node != null) { setPortalRef(node); } }} > {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} {punishment_pool_name ? ( Punishments: {punishment_pool_name} ) : null} {orders.length > 0 ? ( ({ name, value: weight, color: COLORS_ROTATION[idx % COLORS_ROTATION.length], }))} tooltipDataSource="segment" /> ) : null} handleDelete(id)} > Edit
), ) : null}
New ); };