// app/dashboard/[clientId]/addresses/[addressesId]/page.tsx "use client"; import { useCallback, useEffect, useState } from "react"; import { useParams, useRouter } from "next/navigation"; 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"; export default function AddressDetailsPage() { const params = useParams(); const router = useRouter(); const clientId = params?.clientId as string | undefined; const addressId = params?.addressesId as string | undefined; const [address, setAddress] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const loadAddress = useCallback(async () => { if (!clientId || !addressId) return; setLoading(true); 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]); useEffect(() => { loadAddress(); }, [loadAddress]); // ── Loading ────────────────────────────────────────────────────────────── if (loading) { return (
جارٍ تحميل بيانات العنوان…
); } // ── Error ──────────────────────────────────────────────────────────────── if (error || !address) { return (
); } // ── Content ────────────────────────────────────────────────────────────── return (
); }