2026-01-30 16:18:49 +00:00
|
|
|
import {
|
|
|
|
|
Container,
|
|
|
|
|
Title,
|
|
|
|
|
Card,
|
|
|
|
|
Text,
|
|
|
|
|
Button,
|
|
|
|
|
Flex,
|
|
|
|
|
Badge,
|
|
|
|
|
} from "@mantine/core";
|
|
|
|
|
import { TimeValue } from "@mantine/dates";
|
2026-01-30 16:52:32 +00:00
|
|
|
import { IconPencil, IconPlus } from "@tabler/icons-react";
|
2026-01-29 21:30:51 +00:00
|
|
|
import React from "react";
|
2026-01-30 16:18:49 +00:00
|
|
|
import { Params, useLoaderData, useParams, useNavigate } from "react-router";
|
2026-01-29 21:30:51 +00:00
|
|
|
|
|
|
|
|
export const subOrderSetsLoader = async ({
|
|
|
|
|
params: { username },
|
|
|
|
|
}: {
|
|
|
|
|
params: Params<string>;
|
|
|
|
|
}) => fetch(`/api/subs/${username}/sets`).then((response) => response.json());
|
|
|
|
|
|
2026-01-30 16:18:49 +00:00
|
|
|
const NavigateButton: React.FC<{
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
to: string;
|
|
|
|
|
}> = ({ children, to }) => {
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
|
|
const handleClick = React.useCallback(() => {
|
|
|
|
|
navigate(to);
|
|
|
|
|
}, [to]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Button onClick={handleClick} px="md" w="auto">
|
|
|
|
|
{children}
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-29 21:30:51 +00:00
|
|
|
export const SubOrderSets: React.FC = () => {
|
|
|
|
|
const { username: sub_username } = useParams();
|
2026-01-30 16:18:49 +00:00
|
|
|
const orderSets = useLoaderData<
|
|
|
|
|
(Pick<
|
|
|
|
|
OrderSet,
|
|
|
|
|
"id" | "name" | "scheduled" | "time" | "weekends" | "weekdays" | "orders"
|
|
|
|
|
> & {
|
|
|
|
|
orders: Pick<OrderSetOrder, "id" | "name">[];
|
|
|
|
|
})[]
|
2026-01-29 21:30:51 +00:00
|
|
|
>();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Container>
|
2026-01-29 22:23:20 +00:00
|
|
|
<Title order={1} mb="lg">
|
2026-01-30 16:18:49 +00:00
|
|
|
Order Sets for {sub_username}
|
2026-01-29 22:23:20 +00:00
|
|
|
</Title>
|
2026-01-30 16:18:49 +00:00
|
|
|
<Flex gap="md" wrap="wrap">
|
|
|
|
|
{orderSets
|
|
|
|
|
? orderSets.map(
|
|
|
|
|
({ id, name, scheduled, orders, time, weekdays, weekends }) => (
|
|
|
|
|
<Card
|
|
|
|
|
key={id}
|
|
|
|
|
shadow="sm"
|
|
|
|
|
padding="lg"
|
|
|
|
|
radius="md"
|
|
|
|
|
withBorder
|
|
|
|
|
bg="gray.2"
|
|
|
|
|
w="400px"
|
|
|
|
|
>
|
|
|
|
|
<Flex direction="column" gap="md">
|
|
|
|
|
<Title order={4}>{name}</Title>
|
|
|
|
|
{scheduled ? (
|
|
|
|
|
<Flex gap="md" align="center">
|
|
|
|
|
<Text>
|
|
|
|
|
Scheduled: <TimeValue value={time} format="12h" />
|
|
|
|
|
</Text>
|
|
|
|
|
{weekdays ? <Badge color="blue">Weekdays</Badge> : null}
|
|
|
|
|
{weekends ? <Badge color="blue">Weekends</Badge> : null}
|
|
|
|
|
</Flex>
|
|
|
|
|
) : null}
|
|
|
|
|
<Text mb="md">Orders: {orders.length}</Text>
|
|
|
|
|
</Flex>
|
|
|
|
|
<Flex justify="end">
|
|
|
|
|
<NavigateButton
|
|
|
|
|
to={`/dashboard/subs/${sub_username}/${id}`}
|
|
|
|
|
>
|
|
|
|
|
<IconPencil style={{ marginRight: "0.5rem" }} />
|
|
|
|
|
Edit
|
|
|
|
|
</NavigateButton>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Card>
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: null}
|
|
|
|
|
</Flex>
|
2026-01-30 16:52:32 +00:00
|
|
|
<NavigateButton to={`/dashboard/subs/${sub_username}/new`}>
|
|
|
|
|
<IconPlus style={{ marginRight: "0.5rem" }} />
|
|
|
|
|
New
|
|
|
|
|
</NavigateButton>
|
2026-01-29 21:30:51 +00:00
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
};
|