"use client"; import Link from "next/link"; import { useQuery } from "@tanstack/react-query"; import { PageHeader, EmptyState, Button, Badge, DataTable } from "@/components/ds"; import { beautyBusinessApi } from "@/modules/beauty/services/beauty-business-api"; import { useTenantId } from "@/hooks/useTenantId"; import { useBeautyLookups } from "@/modules/beauty/hooks/useBeautyLookups"; import { AppointmentCard, CustomerCard, PackageCard, SalonCard, StaffCard } from "@/modules/beauty/design-system"; import { AggregateStatsRow, BeautyPageError, BeautyPageLoader, ServiceMetaBadges, SettingsListPage, } from "./shared"; export function CustomerDashboard() { const { tenantId } = useTenantId(); const { customers, staffName, serviceName, isLoading } = useBeautyLookups(); const apptsQ = useQuery({ queryKey: ["beauty", tenantId, "customer-appts"], queryFn: () => beautyBusinessApi.appointments.list(tenantId!), enabled: !!tenantId, }); if (!tenantId || isLoading || apptsQ.isLoading) return ; if (apptsQ.error) return apptsQ.refetch()} />; const upcoming = (apptsQ.data ?? []).filter((a) => new Date(a.scheduled_start) >= new Date()); return (
} />

نوبت‌های پیش‌رو

{upcoming.length === 0 ? ( } /> ) : ( upcoming.slice(0, 5).map((a) => ( )) )}
); } function CustomerAppointmentsList({ upcoming }: { upcoming: boolean }) { const { tenantId } = useTenantId(); const { staffName, serviceName } = useBeautyLookups(); const apptsQ = useQuery({ queryKey: ["beauty", tenantId, "customer-appointments", upcoming], queryFn: () => beautyBusinessApi.appointments.list(tenantId!), enabled: !!tenantId, }); if (!tenantId || apptsQ.isLoading) return ; if (apptsQ.error) return apptsQ.refetch()} />; const now = new Date(); const items = (apptsQ.data ?? []).filter((a) => upcoming ? new Date(a.scheduled_start) >= now : new Date(a.scheduled_start) < now ); return (
{items.map((a) => ( ))}
{items.length === 0 ? : null}
); } export function CustomerAppointmentsUpcoming() { return ; } export function CustomerAppointmentsPast() { return ; } export function CustomerAppointmentsBook() { return (
); } export function CustomerPackages() { const { tenantId } = useTenantId(); const pkgsQ = useQuery({ queryKey: ["beauty", tenantId, "customer-packages"], queryFn: () => beautyBusinessApi.packageDefinitions.list(tenantId!), enabled: !!tenantId, }); if (!tenantId || pkgsQ.isLoading) return ; if (pkgsQ.error) return pkgsQ.refetch()} />; return (
{(pkgsQ.data ?? []).map((p) => ( ))}
{(pkgsQ.data ?? []).length === 0 ? : null}
); } export function CustomerMemberships() { const { tenantId } = useTenantId(); const q = useQuery({ queryKey: ["beauty", tenantId, "customer-memberships"], queryFn: () => beautyBusinessApi.membershipPlans.list(tenantId!), enabled: !!tenantId, }); if (!tenantId || q.isLoading) return ; if (q.error) return q.refetch()} />; return (
(r.price != null ? String(r.price) : "—"), }, { key: "status", header: "وضعیت", render: (r) => {String(r.status)}, }, ]} rows={(q.data ?? []) as unknown as Record[]} empty={} />
); } export function CustomerProfile() { const { customers, isLoading } = useBeautyLookups(); if (isLoading) return ; return (
{customers.map((c) => ( ))}
{customers.length === 0 ? : null}
); } export function CustomerFavorites() { const { services, isLoading } = useBeautyLookups(); if (isLoading) return ; return (
); } export function CustomerReviews() { return (
); } export function CustomerNotifications() { return (
); } export function CustomerSettings() { return ; } export function CustomerInvoices() { return (
} />
); } export function CustomerPayments() { return (
} />
); } export function CustomerWallet() { return (
} />
); } export function CustomerLoyaltyPoints() { const { tenantId } = useTenantId(); const q = useQuery({ queryKey: ["beauty", tenantId, "loyalty-integrations"], queryFn: () => beautyBusinessApi.loyaltyIntegrations.list(tenantId!), enabled: !!tenantId, }); if (!tenantId || q.isLoading) return ; if (q.error) return q.refetch()} />; return (
String(r.external_program_ref ?? "—"), }, { key: "status", header: "وضعیت", render: (r) => {String(r.status)}, }, ]} rows={(q.data ?? []) as unknown as Record[]} empty={} />
); } export function CustomerMessages() { const { tenantId } = useTenantId(); const q = useQuery({ queryKey: ["beauty", tenantId, "integration-dispatches"], queryFn: () => beautyBusinessApi.integrationDispatches.list(tenantId!), enabled: !!tenantId, }); if (!tenantId || q.isLoading) return ; if (q.error) return q.refetch()} />; return (
{String(r.status)}, }, ]} rows={(q.data ?? []) as unknown as Record[]} empty={} />
); } export function CustomerSessions() { const { tenantId } = useTenantId(); const q = useQuery({ queryKey: ["beauty", tenantId, "package-sessions"], queryFn: () => beautyBusinessApi.packageDefinitions.list(tenantId!), enabled: !!tenantId, }); if (!tenantId || q.isLoading) return ; if (q.error) return q.refetch()} />; return (
{(q.data ?? []).map((p) => ( ))}
{(q.data ?? []).length === 0 ? : null}
); } export function CustomerFavoriteCenters() { const { tenantId } = useTenantId(); const q = useQuery({ queryKey: ["beauty", tenantId, "favorite-branches"], queryFn: () => beautyBusinessApi.branches.list(tenantId!), enabled: !!tenantId, }); if (!tenantId || q.isLoading) return ; if (q.error) return q.refetch()} />; return (
{(q.data ?? []).map((b) => ( ))}
{(q.data ?? []).length === 0 ? ( } /> ) : null}
); } export function CustomerFavoriteStaff() { const { tenantId } = useTenantId(); const q = useQuery({ queryKey: ["beauty", tenantId, "favorite-staff"], queryFn: () => beautyBusinessApi.staff.list(tenantId!), enabled: !!tenantId, }); if (!tenantId || q.isLoading) return ; if (q.error) return q.refetch()} />; return (
{String(r.status)}, }, ]} rows={(q.data ?? []) as unknown as Record[]} empty={} />
); }