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