@burdenoff/microfe-movethewheels 2026.510.105
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -0
- package/dist/AIAssistantPage-hD0VYJdH.js +210 -0
- package/dist/AnalyticsPage-DHTHCUtr.js +201 -0
- package/dist/CreateOrderPage-Cprg4Y9V.js +471 -0
- package/dist/CustomerDetailsPage-DNDEw7IW.js +239 -0
- package/dist/CustomersPage-CDjjeCEL.js +119 -0
- package/dist/DashboardPage-8iTPXRAG.js +374 -0
- package/dist/DataTable-CRIKfdIN.js +239 -0
- package/dist/DriverDetailsPage-CRyRCno7.js +297 -0
- package/dist/DriversPage-16O8fVmf.js +127 -0
- package/dist/FinancePage-BYUxK5dR.js +154 -0
- package/dist/FleetPage-CHYETCWT.js +293 -0
- package/dist/ImportExportPage-C3MKKxfc.js +232 -0
- package/dist/InventoryPage--822AxZM.js +223 -0
- package/dist/LiveTrackingPage-Dp3rTJDr.js +332 -0
- package/dist/MarketplacePage-DjEqudfM.js +192 -0
- package/dist/MetricCard-GTbxAk1a.js +135 -0
- package/dist/OrderDetailsPage-BIuYG0ub.js +398 -0
- package/dist/OrdersListPage-CW5V0Uvh.js +257 -0
- package/dist/PageLayout-B7b0vl0R.js +1894 -0
- package/dist/ProductDetailsPage-Q3X7AT-7.js +168 -0
- package/dist/ProductsPage-CUj9JpnW.js +131 -0
- package/dist/ReportsPage-DblO5CdJ.js +227 -0
- package/dist/RouteDetailsPage-CLctgk6A.js +240 -0
- package/dist/RoutesPage-8hrv6RWT.js +116 -0
- package/dist/SettingsPage-BJ5BQeqn.js +247 -0
- package/dist/StatusBadge-BrrwraIA.js +206 -0
- package/dist/TrackingPage-BGqHDh-w.js +322 -0
- package/dist/VehicleDetailsPage-XnDH4iQR.js +194 -0
- package/dist/VehiclesPage-Cs4XxHkA.js +127 -0
- package/dist/WarehouseDetailsPage-GemdMvr_.js +215 -0
- package/dist/WarehousesPage-QTiuDuXy.js +121 -0
- package/dist/arrow-left-6CiLhqVp.js +11 -0
- package/dist/box-BunB_4UH.js +18 -0
- package/dist/chart-column-DWwVEVQ-.js +22 -0
- package/dist/chevron-right-DhZVf20o.js +8 -0
- package/dist/circle-alert-D5f6RZxt.js +26 -0
- package/dist/circle-check-big-D-JMHcTe.js +11 -0
- package/dist/clock-CvwBKbQP.js +13 -0
- package/dist/dev/main.d.ts +1 -0
- package/dist/dollar-sign-CP9qeU5d.js +14 -0
- package/dist/download-CIuG04pJ.js +21 -0
- package/dist/file-text-Dd_thxkn.js +26 -0
- package/dist/filter-DyRMX9CU.js +8 -0
- package/dist/formatters-_vJlC-47.js +50 -0
- package/dist/generated/global-operations.d.ts +1 -0
- package/dist/generated/global-types.d.ts +20715 -0
- package/dist/generated/wspace-operations.d.ts +3704 -0
- package/dist/generated/wspace-types.d.ts +53362 -0
- package/dist/graphqlClient-CdJyR_ed.js +55 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +772 -0
- package/dist/map-BqH1cBJi.js +18 -0
- package/dist/map-pin-CFBOmh-A.js +13 -0
- package/dist/movethewheels/MoveTheWheelsRoot.d.ts +25 -0
- package/dist/movethewheels/MoveTheWheelsRoutes.d.ts +7 -0
- package/dist/movethewheels/components/DataTable.d.ts +32 -0
- package/dist/movethewheels/components/MetricCard.d.ts +43 -0
- package/dist/movethewheels/components/PageLayout.d.ts +68 -0
- package/dist/movethewheels/components/StatusBadge.d.ts +49 -0
- package/dist/movethewheels/components/index.d.ts +10 -0
- package/dist/movethewheels/components/ui.d.ts +22 -0
- package/dist/movethewheels/constants/index.d.ts +24 -0
- package/dist/movethewheels/constants/mockData.d.ts +33 -0
- package/dist/movethewheels/hooks/index.d.ts +12 -0
- package/dist/movethewheels/hooks/useAnalytics.d.ts +118 -0
- package/dist/movethewheels/hooks/useCustomers.d.ts +37 -0
- package/dist/movethewheels/hooks/useFleet.d.ts +71 -0
- package/dist/movethewheels/hooks/useInventory.d.ts +60 -0
- package/dist/movethewheels/hooks/useOrders.d.ts +47 -0
- package/dist/movethewheels/hooks/useRoutes.d.ts +41 -0
- package/dist/movethewheels/hooks/useTracking.d.ts +69 -0
- package/dist/movethewheels/index.d.ts +30 -0
- package/dist/movethewheels/pages/AIAssistantPage.d.ts +4 -0
- package/dist/movethewheels/pages/AnalyticsPage.d.ts +4 -0
- package/dist/movethewheels/pages/CreateOrderPage.d.ts +6 -0
- package/dist/movethewheels/pages/CustomerDetailsPage.d.ts +4 -0
- package/dist/movethewheels/pages/CustomersPage.d.ts +4 -0
- package/dist/movethewheels/pages/DashboardPage.d.ts +6 -0
- package/dist/movethewheels/pages/DriverDetailsPage.d.ts +4 -0
- package/dist/movethewheels/pages/DriversPage.d.ts +4 -0
- package/dist/movethewheels/pages/FinancePage.d.ts +4 -0
- package/dist/movethewheels/pages/FleetPage.d.ts +6 -0
- package/dist/movethewheels/pages/ImportExportPage.d.ts +4 -0
- package/dist/movethewheels/pages/InventoryPage.d.ts +4 -0
- package/dist/movethewheels/pages/LiveTrackingPage.d.ts +6 -0
- package/dist/movethewheels/pages/MarketplacePage.d.ts +4 -0
- package/dist/movethewheels/pages/OrderDetailsPage.d.ts +6 -0
- package/dist/movethewheels/pages/OrdersListPage.d.ts +6 -0
- package/dist/movethewheels/pages/ProductDetailsPage.d.ts +4 -0
- package/dist/movethewheels/pages/ProductsPage.d.ts +4 -0
- package/dist/movethewheels/pages/ReportsPage.d.ts +4 -0
- package/dist/movethewheels/pages/RouteDetailsPage.d.ts +4 -0
- package/dist/movethewheels/pages/RoutesPage.d.ts +4 -0
- package/dist/movethewheels/pages/SettingsPage.d.ts +4 -0
- package/dist/movethewheels/pages/TrackingPage.d.ts +6 -0
- package/dist/movethewheels/pages/VehicleDetailsPage.d.ts +4 -0
- package/dist/movethewheels/pages/VehiclesPage.d.ts +4 -0
- package/dist/movethewheels/pages/WarehouseDetailsPage.d.ts +4 -0
- package/dist/movethewheels/pages/WarehousesPage.d.ts +4 -0
- package/dist/movethewheels/providers/MoveTheWheelsProvider.d.ts +16 -0
- package/dist/movethewheels/store/movethewheelsStore.d.ts +73 -0
- package/dist/movethewheels/types/index.d.ts +655 -0
- package/dist/movethewheels/utils/cn.d.ts +6 -0
- package/dist/movethewheels/utils/formatters.d.ts +60 -0
- package/dist/movethewheels/utils/graphqlClient.d.ts +11 -0
- package/dist/movethewheels/utils/index.d.ts +7 -0
- package/dist/movethewheels/utils/navigation.d.ts +23 -0
- package/dist/navigation-BgnOfsVd.js +6 -0
- package/dist/navigation-C2fY_aS9.js +8 -0
- package/dist/package-DVZbDRcV.js +22 -0
- package/dist/phone-KdwpVmC4.js +18 -0
- package/dist/plus-Bl7uX6Ji.js +11 -0
- package/dist/refresh-cw-BYjl3K-8.js +22 -0
- package/dist/route-Ce_poKFi.js +51 -0
- package/dist/save-C-qDVat-.js +18 -0
- package/dist/search-5pdn5eOO.js +13 -0
- package/dist/settings-C4kIDsYg.js +28 -0
- package/dist/square-pen-BwQ67vLE.js +11 -0
- package/dist/star-BlVsC3Ad.js +8 -0
- package/dist/store-DTmQT5M0.js +26 -0
- package/dist/trending-up-C1faflCI.js +11 -0
- package/dist/triangle-alert-CUoVAA4L.js +18 -0
- package/dist/truck-BmDAzu05.js +30 -0
- package/dist/useAnalytics-ph7eTIK6.js +297 -0
- package/dist/useCustomers-bS3a4ytk.js +186 -0
- package/dist/useFleet-BdETplNE.js +398 -0
- package/dist/useInventory-Dwn18FPz.js +323 -0
- package/dist/useOrders-D_3_hGMp.js +324 -0
- package/dist/useRoutes-v4aBaS-E.js +224 -0
- package/dist/useTracking-De2KIUNu.js +261 -0
- package/dist/user-BplzDrLP.js +13 -0
- package/dist/users-i-igmsP4.js +24 -0
- package/dist/warehouse-DewG0PXh.js +25 -0
- package/dist/wrench-CoSDEIC7.js +31 -0
- package/package.json +107 -0
- package/src/dev/main.tsx +110 -0
- package/src/dev/styles.css +139 -0
- package/src/generated/global-operations.ts +2 -0
- package/src/generated/global-types.ts +24048 -0
- package/src/generated/wspace-operations.ts +3734 -0
- package/src/generated/wspace-types.ts +60715 -0
- package/src/index.ts +4 -0
- package/src/movethewheels/MoveTheWheelsRoot.tsx +258 -0
- package/src/movethewheels/MoveTheWheelsRoutes.tsx +119 -0
- package/src/movethewheels/components/DataTable.tsx +367 -0
- package/src/movethewheels/components/MetricCard.tsx +180 -0
- package/src/movethewheels/components/PageLayout.tsx +234 -0
- package/src/movethewheels/components/StatusBadge.tsx +243 -0
- package/src/movethewheels/components/index.ts +26 -0
- package/src/movethewheels/components/ui.tsx +124 -0
- package/src/movethewheels/constants/index.ts +65 -0
- package/src/movethewheels/constants/mockData.ts +1342 -0
- package/src/movethewheels/hooks/index.ts +55 -0
- package/src/movethewheels/hooks/useAnalytics.ts +476 -0
- package/src/movethewheels/hooks/useCustomers.ts +359 -0
- package/src/movethewheels/hooks/useFleet.ts +778 -0
- package/src/movethewheels/hooks/useInventory.ts +632 -0
- package/src/movethewheels/hooks/useOrders.ts +703 -0
- package/src/movethewheels/hooks/useRoutes.ts +453 -0
- package/src/movethewheels/hooks/useTracking.ts +505 -0
- package/src/movethewheels/index.ts +68 -0
- package/src/movethewheels/pages/AIAssistantPage.tsx +160 -0
- package/src/movethewheels/pages/AnalyticsPage.tsx +190 -0
- package/src/movethewheels/pages/CreateOrderPage.tsx +454 -0
- package/src/movethewheels/pages/CustomerDetailsPage.tsx +207 -0
- package/src/movethewheels/pages/CustomersPage.tsx +115 -0
- package/src/movethewheels/pages/DashboardPage.tsx +414 -0
- package/src/movethewheels/pages/DriverDetailsPage.tsx +261 -0
- package/src/movethewheels/pages/DriversPage.tsx +118 -0
- package/src/movethewheels/pages/FinancePage.tsx +141 -0
- package/src/movethewheels/pages/FleetPage.tsx +289 -0
- package/src/movethewheels/pages/ImportExportPage.tsx +165 -0
- package/src/movethewheels/pages/InventoryPage.tsx +212 -0
- package/src/movethewheels/pages/LiveTrackingPage.tsx +325 -0
- package/src/movethewheels/pages/MarketplacePage.tsx +235 -0
- package/src/movethewheels/pages/OrderDetailsPage.tsx +387 -0
- package/src/movethewheels/pages/OrdersListPage.tsx +241 -0
- package/src/movethewheels/pages/ProductDetailsPage.tsx +155 -0
- package/src/movethewheels/pages/ProductsPage.tsx +124 -0
- package/src/movethewheels/pages/ReportsPage.tsx +164 -0
- package/src/movethewheels/pages/RouteDetailsPage.tsx +245 -0
- package/src/movethewheels/pages/RoutesPage.tsx +104 -0
- package/src/movethewheels/pages/SettingsPage.tsx +242 -0
- package/src/movethewheels/pages/TrackingPage.tsx +419 -0
- package/src/movethewheels/pages/VehicleDetailsPage.tsx +218 -0
- package/src/movethewheels/pages/VehiclesPage.tsx +124 -0
- package/src/movethewheels/pages/WarehouseDetailsPage.tsx +216 -0
- package/src/movethewheels/pages/WarehousesPage.tsx +122 -0
- package/src/movethewheels/providers/MoveTheWheelsProvider.tsx +66 -0
- package/src/movethewheels/store/movethewheelsStore.ts +136 -0
- package/src/movethewheels/types/index.ts +744 -0
- package/src/movethewheels/utils/cn.ts +9 -0
- package/src/movethewheels/utils/formatters.ts +215 -0
- package/src/movethewheels/utils/graphqlClient.ts +63 -0
- package/src/movethewheels/utils/index.ts +8 -0
- package/src/movethewheels/utils/navigation.ts +70 -0
- package/src/operations/global/.gitkeep +0 -0
- package/src/operations/wspace/movethewheels/fragments/core.graphql +191 -0
- package/src/operations/wspace/movethewheels/mutations/entities.graphql +87 -0
- package/src/operations/wspace/movethewheels/mutations/logistics.graphql +86 -0
- package/src/operations/wspace/movethewheels/mutations/marketplace-reports.graphql +81 -0
- package/src/operations/wspace/movethewheels/mutations/orders.graphql +21 -0
- package/src/operations/wspace/movethewheels/queries/dashboard.graphql +61 -0
- package/src/operations/wspace/movethewheels/queries/entities.graphql +83 -0
- package/src/operations/wspace/movethewheels/queries/logistics.graphql +84 -0
- package/src/operations/wspace/movethewheels/queries/marketplace-reports.graphql +40 -0
- package/src/operations/wspace/movethewheels/queries/orders.graphql +43 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
3
|
+
import type { Customer, CustomerFilter } from '../types';
|
|
4
|
+
import { executeGraphQL } from '../utils/graphqlClient';
|
|
5
|
+
|
|
6
|
+
interface UseCustomersOptions {
|
|
7
|
+
filters?: CustomerFilter;
|
|
8
|
+
limit?: number;
|
|
9
|
+
offset?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface UseCustomersResult {
|
|
13
|
+
customers: Customer[];
|
|
14
|
+
totalCustomers: number;
|
|
15
|
+
isLoading: boolean;
|
|
16
|
+
error: Error | null;
|
|
17
|
+
refetch: () => void;
|
|
18
|
+
createCustomer: (customer: Partial<Customer>) => Promise<Customer>;
|
|
19
|
+
updateCustomer: (id: string, updates: Partial<Customer>) => Promise<Customer>;
|
|
20
|
+
deleteCustomer: (id: string) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ApiCustomer {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
email?: string | null;
|
|
27
|
+
phone?: string | null;
|
|
28
|
+
type: string;
|
|
29
|
+
company?: string | null;
|
|
30
|
+
address?: Record<string, unknown> | null;
|
|
31
|
+
businessLicense?: string | null;
|
|
32
|
+
taxId?: string | null;
|
|
33
|
+
rating?: number | null;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
updatedAt: string;
|
|
36
|
+
deletedAt?: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const LIST_CUSTOMERS_QUERY = `
|
|
40
|
+
query ListCustomers($filter: CustomerFilterInput, $pagination: PaginationInput) {
|
|
41
|
+
customers(filter: $filter, pagination: $pagination) {
|
|
42
|
+
id
|
|
43
|
+
name
|
|
44
|
+
email
|
|
45
|
+
phone
|
|
46
|
+
type
|
|
47
|
+
company
|
|
48
|
+
address
|
|
49
|
+
businessLicense
|
|
50
|
+
taxId
|
|
51
|
+
rating
|
|
52
|
+
createdAt
|
|
53
|
+
updatedAt
|
|
54
|
+
deletedAt
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
const GET_CUSTOMER_QUERY = `
|
|
60
|
+
query GetCustomer($id: ID!) {
|
|
61
|
+
customer(id: $id) {
|
|
62
|
+
id
|
|
63
|
+
name
|
|
64
|
+
email
|
|
65
|
+
phone
|
|
66
|
+
type
|
|
67
|
+
company
|
|
68
|
+
address
|
|
69
|
+
businessLicense
|
|
70
|
+
taxId
|
|
71
|
+
rating
|
|
72
|
+
createdAt
|
|
73
|
+
updatedAt
|
|
74
|
+
deletedAt
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
const CREATE_CUSTOMER_MUTATION = `
|
|
80
|
+
mutation CreateCustomer($input: CreateCustomerInput!) {
|
|
81
|
+
createCustomer(input: $input) {
|
|
82
|
+
id
|
|
83
|
+
name
|
|
84
|
+
email
|
|
85
|
+
phone
|
|
86
|
+
type
|
|
87
|
+
company
|
|
88
|
+
address
|
|
89
|
+
businessLicense
|
|
90
|
+
taxId
|
|
91
|
+
rating
|
|
92
|
+
createdAt
|
|
93
|
+
updatedAt
|
|
94
|
+
deletedAt
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
|
|
99
|
+
const UPDATE_CUSTOMER_MUTATION = `
|
|
100
|
+
mutation UpdateCustomer($id: ID!, $input: UpdateCustomerInput!) {
|
|
101
|
+
updateCustomer(id: $id, input: $input) {
|
|
102
|
+
id
|
|
103
|
+
name
|
|
104
|
+
email
|
|
105
|
+
phone
|
|
106
|
+
type
|
|
107
|
+
company
|
|
108
|
+
address
|
|
109
|
+
businessLicense
|
|
110
|
+
taxId
|
|
111
|
+
rating
|
|
112
|
+
createdAt
|
|
113
|
+
updatedAt
|
|
114
|
+
deletedAt
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
const DELETE_CUSTOMER_MUTATION = `
|
|
120
|
+
mutation DeleteCustomer($id: ID!) {
|
|
121
|
+
deleteCustomer(id: $id)
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
|
|
125
|
+
function mapCustomer(customer: ApiCustomer): Customer {
|
|
126
|
+
return {
|
|
127
|
+
id: customer.id,
|
|
128
|
+
name: customer.name,
|
|
129
|
+
email: customer.email ?? '',
|
|
130
|
+
phone: customer.phone ?? '',
|
|
131
|
+
type: customer.type.toLowerCase() === 'b2b' ? 'b2b' : 'b2c',
|
|
132
|
+
company: customer.company ?? undefined,
|
|
133
|
+
address: {
|
|
134
|
+
street: '',
|
|
135
|
+
city: '',
|
|
136
|
+
state: '',
|
|
137
|
+
postalCode: '',
|
|
138
|
+
country: '',
|
|
139
|
+
...(customer.address ?? {}),
|
|
140
|
+
},
|
|
141
|
+
businessLicense: customer.businessLicense ?? undefined,
|
|
142
|
+
taxId: customer.taxId ?? undefined,
|
|
143
|
+
preferredContactMethod: 'email',
|
|
144
|
+
marketingOptIn: false,
|
|
145
|
+
isActive: !customer.deletedAt,
|
|
146
|
+
rating: customer.rating ?? 0,
|
|
147
|
+
createdAt: new Date(customer.createdAt),
|
|
148
|
+
updatedAt: new Date(customer.updatedAt),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function useCustomers(options: UseCustomersOptions = {}): UseCustomersResult {
|
|
153
|
+
const { filters: rawFilters, limit = 20, offset = 0 } = options;
|
|
154
|
+
// Stabilize filters by its structural fields so the load callback's inferred
|
|
155
|
+
// `filters` dependency (React Compiler) matches a stable reference and the
|
|
156
|
+
// effect does not re-run on every parent render.
|
|
157
|
+
const filters = useMemo(
|
|
158
|
+
() => rawFilters,
|
|
159
|
+
[rawFilters?.isActive, rawFilters?.search, rawFilters?.type]
|
|
160
|
+
);
|
|
161
|
+
const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
|
|
162
|
+
useMoveTheWheels();
|
|
163
|
+
|
|
164
|
+
const [customers, setCustomers] = useState<Customer[]>([]);
|
|
165
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
166
|
+
const [error, setError] = useState<Error | null>(null);
|
|
167
|
+
|
|
168
|
+
const graphQLOptions = useMemo(
|
|
169
|
+
() => ({
|
|
170
|
+
apiGatewayUrl,
|
|
171
|
+
authToken,
|
|
172
|
+
workspaceToken,
|
|
173
|
+
workspaceId,
|
|
174
|
+
tenantId,
|
|
175
|
+
actorId: currentUser?.id,
|
|
176
|
+
}),
|
|
177
|
+
[apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const loadCustomers = useCallback(async () => {
|
|
181
|
+
setIsLoading(true);
|
|
182
|
+
setError(null);
|
|
183
|
+
try {
|
|
184
|
+
const data = await executeGraphQL<{
|
|
185
|
+
customers: ApiCustomer[];
|
|
186
|
+
}>(graphQLOptions, LIST_CUSTOMERS_QUERY, {
|
|
187
|
+
filter: {
|
|
188
|
+
type: filters?.type,
|
|
189
|
+
search: filters?.search,
|
|
190
|
+
},
|
|
191
|
+
pagination: { limit, offset },
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
let mapped = data.customers.map(mapCustomer);
|
|
195
|
+
if (filters?.isActive !== undefined) {
|
|
196
|
+
mapped = mapped.filter((item) => item.isActive === filters.isActive);
|
|
197
|
+
}
|
|
198
|
+
setCustomers(mapped);
|
|
199
|
+
} catch (fetchError) {
|
|
200
|
+
setError(fetchError instanceof Error ? fetchError : new Error('Failed to load customers'));
|
|
201
|
+
} finally {
|
|
202
|
+
setIsLoading(false);
|
|
203
|
+
}
|
|
204
|
+
}, [filters, graphQLOptions, limit, offset]);
|
|
205
|
+
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
void loadCustomers();
|
|
208
|
+
}, [loadCustomers]);
|
|
209
|
+
|
|
210
|
+
const refetch = useCallback(() => {
|
|
211
|
+
void loadCustomers();
|
|
212
|
+
}, [loadCustomers]);
|
|
213
|
+
|
|
214
|
+
const createCustomer = useCallback(
|
|
215
|
+
async (customerData: Partial<Customer>): Promise<Customer> => {
|
|
216
|
+
const data = await executeGraphQL<{
|
|
217
|
+
createCustomer: ApiCustomer;
|
|
218
|
+
}>(graphQLOptions, CREATE_CUSTOMER_MUTATION, {
|
|
219
|
+
input: {
|
|
220
|
+
name: customerData.name,
|
|
221
|
+
email: customerData.email,
|
|
222
|
+
phone: customerData.phone,
|
|
223
|
+
type: customerData.type ?? 'b2c',
|
|
224
|
+
company: customerData.company,
|
|
225
|
+
address: customerData.address,
|
|
226
|
+
businessLicense: customerData.businessLicense,
|
|
227
|
+
taxId: customerData.taxId,
|
|
228
|
+
rating: customerData.rating,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const created = mapCustomer(data.createCustomer);
|
|
233
|
+
setCustomers((previous) => [created, ...previous]);
|
|
234
|
+
return created;
|
|
235
|
+
},
|
|
236
|
+
[graphQLOptions]
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const updateCustomer = useCallback(
|
|
240
|
+
async (id: string, updates: Partial<Customer>): Promise<Customer> => {
|
|
241
|
+
const data = await executeGraphQL<{
|
|
242
|
+
updateCustomer: ApiCustomer;
|
|
243
|
+
}>(graphQLOptions, UPDATE_CUSTOMER_MUTATION, {
|
|
244
|
+
id,
|
|
245
|
+
input: {
|
|
246
|
+
name: updates.name,
|
|
247
|
+
email: updates.email,
|
|
248
|
+
phone: updates.phone,
|
|
249
|
+
type: updates.type,
|
|
250
|
+
company: updates.company,
|
|
251
|
+
address: updates.address,
|
|
252
|
+
businessLicense: updates.businessLicense,
|
|
253
|
+
taxId: updates.taxId,
|
|
254
|
+
rating: updates.rating,
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const updated = mapCustomer(data.updateCustomer);
|
|
259
|
+
setCustomers((previous) => previous.map((item) => (item.id === id ? updated : item)));
|
|
260
|
+
return updated;
|
|
261
|
+
},
|
|
262
|
+
[graphQLOptions]
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const deleteCustomer = useCallback(
|
|
266
|
+
async (id: string): Promise<void> => {
|
|
267
|
+
await executeGraphQL<{ deleteCustomer: boolean }>(graphQLOptions, DELETE_CUSTOMER_MUTATION, {
|
|
268
|
+
id,
|
|
269
|
+
});
|
|
270
|
+
setCustomers((previous) => previous.filter((item) => item.id !== id));
|
|
271
|
+
},
|
|
272
|
+
[graphQLOptions]
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
customers,
|
|
277
|
+
totalCustomers: customers.length,
|
|
278
|
+
isLoading,
|
|
279
|
+
error,
|
|
280
|
+
refetch,
|
|
281
|
+
createCustomer,
|
|
282
|
+
updateCustomer,
|
|
283
|
+
deleteCustomer,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export function useCustomer(customerId: string | undefined) {
|
|
288
|
+
const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
|
|
289
|
+
useMoveTheWheels();
|
|
290
|
+
const [customer, setCustomer] = useState<Customer | null>(null);
|
|
291
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
292
|
+
const [error, setError] = useState<Error | null>(null);
|
|
293
|
+
|
|
294
|
+
const graphQLOptions = useMemo(
|
|
295
|
+
() => ({
|
|
296
|
+
apiGatewayUrl,
|
|
297
|
+
authToken,
|
|
298
|
+
workspaceToken,
|
|
299
|
+
workspaceId,
|
|
300
|
+
tenantId,
|
|
301
|
+
actorId: currentUser?.id,
|
|
302
|
+
}),
|
|
303
|
+
[apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
const loadCustomer = useCallback(async () => {
|
|
307
|
+
if (!customerId) {
|
|
308
|
+
setCustomer(null);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
setIsLoading(true);
|
|
313
|
+
setError(null);
|
|
314
|
+
try {
|
|
315
|
+
const data = await executeGraphQL<{
|
|
316
|
+
customer: ApiCustomer | null;
|
|
317
|
+
}>(graphQLOptions, GET_CUSTOMER_QUERY, { id: customerId });
|
|
318
|
+
|
|
319
|
+
setCustomer(data.customer ? mapCustomer(data.customer) : null);
|
|
320
|
+
} catch (fetchError) {
|
|
321
|
+
setError(fetchError instanceof Error ? fetchError : new Error('Failed to load customer'));
|
|
322
|
+
} finally {
|
|
323
|
+
setIsLoading(false);
|
|
324
|
+
}
|
|
325
|
+
}, [customerId, graphQLOptions]);
|
|
326
|
+
|
|
327
|
+
useEffect(() => {
|
|
328
|
+
void loadCustomer();
|
|
329
|
+
}, [loadCustomer]);
|
|
330
|
+
|
|
331
|
+
const refetch = useCallback(() => {
|
|
332
|
+
void loadCustomer();
|
|
333
|
+
}, [loadCustomer]);
|
|
334
|
+
|
|
335
|
+
return { customer, isLoading, error, refetch };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function useCustomerStats() {
|
|
339
|
+
const { customers, isLoading, error } = useCustomers({ limit: 500, offset: 0 });
|
|
340
|
+
|
|
341
|
+
const stats = useMemo(() => {
|
|
342
|
+
const total = customers.length;
|
|
343
|
+
const b2b = customers.filter((item) => item.type === 'b2b').length;
|
|
344
|
+
const b2c = total - b2b;
|
|
345
|
+
const active = customers.filter((item) => item.isActive).length;
|
|
346
|
+
const totalRating = customers.reduce((sum, item) => sum + item.rating, 0);
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
total,
|
|
350
|
+
b2b,
|
|
351
|
+
b2c,
|
|
352
|
+
active,
|
|
353
|
+
inactive: total - active,
|
|
354
|
+
avgRating: total > 0 ? totalRating / total : 0,
|
|
355
|
+
};
|
|
356
|
+
}, [customers]);
|
|
357
|
+
|
|
358
|
+
return { stats, isLoading, error };
|
|
359
|
+
}
|