From 1a1fec9d8c4ab9955f2808fed33188a7c58f0985 Mon Sep 17 00:00:00 2001 From: Astalum Date: Sat, 28 Sep 2024 05:02:49 +0900 Subject: [PATCH 01/11] Order_to_OrderEntity --- app/routes/_header.casher.tsx | 143 ++++++++++++++++------------------ 1 file changed, 68 insertions(+), 75 deletions(-) diff --git a/app/routes/_header.casher.tsx b/app/routes/_header.casher.tsx index 0fa05ac9..f1d90e9f 100644 --- a/app/routes/_header.casher.tsx +++ b/app/routes/_header.casher.tsx @@ -1,9 +1,11 @@ import { parseWithZod } from "@conform-to/zod"; import { AlertDialogCancel } from "@radix-ui/react-alert-dialog"; import { TrashIcon } from "@radix-ui/react-icons"; -import { type ClientActionFunction, json } from "@remix-run/react"; +import { type ClientActionFunction, json, useSubmit } from "@remix-run/react"; +import { set } from "lodash"; import { useState } from "react"; import useSWRSubscription from "swr/subscription"; +import { z } from "zod"; import { AlertDialog, AlertDialogAction, @@ -25,35 +27,12 @@ import { TableHeader, TableRow, } from "~/components/ui/table"; -import { itemConverter } from "~/firebase/converter"; +import { itemConverter, orderConverter } from "~/firebase/converter"; import { collectionSub } from "~/firebase/subscription"; -import { ItemEntity, itemSchema } from "~/models/item"; -import type { Order } from "~/models/order"; -import { itemRepository } from "~/repositories/item"; - -const mockOrder: Order = { - orderId: 1, - createdAt: new Date(), - servedAt: null, - items: [ - // { - // id: "1", - // type: "ice", - // name: "珈琲・俺ブレンド", - // price: 300, - // }, - ], - total: 0, - orderReady: false, - description: "", - discountInfo: { - previousOrderId: null, - validCups: 0, - discount: 0, - }, - received: 0, - billingAmount: 0, -}; +import { stringToJSONSchema } from "~/lib/custom-zod"; +import { WithId } from "~/lib/typeguard"; +import { ItemEntity } from "~/models/item"; +import { OrderEntity, orderSchema } from "~/models/order"; export default function Casher() { // const total = mockOrder.items.reduce((acc, cur) => acc + cur.price, 0); @@ -61,8 +40,18 @@ export default function Casher() { "items", collectionSub({ converter: itemConverter }), ); + const { data: orders } = useSWRSubscription( + "orders", + collectionSub({ converter: orderConverter }), + ); + const curOrderId = + orders?.reduce((acc, cur) => Math.max(acc, cur.orderId), 0) ?? 0; + const nextOrderId = curOrderId + 1; + const order = OrderEntity.createNew({ orderId: nextOrderId }); const [recieved, setText] = useState(0); - const [order, setOrder] = useState(mockOrder); + // const [order, setOrder] = useState(newOrder); + const [queue, setQueue] = useState[]>([]); + order.items = queue; return (
@@ -73,18 +62,20 @@ export default function Casher() {
); } - From b6651445af1e9a91a4b19eccea497ebce0119951 Mon Sep 17 00:00:00 2001 From: Astalum Date: Sun, 29 Sep 2024 17:25:02 +0900 Subject: [PATCH 11/11] fix:biome --- app/routes/_header.casher.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/routes/_header.casher.tsx b/app/routes/_header.casher.tsx index 6f06ddfb..ab6b9c2e 100644 --- a/app/routes/_header.casher.tsx +++ b/app/routes/_header.casher.tsx @@ -1,10 +1,7 @@ -// import { parseWithZod } from "@conform-to/zod"; import { AlertDialogCancel } from "@radix-ui/react-alert-dialog"; import { TrashIcon } from "@radix-ui/react-icons"; -// import type { ClientActionFunction } from "@remix-run/react"; import { useState } from "react"; import useSWRSubscription from "swr/subscription"; -// import { z } from "zod"; import { AlertDialog, AlertDialogAction, @@ -28,12 +25,9 @@ import { } from "~/components/ui/table"; import { itemConverter, orderConverter } from "~/firebase/converter"; import { collectionSub } from "~/firebase/subscription"; -// import { stringToJSONSchema } from "~/lib/custom-zod"; import type { WithId } from "~/lib/typeguard"; import type { ItemEntity } from "~/models/item"; -// import { OrderEntity, orderSchema } from "~/models/order"; import { OrderEntity } from "~/models/order"; -// import { itemRepository } from "~/repositories/item"; export default function Casher() { const { data: items } = useSWRSubscription(