2026-03-04 21:14:18 +00:00
|
|
|
import React from "react";
|
2026-03-07 18:38:44 +00:00
|
|
|
import {
|
|
|
|
|
Title,
|
|
|
|
|
Card,
|
|
|
|
|
Text,
|
|
|
|
|
Flex,
|
|
|
|
|
Badge,
|
|
|
|
|
Box,
|
|
|
|
|
RingProgress,
|
|
|
|
|
} from "@mantine/core";
|
2026-03-04 21:14:18 +00:00
|
|
|
import { TimeValue } from "@mantine/dates";
|
|
|
|
|
import { IconPencil, IconPlus, IconTrash } from "@tabler/icons-react";
|
|
|
|
|
|
|
|
|
|
import { ConfirmDialogButton } from "./ConfirmDialogButton";
|
|
|
|
|
import { NavigateButton } from "./NavigateButton";
|
|
|
|
|
import { useFetcher } from "react-router";
|
|
|
|
|
|
|
|
|
|
export interface OrderSetProps {
|
|
|
|
|
orderSets: (Pick<
|
|
|
|
|
OrderSet,
|
2026-03-07 18:38:44 +00:00
|
|
|
| "id"
|
|
|
|
|
| "name"
|
|
|
|
|
| "scheduled"
|
|
|
|
|
| "time"
|
|
|
|
|
| "weekends"
|
|
|
|
|
| "weekdays"
|
|
|
|
|
| "orders"
|
|
|
|
|
| "probability"
|
|
|
|
|
> & {
|
|
|
|
|
orders: Pick<OrderSetOrder, "id" | "name">;
|
|
|
|
|
punishment_pool_name: string;
|
|
|
|
|
})[];
|
2026-03-04 21:14:18 +00:00
|
|
|
username: string;
|
|
|
|
|
linkBack?: React.ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const OrderSets: React.FC<OrderSetProps> = ({
|
|
|
|
|
orderSets,
|
|
|
|
|
username,
|
|
|
|
|
linkBack,
|
|
|
|
|
}) => {
|
|
|
|
|
const fetcher = useFetcher();
|
|
|
|
|
const handleDelete = React.useCallback(
|
|
|
|
|
(id: number) => {
|
|
|
|
|
fetcher.submit(null, {
|
|
|
|
|
action: `/orders/${username}/${id}`,
|
|
|
|
|
method: "DELETE",
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[fetcher],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Box mb="lg">
|
|
|
|
|
<Title order={1}>Order Sets for {username}</Title>
|
|
|
|
|
{linkBack ? linkBack : null}
|
|
|
|
|
</Box>
|
|
|
|
|
<Flex gap="md" wrap="wrap">
|
|
|
|
|
{orderSets
|
|
|
|
|
? orderSets.map(
|
2026-03-07 18:38:44 +00:00
|
|
|
({
|
|
|
|
|
id,
|
|
|
|
|
name,
|
|
|
|
|
scheduled,
|
|
|
|
|
orders,
|
|
|
|
|
time,
|
|
|
|
|
weekdays,
|
|
|
|
|
weekends,
|
|
|
|
|
probability,
|
|
|
|
|
punishment_pool_name,
|
|
|
|
|
}) => (
|
2026-03-04 21:14:18 +00:00
|
|
|
<Card
|
|
|
|
|
key={id}
|
|
|
|
|
shadow="sm"
|
|
|
|
|
padding="lg"
|
|
|
|
|
radius="md"
|
|
|
|
|
withBorder
|
|
|
|
|
bg="gray.2"
|
|
|
|
|
w="400px"
|
|
|
|
|
>
|
|
|
|
|
<Flex direction="column" gap="md" h="100%">
|
|
|
|
|
<Title order={4}>{name}</Title>
|
|
|
|
|
{scheduled ? (
|
2026-03-07 18:38:44 +00:00
|
|
|
<>
|
2026-03-07 20:27:18 +00:00
|
|
|
<Flex gap="xs">
|
|
|
|
|
<Text>Scheduled:</Text>
|
|
|
|
|
{time.split(",").map((time) => (
|
|
|
|
|
<div key={time}>
|
|
|
|
|
<TimeValue key={time} value={time} format="12h" />
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</Flex>
|
2026-03-07 18:38:44 +00:00
|
|
|
<Flex gap="md" align="center">
|
|
|
|
|
{weekdays ? (
|
|
|
|
|
<Badge color="blue">Weekdays</Badge>
|
|
|
|
|
) : null}
|
|
|
|
|
{weekends ? (
|
|
|
|
|
<Badge color="blue">Weekends</Badge>
|
|
|
|
|
) : null}
|
|
|
|
|
<RingProgress
|
|
|
|
|
size={80}
|
|
|
|
|
label={<Text size="xs">{probability * 100}%</Text>}
|
|
|
|
|
sections={[
|
|
|
|
|
{ color: "cyan", value: probability * 100 },
|
|
|
|
|
]}
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
|
|
|
|
</>
|
2026-03-04 21:14:18 +00:00
|
|
|
) : null}
|
|
|
|
|
<Text mb="md" flex={1}>
|
|
|
|
|
Orders: {orders.length}
|
2026-03-07 18:38:44 +00:00
|
|
|
<br />
|
|
|
|
|
{punishment_pool_name
|
|
|
|
|
? `Punishments: ${punishment_pool_name}`
|
|
|
|
|
: null}
|
2026-03-04 21:14:18 +00:00
|
|
|
</Text>
|
|
|
|
|
<Flex gap="md" justify="end">
|
|
|
|
|
<ConfirmDialogButton
|
|
|
|
|
buttonColor="red.8"
|
|
|
|
|
buttonText="Delete"
|
|
|
|
|
text={`Are you sure you want to delete ${name}?`}
|
|
|
|
|
onConfirm={() => handleDelete(id)}
|
|
|
|
|
>
|
|
|
|
|
<IconTrash />
|
|
|
|
|
</ConfirmDialogButton>
|
|
|
|
|
<NavigateButton to={`/orders/${username}/${id}`}>
|
|
|
|
|
<IconPencil style={{ marginRight: "0.5rem" }} />
|
|
|
|
|
Edit
|
|
|
|
|
</NavigateButton>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Card>
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: null}
|
|
|
|
|
</Flex>
|
|
|
|
|
<NavigateButton to={`/orders/${username}/new`}>
|
|
|
|
|
<IconPlus style={{ marginRight: "0.5rem" }} />
|
|
|
|
|
New
|
|
|
|
|
</NavigateButton>
|
|
|
|
|
<Box mb="lg"></Box>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|