import { Container, Title, Card, Text, Box, Flex, Badge } from "@mantine/core"; import { TimeValue } from "@mantine/dates"; import { IconPencil, IconPlus, IconTrash } from "@tabler/icons-react"; import React from "react"; import { Params, useLoaderData, useParams, useFetcher, Link, } from "react-router"; import { ConfirmDialogButton } from "./ConfirmDialogButton"; import { NavigateButton } from "./NavigateButton"; export const subOrderSetsLoader = async ({ params: { username }, }: { params: Params; }) => fetch(`/api/subs/${username}/sets`).then((response) => response.json()); export const SubOrderSets: React.FC = () => { const fetcher = useFetcher(); const { username: sub_username } = useParams(); const orderSets = useLoaderData< (Pick< OrderSet, "id" | "name" | "scheduled" | "time" | "weekends" | "weekdays" | "orders" > & { orders: Pick[]; })[] >(); const handleDelete = React.useCallback( (id: number) => { fetcher.submit(null, { action: `/dashboard/subs/${sub_username}/${id}`, method: "DELETE", }); }, [fetcher], ); return ( Order Sets for {sub_username} Return to all subs {orderSets ? orderSets.map( ({ id, name, scheduled, orders, time, weekdays, weekends }) => ( {name} {scheduled ? ( Scheduled: {weekdays ? Weekdays : null} {weekends ? Weekends : null} ) : null} Orders: {orders.length} handleDelete(id)} > Edit ), ) : null} New ); };