fix: final commit #46
@@ -31,8 +31,6 @@ export default function PaymentPage() {
|
||||
price: 0,
|
||||
} as MenuItemEntity);
|
||||
|
||||
const isCustomer = user?.role === "customer";
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mx-auto w-full max-w-screen-2xl px-4 py-6 md:px-6 md:py-8 lg:px-8">
|
||||
@@ -149,7 +147,7 @@ export default function PaymentPage() {
|
||||
|
||||
<PaymentSummaryCard
|
||||
totalPrice={totalPrice}
|
||||
isCustomer={isCustomer}
|
||||
isCustomer={true}
|
||||
backHref="/"
|
||||
eateryId={eateryId}
|
||||
/>
|
||||
|
||||
@@ -14,7 +14,6 @@ export default function PaymentSummaryCard({
|
||||
}: PaymentSummaryCardProps) {
|
||||
const [isReviewOpen, setIsReviewOpen] = useState(false);
|
||||
const handlePayment = () => {
|
||||
// UI-only: open review modal after "payment"
|
||||
if (isCustomer) {
|
||||
setIsReviewOpen(true);
|
||||
}
|
||||
@@ -52,22 +51,7 @@ export default function PaymentSummaryCard({
|
||||
QR Code
|
||||
</Button>
|
||||
|
||||
{isCustomer && (
|
||||
<Button
|
||||
style="payment"
|
||||
onClick={handlePayment}
|
||||
icon="fa-solid fa-star"
|
||||
size="md"
|
||||
variant="primary"
|
||||
>
|
||||
Review
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Link
|
||||
href={backHref || "/"}
|
||||
className={isCustomer ? "" : "col-span-2"}
|
||||
>
|
||||
<Link href={backHref || "/"} className={"col-span-2"}>
|
||||
<Button
|
||||
style="payment"
|
||||
onClick={() => setIsReviewOpen(false)}
|
||||
|
||||
@@ -29,10 +29,10 @@ export default function ReviewModal({
|
||||
if (!isOpen) return null;
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!user?.id || !eateryId) return;
|
||||
if (!eateryId) return;
|
||||
|
||||
const input: CreateReviewInput = {
|
||||
reviewerId: user.id,
|
||||
reviewerId: user?.id || "",
|
||||
eateryId,
|
||||
rating,
|
||||
...(review.trim() ? { comment: review.trim() } : {}),
|
||||
|
||||
@@ -24,6 +24,7 @@ interface CartContextValue {
|
||||
decreaseQty: (id: string) => void;
|
||||
removeFromCart: (id: string) => void;
|
||||
setQuantity: (id: string, quantity: number) => void;
|
||||
removeCart: (id: string) => void;
|
||||
}
|
||||
|
||||
const CART_ID = "cartId";
|
||||
@@ -151,6 +152,29 @@ export function CartProvider({ children }: { children: React.ReactNode }) {
|
||||
if (result) setCart(result.addItem);
|
||||
};
|
||||
|
||||
const removeCart = async (id: string) => {
|
||||
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,
|
||||
},
|
||||
});
|
||||
|
||||
setCartId(null);
|
||||
setCart(null!);
|
||||
};
|
||||
|
||||
const setQuantity = async (id: string, newQuantity: number) => {
|
||||
if (!cartId) return;
|
||||
|
||||
@@ -191,6 +215,7 @@ export function CartProvider({ children }: { children: React.ReactNode }) {
|
||||
decreaseQty,
|
||||
removeFromCart,
|
||||
setQuantity,
|
||||
removeCart,
|
||||
}),
|
||||
[cart?.items, cart?.totalAmount, cart?.eateryId],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user