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[]>;
|
||||
}
|
||||
Reference in New Issue
Block a user