create driver page and client page also create oll driver , client layer
This commit is contained in:
141
types/client.ts
141
types/client.ts
@@ -1,24 +1,129 @@
|
||||
// ─── Domain Types ─────────────────────────────────────────────────────────────
|
||||
|
||||
export interface Client {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
taxId?: string;
|
||||
notes?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
addresses?: ClientAddress[];
|
||||
}
|
||||
|
||||
export interface ClientAddress {
|
||||
_id: string;
|
||||
id: string;
|
||||
clientId: string;
|
||||
label: string; // e.g. "Billing", "Shipping", "HQ"
|
||||
street: string;
|
||||
city: string;
|
||||
state: string;
|
||||
postalCode: string;
|
||||
country: string;
|
||||
isPrimary: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
// ─── Request / Response shapes ────────────────────────────────────────────────
|
||||
|
||||
export type CreateClientPayload = Omit<Client, "id" | "createdAt" | "updatedAt" | "addresses">;
|
||||
export type UpdateClientPayload = Partial<CreateClientPayload>;
|
||||
|
||||
export type CreateClientAddressPayload = Omit<
|
||||
ClientAddress,
|
||||
"id" | "createdAt" | "updatedAt"
|
||||
>;
|
||||
export type UpdateClientAddressPayload = Partial<CreateClientAddressPayload>;
|
||||
|
||||
// ─── Form & Validation ────────────────────────────────────────────────────────
|
||||
|
||||
export interface ClientFormData {
|
||||
name: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
taxId: string;
|
||||
notes: string;
|
||||
}
|
||||
|
||||
export interface ClientFormErrors {
|
||||
name?: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
taxId?: string;
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
export interface ClientAddressFormData {
|
||||
label: string;
|
||||
branchName: string | null;
|
||||
contactPerson: { name: string; phone: string };
|
||||
details: {
|
||||
city: string;
|
||||
district?: string;
|
||||
street: string;
|
||||
buildingNo?: string;
|
||||
unitNo?: string;
|
||||
zipCode?: string;
|
||||
street: string;
|
||||
city: string;
|
||||
state: string;
|
||||
postalCode: string;
|
||||
country: string;
|
||||
isPrimary: boolean;
|
||||
}
|
||||
|
||||
export interface ClientAddressFormErrors {
|
||||
label?: string;
|
||||
street?: string;
|
||||
city?: string;
|
||||
state?: string;
|
||||
postalCode?: string;
|
||||
country?: string;
|
||||
}
|
||||
|
||||
// ─── Table State / Reducer (mirrors user.ts TableState / TableAction) ─────────
|
||||
|
||||
export type ClientTableState = {
|
||||
clients: Client[];
|
||||
loading: boolean;
|
||||
total: number;
|
||||
pages: number;
|
||||
error: string | null;
|
||||
};
|
||||
|
||||
export type ClientTableAction =
|
||||
| { type: "LOAD_START" }
|
||||
| { type: "LOAD_OK"; clients: Client[]; total: number; pages: number }
|
||||
| { type: "LOAD_ERR"; error: string }
|
||||
| { type: "ADD"; client: Client }
|
||||
| { type: "UPDATE"; client: Client }
|
||||
| { type: "DELETE"; id: string }
|
||||
| { type: "CLEAR_ERR" };
|
||||
|
||||
export type AddressTableState = {
|
||||
addresses: ClientAddress[];
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
};
|
||||
|
||||
export type AddressTableAction =
|
||||
| { type: "LOAD_START" }
|
||||
| { type: "LOAD_OK"; addresses: ClientAddress[] }
|
||||
| { type: "LOAD_ERR"; error: string }
|
||||
| { type: "ADD"; address: ClientAddress }
|
||||
| { type: "UPDATE"; address: ClientAddress }
|
||||
| { type: "DELETE"; id: string }
|
||||
| { type: "CLEAR_ERR" };
|
||||
|
||||
// ─── Generic API wrapper ──────────────────────────────────────────────────────
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
data: T;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export interface ApiListResponse<T> {
|
||||
data: {
|
||||
data: T[];
|
||||
pagination: { total: number; page: number; pages: number };
|
||||
meta?: { total: number; pages: number };
|
||||
};
|
||||
}
|
||||
|
||||
export type OrderStatus = "CREATED" | "IN_TRANSIT" | "DELIVERED" | "CANCELLED";
|
||||
|
||||
export interface Order {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
status: OrderStatus;
|
||||
totalAmount: number;
|
||||
description: string;
|
||||
export interface ApiError {
|
||||
message: string;
|
||||
errors?: Record<string, string[]>;
|
||||
}
|
||||
124
types/driver.ts
Normal file
124
types/driver.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
export type DriverStatus = "Active" | "Inactive" | "InTrip" | "Suspended";
|
||||
export type NationalIdType = "NationalID" | "Iqama" | "Passport";
|
||||
export type DriverCardType = "Temporary" | "Seasonal" | "Annual" | "Restricted";
|
||||
|
||||
// ── Core Driver ──────────────────────────────────────────────────────────────
|
||||
|
||||
export interface Driver {
|
||||
id: string;
|
||||
name: string;
|
||||
userName?: string | null;
|
||||
email?: string | null;
|
||||
address?: string | null;
|
||||
nationality?: string | null;
|
||||
nationalId?: string | null;
|
||||
nationalIdType?: NationalIdType | null;
|
||||
nationalIdExpiry?: string | null;
|
||||
gosiNumber?: string | null;
|
||||
phone: string;
|
||||
licenseNumber?: string | null;
|
||||
licenseType?: string | null;
|
||||
licenseExpiry?: string | null;
|
||||
photo?: string | null;
|
||||
nationalPhoto?: string | null;
|
||||
driverCardPhoto?: string | null;
|
||||
driverCardNumber?: string | null;
|
||||
driverCardType?: DriverCardType | null;
|
||||
driverCardExpiry?: string | null;
|
||||
driverType?: string | null;
|
||||
status: DriverStatus;
|
||||
branchId?: string | null;
|
||||
branch?: { name: string } | null;
|
||||
statusHistory?: DriverStatusHistoryEntry[];
|
||||
isActive: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
isDeleted?: boolean;
|
||||
}
|
||||
|
||||
export interface DriverStatusHistoryEntry {
|
||||
id: string;
|
||||
status: DriverStatus;
|
||||
reason?: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
// ── Payloads ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface CreateDriverPayload {
|
||||
name: string;
|
||||
phone: string;
|
||||
email?: string;
|
||||
address?: string;
|
||||
nationality?: string;
|
||||
nationalIdType?: NationalIdType;
|
||||
gosiNumber?: string;
|
||||
licenseNumber?: string;
|
||||
licenseType?: string;
|
||||
licenseExpiry?: string;
|
||||
driverCardNumber?: string;
|
||||
driverCardType?: DriverCardType;
|
||||
driverCardExpiry?: string;
|
||||
driverType?: string;
|
||||
branchId?: string;
|
||||
}
|
||||
|
||||
export type UpdateDriverPayload = Partial<CreateDriverPayload> & {
|
||||
status?: DriverStatus;
|
||||
reason?: string;
|
||||
};
|
||||
|
||||
// ── API Responses ─────────────────────────────────────────────────────────────
|
||||
|
||||
export interface DriverListResponse {
|
||||
data: {
|
||||
data: Driver[];
|
||||
pagination: { total: number; page: number; pages: number };
|
||||
meta?: { total: number; pages: number };
|
||||
};
|
||||
}
|
||||
|
||||
export interface DriverDetailResponse {
|
||||
data: Driver;
|
||||
}
|
||||
|
||||
export interface DriverReportResponse {
|
||||
data: {
|
||||
reportUrl: string;
|
||||
filename: string;
|
||||
};
|
||||
}
|
||||
|
||||
// ── Form state ────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface DriverFormErrors {
|
||||
name?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
licenseNumber?: string;
|
||||
}
|
||||
|
||||
// ── Status config ─────────────────────────────────────────────────────────────
|
||||
|
||||
export const DRIVER_STATUS_MAP: Record<
|
||||
DriverStatus,
|
||||
{ label: string; color: string; bg: string; border: string; dot: string }
|
||||
> = {
|
||||
Active: { label: "نشط", color: "#166534", bg: "#DCFCE7", border: "#BBF7D0", dot: "#16A34A" },
|
||||
InTrip: { label: "في رحلة", color: "#1E40AF", bg: "#EFF6FF", border: "#BFDBFE", dot: "#3B82F6" },
|
||||
Inactive: { label: "غير نشط", color: "#64748B", bg: "#F1F5F9", border: "#E2E8F0", dot: "#94A3B8" },
|
||||
Suspended: { label: "موقوف", color: "#991B1B", bg: "#FEF2F2", border: "#FECACA", dot: "#DC2626" },
|
||||
};
|
||||
|
||||
export const NATIONAL_ID_TYPE_MAP: Record<NationalIdType, string> = {
|
||||
NationalID: "هوية وطنية",
|
||||
Iqama: "إقامة",
|
||||
Passport: "جواز سفر",
|
||||
};
|
||||
|
||||
export const DRIVER_CARD_TYPE_MAP: Record<DriverCardType, string> = {
|
||||
Temporary: "مؤقتة",
|
||||
Seasonal: "موسمية",
|
||||
Annual: "سنوية",
|
||||
Restricted: "مقيدة",
|
||||
};
|
||||
Reference in New Issue
Block a user