Skip to content

Commit

Permalink
とりあえず
Browse files Browse the repository at this point in the history
  • Loading branch information
toririm committed Oct 1, 2024
1 parent 8ca4c11 commit 1121fee
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/components/pages/CashierV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type props = {
};

export type Action =
| { type: "clear" }
| { type: "clear"; effectFn?: () => void }
| { type: "updateOrderId"; orderId: number }
| {
type: "addItem";
Expand Down Expand Up @@ -86,10 +86,16 @@ const reducer = (state: OrderEntity, action: Action): OrderEntity => {
updated.description = description;
return updated;
};
const clear = (effectFn?: () => void) => {
if (effectFn) {
effectFn();
}
return OrderEntity.createNew({ orderId: state.orderId });
};

switch (action.type) {
case "clear":
return OrderEntity.createNew({ orderId: state.orderId });
return clear(action.effectFn);
case "applyDiscount":
return applyDiscount(action.discountOrder);
case "removeDiscount":
Expand Down Expand Up @@ -122,6 +128,7 @@ const CashierV2 = ({ items, orders, submitPayload }: props) => {
const [inputStatus, setInputStatus] =
useState<(typeof InputStatus)[number]>("discount");
const [dialogOpen, setDialogOpen] = useState(false);
const [inputSession, setInputSession] = useState(new Date());

const nextOrderId = useMemo(() => latestOrderId(orders) + 1, [orders]);
useEffect(() => {
Expand Down Expand Up @@ -152,7 +159,7 @@ const CashierV2 = ({ items, orders, submitPayload }: props) => {
if (newOrder.items.length === 0) {
return;
}
dispatch({ type: "clear" });
dispatch({ type: "clear", effectFn: () => setInputSession(new Date()) });
submitPayload(newOrder);
}, [charge, newOrder, submitPayload]);

Expand Down Expand Up @@ -230,6 +237,7 @@ const CashierV2 = ({ items, orders, submitPayload }: props) => {
<p>{newOrder.billingAmount}</p>
</div>
<DiscountInput
key={`DiscountInput-${inputSession.toJSON()}`}
ref={discountInputDOM}
disabled={inputStatus !== "discount"}
orders={orders}
Expand All @@ -244,6 +252,7 @@ const CashierV2 = ({ items, orders, submitPayload }: props) => {
)}
/>
<AttractiveTextBox
key={`Received-${inputSession.toJSON()}`}
type="number"
onTextSet={useCallback(
(text) => dispatch({ type: "setReceived", received: text }),
Expand All @@ -253,6 +262,7 @@ const CashierV2 = ({ items, orders, submitPayload }: props) => {
/>
<Input disabled value={chargeView} />
<AttractiveTextBox
key={`Description-${inputSession.toJSON()}`}
onTextSet={useCallback(
(text) => dispatch({ type: "setDescription", description: text }),
[],
Expand Down

0 comments on commit 1121fee

Please sign in to comment.