fix: final commit #46
@@ -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
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import Button from "@/components/atoms/buttons/Button";
|
import Button from "@/components/atoms/buttons/Button";
|
||||||
import PaymentSummaryCard from "@/components/molecules/cards/PaymentSummaryCard";
|
import PaymentSummaryCard from "@/components/molecules/cards/PaymentSummaryCard";
|
||||||
import { useAuth } from "@/lib/auth-context";
|
|
||||||
import { useCart } from "@/lib/cart-context";
|
import { useCart } from "@/lib/cart-context";
|
||||||
import { useManager } from "@/lib/manager-context";
|
import { useManager } from "@/lib/manager-context";
|
||||||
import { MenuItemEntity } from "@/lib/types";
|
import { MenuItemEntity } from "@/lib/types";
|
||||||
@@ -20,7 +19,7 @@ export default function PaymentPage() {
|
|||||||
removeFromCart,
|
removeFromCart,
|
||||||
setQuantity,
|
setQuantity,
|
||||||
} = useCart();
|
} = useCart();
|
||||||
const { user } = useAuth();
|
|
||||||
const { products } = useManager();
|
const { products } = useManager();
|
||||||
|
|
||||||
const findProduct = (id: string): MenuItemEntity =>
|
const findProduct = (id: string): MenuItemEntity =>
|
||||||
@@ -31,8 +30,6 @@ export default function PaymentPage() {
|
|||||||
price: 0,
|
price: 0,
|
||||||
} as MenuItemEntity);
|
} as MenuItemEntity);
|
||||||
|
|
||||||
const isCustomer = user?.role === "customer";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="mx-auto w-full max-w-screen-2xl px-4 py-6 md:px-6 md:py-8 lg:px-8">
|
<div className="mx-auto w-full max-w-screen-2xl px-4 py-6 md:px-6 md:py-8 lg:px-8">
|
||||||
@@ -82,7 +79,6 @@ export default function PaymentPage() {
|
|||||||
quantity,
|
quantity,
|
||||||
}) => {
|
}) => {
|
||||||
const { name, description } = findProduct(id);
|
const { name, description } = findProduct(id);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr
|
<tr
|
||||||
key={id}
|
key={id}
|
||||||
@@ -102,24 +98,20 @@ export default function PaymentPage() {
|
|||||||
<button
|
<button
|
||||||
onClick={() => decreaseQty(id)}
|
onClick={() => decreaseQty(id)}
|
||||||
className="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-(--color-border) hover:bg-(--color-border-light)"
|
className="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-(--color-border) hover:bg-(--color-border-light)"
|
||||||
aria-label={`Decrease quantity of ${name}`}
|
|
||||||
>
|
>
|
||||||
-
|
-
|
||||||
</button>
|
</button>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
min={1}
|
|
||||||
value={quantity}
|
value={quantity}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setQuantity(id, Number(e.target.value))
|
setQuantity(id, Number(e.target.value))
|
||||||
}
|
}
|
||||||
className="h-8 w-16 rounded-lg border border-(--color-border) bg-transparent text-center"
|
className="h-8 w-16 rounded-lg border border-(--color-border) bg-transparent text-center"
|
||||||
title="Enter quantity"
|
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
onClick={() => increaseQty(id)}
|
onClick={() => increaseQty(id)}
|
||||||
className="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-(--color-border) hover:bg-(--color-border-light)"
|
className="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-(--color-border) hover:bg-(--color-border-light)"
|
||||||
aria-label={`Increase quantity of ${name}`}
|
|
||||||
>
|
>
|
||||||
+
|
+
|
||||||
</button>
|
</button>
|
||||||
@@ -131,7 +123,6 @@ export default function PaymentPage() {
|
|||||||
variant="danger"
|
variant="danger"
|
||||||
size="md"
|
size="md"
|
||||||
style="payment"
|
style="payment"
|
||||||
aria-label={`Remove ${name} from cart`}
|
|
||||||
>
|
>
|
||||||
Delete product
|
Delete product
|
||||||
</Button>
|
</Button>
|
||||||
@@ -149,7 +140,7 @@ export default function PaymentPage() {
|
|||||||
|
|
||||||
<PaymentSummaryCard
|
<PaymentSummaryCard
|
||||||
totalPrice={totalPrice}
|
totalPrice={totalPrice}
|
||||||
isCustomer={isCustomer}
|
isCustomer={true}
|
||||||
backHref="/"
|
backHref="/"
|
||||||
eateryId={eateryId}
|
eateryId={eateryId}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +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 { 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";
|
||||||
|
|
||||||
@@ -12,9 +16,10 @@ export default function PaymentSummaryCard({
|
|||||||
backHref,
|
backHref,
|
||||||
eateryId,
|
eateryId,
|
||||||
}: PaymentSummaryCardProps) {
|
}: PaymentSummaryCardProps) {
|
||||||
|
const { cart,removeCart } = useCart();
|
||||||
const [isReviewOpen, setIsReviewOpen] = useState(false);
|
const [isReviewOpen, setIsReviewOpen] = useState(false);
|
||||||
|
const [isQrModalOpen, setIsQrModalOpen] = useState(false);
|
||||||
const handlePayment = () => {
|
const handlePayment = () => {
|
||||||
// UI-only: open review modal after "payment"
|
|
||||||
if (isCustomer) {
|
if (isCustomer) {
|
||||||
setIsReviewOpen(true);
|
setIsReviewOpen(true);
|
||||||
}
|
}
|
||||||
@@ -44,7 +49,9 @@ export default function PaymentSummaryCard({
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
style="payment"
|
style="payment"
|
||||||
onClick={handlePayment}
|
onClick={() => {
|
||||||
|
setIsQrModalOpen(true);
|
||||||
|
}}
|
||||||
icon="fa-solid fa-qrcode"
|
icon="fa-solid fa-qrcode"
|
||||||
size="md"
|
size="md"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
@@ -52,22 +59,7 @@ export default function PaymentSummaryCard({
|
|||||||
QR Code
|
QR Code
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{isCustomer && (
|
<Link href={backHref || "/"} className={"col-span-2"}>
|
||||||
<Button
|
|
||||||
style="payment"
|
|
||||||
onClick={handlePayment}
|
|
||||||
icon="fa-solid fa-star"
|
|
||||||
size="md"
|
|
||||||
variant="primary"
|
|
||||||
>
|
|
||||||
Review
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Link
|
|
||||||
href={backHref || "/"}
|
|
||||||
className={isCustomer ? "" : "col-span-2"}
|
|
||||||
>
|
|
||||||
<Button
|
<Button
|
||||||
style="payment"
|
style="payment"
|
||||||
onClick={() => setIsReviewOpen(false)}
|
onClick={() => setIsReviewOpen(false)}
|
||||||
@@ -84,9 +76,51 @@ export default function PaymentSummaryCard({
|
|||||||
|
|
||||||
<ReviewModal
|
<ReviewModal
|
||||||
isOpen={isReviewOpen}
|
isOpen={isReviewOpen}
|
||||||
onClose={() => setIsReviewOpen(false)}
|
onClose={() => {
|
||||||
|
setIsReviewOpen(false);
|
||||||
|
|
||||||
|
removeCart();
|
||||||
|
}}
|
||||||
eateryId={eateryId}
|
eateryId={eateryId}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{isQrModalOpen && (
|
||||||
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4 backdrop-blur-sm">
|
||||||
|
<div className="animate-in fade-in zoom-in w-full max-w-sm rounded-3xl bg-white p-6 text-center shadow-2xl duration-300">
|
||||||
|
<h2 className="mb-4 text-xl font-bold">Scan to Pay</h2>
|
||||||
|
|
||||||
|
{cart.paymentQrUrl ? (
|
||||||
|
<div className="mb-4 rounded-2xl bg-gray-100 p-4">
|
||||||
|
<img
|
||||||
|
src={cart.paymentQrUrl}
|
||||||
|
alt="Payment QR Code"
|
||||||
|
className="mx-auto h-auto w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="p-10 text-gray-400">QR Code not available</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<p className="mb-6 text-sm text-gray-500">
|
||||||
|
Total:{" "}
|
||||||
|
<span className="font-bold text-black">
|
||||||
|
{formatPrice(totalPrice)}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setIsQrModalOpen(false);
|
||||||
|
setIsReviewOpen(true);
|
||||||
|
}}
|
||||||
|
variant="secondary"
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</aside>
|
</aside>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ export default function ReviewModal({
|
|||||||
if (!isOpen) return null;
|
if (!isOpen) return null;
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!user?.id || !eateryId) return;
|
if (!eateryId) return;
|
||||||
|
|
||||||
const input: CreateReviewInput = {
|
const input: CreateReviewInput = {
|
||||||
reviewerId: user.id,
|
reviewerId: user?.id || "",
|
||||||
eateryId,
|
eateryId,
|
||||||
rating,
|
rating,
|
||||||
...(review.trim() ? { comment: review.trim() } : {}),
|
...(review.trim() ? { comment: review.trim() } : {}),
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ interface CartContextValue {
|
|||||||
items: CartItemEntity[];
|
items: CartItemEntity[];
|
||||||
totalItems: number;
|
totalItems: number;
|
||||||
totalPrice: number;
|
totalPrice: number;
|
||||||
|
cart: CartEntity;
|
||||||
eateryId: string | undefined;
|
eateryId: string | undefined;
|
||||||
addToCart: (product: CartItemEntity) => void;
|
addToCart: (product: CartItemEntity) => void;
|
||||||
increaseQty: (id: string) => void;
|
increaseQty: (id: string) => void;
|
||||||
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: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CART_ID = "cartId";
|
const CART_ID = "cartId";
|
||||||
@@ -120,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -151,6 +154,25 @@ export function CartProvider({ children }: { children: React.ReactNode }) {
|
|||||||
if (result) setCart(result.addItem);
|
if (result) setCart(result.addItem);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
await mutateDeleteCart({ variables: { cartId } });
|
||||||
|
|
||||||
|
setCartId(null);
|
||||||
|
setCart(null!);
|
||||||
|
};
|
||||||
|
|
||||||
const setQuantity = async (id: string, newQuantity: number) => {
|
const setQuantity = async (id: string, newQuantity: number) => {
|
||||||
if (!cartId) return;
|
if (!cartId) return;
|
||||||
|
|
||||||
@@ -191,6 +213,8 @@ export function CartProvider({ children }: { children: React.ReactNode }) {
|
|||||||
decreaseQty,
|
decreaseQty,
|
||||||
removeFromCart,
|
removeFromCart,
|
||||||
setQuantity,
|
setQuantity,
|
||||||
|
removeCart,
|
||||||
|
cart,
|
||||||
}),
|
}),
|
||||||
[cart?.items, cart?.totalAmount, cart?.eateryId],
|
[cart?.items, cart?.totalAmount, cart?.eateryId],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user