Order Sets - Nicer UI
This commit is contained in:
parent
0511e0f488
commit
cb7e8730c0
2 changed files with 83 additions and 16 deletions
|
|
@ -31,6 +31,13 @@ def sub_order_sets(username):
|
||||||
{
|
{
|
||||||
'id': op.id,
|
'id': op.id,
|
||||||
'name': op.name,
|
'name': op.name,
|
||||||
|
'scheduled': op.scheduled,
|
||||||
|
'time': op.time,
|
||||||
|
'weekends': op.weekends,
|
||||||
|
'weekdays': op.weekdays,
|
||||||
|
'orders': [{
|
||||||
|
'id': order.id,
|
||||||
|
} for order in op.orders]
|
||||||
}
|
}
|
||||||
for op
|
for op
|
||||||
in orders_pool_list(sub.id)
|
in orders_pool_list(sub.id)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,16 @@
|
||||||
import { Container, Title } from "@mantine/core";
|
import {
|
||||||
|
Container,
|
||||||
|
Title,
|
||||||
|
Card,
|
||||||
|
Text,
|
||||||
|
Button,
|
||||||
|
Flex,
|
||||||
|
Badge,
|
||||||
|
} from "@mantine/core";
|
||||||
|
import { TimeValue } from "@mantine/dates";
|
||||||
|
import { IconPencil } from "@tabler/icons-react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Link, Params, useLoaderData, useParams } from "react-router";
|
import { Params, useLoaderData, useParams, useNavigate } from "react-router";
|
||||||
|
|
||||||
export const subOrderSetsLoader = async ({
|
export const subOrderSetsLoader = async ({
|
||||||
params: { username },
|
params: { username },
|
||||||
|
|
@ -8,28 +18,78 @@ export const subOrderSetsLoader = async ({
|
||||||
params: Params<string>;
|
params: Params<string>;
|
||||||
}) => fetch(`/api/subs/${username}/sets`).then((response) => response.json());
|
}) => fetch(`/api/subs/${username}/sets`).then((response) => response.json());
|
||||||
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const SubOrderSets: React.FC = () => {
|
export const SubOrderSets: React.FC = () => {
|
||||||
const { username: sub_username } = useParams();
|
const { username: sub_username } = useParams();
|
||||||
const orders = useLoaderData<
|
const orderSets = useLoaderData<
|
||||||
{
|
(Pick<
|
||||||
id: number;
|
OrderSet,
|
||||||
name: string;
|
"id" | "name" | "scheduled" | "time" | "weekends" | "weekdays" | "orders"
|
||||||
orders: Pick<OrderSet, "id" | "name">[];
|
> & {
|
||||||
}[]
|
orders: Pick<OrderSetOrder, "id" | "name">[];
|
||||||
|
})[]
|
||||||
>();
|
>();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<Title order={1} mb="lg">
|
<Title order={1} mb="lg">
|
||||||
Orders for {sub_username}
|
Order Sets for {sub_username}
|
||||||
</Title>
|
</Title>
|
||||||
{orders
|
<Flex gap="md" wrap="wrap">
|
||||||
? orders.map(({ id, name }) => (
|
{orderSets
|
||||||
<Link key={id} to={`/dashboard/subs/${sub_username}/${id}`}>
|
? orderSets.map(
|
||||||
{name}
|
({ id, name, scheduled, orders, time, weekdays, weekends }) => (
|
||||||
</Link>
|
<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}
|
: null}
|
||||||
|
</Flex>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue