Compare commits
6 Commits
2d76214f05
...
73fec3e85a
| Author | SHA1 | Date | |
|---|---|---|---|
| 73fec3e85a | |||
| 3d566e2468 | |||
| 553f683df7 | |||
| 1f15f4e9bd | |||
| d15d51080a | |||
| 27bb95dea5 |
@@ -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)}
|
||||
|
||||
@@ -90,6 +90,44 @@ export default function ReviewsTab() {
|
||||
const avgRating =
|
||||
reviews.reduce((sum, r) => sum + r.rating, 0) / reviews.length;
|
||||
|
||||
const CustomerName = ({ customerId }: { customerId: string }) => {
|
||||
const [name, setName] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Hàm gọi API
|
||||
const getName = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
const response = await fetch(`/api/customer/${customerId}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Mạng lỗi hoặc không tìm thấy nhân viên");
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
setName(data["name"]);
|
||||
} catch (error) {
|
||||
console.error("Lỗi khi lấy tên:", error);
|
||||
setName("Lỗi tải tên");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (customerId) {
|
||||
getName();
|
||||
}
|
||||
}, [customerId]); // Chạy lại nếu customerId thay đổi
|
||||
|
||||
if (loading)
|
||||
return <span className="animate-pulse text-gray-400">...</span>;
|
||||
|
||||
return <span>{name || "N/A"}</span>;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Summary header */}
|
||||
@@ -124,7 +162,7 @@ export default function ReviewsTab() {
|
||||
<i className="fa-solid fa-user text-xs text-(--color-primary)"></i>
|
||||
</div>
|
||||
<span className="text-sm font-medium text-(--color-text-secondary)">
|
||||
{review.reviewerId}
|
||||
<CustomerName customerId={review.reviewerId!} />
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex shrink-0 flex-col items-end gap-1">
|
||||
|
||||
@@ -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() } : {}),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { CartFab } from "@/components/organisms/cart";
|
||||
import Footer from "@/layouts/footer";
|
||||
import Header from "@/layouts/header";
|
||||
import { ManagerProvider } from "@/lib/manager-context";
|
||||
|
||||
import type { MainLayoutProps } from "./MainLayout.types";
|
||||
|
||||
@@ -12,7 +13,9 @@ export default function MainLayout({ children }: MainLayoutProps) {
|
||||
return (
|
||||
<>
|
||||
{/* Sticky top header */}
|
||||
<Header />
|
||||
<ManagerProvider>
|
||||
<Header />
|
||||
</ManagerProvider>
|
||||
|
||||
{/* Page content (grows to fill remaining height) */}
|
||||
<div className="flex-1">{children}</div>
|
||||
|
||||
+4
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useAuth } from "@/lib/auth-context";
|
||||
import { SHOP_INFO } from "@/lib/constants";
|
||||
import { useManager } from "@/lib/manager-context";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
@@ -25,6 +26,7 @@ import { useRouter } from "next/navigation";
|
||||
*/
|
||||
export default function Header() {
|
||||
const router = useRouter();
|
||||
const { eatery } = useManager();
|
||||
const { user, logout } = useAuth();
|
||||
|
||||
const handleAuthClick = () => {
|
||||
@@ -47,7 +49,7 @@ export default function Header() {
|
||||
<div className="relative h-10 w-10 shrink-0 md:h-11 md:w-11">
|
||||
<Image
|
||||
src={SHOP_INFO.logo}
|
||||
alt={`${SHOP_INFO.name} logo`}
|
||||
alt={`${eatery?.name} logo`}
|
||||
fill
|
||||
className="object-contain transition-transform duration-200 group-hover:scale-105"
|
||||
sizes="44px"
|
||||
@@ -58,7 +60,7 @@ export default function Header() {
|
||||
{/* Name + tagline */}
|
||||
<div className="flex flex-col leading-tight">
|
||||
<span className="text-base font-bold text-(--color-primary-dark) transition-colors duration-150 group-hover:text-(--color-primary) md:text-lg">
|
||||
{SHOP_INFO.name}
|
||||
{eatery?.name}
|
||||
</span>
|
||||
<span className="hidden text-xs text-(--color-text-muted) md:block">
|
||||
{SHOP_INFO.tagline}
|
||||
|
||||
@@ -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],
|
||||
);
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
|
||||
import { eateryClient } from "./apollo-clients";
|
||||
import {
|
||||
EateryEntity,
|
||||
type MenuItemEntity,
|
||||
type addMenuItemMutation,
|
||||
type allEateriesQuery,
|
||||
@@ -27,6 +28,7 @@ interface ManagerContextType {
|
||||
// Data
|
||||
products: MenuItemEntity[];
|
||||
eateryId: string | null;
|
||||
eatery?: EateryEntity;
|
||||
|
||||
// Active tab
|
||||
activeTab: ManagerTab;
|
||||
@@ -49,6 +51,7 @@ const GET_EATERY_MENU = gql`
|
||||
query GetEateryMenu {
|
||||
allEateries {
|
||||
id
|
||||
name
|
||||
menuItems {
|
||||
id
|
||||
name
|
||||
@@ -97,6 +100,7 @@ const DELETE_MENU_ITEM = gql`
|
||||
|
||||
export function ManagerProvider({ children }: { children: ReactNode }) {
|
||||
const [products, setProducts] = useState<MenuItemEntity[]>([]);
|
||||
const [eatery, setEatery] = useState<EateryEntity>();
|
||||
const [activeTab, setActiveTab] = useState<ManagerTab>("products");
|
||||
|
||||
const { data } = useQuery<allEateriesQuery>(GET_EATERY_MENU, {
|
||||
@@ -123,6 +127,7 @@ export function ManagerProvider({ children }: { children: ReactNode }) {
|
||||
useEffect(() => {
|
||||
if (data?.allEateries?.[0]) {
|
||||
setProducts(data.allEateries[0].menuItems);
|
||||
setEatery(data.allEateries[0]);
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
@@ -193,6 +198,7 @@ export function ManagerProvider({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<ManagerContext.Provider
|
||||
value={{
|
||||
eatery,
|
||||
products,
|
||||
eateryId,
|
||||
activeTab,
|
||||
|
||||
Reference in New Issue
Block a user