This commit is contained in:
@@ -19,12 +19,14 @@ export default function ManagerSignupPage() {
|
||||
phone: "",
|
||||
password: "",
|
||||
eateryName: "",
|
||||
bankAccount: "", // 1. Thêm bankAccount vào state
|
||||
});
|
||||
const [errors, setErrors] = useState({
|
||||
name: "",
|
||||
phone: "",
|
||||
password: "",
|
||||
eateryName: "",
|
||||
bankAccount: "", // 2. Thêm bankAccount vào errors state
|
||||
submit: "",
|
||||
});
|
||||
|
||||
@@ -32,9 +34,6 @@ export default function ManagerSignupPage() {
|
||||
fetch("/api/manager/signup")
|
||||
.then((res) => {
|
||||
setPageState("available");
|
||||
// if (res.ok) ;
|
||||
// else if (res.status === 403) setPageState("closed");
|
||||
// else setPageState("error");
|
||||
})
|
||||
.catch(() => setPageState("error"));
|
||||
}, []);
|
||||
@@ -54,6 +53,7 @@ export default function ManagerSignupPage() {
|
||||
phone: "",
|
||||
password: "",
|
||||
eateryName: "",
|
||||
bankAccount: "",
|
||||
submit: "",
|
||||
};
|
||||
if (!form.name.trim()) next.name = "Please enter your full name";
|
||||
@@ -65,8 +65,18 @@ export default function ManagerSignupPage() {
|
||||
next.password = "Password must be at least 6 characters";
|
||||
if (!form.eateryName.trim())
|
||||
next.eateryName = "Please enter the restaurant name";
|
||||
|
||||
if (!form.bankAccount.trim())
|
||||
next.bankAccount = "Please enter your bank account number";
|
||||
|
||||
setErrors(next);
|
||||
return !next.name && !next.phone && !next.password && !next.eateryName;
|
||||
return (
|
||||
!next.name &&
|
||||
!next.phone &&
|
||||
!next.password &&
|
||||
!next.eateryName &&
|
||||
!next.bankAccount
|
||||
);
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
|
||||
@@ -232,6 +242,14 @@ export default function ManagerSignupPage() {
|
||||
field: "eateryName" as const,
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
id: "bankAccount",
|
||||
label: "Bank account number (example: acb-44359797)",
|
||||
icon: "fa-credit-card",
|
||||
placeholder: "Enter account number (for QR payment)",
|
||||
field: "bankAccount" as const,
|
||||
type: "text",
|
||||
},
|
||||
].map(({ id, label, icon, placeholder, field, type }) => (
|
||||
<div key={id}>
|
||||
<label
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { formatPrice } from "@/app/(main)/payment/page";
|
||||
import Button from "@/components/atoms/buttons/Button";
|
||||
import { ReviewModal } from "@/components/organisms/modals";
|
||||
import { cartClient } from "@/lib/apollo-clients";
|
||||
import { useCart } from "@/lib/cart-context";
|
||||
import { gql } from "@apollo/client";
|
||||
import { useMutation } from "@apollo/client/react";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
|
||||
@@ -13,7 +16,7 @@ export default function PaymentSummaryCard({
|
||||
backHref,
|
||||
eateryId,
|
||||
}: PaymentSummaryCardProps) {
|
||||
const { cart } = useCart();
|
||||
const { cart,removeCart } = useCart();
|
||||
const [isReviewOpen, setIsReviewOpen] = useState(false);
|
||||
const [isQrModalOpen, setIsQrModalOpen] = useState(false);
|
||||
const handlePayment = () => {
|
||||
@@ -73,7 +76,11 @@ export default function PaymentSummaryCard({
|
||||
|
||||
<ReviewModal
|
||||
isOpen={isReviewOpen}
|
||||
onClose={() => setIsReviewOpen(false)}
|
||||
onClose={() => {
|
||||
setIsReviewOpen(false);
|
||||
|
||||
removeCart();
|
||||
}}
|
||||
eateryId={eateryId}
|
||||
/>
|
||||
|
||||
|
||||
+14
-17
@@ -25,7 +25,7 @@ interface CartContextValue {
|
||||
decreaseQty: (id: string) => void;
|
||||
removeFromCart: (id: string) => void;
|
||||
setQuantity: (id: string, quantity: number) => void;
|
||||
removeCart: (id: string) => void;
|
||||
removeCart: () => void;
|
||||
}
|
||||
|
||||
const CART_ID = "cartId";
|
||||
@@ -122,6 +122,7 @@ export function CartProvider({ children }: { children: React.ReactNode }) {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Lỗi khi tạo giỏ hàng:", err);
|
||||
localStorage.removeItem(CART_ID);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -153,24 +154,20 @@ export function CartProvider({ children }: { children: React.ReactNode }) {
|
||||
if (result) setCart(result.addItem);
|
||||
};
|
||||
|
||||
const removeCart = async (id: string) => {
|
||||
const DELETE_CART = gql`
|
||||
mutation deleteCart($cartId: String!) {
|
||||
deleteCart(cartId: $cartId)
|
||||
}
|
||||
`;
|
||||
|
||||
const [mutateDeleteCart] = useMutation(DELETE_CART, {
|
||||
client: cartClient,
|
||||
});
|
||||
|
||||
const removeCart = async () => {
|
||||
localStorage.removeItem(CART_ID);
|
||||
|
||||
const DELETE_CART = gql`
|
||||
mutation deleteCart($cartId: String!) {
|
||||
deleteCart(cartId: $cartId)
|
||||
}
|
||||
`;
|
||||
|
||||
const [mutateDeleteCart] = useMutation(DELETE_CART, {
|
||||
client: cartClient,
|
||||
});
|
||||
|
||||
await mutateDeleteCart({
|
||||
variables: {
|
||||
cartId: id,
|
||||
},
|
||||
});
|
||||
await mutateDeleteCart({ variables: { cartId } });
|
||||
|
||||
setCartId(null);
|
||||
setCart(null!);
|
||||
|
||||
Reference in New Issue
Block a user