diff --git a/sysken-pay-front/src/pages/charge/complete.tsx b/sysken-pay-front/src/pages/charge/complete.tsx new file mode 100644 index 0000000..d2bf8db --- /dev/null +++ b/sysken-pay-front/src/pages/charge/complete.tsx @@ -0,0 +1,25 @@ +import { useNavigate } from "react-router-dom"; +import Button from "../../components/ui/Button"; +import { useBalanceStore } from "../../store/useBalanceStore"; + +export default function Charge() { + const navigate = useNavigate(); + + const handleHome = () => { + navigate("/"); + }; + return ( +
+
+
+ チャージが完了しました +
+
+ 現在のカード残高 ¥ + {useBalanceStore((state) => state.balance?.balance ?? 0)} +
+ +
+
+ ); +} diff --git a/sysken-pay-front/src/pages/charge/index.tsx b/sysken-pay-front/src/pages/charge/index.tsx index 0df996c..e21bc34 100644 --- a/sysken-pay-front/src/pages/charge/index.tsx +++ b/sysken-pay-front/src/pages/charge/index.tsx @@ -12,7 +12,7 @@ export default function Charge() { // TODO: APIから残高を参照 setBalance({ userId: barcode, - balance: 150, + balance: 550, }); navigate("/charge/select"); }; diff --git a/sysken-pay-front/src/pages/charge/insert.tsx b/sysken-pay-front/src/pages/charge/insert.tsx new file mode 100644 index 0000000..524c0ec --- /dev/null +++ b/sysken-pay-front/src/pages/charge/insert.tsx @@ -0,0 +1,39 @@ +import Header from "../../components/layouts/Header/index"; +import { useNavigate } from "react-router-dom"; +import ArrowButton from "../../components/ui/ArrowButton"; +import { PriceLabel } from "../../components/ui/PriceLabel"; +import { useChargeStore } from "../../store/useChargeStore"; +import { useBalanceStore } from "../../store/useBalanceStore"; + +export default function ChargeInsertPage() { + const navigate = useNavigate(); + const chargeAmount = useChargeStore((state) => state.chargeAmount); + const setBalance = useBalanceStore((state) => state.setBalance); + + const handleNext = (barcode: string) => { + // TODO: APIから残高を参照 + setBalance({ + userId: barcode, + balance: 550, + }); + navigate("/charge/complete"); + }; + + return ( +
+
+
+
+ 箱にお金を入れてください +
+ +
+ navigate("/charge/select")}> + 戻る + + handleNext("user123")}> + 完了 + +
+ ); +} diff --git a/sysken-pay-front/src/pages/charge/select.tsx b/sysken-pay-front/src/pages/charge/select.tsx index b2605f4..f919f31 100644 --- a/sysken-pay-front/src/pages/charge/select.tsx +++ b/sysken-pay-front/src/pages/charge/select.tsx @@ -6,13 +6,19 @@ import { PriceLabel } from "../../components/ui/PriceLabel"; import { Input } from "../../components/ui/Input"; import { useBalanceStore } from "../../store/useBalanceStore"; import { useState } from "react"; +import { useChargeStore } from "../../store/useChargeStore"; export default function ChargeSelectPage() { const navigate = useNavigate(); const balance = useBalanceStore((state) => state.balance?.balance ?? 0); + const saveChargeAmount = useChargeStore((state) => state.setChargeAmount); const [chargeAmount, setChargeAmount] = useState(""); - const handleHome = () => { - navigate("/"); + + const handleNext = () => { + const normalizedChargeAmount = + Number(chargeAmount.replace(/[^\d]/g, "")) || 0; + saveChargeAmount(normalizedChargeAmount); + navigate("/charge/insert"); }; return ( @@ -33,10 +39,10 @@ export default function ChargeSelectPage() { - + navigate("/charge")}> 戻る - navigate("/charge/insert")}> + 次へ diff --git a/sysken-pay-front/src/router.ts b/sysken-pay-front/src/router.ts index 8bd0698..b924ba1 100644 --- a/sysken-pay-front/src/router.ts +++ b/sysken-pay-front/src/router.ts @@ -21,6 +21,8 @@ export type Path = | `/buy/confirm` | `/buy/list` | `/charge` + | `/charge/complete` + | `/charge/insert` | `/charge/select` export type Params = { diff --git a/sysken-pay-front/src/store/useChargeStore.ts b/sysken-pay-front/src/store/useChargeStore.ts new file mode 100644 index 0000000..8fcccb4 --- /dev/null +++ b/sysken-pay-front/src/store/useChargeStore.ts @@ -0,0 +1,13 @@ +import { create } from "zustand"; + +type ChargeStore = { + chargeAmount: number; + setChargeAmount: (amount: number) => void; + clearChargeAmount: () => void; +}; + +export const useChargeStore = create((set) => ({ + chargeAmount: 0, + setChargeAmount: (amount) => set({ chargeAmount: amount }), + clearChargeAmount: () => set({ chargeAmount: 0 }), +}));