update saidebar layout build order crud
This commit is contained in:
@@ -1,116 +1,226 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useState, useEffect, createContext, useContext } from "react";
|
||||
import { getStoredUser } from "@/src/lib/auth";
|
||||
import Logo from "@/src/utils/logo";
|
||||
import BrandIcon from "@/src/utils/brandIcon";
|
||||
|
||||
|
||||
//ــــــــــــــ Drawer Context
|
||||
|
||||
const DrawerCtx = createContext<{
|
||||
open: boolean;
|
||||
setOpen: (v: boolean) => void;
|
||||
}>({ open: false, setOpen: () => {} });
|
||||
|
||||
export function useSidebarDrawer() {
|
||||
return useContext(DrawerCtx);
|
||||
}
|
||||
|
||||
export function SidebarProvider({ children }: { children: React.ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<DrawerCtx.Provider value={{ open, setOpen }}>
|
||||
{children}
|
||||
</DrawerCtx.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════
|
||||
Nav items
|
||||
══════════════════════════════════════════ */
|
||||
const navSections = [
|
||||
{
|
||||
label: "الرئيسية",
|
||||
items: [
|
||||
{ href: "/dashboard", label: "Dashboard", icon: "ti-layout-dashboard", permission: "read-dashboard" },
|
||||
{ href: "/dashboard/users", label: "Users", icon: "ti-users", permission: "read-user" },
|
||||
{ href: "/dashboard", label: "Dashboard", icon: "ti-layout-dashboard", permission: "read-dashboard" },
|
||||
{ href: "/dashboard/users", label: "Users", icon: "ti-users", permission: "read-user" },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "الأسطول",
|
||||
items: [
|
||||
{ href: "/dashboard/cars", label: "Cars", icon: "ti-car", permission: "read-car" },
|
||||
{ href: "/dashboard/drivers", label: "Drivers", icon: "ti-steering-wheel",permission: "read-driver" },
|
||||
{ href: "/dashboard/trips", label: "Trips", icon: "ti-route", permission: "read-trip" },
|
||||
{ href: "/dashboard/cars", label: "Cars", icon: "ti-car", permission: "read-car" },
|
||||
{ href: "/dashboard/drivers", label: "Drivers", icon: "ti-steering-wheel", permission: "read-driver" },
|
||||
{ href: "/dashboard/trips", label: "Trips", icon: "ti-route", permission: "read-trip" },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "العمليات",
|
||||
items: [
|
||||
{ href: "/dashboard/orders", label: "Orders", icon: "ti-package", permission: "read-order" },
|
||||
{ href: "/dashboard/clients", label: "Clients", icon: "ti-users-group", permission: "read-client" },
|
||||
{ href: "/dashboard/branches", label: "Branches", icon: "ti-building", permission: "read-branch" },
|
||||
{ href: "/dashboard/roles", label: "Roles", icon: "ti-shield", permission: "read-role" },
|
||||
{ href: "/dashboard/role_permission", label: "Roles & Permission", icon: "ti-shield", permission: "manage-role-permissions" },
|
||||
{ href: "/dashboard/audit", label: "Audit", icon: "ti-clipboard-list", permission: "read-audit" },
|
||||
{ href: "/dashboard/orders", label: "Orders", icon: "ti-package", permission: "read-order" },
|
||||
{ href: "/dashboard/clients", label: "Clients", icon: "ti-users-group", permission: "read-client" },
|
||||
{ href: "/dashboard/branches", label: "Branches", icon: "ti-building", permission: "read-branch" },
|
||||
{ href: "/dashboard/roles", label: "Roles", icon: "ti-shield", permission: "read-role" },
|
||||
{ href: "/dashboard/role_permission", label: "Roles & Permission", icon: "ti-shield", permission: "manage-role-permissions" },
|
||||
{ href: "/dashboard/audit", label: "Audit", icon: "ti-clipboard-list", permission: "read-audit" },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
/* ══════════════════════════════════════════
|
||||
Brand Icon
|
||||
══════════════════════════════════════════ */
|
||||
|
||||
|
||||
export function BrandIconButton({ onClick }: { onClick: () => void }) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
aria-label="فتح القائمة"
|
||||
style={{
|
||||
background: "transparent",
|
||||
border: "1px solid var(--color-border)",
|
||||
borderRadius: 8,
|
||||
width: 36, height: 36,
|
||||
padding: 2,
|
||||
display: "flex", alignItems: "center", justifyContent: "center",
|
||||
cursor: "pointer",
|
||||
flexShrink: 0,
|
||||
}}
|
||||
>
|
||||
<BrandIcon size={28} bg="#2563EB" />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
const GRAD = "linear-gradient(175deg, #1E3A8A 0%, #1D4ED8 60%, #1565C0 100%)";
|
||||
|
||||
/* ══════════════════════════════════════════
|
||||
Sidebar
|
||||
⚠️ NO display property in any inline style here
|
||||
globals.css controls ALL display with !important
|
||||
══════════════════════════════════════════ */
|
||||
export function Sidebar() {
|
||||
const pathname = usePathname();
|
||||
const user = getStoredUser();
|
||||
const permissions = user?.permissions ?? navSections.flatMap(s => s.items.map(i => i.permission));
|
||||
const { open, setOpen } = useSidebarDrawer();
|
||||
|
||||
useEffect(() => { setOpen(false); }, [pathname, setOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
document.body.style.overflow = open ? "hidden" : "";
|
||||
return () => { document.body.style.overflow = ""; };
|
||||
}, [open]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/*
|
||||
Full sidebar — visible lg+.
|
||||
No `left`/`right` is set anywhere: placement comes purely from
|
||||
document order + `dir="rtl"` on <html>. A flex row in RTL lays
|
||||
its first child against the inline-start edge, which is
|
||||
physically the RIGHT of the screen. Because <Sidebar /> is
|
||||
still the first child in DashboardLayout, it now renders on
|
||||
the right automatically — no positional CSS to flip.
|
||||
*/}
|
||||
{/* ══ 1. Full sidebar — lg+ ══*/}
|
||||
<aside
|
||||
id="sb-full"
|
||||
suppressHydrationWarning
|
||||
className="hidden lg:flex lg:flex-col"
|
||||
style={{
|
||||
background: GRAD,
|
||||
flexDirection: "column", /* NO display property */
|
||||
width: "var(--sidebar-width)",
|
||||
flexShrink: 0,
|
||||
background: "linear-gradient(175deg, #1E3A8A 0%, #1D4ED8 60%, #1565C0 100%)",
|
||||
minHeight: "100vh",
|
||||
padding: "20px 12px",
|
||||
}}
|
||||
>
|
||||
<SidebarContent
|
||||
pathname={pathname}
|
||||
permissions={permissions}
|
||||
user={user}
|
||||
compact={false}
|
||||
/>
|
||||
<SidebarContent pathname={pathname} permissions={permissions} user={user} compact={false} />
|
||||
</aside>
|
||||
|
||||
{/*
|
||||
Compact icon rail — md and below (replaces the old behavior of
|
||||
hiding the sidebar entirely under `lg`). Fixed to the
|
||||
inline-end... no: fixed to the RIGHT edge explicitly, because a
|
||||
`position: fixed` element takes no part in flex flow and so
|
||||
gets no automatic RTL placement from document order. This is
|
||||
exactly the kind of element logical properties exist for:
|
||||
`inset-inline-end: 0` means "right in RTL, left in LTR"
|
||||
without a manual swap if direction ever toggles.
|
||||
*/}
|
||||
{/* ══ 2. Compact rail */}
|
||||
<aside
|
||||
id="sb-compact"
|
||||
suppressHydrationWarning
|
||||
className="hidden md:flex lg:hidden md:flex-col md:items-center"
|
||||
aria-label="التنقل المصغر"
|
||||
style={{
|
||||
background: GRAD,
|
||||
flexDirection: "column", /* NO display property */
|
||||
alignItems: "center",
|
||||
position: "fixed",
|
||||
insetBlockStart: 0,
|
||||
insetBlockEnd: 0,
|
||||
insetInlineEnd: 0,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
left: "auto",
|
||||
width: "var(--sidebar-width-compact)",
|
||||
background: "linear-gradient(175deg, #1E3A8A 0%, #1D4ED8 60%, #1565C0 100%)",
|
||||
padding: "16px 0",
|
||||
zIndex: 30,
|
||||
overflowY: "auto",
|
||||
}}
|
||||
aria-label="التنقل المصغر"
|
||||
>
|
||||
<SidebarContent
|
||||
pathname={pathname}
|
||||
permissions={permissions}
|
||||
user={user}
|
||||
compact={true}
|
||||
<SidebarContent pathname={pathname} permissions={permissions} user={user} compact={true} />
|
||||
</aside>
|
||||
|
||||
{/* mobile drower*/}
|
||||
|
||||
{/* open drower*/}
|
||||
{open && (
|
||||
<div
|
||||
onClick={() => setOpen(false)}
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
position: "fixed",
|
||||
top: 0, left: 0, right: 0, bottom: 0,
|
||||
background: "rgba(0,0,0,0.5)",
|
||||
zIndex: 40,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Drawer panel */}
|
||||
<aside
|
||||
id="sb-drawer"
|
||||
suppressHydrationWarning
|
||||
aria-label="قائمة التنقل"
|
||||
style={{
|
||||
background: GRAD,
|
||||
flexDirection: "column", /* NO display property */
|
||||
position: "fixed",
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
left: "auto",
|
||||
width: "var(--sidebar-width)",
|
||||
padding: "20px 12px",
|
||||
zIndex: 50,
|
||||
overflowY: "auto",
|
||||
/* transform بيخفي/يظهر الـ drawer على sm */
|
||||
transform: open ? "translateX(0)" : "translateX(100%)",
|
||||
transition: "transform 280ms cubic-bezier(0.4,0,0.2,1)",
|
||||
}}
|
||||
>
|
||||
{/* زرار الإغلاق */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(false)}
|
||||
aria-label="إغلاق القائمة"
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: 14,
|
||||
left: 12,
|
||||
background: "rgba(255,255,255,0.12)",
|
||||
border: "none",
|
||||
borderRadius: 8,
|
||||
width: 30, height: 30,
|
||||
display: "flex", alignItems: "center", justifyContent: "center",
|
||||
cursor: "pointer",
|
||||
color: "#fff",
|
||||
}}
|
||||
>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" strokeWidth="2.5" strokeLinecap="round">
|
||||
<path d="M18 6 6 18M6 6l12 12"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<SidebarContent pathname={pathname} permissions={permissions} user={user} compact={false} />
|
||||
</aside>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════
|
||||
SidebarContent
|
||||
══════════════════════════════════════════ */
|
||||
function SidebarContent({
|
||||
pathname,
|
||||
permissions,
|
||||
user,
|
||||
compact,
|
||||
pathname, permissions, user, compact,
|
||||
}: {
|
||||
pathname: string;
|
||||
permissions: string[];
|
||||
@@ -119,40 +229,28 @@ function SidebarContent({
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
{/* Logo */}
|
||||
<div style={{ marginBottom: 28, display: "flex", justifyContent: compact ? "center" : "flex-start" }}>
|
||||
<Logo white />
|
||||
{compact ? <BrandIcon size={36} /> : <Logo white />}
|
||||
</div>
|
||||
|
||||
{/* Nav sections */}
|
||||
<nav
|
||||
style={{ flex: 1, display: "flex", flexDirection: "column", gap: 0, width: "100%" }}
|
||||
aria-label="Main navigation"
|
||||
>
|
||||
<nav style={{ flex: 1, display: "flex", flexDirection: "column", width: "100%" }}
|
||||
aria-label="Main navigation">
|
||||
{navSections.map((section) => (
|
||||
<div key={section.label} style={{ marginBottom: 8 }}>
|
||||
{!compact && (
|
||||
<p style={{
|
||||
fontSize: 9,
|
||||
letterSpacing: "0.14em",
|
||||
textTransform: "uppercase",
|
||||
color: "rgba(255,255,255,0.45)",
|
||||
padding: "8px 8px 4px",
|
||||
fontWeight: 600,
|
||||
textAlign: "start",
|
||||
fontSize: 9, letterSpacing: "0.14em", textTransform: "uppercase",
|
||||
color: "rgba(255,255,255,0.45)", padding: "8px 8px 4px",
|
||||
fontWeight: 600, textAlign: "start", margin: 0,
|
||||
}}>
|
||||
{section.label}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{section.items.map((item) => {
|
||||
const allowed = item.permission === "read-dashboard"
|
||||
|| permissions.includes(item.permission);
|
||||
const allowed = item.permission === "read-dashboard" || permissions.includes(item.permission);
|
||||
if (!allowed) return null;
|
||||
|
||||
const active = pathname === item.href
|
||||
|| (item.href !== "/dashboard" && pathname.startsWith(item.href));
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
@@ -176,11 +274,8 @@ function SidebarContent({
|
||||
textAlign: "start",
|
||||
}}
|
||||
>
|
||||
<i
|
||||
className={`ti ${item.icon}`}
|
||||
aria-hidden="true"
|
||||
style={{ fontSize: compact ? 18 : 16, flexShrink: 0 }}
|
||||
/>
|
||||
<i className={`ti ${item.icon}`} aria-hidden="true"
|
||||
style={{ fontSize: compact ? 18 : 16, flexShrink: 0 }} />
|
||||
{!compact && item.label}
|
||||
</Link>
|
||||
);
|
||||
@@ -189,34 +284,23 @@ function SidebarContent({
|
||||
))}
|
||||
</nav>
|
||||
|
||||
{/* User badge — collapses to an avatar dot in compact mode */}
|
||||
{compact ? (
|
||||
<div
|
||||
suppressHydrationWarning
|
||||
title={user?.name ?? user?.userName ?? "—"}
|
||||
style={{
|
||||
width: 36,
|
||||
height: 36,
|
||||
borderRadius: "var(--radius-full)",
|
||||
width: 36, height: 36, borderRadius: "var(--radius-full)",
|
||||
background: "rgba(255,255,255,0.18)",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
color: "#fff",
|
||||
marginTop: 8,
|
||||
display: "flex", alignItems: "center", justifyContent: "center",
|
||||
fontSize: 13, fontWeight: 600, color: "#fff", marginTop: 8,
|
||||
}}
|
||||
>
|
||||
{(user?.name ?? user?.userName ?? "—").slice(0, 1)}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{
|
||||
background: "rgba(255,255,255,0.12)",
|
||||
borderRadius: 10,
|
||||
padding: "10px 12px",
|
||||
marginTop: 8,
|
||||
width: "100%",
|
||||
background: "rgba(255,255,255,0.12)", borderRadius: 10,
|
||||
padding: "10px 12px", marginTop: 8, width: "100%",
|
||||
}}>
|
||||
<p suppressHydrationWarning style={{ fontSize: 13, fontWeight: 500, color: "#fff", margin: 0, textAlign: "start" }}>
|
||||
{user?.name ?? user?.userName ?? "—"}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { clearAuth, getStoredUser } from "@/src/lib/auth";
|
||||
import { useSidebarDrawer, BrandIconButton } from "./Sidebar";
|
||||
|
||||
export function Topbar() {
|
||||
const router = useRouter();
|
||||
const { setOpen } = useSidebarDrawer();
|
||||
|
||||
async function handleLogout() {
|
||||
await clearAuth();
|
||||
@@ -24,33 +26,27 @@ export function Topbar() {
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
/*
|
||||
`justify-content: space-between` and `display: flex` are
|
||||
direction-agnostic — they already flip with `dir` for free.
|
||||
The title block (first child) lands at the inline-start edge
|
||||
(right, in RTL) and the actions cluster (second child) lands
|
||||
at inline-end (left). That matches the brief's "primary
|
||||
actions easily accessible" requirement: in Arabic dashboards
|
||||
the page title reads first at the right, and the role badge
|
||||
+ logout sit together at the natural reading end — unchanged
|
||||
from before, just now correctly positioned by `dir` instead
|
||||
of by accident.
|
||||
*/
|
||||
}}
|
||||
>
|
||||
{/* عنوان الصفحة */}
|
||||
<div>
|
||||
<p style={{ fontSize: 14, fontWeight: 600, color: "var(--color-text-primary)", margin: 0, textAlign: "start" }}>
|
||||
لوحة التحكم
|
||||
</p>
|
||||
<p style={{ fontSize: 11, color: "var(--color-text-muted)", margin: 0, textAlign: "start" }}>
|
||||
{/* English product label intentionally stays LTR-embedded so
|
||||
"Operations dashboard" doesn't get its word order or
|
||||
punctuation reversed by the surrounding RTL run. */}
|
||||
<span className="ltr-embed">Operations dashboard</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div style={{ display: "flex", alignItems: "center", gap: 12 }}>
|
||||
{/* أكشنز */}
|
||||
<div style={{ display: "flex", alignItems: "center", gap: 10 }}>
|
||||
|
||||
{/* زرار المنيو — sm فقط، globals.css بتتحكم في الـ display */}
|
||||
<div id="topbar-menu-btn">
|
||||
<BrandIconButton onClick={() => setOpen(true)} />
|
||||
</div>
|
||||
|
||||
{/* الدور */}
|
||||
<div
|
||||
suppressHydrationWarning
|
||||
style={{
|
||||
@@ -65,14 +61,13 @@ export function Topbar() {
|
||||
{user?.role ?? "—"}
|
||||
</div>
|
||||
|
||||
{/* خروج */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleLogout}
|
||||
style={{
|
||||
fontSize: 12,
|
||||
fontWeight: 500,
|
||||
color: "#DC2626",
|
||||
background: "#FEF2F2",
|
||||
fontSize: 12, fontWeight: 500,
|
||||
color: "#DC2626", background: "#FEF2F2",
|
||||
border: "1px solid #FECACA",
|
||||
borderRadius: "var(--radius-full)",
|
||||
padding: "5px 14px",
|
||||
|
||||
@@ -1,36 +1,64 @@
|
||||
import { Sidebar } from "../components/layout/Sidebar";
|
||||
import { Topbar } from "../components/layout/Topbar";
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { Sidebar, SidebarProvider } from "../components/layout/Sidebar";
|
||||
import { Topbar } from "../components/layout/Topbar";
|
||||
|
||||
function DashShell({ children }: { children: React.ReactNode }) {
|
||||
const contentRef = useRef<HTMLDivElement>(null);
|
||||
const pathname = usePathname();
|
||||
|
||||
useEffect(() => {
|
||||
const el = contentRef.current;
|
||||
if (!el) return;
|
||||
|
||||
function applyPadding() {
|
||||
if (!el) return;
|
||||
const w = window.innerWidth;
|
||||
if (w >= 768 && w < 1024) {
|
||||
|
||||
el.style.paddingInlineEnd = "72px";
|
||||
} else {
|
||||
el.style.paddingInlineEnd = "0px";
|
||||
}
|
||||
}
|
||||
|
||||
applyPadding();
|
||||
window.addEventListener("resize", applyPadding);
|
||||
return () => window.removeEventListener("resize", applyPadding);
|
||||
}, [pathname]);
|
||||
|
||||
export default function DashboardLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className="flex min-h-screen"
|
||||
style={{ background: "var(--color-surface-muted)" }}
|
||||
style={{
|
||||
display: "flex",
|
||||
minHeight: "100vh",
|
||||
background: "var(--color-surface-muted)",
|
||||
}}
|
||||
>
|
||||
{/*
|
||||
Sidebar is still the first flex child. With dir="rtl" on <html>
|
||||
(set in app/layout.tsx) this is enough to place the full
|
||||
sidebar on the right with no positional CSS — see Sidebar.tsx.
|
||||
*/}
|
||||
<Sidebar />
|
||||
|
||||
{/*
|
||||
The compact icon rail (md and below) is `position: fixed`, so it
|
||||
doesn't take up flex space. This wrapper reserves room for it
|
||||
with `paddingInlineEnd`, which means "right padding in RTL,
|
||||
left padding in LTR" — it never needs to be touched again if
|
||||
direction changes.
|
||||
*/}
|
||||
<div
|
||||
className="flex min-w-0 flex-1 flex-col md:[padding-inline-end:var(--sidebar-width-compact)] lg:[padding-inline-end:0]"
|
||||
ref={contentRef}
|
||||
id="dash-content"
|
||||
style={{
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
}}
|
||||
>
|
||||
<Topbar />
|
||||
<main className="flex-1 p-6">{children}</main>
|
||||
<main style={{ flex: 1, padding: "1.7rem" }}>{children}</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<SidebarProvider>
|
||||
<DashShell>{children}</DashShell>
|
||||
</SidebarProvider>
|
||||
);
|
||||
}
|
||||
@@ -1,47 +1,32 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { getStoredToken } from "@/src/lib/auth";
|
||||
import { get } from "@/src/services/api";
|
||||
import { Spinner, Alert } from "@/src/Components/UI";
|
||||
|
||||
interface Order {
|
||||
id: string;
|
||||
shipmentNumber: string;
|
||||
recipientName: string;
|
||||
recipientPhone: string;
|
||||
currentStatus: "Created" | "Assigned" | "InTransit" | "Delivered" | "Returned" | "Cancelled";
|
||||
totalPrice?: number;
|
||||
paymentMethod?: string;
|
||||
paymentStatus?: "Pending" | "Paid" | "Failed" | "Refunded";
|
||||
client?: { name: string };
|
||||
trip?: { tripNumber: string };
|
||||
createdAt: string;
|
||||
|
||||
import { useState, useCallback } from "react";
|
||||
import { Alert, Spinner, Toast } from "@/src/Components/UI";
|
||||
import { OrderFormModal } from "@/src/Components/Order/Orderformmodal";
|
||||
import { OrderDeleteModal } from "@/src/Components/Order/Orderdeletemodal";
|
||||
import { OrderDetailPanel, ORDER_STATUS_MAP } from "@/src/Components/Order/OrderDetailBanel";
|
||||
import { useOrders } from "@/src/hooks/useOrder";
|
||||
import type { CreateOrderPayload, Order, UpdateOrderPayload } from "@/src/types/order";
|
||||
|
||||
// ── Helpers — copied verbatim from app/dashboard/drivers/page.tsx ───────
|
||||
|
||||
function fmtDate(iso?: string | null): string {
|
||||
if (!iso) return "—";
|
||||
return new Date(iso).toLocaleDateString("ar-SA", {
|
||||
year: "numeric", month: "short", day: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
interface ApiResponse {
|
||||
data: {
|
||||
data: Order[];
|
||||
pagination: { total: number; page: number; pages: number };
|
||||
meta?: { total: number; pages: number };
|
||||
};
|
||||
function fmtAmount(n?: number | null): string {
|
||||
if (n == null) return "—";
|
||||
return `${n.toFixed(2)} ر.س`;
|
||||
}
|
||||
|
||||
const STATUS_MAP: Record<Order["currentStatus"], { label: string; color: string; bg: string; border: string }> = {
|
||||
Created: { label: "تم الإنشاء", color: "#1E40AF", bg: "#EFF6FF", border: "#BFDBFE" },
|
||||
Assigned: { label: "مُعيَّن", color: "#5B21B6", bg: "#F5F3FF", border: "#DDD6FE" },
|
||||
InTransit: { label: "قيد التوصيل", color: "#854D0E", bg: "#FFFBEB", border: "#FDE68A" },
|
||||
Delivered: { label: "تم التسليم", color: "#166534", bg: "#DCFCE7", border: "#BBF7D0" },
|
||||
Returned: { label: "مُرتجع", color: "#991B1B", bg: "#FEF2F2", border: "#FECACA" },
|
||||
Cancelled: { label: "ملغي", color: "#64748B", bg: "#F1F5F9", border: "#E2E8F0" },
|
||||
};
|
||||
|
||||
const PAY_MAP: Record<string, { label: string; color: string }> = {
|
||||
Pending: { label: "معلَّق", color: "#D97706" },
|
||||
Paid: { label: "مدفوع", color: "#16A34A" },
|
||||
Failed: { label: "فشل", color: "#DC2626" },
|
||||
Refunded: { label: "مُسترجع", color: "#64748B" },
|
||||
};
|
||||
// ── Styles — identical tokens/values to the Drivers page, per the
|
||||
// "no new styles" constraint; only column widths differ to fit Order's
|
||||
// field set (shipment / recipient / client / amount / status / actions).
|
||||
|
||||
const cardStyle: React.CSSProperties = {
|
||||
borderRadius: "var(--radius-xl)",
|
||||
@@ -62,220 +47,417 @@ const thStyle: React.CSSProperties = {
|
||||
borderBottom: "1px solid var(--color-border)",
|
||||
};
|
||||
|
||||
export default function OrdersPage() {
|
||||
const [orders, setOrders] = useState<Order[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [pages, setPages] = useState(1);
|
||||
const [statusFilter, setStatusFilter] = useState<string>("");
|
||||
// Shared across header + rows — keep these in sync or columns will misalign.
|
||||
const ROW_GRID_COLUMNS = "1.6fr 1.6fr 1.2fr 1.1fr 1fr 0.8fr";
|
||||
|
||||
useEffect(() => {
|
||||
const token = getStoredToken();
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
const params = new URLSearchParams({ page: String(page), limit: "10" });
|
||||
if (search) params.set("search", search);
|
||||
if (statusFilter) params.set("currentStatus", statusFilter);
|
||||
get<ApiResponse>(`orders?${params}`, token)
|
||||
.then((res) => {
|
||||
const payload = res.data ?? res;
|
||||
setOrders(payload.data ?? []);
|
||||
setTotal(payload.meta?.total ?? 0);
|
||||
setPages(payload.meta?.pages ?? 1);
|
||||
})
|
||||
.catch((err: Error) => setError(err.message))
|
||||
.finally(() => setLoading(false));
|
||||
}, [page, search, statusFilter]);
|
||||
const iconBtnBase: React.CSSProperties = {
|
||||
width: 30,
|
||||
height: 30,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
borderRadius: "var(--radius-md)",
|
||||
cursor: "pointer",
|
||||
flexShrink: 0,
|
||||
};
|
||||
|
||||
// ── Page Component ───────────────────────────────────────────────────────
|
||||
|
||||
export default function OrderComponent() {
|
||||
const {
|
||||
orders, loading, error, total, pages, page,
|
||||
search, statusFilter, setPage, handleSearch, handleStatusFilter, clearError,
|
||||
createOrder, updateOrder, updateStatus, deleteOrder,
|
||||
notification, reload,
|
||||
} = useOrders();
|
||||
|
||||
// ── Panel / modal state — same three-state shape as DriversPage
|
||||
// (selected id for the detail panel, "new" | Order | null for the
|
||||
// form modal, Order | null for the delete modal). ───────────────────
|
||||
const [selectedOrderId, setSelectedOrderId] = useState<string | null>(null);
|
||||
const [formOrder, setFormOrder] = useState<Order | null | "new">(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<Order | null>(null);
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
// Bumped after a successful edit/status-change to force the detail panel
|
||||
// to re-fetch — same trick as DriversPage's panelRefreshKey.
|
||||
const [panelRefreshKey, setPanelRefreshKey] = useState(0);
|
||||
|
||||
// ── Handlers ─────────────────────────────────────────────────────────
|
||||
const handleEdit = useCallback((order: Order) => {
|
||||
setSelectedOrderId(null);
|
||||
setFormOrder(order);
|
||||
}, []);
|
||||
|
||||
const handleDelete = useCallback((order: Order) => {
|
||||
setSelectedOrderId(null);
|
||||
setDeleteTarget(order);
|
||||
}, []);
|
||||
|
||||
// ── Notifications: create/update success or failure surfaces as a
|
||||
// toast via useOrders()' notify() — see useOrders.ts createOrder /
|
||||
// updateOrder. Field-level / request errors additionally render
|
||||
// inside the form modal itself via its own <Alert>. ────────────────
|
||||
const handleFormSubmit = useCallback(
|
||||
async (
|
||||
payload: CreateOrderPayload | UpdateOrderPayload,
|
||||
isNew: boolean,
|
||||
): Promise<boolean> => {
|
||||
let ok: boolean;
|
||||
|
||||
if (isNew) {
|
||||
ok = await createOrder(payload as CreateOrderPayload);
|
||||
} else {
|
||||
const id = (formOrder as Order).id;
|
||||
ok = await updateOrder(id, payload as UpdateOrderPayload);
|
||||
// Re-fetch detail panel so updated fields are visible immediately
|
||||
if (ok && selectedOrderId) setPanelRefreshKey((k) => k + 1);
|
||||
}
|
||||
|
||||
return ok;
|
||||
},
|
||||
[formOrder, createOrder, updateOrder, selectedOrderId],
|
||||
);
|
||||
|
||||
// ── Notification: status change made from the detail panel bubbles up
|
||||
// here and fires the same success toast the table-level actions use,
|
||||
// keeping feedback consistent regardless of where the action started. ──
|
||||
const handleStatusChanged = useCallback(() => {
|
||||
setPanelRefreshKey((k) => k + 1);
|
||||
reload();
|
||||
}, [reload]);
|
||||
|
||||
const handleConfirmDelete = useCallback(async () => {
|
||||
if (!deleteTarget) return;
|
||||
setDeleting(true);
|
||||
const ok = await deleteOrder(deleteTarget.id);
|
||||
setDeleting(false);
|
||||
if (ok) setDeleteTarget(null);
|
||||
}, [deleteTarget, deleteOrder]);
|
||||
|
||||
// ── Render ───────────────────────────────────────────────────────────
|
||||
return (
|
||||
<section style={{ display: "flex", flexDirection: "column", gap: "1.5rem" }}>
|
||||
<>
|
||||
<section style={{ display: "flex", flexDirection: "column", gap: "1.5rem" }}>
|
||||
|
||||
{/* 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)",
|
||||
}}>
|
||||
<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>
|
||||
<p style={{ marginTop: "0.25rem", fontSize: 13, color: "var(--color-text-muted)" }}>
|
||||
إجمالي <strong style={{ color: "var(--color-text-primary)" }}>{total}</strong> طلب
|
||||
</p>
|
||||
{/* ── 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)",
|
||||
}}>
|
||||
<p style={{ fontSize: 11, letterSpacing: "0.3em", textTransform: "uppercase", color: "#2563EB", fontWeight: 600 }}>
|
||||
إدارة الشحنات
|
||||
</p>
|
||||
<div style={{ marginTop: "0.75rem", display: "flex", flexDirection: "column", gap: "1rem" }}>
|
||||
<div style={{ display: "flex", alignItems: "flex-end", justifyContent: "space-between", flexWrap: "wrap", gap: "1rem" }}>
|
||||
<div>
|
||||
<h1 style={{ fontSize: "1.5rem", fontWeight: 700, color: "var(--color-text-primary)", margin: 0 }}>
|
||||
الطلبات
|
||||
</h1>
|
||||
<p style={{ marginTop: "0.25rem", fontSize: 13, color: "var(--color-text-muted)" }}>
|
||||
إجمالي{" "}
|
||||
<strong style={{ color: "var(--color-text-primary)" }}>{total}</strong>{" "}
|
||||
طلب مسجل
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div style={{ display: "flex", gap: "0.75rem", alignItems: "center", flexWrap: "wrap" }}>
|
||||
{/* Status filter — ported from app/dashboard/orders/page.tsx */}
|
||||
<select
|
||||
value={statusFilter}
|
||||
onChange={(e) => handleStatusFilter(e.target.value)}
|
||||
dir="rtl"
|
||||
style={{
|
||||
height: 40, borderRadius: "var(--radius-lg)",
|
||||
border: "1px solid var(--color-border)",
|
||||
background: "var(--color-surface)",
|
||||
fontSize: 13, color: "var(--color-text-secondary)",
|
||||
padding: "0 0.75rem", outline: "none",
|
||||
fontFamily: "var(--font-sans)", cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
<option value="">كل الحالات</option>
|
||||
{Object.entries(ORDER_STATUS_MAP).map(([k, v]) => (
|
||||
<option key={k} value={k}>{v.label}</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
{/* Search */}
|
||||
<div style={{ position: "relative", width: 288 }}>
|
||||
<svg
|
||||
style={{ position: "absolute", right: 12, top: "50%", transform: "translateY(-50%)", width: 16, height: 16, color: "var(--color-text-hint)", pointerEvents: "none" }}
|
||||
fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24"
|
||||
>
|
||||
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.35-4.35" />
|
||||
</svg>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="رقم الشحنة أو المستلم..."
|
||||
value={search}
|
||||
onChange={(e) => handleSearch(e.target.value)}
|
||||
dir="rtl"
|
||||
style={{
|
||||
width: "100%", height: 40, paddingRight: 36, paddingLeft: 12,
|
||||
borderRadius: "var(--radius-lg)",
|
||||
border: "1px solid var(--color-border)",
|
||||
background: "var(--color-surface)",
|
||||
fontSize: 13, color: "var(--color-text-primary)",
|
||||
outline: "none", fontFamily: "var(--font-sans)",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Add button */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setFormOrder("new")}
|
||||
style={{
|
||||
height: 40, padding: "0 1.25rem",
|
||||
borderRadius: "var(--radius-lg)",
|
||||
border: "none",
|
||||
background: "var(--color-brand-600)",
|
||||
fontSize: 13, fontWeight: 700, color: "#FFF",
|
||||
cursor: "pointer",
|
||||
display: "flex", alignItems: "center", gap: 8,
|
||||
fontFamily: "var(--font-sans)",
|
||||
flexShrink: 0,
|
||||
}}
|
||||
>
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">
|
||||
<path d="M12 5v14M5 12h14" />
|
||||
</svg>
|
||||
إضافة طلب
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: "0.5rem", flexWrap: "wrap" }}>
|
||||
{/* Status filter */}
|
||||
<select
|
||||
value={statusFilter}
|
||||
onChange={(e) => { setStatusFilter(e.target.value); setPage(1); }}
|
||||
</header>
|
||||
|
||||
{/* ── Notifications: page-level error banner (e.g. failed list load)
|
||||
dismissible via clearError() from the hook. Action-result
|
||||
toasts (create/update/delete/status success or failure) render
|
||||
separately below via <Toast>, matching DriversPage's split
|
||||
between a persistent <Alert> for fetch errors and a transient
|
||||
<Toast> for action feedback. ── */}
|
||||
{error && (
|
||||
<Alert type="error" message={error} onClose={clearError} />
|
||||
)}
|
||||
|
||||
{/* ── Table ── */}
|
||||
<div style={cardStyle}>
|
||||
<div
|
||||
dir="rtl"
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: ROW_GRID_COLUMNS,
|
||||
...thStyle,
|
||||
}}
|
||||
>
|
||||
<span>رقم الشحنة</span>
|
||||
<span>المستلم</span>
|
||||
<span>العميل</span>
|
||||
<span>المبلغ</span>
|
||||
<span>الحالة</span>
|
||||
<span>إجراءات</span>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 12, padding: "4rem 0", color: "var(--color-text-muted)" }}>
|
||||
<Spinner size="sm" className="text-blue-600" />
|
||||
<span style={{ fontSize: 13 }}>جارٍ التحميل…</span>
|
||||
</div>
|
||||
) : orders.length === 0 ? (
|
||||
<p style={{ textAlign: "center", padding: "4rem 0", fontSize: 13, color: "var(--color-text-muted)" }}>
|
||||
لا توجد نتائج {search && `لـ "${search}"`}
|
||||
</p>
|
||||
) : (
|
||||
<ul dir="rtl" style={{ listStyle: "none", margin: 0, padding: 0 }}>
|
||||
{orders.map((o, i) => {
|
||||
const statusCfg = ORDER_STATUS_MAP[o.currentStatus] ?? ORDER_STATUS_MAP.Created;
|
||||
|
||||
return (
|
||||
<li
|
||||
key={o.id}
|
||||
onClick={() => setSelectedOrderId(o.id)}
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: ROW_GRID_COLUMNS,
|
||||
alignItems: "center", gap: "0.5rem",
|
||||
padding: "0.875rem 1.5rem",
|
||||
borderBottom: "1px solid var(--color-border)",
|
||||
background: i % 2 !== 0 ? "var(--color-surface-muted)" : "transparent",
|
||||
fontSize: 13,
|
||||
cursor: "pointer",
|
||||
transition: "background 0.15s",
|
||||
}}
|
||||
onMouseEnter={(e) => (e.currentTarget.style.background = "var(--color-surface-hover, #F8FAFC)")}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.background = i % 2 !== 0 ? "var(--color-surface-muted)" : "transparent")}
|
||||
>
|
||||
<div>
|
||||
<p style={{ fontWeight: 600, fontFamily: "var(--font-mono)", color: "#2563EB", margin: 0 }}>{o.shipmentNumber}</p>
|
||||
<p style={{ marginTop: 2, fontSize: 11, color: "var(--color-text-muted)" }}>{fmtDate(o.createdAt)}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p style={{ fontWeight: 600, color: "var(--color-text-primary)", margin: 0 }}>{o.recipientName}</p>
|
||||
<p style={{ marginTop: 2, fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--color-text-muted)" }}>{o.recipientPhone}</p>
|
||||
</div>
|
||||
<span style={{ color: "var(--color-text-secondary)" }}>{o.client?.name ?? "—"}</span>
|
||||
<span style={{ fontWeight: 600, color: "var(--color-text-primary)", fontFamily: "var(--font-mono)" }}>
|
||||
{fmtAmount(o.totalPrice)}
|
||||
</span>
|
||||
<span style={{
|
||||
display: "inline-flex", alignItems: "center", gap: 5,
|
||||
borderRadius: "var(--radius-full)",
|
||||
border: `1px solid ${statusCfg.border}`,
|
||||
background: statusCfg.bg,
|
||||
padding: "0.2rem 0.625rem",
|
||||
fontSize: 11, fontWeight: 600, color: statusCfg.color,
|
||||
width: "fit-content",
|
||||
}}>
|
||||
<span style={{ width: 6, height: 6, borderRadius: "50%", background: statusCfg.dot, flexShrink: 0 }} />
|
||||
{statusCfg.label}
|
||||
</span>
|
||||
|
||||
{/* ── Inline row actions: edit / delete ──
|
||||
stopPropagation is required on both buttons so the
|
||||
click doesn't bubble up to the <li> onClick and
|
||||
open the detail panel as well. */}
|
||||
<div style={{ display: "flex", gap: "0.4rem" }}>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="تعديل الطلب"
|
||||
title="تعديل"
|
||||
onClick={(e) => { e.stopPropagation(); handleEdit(o); }}
|
||||
style={{
|
||||
...iconBtnBase,
|
||||
border: "1px solid var(--color-brand-200)",
|
||||
background: "var(--color-brand-50, #EFF6FF)",
|
||||
color: "var(--color-brand-600)",
|
||||
}}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">
|
||||
<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"
|
||||
aria-label="حذف الطلب"
|
||||
title="حذف"
|
||||
onClick={(e) => { e.stopPropagation(); handleDelete(o); }}
|
||||
style={{
|
||||
...iconBtnBase,
|
||||
border: "1px solid #FECACA",
|
||||
background: "#FEF2F2",
|
||||
color: "#DC2626",
|
||||
}}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="3 6 5 6 21 6" />
|
||||
<path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6" />
|
||||
<path d="M10 11v6M14 11v6" />
|
||||
<path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{/* ── Pagination ── */}
|
||||
{pages > 1 && (
|
||||
<div
|
||||
dir="rtl"
|
||||
style={{
|
||||
height: 40, borderRadius: "var(--radius-lg)",
|
||||
border: "1px solid var(--color-border)",
|
||||
background: "var(--color-surface)",
|
||||
fontSize: 13, color: "var(--color-text-secondary)",
|
||||
padding: "0 0.75rem", outline: "none",
|
||||
fontFamily: "var(--font-sans)",
|
||||
display: "flex", alignItems: "center", justifyContent: "space-between",
|
||||
borderTop: "1px solid var(--color-border)", padding: "0.875rem 1.5rem",
|
||||
}}
|
||||
>
|
||||
<option value="">كل الحالات</option>
|
||||
{Object.entries(STATUS_MAP).map(([k, v]) => (
|
||||
<option key={k} value={k}>{v.label}</option>
|
||||
))}
|
||||
</select>
|
||||
{/* Search */}
|
||||
<div style={{ position: "relative", width: 256 }}>
|
||||
<svg style={{ position: "absolute", right: 12, top: "50%", transform: "translateY(-50%)", width: 16, height: 16, color: "var(--color-text-hint)", pointerEvents: "none" }}
|
||||
fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
|
||||
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/>
|
||||
</svg>
|
||||
<input type="text" placeholder="رقم الشحنة أو المستلم..." value={search}
|
||||
onChange={(e) => { setSearch(e.target.value); setPage(1); }} dir="rtl"
|
||||
style={{
|
||||
width: "100%", height: 40, paddingRight: 36, paddingLeft: 12,
|
||||
borderRadius: "var(--radius-lg)",
|
||||
border: "1px solid var(--color-border)",
|
||||
background: "var(--color-surface)",
|
||||
fontSize: 13, color: "var(--color-text-primary)",
|
||||
outline: "none", fontFamily: "var(--font-sans)",
|
||||
}}
|
||||
/>
|
||||
<span style={{ fontSize: 12, color: "var(--color-text-muted)" }}>
|
||||
صفحة{" "}
|
||||
<strong style={{ color: "var(--color-text-primary)" }}>{page}</strong>{" "}
|
||||
من{" "}
|
||||
<strong style={{ color: "var(--color-text-primary)" }}>{pages}</strong>
|
||||
</span>
|
||||
<div style={{ display: "flex", gap: "0.5rem" }}>
|
||||
{[
|
||||
{ label: "السابق", action: () => setPage(p => Math.max(1, p - 1)), disabled: page === 1 },
|
||||
{ label: "التالي", action: () => setPage(p => Math.min(pages, p + 1)), disabled: page === pages },
|
||||
].map(btn => (
|
||||
<button
|
||||
key={btn.label}
|
||||
onClick={btn.action}
|
||||
disabled={btn.disabled}
|
||||
style={{
|
||||
borderRadius: "var(--radius-lg)",
|
||||
border: "1px solid var(--color-border)",
|
||||
background: "var(--color-surface-muted)",
|
||||
padding: "0.375rem 0.875rem",
|
||||
fontSize: 12, color: "var(--color-text-secondary)",
|
||||
cursor: btn.disabled ? "not-allowed" : "pointer",
|
||||
opacity: btn.disabled ? 0.4 : 1,
|
||||
fontFamily: "var(--font-sans)",
|
||||
}}
|
||||
>
|
||||
{btn.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
</section>
|
||||
|
||||
{error && <Alert type="error" message={error} onClose={() => setError(null)} />}
|
||||
{/* ── Detail panel — key forces re-fetch after a successful edit or
|
||||
status change. Status updates triggered inside the panel call
|
||||
updateStatus() from useOrders() (via handleStatusChanged), which
|
||||
fires the same toast as a table-level action. ── */}
|
||||
{selectedOrderId && (
|
||||
<OrderDetailPanel
|
||||
key={`${selectedOrderId}-${panelRefreshKey}`}
|
||||
orderId={selectedOrderId}
|
||||
onClose={() => setSelectedOrderId(null)}
|
||||
onEdit={handleEdit}
|
||||
onDelete={handleDelete}
|
||||
onStatusChanged={handleStatusChanged}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Table */}
|
||||
<div style={cardStyle}>
|
||||
<div dir="rtl" style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "1.8fr 1.5fr 1.2fr 1fr 1fr 1fr",
|
||||
...thStyle,
|
||||
}}>
|
||||
<span>رقم الشحنة</span>
|
||||
<span>المستلم</span>
|
||||
<span>العميل</span>
|
||||
<span>المبلغ</span>
|
||||
<span>الحالة</span>
|
||||
<span style={{ textAlign: "center" }}>التاريخ</span>
|
||||
</div>
|
||||
{/* ── Form modal ── */}
|
||||
{formOrder !== null && (
|
||||
<OrderFormModal
|
||||
editOrder={formOrder === "new" ? null : formOrder}
|
||||
onClose={() => setFormOrder(null)}
|
||||
onSubmit={handleFormSubmit}
|
||||
/>
|
||||
)}
|
||||
|
||||
{loading ? (
|
||||
<div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 12, padding: "4rem 0", color: "var(--color-text-muted)" }}>
|
||||
<Spinner size="sm" className="text-blue-600" />
|
||||
<span style={{ fontSize: 13 }}>جارٍ التحميل…</span>
|
||||
</div>
|
||||
) : orders.length === 0 ? (
|
||||
<p style={{ textAlign: "center", padding: "4rem 0", fontSize: 13, color: "var(--color-text-muted)" }}>
|
||||
لا توجد نتائج
|
||||
</p>
|
||||
) : (
|
||||
<ul dir="rtl" style={{ listStyle: "none", margin: 0, padding: 0 }}>
|
||||
{orders.map((o, i) => {
|
||||
const status = STATUS_MAP[o.currentStatus];
|
||||
const pay = o.paymentStatus ? PAY_MAP[o.paymentStatus] : null;
|
||||
return (
|
||||
<li key={o.id} style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "1.8fr 1.5fr 1.2fr 1fr 1fr 1fr",
|
||||
alignItems: "center", gap: "0.5rem",
|
||||
padding: "0.875rem 1.5rem",
|
||||
borderBottom: "1px solid var(--color-border)",
|
||||
background: i % 2 !== 0 ? "var(--color-surface-muted)" : "transparent",
|
||||
fontSize: 13,
|
||||
}}>
|
||||
<div>
|
||||
<p style={{ fontFamily: "var(--font-mono)", fontSize: 12, fontWeight: 700, color: "#2563EB", margin: 0 }}>
|
||||
{o.shipmentNumber}
|
||||
</p>
|
||||
{o.trip && (
|
||||
<p style={{ marginTop: 2, fontSize: 11, color: "var(--color-text-muted)" }}>
|
||||
رحلة: {o.trip.tripNumber}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<p style={{ color: "var(--color-text-primary)", margin: 0 }}>{o.recipientName}</p>
|
||||
<p style={{ marginTop: 2, fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--color-text-muted)" }}>
|
||||
{o.recipientPhone}
|
||||
</p>
|
||||
</div>
|
||||
<span style={{ color: "var(--color-text-secondary)" }}>{o.client?.name ?? "—"}</span>
|
||||
<div>
|
||||
<p style={{ fontWeight: 600, color: "var(--color-text-primary)", margin: 0 }}>
|
||||
{o.totalPrice != null ? `${o.totalPrice.toFixed(2)} ر.س` : "—"}
|
||||
</p>
|
||||
{pay && (
|
||||
<p style={{ marginTop: 2, fontSize: 11, fontWeight: 600, color: pay.color }}>
|
||||
{pay.label}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<span style={{
|
||||
display: "inline-flex", alignItems: "center",
|
||||
borderRadius: "var(--radius-full)",
|
||||
border: `1px solid ${status.border}`,
|
||||
background: status.bg,
|
||||
padding: "0.2rem 0.625rem",
|
||||
fontSize: 11, fontWeight: 600, color: status.color,
|
||||
width: "fit-content",
|
||||
}}>
|
||||
{status.label}
|
||||
</span>
|
||||
<span style={{ textAlign: "center", fontSize: 11, color: "var(--color-text-muted)" }}>
|
||||
{new Date(o.createdAt).toLocaleDateString("ar-SA", {
|
||||
year: "numeric", month: "short", day: "numeric",
|
||||
})}
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
{/* ── Delete modal ── */}
|
||||
{deleteTarget && (
|
||||
<OrderDeleteModal
|
||||
order={deleteTarget}
|
||||
deleting={deleting}
|
||||
onCancel={() => setDeleteTarget(null)}
|
||||
onConfirm={handleConfirmDelete}
|
||||
/>
|
||||
)}
|
||||
|
||||
{pages > 1 && (
|
||||
<div dir="rtl" style={{
|
||||
display: "flex", alignItems: "center", justifyContent: "space-between",
|
||||
borderTop: "1px solid var(--color-border)", padding: "0.875rem 1.5rem",
|
||||
}}>
|
||||
<span style={{ fontSize: 12, color: "var(--color-text-muted)" }}>
|
||||
صفحة <strong style={{ color: "var(--color-text-primary)" }}>{page}</strong> من <strong style={{ color: "var(--color-text-primary)" }}>{pages}</strong>
|
||||
</span>
|
||||
<div style={{ display: "flex", gap: "0.5rem" }}>
|
||||
{[
|
||||
{ label: "السابق", action: () => setPage(p => Math.max(1, p - 1)), disabled: page === 1 },
|
||||
{ label: "التالي", action: () => setPage(p => Math.min(pages, p + 1)), disabled: page === pages },
|
||||
].map(btn => (
|
||||
<button key={btn.label} onClick={btn.action} disabled={btn.disabled}
|
||||
style={{
|
||||
borderRadius: "var(--radius-lg)",
|
||||
border: "1px solid var(--color-border)",
|
||||
background: "var(--color-surface-muted)",
|
||||
padding: "0.375rem 0.875rem",
|
||||
fontSize: 12, color: "var(--color-text-secondary)",
|
||||
cursor: btn.disabled ? "not-allowed" : "pointer",
|
||||
opacity: btn.disabled ? 0.4 : 1,
|
||||
fontFamily: "var(--font-sans)",
|
||||
}}>
|
||||
{btn.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
{/* ── Toast: transient success/error feedback for create, update,
|
||||
delete, and status-change actions — sourced from useOrders()'
|
||||
`notification` state (see useOrders.ts notify()). This is the
|
||||
same toast used by the Driver pages via DriverDeleteModal's
|
||||
parent and useDriver.ts, kept consistent here. ── */}
|
||||
<Toast notification={notification} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Named export alongside the default, mirroring src/Components/Driver/index.ts's
|
||||
// pattern of re-exporting each piece for use elsewhere (e.g. a future
|
||||
// app/dashboard/orders/page.tsx importing { OrderComponent }).
|
||||
export { OrderComponent };
|
||||
@@ -1,7 +1,6 @@
|
||||
@import "../src/styles/tokens.css";
|
||||
@import "tailwindcss";
|
||||
|
||||
|
||||
/* ── Base resets ────────────────────────────────────── */
|
||||
*,
|
||||
*::before,
|
||||
@@ -12,11 +11,6 @@
|
||||
html {
|
||||
scroll-behavior: smooth;
|
||||
font-size: 14px;
|
||||
/* `dir` is now set on <html> in app/layout.tsx (lang="ar" dir="rtl").
|
||||
Tailwind v4 ships native `rtl:` / `ltr:` variants that key off this
|
||||
attribute, so utility classes like `rtl:flex-row-reverse` work
|
||||
without a plugin. Route groups no longer need to set `dir`
|
||||
individually — see report Section 1. */
|
||||
}
|
||||
|
||||
body {
|
||||
@@ -29,8 +23,63 @@ body {
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
/* ════════════════════════════════════════════════════
|
||||
SIDEBAR VISIBILITY
|
||||
⚠️ مفيش display في أي inline style على الـ sidebar elements
|
||||
⚠️ !important عشان يغلب أي حاجة تانية
|
||||
════════════════════════════════════════════════════ */
|
||||
|
||||
/* default: كل العناصر مخفية */
|
||||
#sb-full,
|
||||
#sb-compact,
|
||||
#sb-drawer,
|
||||
#topbar-menu-btn {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* lg+ (≥1024px): full sidebar */
|
||||
@media (min-width: 1024px) {
|
||||
#sb-full { display: flex !important; }
|
||||
#sb-compact { display: none !important; }
|
||||
#sb-drawer { display: none !important; }
|
||||
#topbar-menu-btn { display: none !important; }
|
||||
}
|
||||
|
||||
/* md (768px–1023px): compact rail */
|
||||
@media (min-width: 768px) and (max-width: 1023px) {
|
||||
#sb-full { display: none !important; }
|
||||
#sb-compact { display: flex !important; }
|
||||
#sb-drawer { display: none !important; }
|
||||
#topbar-menu-btn { display: none !important; }
|
||||
}
|
||||
|
||||
/* sm (<768px): drawer + topbar button */
|
||||
@media (max-width: 767px) {
|
||||
#sb-full { display: none !important; }
|
||||
#sb-compact { display: none !important; }
|
||||
#sb-drawer { display: flex !important; }
|
||||
#topbar-menu-btn { display: flex !important; }
|
||||
}
|
||||
|
||||
/* ════════════════════════════════════════════════════
|
||||
DASH CONTENT PADDING
|
||||
class selector بيغلب على inline style في CSS
|
||||
بيحجز مكان الـ compact rail الـ fixed على md
|
||||
════════════════════════════════════════════════════ */
|
||||
|
||||
/* sm + lg: مفيش padding إضافي */
|
||||
.dash-content-wrapper {
|
||||
padding-inline-end: 0;
|
||||
}
|
||||
|
||||
/* md فقط: حجز 72px لمكان الـ compact rail */
|
||||
@media (min-width: 768px) and (max-width: 1023px) {
|
||||
.dash-content-wrapper {
|
||||
padding-inline-end: var(--sidebar-width-compact);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Tailwind theme bridge ──────────────────────────── */
|
||||
/* Expose CSS variables as Tailwind color utilities. */
|
||||
@theme inline {
|
||||
--color-primary-*: initial;
|
||||
--color-sand-*: initial;
|
||||
@@ -88,18 +137,20 @@ body {
|
||||
--font-mono: var(--font-mono);
|
||||
}
|
||||
|
||||
/* ── Focus ring utility ─────────────────────────────── */
|
||||
/* Unchanged: box-shadow rings are direction-neutral. */
|
||||
/* ── Focus ring ─────────────────────────────────────── */
|
||||
.focus-ring {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 2px var(--color-brand-600);
|
||||
}
|
||||
|
||||
/* ── RTL icon mirroring ─────────────────────────────────
|
||||
Directional glyphs (chevrons, arrows, "back") need to visually
|
||||
point the opposite way in RTL even though the underlying icon
|
||||
font glyph doesn't change. Apply .icon-flip-rtl to any <i>/<svg>
|
||||
whose meaning is "forward"/"back" rather than purely decorative. */
|
||||
/* ── RTL icon mirroring ─────────────────────────────── */
|
||||
[dir="rtl"] .icon-flip-rtl {
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
|
||||
/* ── LTR embed for codes/paths ──────────────────────── */
|
||||
.ltr-embed {
|
||||
direction: ltr;
|
||||
unicode-bidi: isolate;
|
||||
display: inline-block;
|
||||
}
|
||||
Reference in New Issue
Block a user