The client files, client address files, and order files have been modified to implement all CRUD operations and endpoints related to the archive.

This commit is contained in:
m7amedez511
2026-07-22 16:30:20 +03:00
parent b87d81100f
commit fa49ba8817
14 changed files with 601 additions and 628 deletions

View File

@@ -1,339 +1,100 @@
// app/dashboard/[clientId]/addresses/[addressesId]/page.tsx
"use client";
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { useParams, useRouter } from "next/navigation";
import { Alert, ConfirmDialog, Toast } from "@/src/Components/UI";
import { AddressFormModal } from "@/src/Components/Client";
import { AddressDetails } from "@/src/Components/Client_Adress/AddressDetails";
import { clientAddressService } from "@/src/services/clientAddress.service";
import { clientService } from "@/src/services/client.service";
import { getStoredToken } from "@/src/lib/auth";
import { Alert, Spinner, Button } from "@/src/Components/UI";
import { AddressDetails } from "@/src/Components/Client_Adress/AddressDetails";
import { clientAddressService } from "@/src/services/clientAddress.service";
import { getStoredToken } from "@/src/lib/auth";
import type { ClientAddress } from "@/src/types/client_adresses";
import type { Client } from "@/src/types/client";
import type { ClientAddress } from "@/src/types/client_adresses";
import type { ToastNotification } from "@/src/Components/UI";
import type {
CreateAddressFormValues,
UpdateAddressFormValues,
} from "@/src/validations/client_address.validator";
export default function AddressDetailsPage() {
const params = useParams();
const router = useRouter();
// ─── Page ──────────────────────────────────────────────────────────────────
const clientId = params?.clientId as string | undefined;
const addressId = params?.addressesId as string | undefined;
export default function AddressDetailPage() {
const params = useParams();
const router = useRouter();
const clientId = (params?.clientId ?? params?.id) as string | undefined;
const addressId = params?.addressId as string | undefined;
// ── Data state ───────────────────────────────────────────────────────────
const [address, setAddress] = useState<ClientAddress | null>(null);
const [client, setClient] = useState<Client | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
// ── Modal state ──────────────────────────────────────────────────────────
const [editOpen, setEditOpen] = useState(false);
const [deleteOpen, setDeleteOpen] = useState(false);
const [deleting, setDeleting] = useState(false);
// ── Toast ────────────────────────────────────────────────────────────────
const [notification, setNotification] = useState<ToastNotification | null>(null);
const notify = (n: ToastNotification) => {
setNotification(n);
setTimeout(() => setNotification(null), 4000);
};
// ── Fetch ────────────────────────────────────────────────────────────────
useEffect(() => {
const loadAddress = useCallback(async () => {
if (!clientId || !addressId) return;
setLoading(true);
Promise.all([
clientAddressService.getById(clientId, addressId, getStoredToken()),
clientService.getById(clientId, getStoredToken()),
])
.then(([addrRes, clientRes]) => {
const raw = (addrRes as any).data ?? addrRes;
setAddress({ ...raw, id: raw.id ?? raw._id });
setClient(clientRes?.data);
})
.catch(() => setError("تعذّر تحميل بيانات العنوان. يرجى المحاولة مجدداً."))
.finally(() => setLoading(false));
setError(null);
try {
const token = getStoredToken();
const res = await clientAddressService.getById(clientId, addressId, token);
// normalize in case the API returns _id instead of id
const raw = res.data as ClientAddress & { _id?: string };
setAddress({ ...raw, id: raw.id ?? raw._id ?? "" });
} catch {
setError("تعذّر تحميل بيانات العنوان. يرجى المحاولة لاحقاً.");
} finally {
setLoading(false);
}
}, [clientId, addressId]);
// ── Update ───────────────────────────────────────────────────────────────
const handleUpdateSubmit = async (
data: CreateAddressFormValues | UpdateAddressFormValues
): Promise<boolean> => {
if (!clientId || !addressId) return false;
try {
const res = await clientAddressService.update(
clientId,
addressId,
data as UpdateAddressFormValues,
getStoredToken()
);
const raw = (res as any).data ?? res;
setAddress({ ...raw, id: raw.id ?? raw._id });
notify({ type: "success", message: "تم تحديث العنوان بنجاح." });
return true;
} catch (err) {
notify({
type: "error",
message: err instanceof Error ? err.message : "تعذّر تحديث العنوان.",
});
return false;
}
};
useEffect(() => {
loadAddress();
}, [loadAddress]);
// ── Delete ───────────────────────────────────────────────────────────────
const handleDeleteConfirm = async () => {
if (!clientId || !addressId || deleting) return;
setDeleting(true);
try {
await clientAddressService.delete(clientId, addressId, getStoredToken());
notify({ type: "success", message: "تم حذف العنوان بنجاح." });
// short delay so the toast shows before navigation
setTimeout(() => {
router.replace(`/dashboard/clients/${clientId}/addresses`);
}, 700);
} catch (err) {
notify({
type: "error",
message: err instanceof Error ? err.message : "تعذّر حذف العنوان.",
});
setDeleting(false);
}
};
// ── Guards ───────────────────────────────────────────────────────────────
// ── Loading ──────────────────────────────────────────────────────────────
if (loading) {
return (
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
minHeight: "60vh",
}}
>
<div
style={{
width: 36,
height: 36,
borderRadius: "50%",
border: "3px solid var(--color-border)",
borderTopColor: "var(--color-brand-600)",
animation: "spin 0.7s linear infinite",
}}
/>
<div style={{ display: "flex", alignItems: "center", justifyContent: "center", minHeight: "60vh", gap: 12 }}>
<Spinner size="sm" className="text-blue-600" />
<span style={{ fontSize: 13, color: "var(--color-text-muted)" }}>جارٍ تحميل بيانات العنوان</span>
</div>
);
}
// ── Error ────────────────────────────────────────────────────────────────
if (error || !address) {
return (
<section style={{ padding: "2rem", display: "flex", flexDirection: "column", gap: "1rem" }}>
<Alert type="error" message={error ?? "لم يتم العثور على العنوان."} />
<button
<div style={{ display: "flex", flexDirection: "column", gap: "1rem", maxWidth: 640, margin: "2rem auto" }}>
<Alert type="error" message={error ?? "العنوان غير موجود."} />
<Button
type="button"
onClick={() => router.back()}
style={{
alignSelf: "flex-start",
fontSize: 13,
fontWeight: 600,
color: "var(--color-brand-600)",
background: "none",
border: "none",
cursor: "pointer",
fontFamily: "var(--font-sans)",
}}
variant="secondary"
onClick={() => router.push(`/dashboard/${clientId}/addresses`)}
>
رجوع
</button>
</section>
العودة إلى العناوين
</Button>
</div>
);
}
// ── Render ────────────────────────────────────────────────────────────────
// ── Content ──────────────────────────────────────────────────────────────
return (
<>
<Toast notification={notification} />
<section style={{ display: "flex", flexDirection: "column", gap: "1.25rem", maxWidth: 720, margin: "0 auto", padding: "2rem 1rem" }}>
<button
type="button"
onClick={() => router.push(`/dashboard/${clientId}/addresses`)}
style={{
display: "inline-flex",
alignItems: "center",
gap: 6,
fontSize: 12,
fontWeight: 600,
color: "var(--color-text-muted)",
background: "none",
border: "none",
cursor: "pointer",
alignSelf: "flex-start",
fontFamily: "var(--font-sans)",
}}
>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M15 18l-6-6 6-6" />
</svg>
كل العناوين
</button>
{/* Edit modal */}
{editOpen && (
<AddressFormModal
editAddress={address}
onClose={() => setEditOpen(false)}
onSubmit={handleUpdateSubmit}
/>
)}
{/* Delete confirmation */}
<ConfirmDialog
open={deleteOpen}
loading={deleting}
onCancel={() => { if (!deleting) setDeleteOpen(false); }}
onConfirm={handleDeleteConfirm}
title="حذف العميل"
description={`هل أنت متأكد من حذف ${address.label}؟ سيتم حذف جميع عناوينه أيضاً. لا يمكن التراجع عن هذا الإجراء.`}
/>
<section style={{ display: "flex", flexDirection: "column", gap: "1.5rem" }}>
{/* ── Page header ── */}
<header
style={{
borderRadius: "var(--radius-xl)",
border: "1px solid var(--color-border)",
background: "var(--color-surface)",
padding: "1.5rem 2rem",
boxShadow: "var(--shadow-card)",
}}
>
{/* Back link */}
<button
type="button"
onClick={() => router.push(`/dashboard/clients/${clientId}/addresses`)}
style={{
display: "inline-flex",
alignItems: "center",
gap: 6,
fontSize: 12,
fontWeight: 600,
color: "var(--color-text-muted)",
background: "none",
border: "none",
cursor: "pointer",
marginBottom: 12,
fontFamily: "var(--font-sans)",
}}
>
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
>
<path d="M15 18l-6-6 6-6" />
</svg>
{client ? `${client.name} — العناوين` : "العناوين"}
</button>
<p
style={{
fontSize: 11,
letterSpacing: "0.3em",
textTransform: "uppercase",
color: "#2563EB",
fontWeight: 600,
margin: 0,
}}
>
تفاصيل العنوان
</p>
<div className="mt-3 flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
<div>
<h1
style={{
fontSize: "1.5rem",
fontWeight: 700,
color: "var(--color-text-primary)",
margin: 0,
}}
>
{address.label}
</h1>
{client && (
<p style={{ marginTop: "0.25rem", fontSize: 13, color: "var(--color-text-muted)" }}>
{client.name}
</p>
)}
</div>
{/* Action buttons */}
<div style={{ display: "flex", gap: "0.5rem" }}>
<button
type="button"
onClick={() => setEditOpen(true)}
style={{
height: 40,
padding: "0 1rem",
borderRadius: "var(--radius-lg)",
border: "1px solid #BFDBFE",
background: "#EFF6FF",
fontSize: 13,
fontWeight: 600,
color: "#1D4ED8",
cursor: "pointer",
display: "inline-flex",
alignItems: "center",
gap: 7,
fontFamily: "var(--font-sans)",
}}
>
<svg
width="13"
height="13"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
>
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
</svg>
تعديل العنوان
</button>
<button
type="button"
onClick={() => setDeleteOpen(true)}
style={{
height: 40,
padding: "0 1rem",
borderRadius: "var(--radius-lg)",
border: "1px solid #FECACA",
background: "#FEF2F2",
fontSize: 13,
fontWeight: 600,
color: "#DC2626",
cursor: "pointer",
display: "inline-flex",
alignItems: "center",
gap: 7,
fontFamily: "var(--font-sans)",
}}
>
<svg
width="13"
height="13"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
>
<polyline points="3 6 5 6 21 6" />
<path d="M19 6l-1 14H6L5 6" />
<path d="M10 11v6M14 11v6" />
<path d="M9 6V4h6v2" />
</svg>
حذف
</button>
</div>
</div>
</header>
{/* ── Address details component ── */}
<AddressDetails address={address} />
</section>
</>
<AddressDetails address={address} />
</section>
);
}

View File

@@ -3,14 +3,19 @@
import { useCallback, useEffect, useState } from "react";
import { useParams, useRouter } from "next/navigation";
import { Alert, ConfirmDialog, Toast, ArchiveButton } from "@/src/Components/UI";
import {
Alert,
ConfirmDialog,
Toast,
ArchiveButton,
} from "@/src/Components/UI";
import { useClientAddresses } from "@/src/hooks/useClientAddresses";
import { clientService } from "@/src/services/client.service";
import { getStoredToken } from "@/src/lib/auth";
import { clientService } from "@/src/services/client.service";
import { getStoredToken } from "@/src/lib/auth";
import type { Client, ClientFormData } from "@/src/types/client";
import type { ClientAddress } from "@/src/types/client_adresses";
import type { ClientAddress } from "@/src/types/client_adresses";
import { AddressFormModal, ClientFormModal } from "@/src/Components/Client";
import { ArchivedClientsAddressesModal } from "@/src/Components/Client_Adress/archive/ArchivedClientsAddressesModal";
@@ -23,16 +28,16 @@ import type {
function labelIcon(label: string): string {
const map: Record<string, string> = {
"فوترة": "💳",
"شحن": "📦",
"المقر الرئيسي": "🏢",
"فرع": "🏬",
"مستودع": "🏭",
billing: "💳",
shipping: "📦",
"head office": "🏢",
branch: "🏬",
warehouse: "🏭",
فوترة: "💳",
شحن: "📦",
"المقر الرئيسي": "🏢",
فرع: "🏬",
مستودع: "🏭",
billing: "💳",
shipping: "📦",
"head office": "🏢",
branch: "🏬",
warehouse: "🏭",
};
return map[label.toLowerCase()] ?? "📍";
}
@@ -40,14 +45,21 @@ function labelIcon(label: string): string {
// ─── AddressCard ───────────────────────────────────────────────────────────
interface AddressCardProps {
address: ClientAddress;
onEdit: () => void;
onDelete: () => void;
onSetPrimary: () => void;
address: ClientAddress;
onView: () => void;
onEdit: () => void;
onDelete: () => void;
onSetPrimary: () => void;
settingPrimary: boolean; // true only while THIS card's request is in flight
}
function AddressCard({ address, onEdit, onDelete, onSetPrimary, settingPrimary }: AddressCardProps) {
function AddressCard({
address,
onEdit,
onDelete,
onSetPrimary,
settingPrimary,
}: AddressCardProps) {
const { details, contactPerson } = address;
const {
street,
@@ -73,6 +85,7 @@ function AddressCard({ address, onEdit, onDelete, onSetPrimary, settingPrimary }
padding: "1.25rem",
background: "var(--color-surface)",
boxShadow: "var(--shadow-card)",
cursor: "pointer",
}}
>
{/* Label row */}
@@ -136,7 +149,13 @@ function AddressCard({ address, onEdit, onDelete, onSetPrimary, settingPrimary }
gap: 2,
}}
>
<p style={{ margin: 0, fontWeight: 600, color: "var(--color-text-primary)" }}>
<p
style={{
margin: 0,
fontWeight: 600,
color: "var(--color-text-primary)",
}}
>
{street}
</p>
@@ -149,7 +168,14 @@ function AddressCard({ address, onEdit, onDelete, onSetPrimary, settingPrimary }
</p>
{(buildingNo || unitNo || additionalNo) && (
<p style={{ margin: 0, fontSize: 12, color: "var(--color-text-muted)" }} dir="ltr">
<p
style={{
margin: 0,
fontSize: 12,
color: "var(--color-text-muted)",
}}
dir="ltr"
>
{buildingNo && `مبنى ${buildingNo}`}
{unitNo && ` · وحدة ${unitNo}`}
{additionalNo && ` · رقم إضافي ${additionalNo}`}
@@ -185,6 +211,7 @@ function AddressCard({ address, onEdit, onDelete, onSetPrimary, settingPrimary }
{/* Actions */}
<div
onClick={(e) => e.stopPropagation()}
style={{
display: "flex",
flexWrap: "wrap",
@@ -194,7 +221,12 @@ function AddressCard({ address, onEdit, onDelete, onSetPrimary, settingPrimary }
borderTop: "1px solid var(--color-border)",
}}
>
<ActionBtn onClick={onEdit} color="#1D4ED8" bg="#EFF6FF" border="#BFDBFE">
<ActionBtn
onClick={onEdit}
color="#1D4ED8"
bg="#EFF6FF"
border="#BFDBFE"
>
تعديل
</ActionBtn>
@@ -233,13 +265,13 @@ function ActionBtn({
disabled,
children,
}: {
onClick: () => void;
color: string;
bg: string;
border: string;
style?: React.CSSProperties;
onClick: () => void;
color: string;
bg: string;
border: string;
style?: React.CSSProperties;
disabled?: boolean;
children: React.ReactNode;
children: React.ReactNode;
}) {
return (
<button
@@ -270,8 +302,8 @@ function ActionBtn({
// ─── ClientEditModal ───────────────────────────────────────────────────────
interface ClientEditModalProps {
client: Client;
onClose: () => void;
client: Client;
onClose: () => void;
onSubmit: (data: ClientFormData, isNew: boolean) => Promise<boolean>;
}
@@ -281,7 +313,9 @@ function ClientEditModal({ client, onClose, onSubmit }: ClientEditModalProps) {
role="dialog"
aria-modal="true"
aria-label="تعديل بيانات العميل"
onClick={(e) => { if (e.target === e.currentTarget) onClose(); }}
onClick={(e) => {
if (e.target === e.currentTarget) onClose();
}}
style={{
position: "fixed",
inset: 0,
@@ -320,8 +354,8 @@ function ClientEditModal({ client, onClose, onSubmit }: ClientEditModalProps) {
// ─── Page ──────────────────────────────────────────────────────────────────
export default function ClientAddressesPage() {
const params = useParams();
const router = useRouter();
const params = useParams();
const router = useRouter();
const clientId = (params?.clientId ?? params?.id) as string | undefined;
@@ -332,7 +366,7 @@ export default function ClientAddressesPage() {
}, [clientId]);
// ── Parent client ────────────────────────────────────────────────────────
const [client, setClient] = useState<Client | null>(null);
const [client, setClient] = useState<Client | null>(null);
const [clientLoading, setClientLoading] = useState(true);
const loadClient = useCallback(() => {
@@ -341,7 +375,7 @@ export default function ClientAddressesPage() {
setClientLoading(true);
clientService
.getById(clientId, getStoredToken())
.then((res) => setClient(res.data))
.then((res) => setClient(res))
.catch(() => router.replace("/dashboard/clients"))
.finally(() => setClientLoading(false));
});
@@ -366,18 +400,21 @@ export default function ClientAddressesPage() {
} = useClientAddresses(clientId ?? "");
// ── Modal state ──────────────────────────────────────────────────────────
const [addrFormTarget, setAddrFormTarget] = useState<ClientAddress | null | false>(false);
const [deleteTarget, setDeleteTarget] = useState<ClientAddress | null>(null);
const [deleting, setDeleting] = useState(false);
const [editingClient, setEditingClient] = useState(false);
const [addrFormTarget, setAddrFormTarget] = useState<
ClientAddress | null | false
>(false);
const [deleteTarget, setDeleteTarget] = useState<ClientAddress | null>(null);
const [deleting, setDeleting] = useState(false);
const [editingClient, setEditingClient] = useState(false);
// Archive browser modal open/closed — scoped to this client's addresses
const [archiveOpen, setArchiveOpen] = useState(false);
const [archiveOpen, setArchiveOpen] = useState(false);
// ── Address form handler ─────────────────────────────────────────────────
const handleAddressSubmit = async (
data: CreateAddressFormValues | UpdateAddressFormValues
data: CreateAddressFormValues | UpdateAddressFormValues,
): Promise<boolean> => {
if (addrFormTarget === null) return createAddress(data as CreateAddressFormValues);
if (addrFormTarget === null)
return createAddress(data as CreateAddressFormValues);
if (addrFormTarget === false) return false;
return updateAddress(addrFormTarget.id, data as UpdateAddressFormValues);
};
@@ -403,7 +440,7 @@ export default function ClientAddressesPage() {
if (!client) return false;
try {
const res = await clientService.update(client.id, data, getStoredToken());
setClient(res.data);
setClient(res);
return true;
} catch {
return false;
@@ -413,7 +450,14 @@ export default function ClientAddressesPage() {
// ── Loading guard ────────────────────────────────────────────────────────
if (!clientId || clientLoading) {
return (
<div style={{ display: "flex", alignItems: "center", justifyContent: "center", minHeight: "100vh" }}>
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
minHeight: "100vh",
}}
>
<div
style={{
width: 40,
@@ -446,7 +490,9 @@ export default function ClientAddressesPage() {
<ConfirmDialog
open={!!deleteTarget}
loading={deleting}
onCancel={() => { if (!deleting) setDeleteTarget(null); }}
onCancel={() => {
if (!deleting) setDeleteTarget(null);
}}
onConfirm={handleDeleteConfirm}
title="حذف العميل"
description={`هل أنت متأكد من حذف ${deleteTarget?.label ?? ""}؟ سيتم حذف جميع عناوينه أيضاً. لا يمكن التراجع عن هذا الإجراء.`}
@@ -469,8 +515,9 @@ export default function ClientAddressesPage() {
/>
)}
<section style={{ display: "flex", flexDirection: "column", gap: "1.5rem" }}>
<section
style={{ display: "flex", flexDirection: "column", gap: "1.5rem" }}
>
{/* ── Header ── */}
<header
style={{
@@ -498,24 +545,54 @@ export default function ClientAddressesPage() {
fontFamily: "var(--font-sans)",
}}
>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
>
<path d="M15 18l-6-6 6-6" />
</svg>
جميع العملاء
</button>
<p style={{ fontSize: 11, letterSpacing: "0.3em", textTransform: "uppercase", color: "#2563EB", fontWeight: 600 }}>
<p
style={{
fontSize: 11,
letterSpacing: "0.3em",
textTransform: "uppercase",
color: "#2563EB",
fontWeight: 600,
}}
>
إدارة العناوين
</p>
<div className="mt-3 flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
<div>
<h1 style={{ fontSize: "1.5rem", fontWeight: 700, color: "var(--color-text-primary)", margin: 0 }}>
<h1
style={{
fontSize: "1.5rem",
fontWeight: 700,
color: "var(--color-text-primary)",
margin: 0,
}}
>
{client ? `${client.name} — العناوين` : "العناوين"}
</h1>
<p style={{ marginTop: "0.25rem", fontSize: 13, color: "var(--color-text-muted)" }}>
<p
style={{
marginTop: "0.25rem",
fontSize: 13,
color: "var(--color-text-muted)",
}}
>
إجمالي{" "}
<strong style={{ color: "var(--color-text-primary)" }}>{addresses.length}</strong>{" "}
<strong style={{ color: "var(--color-text-primary)" }}>
{addresses.length}
</strong>{" "}
عنوان
</p>
</div>
@@ -541,7 +618,14 @@ export default function ClientAddressesPage() {
fontFamily: "var(--font-sans)",
}}
>
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<svg
width="13"
height="13"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
>
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
</svg>
@@ -570,7 +654,14 @@ export default function ClientAddressesPage() {
whiteSpace: "nowrap",
}}
>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2.5"
>
<line x1="12" y1="5" x2="12" y2="19" />
<line x1="5" y1="12" x2="19" y2="12" />
</svg>
@@ -594,8 +685,15 @@ export default function ClientAddressesPage() {
borderTop: "1px solid var(--color-border)",
}}
>
<span style={{ fontWeight: 600, color: "var(--color-text-primary)" }}>{client.name}</span>
<a href={`mailto:${client.email}`} style={{ color: "#2563EB", textDecoration: "none" }}>
<span
style={{ fontWeight: 600, color: "var(--color-text-primary)" }}
>
{client.name}
</span>
<a
href={`mailto:${client.email}`}
style={{ color: "#2563EB", textDecoration: "none" }}
>
{client.email}
</a>
<span>{client.phone}</span>
@@ -620,7 +718,17 @@ export default function ClientAddressesPage() {
{/* ── Address grid ── */}
{addrLoading ? (
<div style={{ display: "flex", alignItems: "center", justifyContent: "center", padding: "4rem 0", color: "var(--color-text-muted)", gap: 12, fontSize: 13 }}>
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
padding: "4rem 0",
color: "var(--color-text-muted)",
gap: 12,
fontSize: 13,
}}
>
<div
style={{
width: 20,
@@ -646,16 +754,39 @@ export default function ClientAddressesPage() {
}}
>
<p style={{ fontSize: 32, margin: 0 }}>📍</p>
<p style={{ marginTop: 12, fontSize: 15, fontWeight: 700, color: "var(--color-text-primary)" }}>
<p
style={{
marginTop: 12,
fontSize: 15,
fontWeight: 700,
color: "var(--color-text-primary)",
}}
>
لا توجد عناوين بعد
</p>
<p style={{ marginTop: 4, fontSize: 13, color: "var(--color-text-muted)" }}>
أضف عنواناً واحداً على الأقل حتى يتمكن العميل من استقبال الشحنات والفواتير.
<p
style={{
marginTop: 4,
fontSize: 13,
color: "var(--color-text-muted)",
}}
>
أضف عنواناً واحداً على الأقل حتى يتمكن العميل من استقبال الشحنات
والفواتير.
</p>
<button
type="button"
onClick={() => setAddrFormTarget(null)}
style={{ marginTop: 16, fontSize: 13, fontWeight: 600, color: "var(--color-brand-600)", background: "none", border: "none", cursor: "pointer", textDecoration: "underline" }}
style={{
marginTop: 16,
fontSize: 13,
fontWeight: 600,
color: "var(--color-brand-600)",
background: "none",
border: "none",
cursor: "pointer",
textDecoration: "underline",
}}
>
أضف أول عنوان
</button>
@@ -668,22 +799,26 @@ export default function ClientAddressesPage() {
gap: "1rem",
}}
>
{addresses.map((addr) => (
<AddressCard
key={addr.id}
address={addr}
onEdit={() => setAddrFormTarget(addr)}
onDelete={() => setDeleteTarget(addr)}
onSetPrimary={() => handleSetPrimary(addr)}
settingPrimary={settingPrimaryId === addr.id}
/>
))}
{addresses.map((addr) => (
<AddressCard
key={addr.id}
address={addr}
onView={() => router.push(`/dashboard/${clientId}/addresses/${addr.id}`)}
onEdit={() => setAddrFormTarget(addr)}
onDelete={() => setDeleteTarget(addr)}
onSetPrimary={() => handleSetPrimary(addr)}
settingPrimary={settingPrimaryId === addr.id}
/>
))}
</div>
)}
</section>
{/* Floating button to open the address archive for this client */}
<ArchiveButton onClick={() => setArchiveOpen(true)} label="أرشيف العناوين" />
<ArchiveButton
onClick={() => setArchiveOpen(true)}
label="أرشيف العناوين"
/>
</>
);
}
}

View File

@@ -131,7 +131,7 @@ export default function ClientsPage() {
</section>
{/* Floating button to open the archive browser */}
<ArchiveButton onClick={() => setArchiveOpen(true)} label="أرشيف العملاء" />
<ArchiveButton onClick={() => setArchiveOpen(true)} label="الأرشيف" />
</>
);
}