chore: update
This commit is contained in:
@@ -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 =>
|
||||||
@@ -80,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}
|
||||||
@@ -100,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>
|
||||||
@@ -129,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>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
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 { useCart } from "@/lib/cart-context";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
@@ -12,7 +13,9 @@ export default function PaymentSummaryCard({
|
|||||||
backHref,
|
backHref,
|
||||||
eateryId,
|
eateryId,
|
||||||
}: PaymentSummaryCardProps) {
|
}: PaymentSummaryCardProps) {
|
||||||
|
const { cart } = useCart();
|
||||||
const [isReviewOpen, setIsReviewOpen] = useState(false);
|
const [isReviewOpen, setIsReviewOpen] = useState(false);
|
||||||
|
const [isQrModalOpen, setIsQrModalOpen] = useState(false);
|
||||||
const handlePayment = () => {
|
const handlePayment = () => {
|
||||||
if (isCustomer) {
|
if (isCustomer) {
|
||||||
setIsReviewOpen(true);
|
setIsReviewOpen(true);
|
||||||
@@ -43,7 +46,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"
|
||||||
@@ -71,6 +76,44 @@ export default function PaymentSummaryCard({
|
|||||||
onClose={() => setIsReviewOpen(false)}
|
onClose={() => setIsReviewOpen(false)}
|
||||||
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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ 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;
|
||||||
@@ -216,6 +217,7 @@ export function CartProvider({ children }: { children: React.ReactNode }) {
|
|||||||
removeFromCart,
|
removeFromCart,
|
||||||
setQuantity,
|
setQuantity,
|
||||||
removeCart,
|
removeCart,
|
||||||
|
cart,
|
||||||
}),
|
}),
|
||||||
[cart?.items, cart?.totalAmount, cart?.eateryId],
|
[cart?.items, cart?.totalAmount, cart?.eateryId],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user