@instockng/api-client 1.0.5 → 1.0.7
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/dist/apps/backend/src/lib/meta-capi.d.ts +1 -1
- package/dist/apps/backend/src/lib/meta-capi.js +1 -1
- package/dist/apps/backend/src/lib/order-recovery.d.ts +86 -0
- package/dist/apps/backend/src/lib/order-recovery.js +7 -2
- package/dist/apps/backend/src/notifications/producers/meta-capi-producer.d.ts +7 -0
- package/dist/apps/backend/src/notifications/producers/meta-capi-producer.js +41 -0
- package/dist/apps/backend/src/routes/admin/orders.d.ts +310 -20
- package/dist/apps/backend/src/routes/admin/orders.js +26 -2
- package/dist/apps/backend/src/routes/public/orders.d.ts +288 -6
- package/dist/apps/backend/src/routes/public/orders.js +1 -1
- package/dist/apps/backend/src/validators/order.d.ts +6 -37
- package/dist/apps/backend/src/validators/order.js +6 -7
- package/dist/enum-types.d.ts +8 -0
- package/dist/enum-types.js +5 -0
- package/dist/fetchers/carts.js +5 -0
- package/dist/fetchers/orders.d.ts +258 -1
- package/dist/hooks/admin/abandoned-carts.js +12 -8
- package/dist/hooks/admin/brands.js +15 -10
- package/dist/hooks/admin/customers.js +3 -2
- package/dist/hooks/admin/delivery-zones.js +24 -16
- package/dist/hooks/admin/discount-codes.js +24 -16
- package/dist/hooks/admin/inventory.js +15 -10
- package/dist/hooks/admin/orders.d.ts +285 -3
- package/dist/hooks/admin/orders.js +24 -15
- package/dist/hooks/admin/products.js +15 -10
- package/dist/hooks/admin/stats.js +3 -2
- package/dist/hooks/admin/variants.js +18 -12
- package/dist/hooks/admin/warehouses.js +15 -10
- package/dist/hooks/public/orders.d.ts +258 -1
- package/dist/hooks/useApiConfig.d.ts +2 -1
- package/dist/hooks/useApiConfig.js +2 -2
- package/dist/packages/api-client/src/enum-types.d.ts +8 -0
- package/dist/packages/api-client/src/enum-types.js +5 -0
- package/dist/packages/api-client/src/fetchers/carts.js +5 -0
- package/dist/packages/api-client/src/fetchers/orders.d.ts +258 -1
- package/dist/packages/api-client/src/hooks/admin/orders.d.ts +285 -3
- package/dist/packages/api-client/src/hooks/admin/orders.js +7 -4
- package/dist/packages/api-client/src/hooks/public/orders.d.ts +258 -1
- package/dist/packages/api-client/src/rpc-client.d.ts +891 -319
- package/dist/packages/api-client/src/types.d.ts +1 -4
- package/dist/packages/api-client/src/utils/query-keys.d.ts +1 -1
- package/dist/packages/api-client/src/utils/query-keys.js +1 -1
- package/dist/provider.d.ts +7 -4
- package/dist/provider.js +5 -3
- package/dist/rpc-client.d.ts +891 -319
- package/dist/types.d.ts +1 -0
- package/dist/utils/query-keys.d.ts +1 -1
- package/dist/utils/query-keys.js +1 -1
- package/package.json +1 -1
|
@@ -10,12 +10,13 @@ import { useApiConfig } from '../useApiConfig';
|
|
|
10
10
|
* Hook to get inventory overview using admin RPC
|
|
11
11
|
*/
|
|
12
12
|
export function useListInventory(params, options) {
|
|
13
|
-
const { baseURL,
|
|
13
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
14
14
|
return useQueryUnwrapped({
|
|
15
15
|
queryKey: queryKeys.admin.inventory.list(params),
|
|
16
16
|
queryFn: async () => {
|
|
17
|
+
const token = await getAuthToken();
|
|
17
18
|
const clients = createAdminRpcClients(baseURL);
|
|
18
|
-
const res = await clients.inventory.index.$get({ query: params }, authHeaders(
|
|
19
|
+
const res = await clients.inventory.index.$get({ query: params }, authHeaders(token));
|
|
19
20
|
if (!res.ok)
|
|
20
21
|
throw new Error(`Failed to fetch inventory: ${res.statusText}`);
|
|
21
22
|
return res.json();
|
|
@@ -27,12 +28,13 @@ export function useListInventory(params, options) {
|
|
|
27
28
|
* Hook to adjust inventory using admin RPC
|
|
28
29
|
*/
|
|
29
30
|
export function useAdjustInventory(options) {
|
|
30
|
-
const { baseURL,
|
|
31
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
31
32
|
const queryClient = useQueryClient();
|
|
32
33
|
return useMutation({
|
|
33
34
|
mutationFn: async (data) => {
|
|
35
|
+
const token = await getAuthToken();
|
|
34
36
|
const clients = createAdminRpcClients(baseURL);
|
|
35
|
-
const res = await clients.inventory.adjust.$post({ json: data }, authHeaders(
|
|
37
|
+
const res = await clients.inventory.adjust.$post({ json: data }, authHeaders(token));
|
|
36
38
|
if (!res.ok)
|
|
37
39
|
throw new Error(`Failed to adjust inventory: ${res.statusText}`);
|
|
38
40
|
return res.json();
|
|
@@ -49,12 +51,13 @@ export function useAdjustInventory(options) {
|
|
|
49
51
|
* Hook to transfer inventory between warehouses using admin RPC
|
|
50
52
|
*/
|
|
51
53
|
export function useTransferInventory(options) {
|
|
52
|
-
const { baseURL,
|
|
54
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
53
55
|
const queryClient = useQueryClient();
|
|
54
56
|
return useMutation({
|
|
55
57
|
mutationFn: async (data) => {
|
|
58
|
+
const token = await getAuthToken();
|
|
56
59
|
const clients = createAdminRpcClients(baseURL);
|
|
57
|
-
const res = await clients.inventory.transfer.$post({ json: data }, authHeaders(
|
|
60
|
+
const res = await clients.inventory.transfer.$post({ json: data }, authHeaders(token));
|
|
58
61
|
if (!res.ok)
|
|
59
62
|
throw new Error(`Failed to transfer inventory: ${res.statusText}`);
|
|
60
63
|
return res.json();
|
|
@@ -70,12 +73,13 @@ export function useTransferInventory(options) {
|
|
|
70
73
|
* Hook to get inventory transaction history using admin RPC
|
|
71
74
|
*/
|
|
72
75
|
export function useGetInventoryTransactions(params, options) {
|
|
73
|
-
const { baseURL,
|
|
76
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
74
77
|
return useQueryUnwrapped({
|
|
75
78
|
queryKey: queryKeys.admin.inventory.transactions(params),
|
|
76
79
|
queryFn: async () => {
|
|
80
|
+
const token = await getAuthToken();
|
|
77
81
|
const clients = createAdminRpcClients(baseURL);
|
|
78
|
-
const res = await clients.inventory.transactions.$get({ query: params }, authHeaders(
|
|
82
|
+
const res = await clients.inventory.transactions.$get({ query: params }, authHeaders(token));
|
|
79
83
|
if (!res.ok)
|
|
80
84
|
throw new Error(`Failed to fetch inventory transactions: ${res.statusText}`);
|
|
81
85
|
return res.json();
|
|
@@ -87,12 +91,13 @@ export function useGetInventoryTransactions(params, options) {
|
|
|
87
91
|
* Hook to get low stock alerts using admin RPC
|
|
88
92
|
*/
|
|
89
93
|
export function useGetLowStockVariants(params, options) {
|
|
90
|
-
const { baseURL,
|
|
94
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
91
95
|
return useQueryUnwrapped({
|
|
92
96
|
queryKey: queryKeys.admin.inventory.lowStock(params?.brandId),
|
|
93
97
|
queryFn: async () => {
|
|
98
|
+
const token = await getAuthToken();
|
|
94
99
|
const clients = createAdminRpcClients(baseURL);
|
|
95
|
-
const res = await clients.inventory['low-stock'].$get({ query: params }, authHeaders(
|
|
100
|
+
const res = await clients.inventory['low-stock'].$get({ query: params }, authHeaders(token));
|
|
96
101
|
if (!res.ok)
|
|
97
102
|
throw new Error(`Failed to fetch low stock alerts: ${res.statusText}`);
|
|
98
103
|
return res.json();
|
|
@@ -9,14 +9,24 @@ import { createAdminRpcClients } from '../../rpc-client';
|
|
|
9
9
|
/**
|
|
10
10
|
* Hook to list all orders with pagination using admin RPC
|
|
11
11
|
*
|
|
12
|
+
* @param filters - Query parameters for filtering orders
|
|
12
13
|
* @param options - React Query options
|
|
13
14
|
*
|
|
14
15
|
* @example
|
|
15
16
|
* ```tsx
|
|
16
|
-
* const { data: orders, isLoading } = useListOrders();
|
|
17
|
+
* const { data: orders, isLoading } = useListOrders({ search: 'john', page: 1 });
|
|
17
18
|
* ```
|
|
18
19
|
*/
|
|
19
|
-
export declare function useListOrders(
|
|
20
|
+
export declare function useListOrders(filters?: {
|
|
21
|
+
page?: number;
|
|
22
|
+
limit?: number;
|
|
23
|
+
brandId?: string;
|
|
24
|
+
status?: string;
|
|
25
|
+
paymentMethod?: string;
|
|
26
|
+
search?: string;
|
|
27
|
+
startDate?: string;
|
|
28
|
+
endDate?: string;
|
|
29
|
+
}, options?: Omit<UseQueryOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['orders']['index']['$get']>>['json']>>, Error>, 'queryKey' | 'queryFn'>): import("@tanstack/react-query").UseQueryResult<{
|
|
20
30
|
data: {
|
|
21
31
|
subtotal: number;
|
|
22
32
|
deliveryCharge: number;
|
|
@@ -1370,7 +1380,279 @@ export declare function useUpdateOrder(orderId: string, options?: UseMutationOpt
|
|
|
1370
1380
|
* @param orderId - Order UUID
|
|
1371
1381
|
* @param options - React Query mutation options
|
|
1372
1382
|
*/
|
|
1373
|
-
export declare function useUpdateOrderStatus(orderId: string, options?: UseMutationOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['orders'][':id']['status']['$patch']>>['json']>>, Error, any>): import("@tanstack/react-query").UseMutationResult<
|
|
1383
|
+
export declare function useUpdateOrderStatus(orderId: string, options?: UseMutationOptions<Awaited<ReturnType<Awaited<ReturnType<ReturnType<typeof createAdminRpcClients>['orders'][':id']['status']['$patch']>>['json']>>, Error, any>): import("@tanstack/react-query").UseMutationResult<{
|
|
1384
|
+
subtotal: number;
|
|
1385
|
+
deliveryCharge: number;
|
|
1386
|
+
totalPrice: number;
|
|
1387
|
+
discountAmount: number;
|
|
1388
|
+
createdAt: string;
|
|
1389
|
+
updatedAt: string;
|
|
1390
|
+
deletedAt: string;
|
|
1391
|
+
prospectSince: string;
|
|
1392
|
+
lastRecoveryAttemptAt: string;
|
|
1393
|
+
brand: {
|
|
1394
|
+
createdAt: string;
|
|
1395
|
+
updatedAt: string;
|
|
1396
|
+
deletedAt: string;
|
|
1397
|
+
name: string;
|
|
1398
|
+
id: string;
|
|
1399
|
+
slug: string;
|
|
1400
|
+
logoUrl: string | null;
|
|
1401
|
+
siteUrl: string;
|
|
1402
|
+
domain: string;
|
|
1403
|
+
metaPixelId: string | null;
|
|
1404
|
+
};
|
|
1405
|
+
deliveryZone: {
|
|
1406
|
+
deliveryCost: number;
|
|
1407
|
+
freeShippingThreshold: number;
|
|
1408
|
+
createdAt: string;
|
|
1409
|
+
updatedAt: string;
|
|
1410
|
+
deletedAt: string;
|
|
1411
|
+
state: {
|
|
1412
|
+
createdAt: string;
|
|
1413
|
+
updatedAt: string;
|
|
1414
|
+
deletedAt: string;
|
|
1415
|
+
name: string;
|
|
1416
|
+
id: string;
|
|
1417
|
+
isActive: boolean;
|
|
1418
|
+
};
|
|
1419
|
+
name: string;
|
|
1420
|
+
id: string;
|
|
1421
|
+
brandId: string | null;
|
|
1422
|
+
stateId: string;
|
|
1423
|
+
allowCOD: boolean;
|
|
1424
|
+
allowOnline: boolean;
|
|
1425
|
+
waybillOnly: boolean;
|
|
1426
|
+
estimatedDays: number | null;
|
|
1427
|
+
isActive: boolean;
|
|
1428
|
+
};
|
|
1429
|
+
items: {
|
|
1430
|
+
priceAtPurchase: number;
|
|
1431
|
+
variant: {
|
|
1432
|
+
price: number;
|
|
1433
|
+
createdAt: string;
|
|
1434
|
+
updatedAt: string;
|
|
1435
|
+
deletedAt: string;
|
|
1436
|
+
product: {
|
|
1437
|
+
createdAt: string;
|
|
1438
|
+
updatedAt: string;
|
|
1439
|
+
deletedAt: string;
|
|
1440
|
+
name: string;
|
|
1441
|
+
id: string;
|
|
1442
|
+
slug: string;
|
|
1443
|
+
brandId: string;
|
|
1444
|
+
isActive: boolean;
|
|
1445
|
+
description: string | null;
|
|
1446
|
+
thumbnailUrl: string | null;
|
|
1447
|
+
quantityDiscounts: string | number | boolean | {
|
|
1448
|
+
[x: string]: string | number | boolean | /*elided*/ any | {
|
|
1449
|
+
[x: number]: string | number | boolean | /*elided*/ any | /*elided*/ any;
|
|
1450
|
+
length: number;
|
|
1451
|
+
toString: never;
|
|
1452
|
+
toLocaleString: never;
|
|
1453
|
+
pop: never;
|
|
1454
|
+
push: never;
|
|
1455
|
+
concat: never;
|
|
1456
|
+
join: never;
|
|
1457
|
+
reverse: never;
|
|
1458
|
+
shift: never;
|
|
1459
|
+
slice: never;
|
|
1460
|
+
sort: never;
|
|
1461
|
+
splice: never;
|
|
1462
|
+
unshift: never;
|
|
1463
|
+
indexOf: never;
|
|
1464
|
+
lastIndexOf: never;
|
|
1465
|
+
every: never;
|
|
1466
|
+
some: never;
|
|
1467
|
+
forEach: never;
|
|
1468
|
+
map: never;
|
|
1469
|
+
filter: never;
|
|
1470
|
+
reduce: never;
|
|
1471
|
+
reduceRight: never;
|
|
1472
|
+
find: never;
|
|
1473
|
+
findIndex: never;
|
|
1474
|
+
fill: never;
|
|
1475
|
+
copyWithin: never;
|
|
1476
|
+
entries: never;
|
|
1477
|
+
keys: never;
|
|
1478
|
+
values: never;
|
|
1479
|
+
includes: never;
|
|
1480
|
+
flatMap: never;
|
|
1481
|
+
flat: never;
|
|
1482
|
+
[Symbol.iterator]: never;
|
|
1483
|
+
readonly [Symbol.unscopables]: {
|
|
1484
|
+
[x: number]: boolean;
|
|
1485
|
+
length?: boolean;
|
|
1486
|
+
toString?: boolean;
|
|
1487
|
+
toLocaleString?: boolean;
|
|
1488
|
+
pop?: boolean;
|
|
1489
|
+
push?: boolean;
|
|
1490
|
+
concat?: boolean;
|
|
1491
|
+
join?: boolean;
|
|
1492
|
+
reverse?: boolean;
|
|
1493
|
+
shift?: boolean;
|
|
1494
|
+
slice?: boolean;
|
|
1495
|
+
sort?: boolean;
|
|
1496
|
+
splice?: boolean;
|
|
1497
|
+
unshift?: boolean;
|
|
1498
|
+
indexOf?: boolean;
|
|
1499
|
+
lastIndexOf?: boolean;
|
|
1500
|
+
every?: boolean;
|
|
1501
|
+
some?: boolean;
|
|
1502
|
+
forEach?: boolean;
|
|
1503
|
+
map?: boolean;
|
|
1504
|
+
filter?: boolean;
|
|
1505
|
+
reduce?: boolean;
|
|
1506
|
+
reduceRight?: boolean;
|
|
1507
|
+
find?: boolean;
|
|
1508
|
+
findIndex?: boolean;
|
|
1509
|
+
fill?: boolean;
|
|
1510
|
+
copyWithin?: boolean;
|
|
1511
|
+
entries?: boolean;
|
|
1512
|
+
keys?: boolean;
|
|
1513
|
+
values?: boolean;
|
|
1514
|
+
includes?: boolean;
|
|
1515
|
+
flatMap?: boolean;
|
|
1516
|
+
flat?: boolean;
|
|
1517
|
+
};
|
|
1518
|
+
};
|
|
1519
|
+
} | {
|
|
1520
|
+
[x: number]: string | number | boolean | {
|
|
1521
|
+
[x: string]: string | number | boolean | /*elided*/ any | /*elided*/ any;
|
|
1522
|
+
} | /*elided*/ any;
|
|
1523
|
+
length: number;
|
|
1524
|
+
toString: never;
|
|
1525
|
+
toLocaleString: never;
|
|
1526
|
+
pop: never;
|
|
1527
|
+
push: never;
|
|
1528
|
+
concat: never;
|
|
1529
|
+
join: never;
|
|
1530
|
+
reverse: never;
|
|
1531
|
+
shift: never;
|
|
1532
|
+
slice: never;
|
|
1533
|
+
sort: never;
|
|
1534
|
+
splice: never;
|
|
1535
|
+
unshift: never;
|
|
1536
|
+
indexOf: never;
|
|
1537
|
+
lastIndexOf: never;
|
|
1538
|
+
every: never;
|
|
1539
|
+
some: never;
|
|
1540
|
+
forEach: never;
|
|
1541
|
+
map: never;
|
|
1542
|
+
filter: never;
|
|
1543
|
+
reduce: never;
|
|
1544
|
+
reduceRight: never;
|
|
1545
|
+
find: never;
|
|
1546
|
+
findIndex: never;
|
|
1547
|
+
fill: never;
|
|
1548
|
+
copyWithin: never;
|
|
1549
|
+
entries: never;
|
|
1550
|
+
keys: never;
|
|
1551
|
+
values: never;
|
|
1552
|
+
includes: never;
|
|
1553
|
+
flatMap: never;
|
|
1554
|
+
flat: never;
|
|
1555
|
+
[Symbol.iterator]: never;
|
|
1556
|
+
readonly [Symbol.unscopables]: {
|
|
1557
|
+
[x: number]: boolean;
|
|
1558
|
+
length?: boolean;
|
|
1559
|
+
toString?: boolean;
|
|
1560
|
+
toLocaleString?: boolean;
|
|
1561
|
+
pop?: boolean;
|
|
1562
|
+
push?: boolean;
|
|
1563
|
+
concat?: boolean;
|
|
1564
|
+
join?: boolean;
|
|
1565
|
+
reverse?: boolean;
|
|
1566
|
+
shift?: boolean;
|
|
1567
|
+
slice?: boolean;
|
|
1568
|
+
sort?: boolean;
|
|
1569
|
+
splice?: boolean;
|
|
1570
|
+
unshift?: boolean;
|
|
1571
|
+
indexOf?: boolean;
|
|
1572
|
+
lastIndexOf?: boolean;
|
|
1573
|
+
every?: boolean;
|
|
1574
|
+
some?: boolean;
|
|
1575
|
+
forEach?: boolean;
|
|
1576
|
+
map?: boolean;
|
|
1577
|
+
filter?: boolean;
|
|
1578
|
+
reduce?: boolean;
|
|
1579
|
+
reduceRight?: boolean;
|
|
1580
|
+
find?: boolean;
|
|
1581
|
+
findIndex?: boolean;
|
|
1582
|
+
fill?: boolean;
|
|
1583
|
+
copyWithin?: boolean;
|
|
1584
|
+
entries?: boolean;
|
|
1585
|
+
keys?: boolean;
|
|
1586
|
+
values?: boolean;
|
|
1587
|
+
includes?: boolean;
|
|
1588
|
+
flatMap?: boolean;
|
|
1589
|
+
flat?: boolean;
|
|
1590
|
+
};
|
|
1591
|
+
};
|
|
1592
|
+
};
|
|
1593
|
+
name: string | null;
|
|
1594
|
+
id: string;
|
|
1595
|
+
isActive: boolean;
|
|
1596
|
+
thumbnailUrl: string | null;
|
|
1597
|
+
productId: string;
|
|
1598
|
+
sku: string;
|
|
1599
|
+
trackInventory: boolean;
|
|
1600
|
+
lowStockThreshold: number | null;
|
|
1601
|
+
};
|
|
1602
|
+
warehouse: {
|
|
1603
|
+
createdAt: string;
|
|
1604
|
+
updatedAt: string;
|
|
1605
|
+
deletedAt: string;
|
|
1606
|
+
name: string;
|
|
1607
|
+
id: string;
|
|
1608
|
+
isActive: boolean;
|
|
1609
|
+
address: string | null;
|
|
1610
|
+
city: string | null;
|
|
1611
|
+
state: string | null;
|
|
1612
|
+
};
|
|
1613
|
+
id: string;
|
|
1614
|
+
orderId: string;
|
|
1615
|
+
variantId: string;
|
|
1616
|
+
warehouseId: string | null;
|
|
1617
|
+
quantity: number;
|
|
1618
|
+
}[];
|
|
1619
|
+
id: string;
|
|
1620
|
+
email: string | null;
|
|
1621
|
+
brandId: string;
|
|
1622
|
+
deliveryZoneId: string;
|
|
1623
|
+
recoveryAttempts: number;
|
|
1624
|
+
recoveryDiscountCodeId: string | null;
|
|
1625
|
+
wasRecovered: boolean;
|
|
1626
|
+
estimatedDays: number | null;
|
|
1627
|
+
orderNumber: number;
|
|
1628
|
+
firstName: string;
|
|
1629
|
+
lastName: string;
|
|
1630
|
+
phone: string;
|
|
1631
|
+
address: string;
|
|
1632
|
+
city: string;
|
|
1633
|
+
discountCodeId: string | null;
|
|
1634
|
+
paymentMethod: import("@prisma/client").$Enums.PaymentMethod;
|
|
1635
|
+
paystackReference: string | null;
|
|
1636
|
+
status: import("@prisma/client").$Enums.OrderStatus;
|
|
1637
|
+
cancellationReason: string | null;
|
|
1638
|
+
prospectReason: import("@prisma/client").$Enums.ProspectReason | null;
|
|
1639
|
+
userActionToken: string;
|
|
1640
|
+
} | {
|
|
1641
|
+
error: {
|
|
1642
|
+
code: string;
|
|
1643
|
+
message: string;
|
|
1644
|
+
};
|
|
1645
|
+
} | {
|
|
1646
|
+
error: {
|
|
1647
|
+
code: string;
|
|
1648
|
+
message: string;
|
|
1649
|
+
};
|
|
1650
|
+
} | {
|
|
1651
|
+
error: {
|
|
1652
|
+
code: string;
|
|
1653
|
+
message: string;
|
|
1654
|
+
};
|
|
1655
|
+
}, Error, any, unknown>;
|
|
1374
1656
|
/**
|
|
1375
1657
|
* Hook to delete an order using admin RPC
|
|
1376
1658
|
*
|
|
@@ -12,20 +12,24 @@ import { useApiConfig } from '../useApiConfig';
|
|
|
12
12
|
/**
|
|
13
13
|
* Hook to list all orders with pagination using admin RPC
|
|
14
14
|
*
|
|
15
|
+
* @param filters - Query parameters for filtering orders
|
|
15
16
|
* @param options - React Query options
|
|
16
17
|
*
|
|
17
18
|
* @example
|
|
18
19
|
* ```tsx
|
|
19
|
-
* const { data: orders, isLoading } = useListOrders();
|
|
20
|
+
* const { data: orders, isLoading } = useListOrders({ search: 'john', page: 1 });
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
|
-
export function useListOrders(options) {
|
|
23
|
-
const { baseURL,
|
|
23
|
+
export function useListOrders(filters, options) {
|
|
24
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
24
25
|
return useQueryUnwrapped({
|
|
25
|
-
queryKey: queryKeys.admin.orders.list(),
|
|
26
|
+
queryKey: queryKeys.admin.orders.list(filters),
|
|
26
27
|
queryFn: async () => {
|
|
28
|
+
const token = await getAuthToken();
|
|
27
29
|
const clients = createAdminRpcClients(baseURL);
|
|
28
|
-
|
|
30
|
+
// Clean undefined values from filters
|
|
31
|
+
const cleanFilters = filters ? Object.fromEntries(Object.entries(filters).filter(([_, v]) => v !== undefined)) : undefined;
|
|
32
|
+
const res = await clients.orders.index.$get({ query: cleanFilters }, authHeaders(token));
|
|
29
33
|
if (!res.ok) {
|
|
30
34
|
throw new Error(`Failed to fetch orders: ${res.statusText}`);
|
|
31
35
|
}
|
|
@@ -46,12 +50,13 @@ export function useListOrders(options) {
|
|
|
46
50
|
* ```
|
|
47
51
|
*/
|
|
48
52
|
export function useGetOrder(orderId, options) {
|
|
49
|
-
const { baseURL,
|
|
53
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
50
54
|
return useQueryUnwrapped({
|
|
51
55
|
queryKey: queryKeys.admin.orders.detail(orderId),
|
|
52
56
|
queryFn: async () => {
|
|
57
|
+
const token = await getAuthToken();
|
|
53
58
|
const clients = createAdminRpcClients(baseURL);
|
|
54
|
-
const res = await clients.orders[':id'].$get({ param: { id: orderId } }, authHeaders(
|
|
59
|
+
const res = await clients.orders[':id'].$get({ param: { id: orderId } }, authHeaders(token));
|
|
55
60
|
if (!res.ok) {
|
|
56
61
|
throw new Error(`Failed to fetch order: ${res.statusText}`);
|
|
57
62
|
}
|
|
@@ -76,12 +81,13 @@ export function useGetOrder(orderId, options) {
|
|
|
76
81
|
* ```
|
|
77
82
|
*/
|
|
78
83
|
export function useCreateOrder(options) {
|
|
79
|
-
const { baseURL,
|
|
84
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
80
85
|
const queryClient = useQueryClient();
|
|
81
86
|
return useMutation({
|
|
82
87
|
mutationFn: async (data) => {
|
|
88
|
+
const token = await getAuthToken();
|
|
83
89
|
const clients = createAdminRpcClients(baseURL);
|
|
84
|
-
const res = await clients.orders.index.$post({ json: data }, authHeaders(
|
|
90
|
+
const res = await clients.orders.index.$post({ json: data }, authHeaders(token));
|
|
85
91
|
if (!res.ok) {
|
|
86
92
|
throw new Error(`Failed to create order: ${res.statusText}`);
|
|
87
93
|
}
|
|
@@ -100,12 +106,13 @@ export function useCreateOrder(options) {
|
|
|
100
106
|
* @param options - React Query mutation options
|
|
101
107
|
*/
|
|
102
108
|
export function useUpdateOrder(orderId, options) {
|
|
103
|
-
const { baseURL,
|
|
109
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
104
110
|
const queryClient = useQueryClient();
|
|
105
111
|
return useMutation({
|
|
106
112
|
mutationFn: async (data) => {
|
|
113
|
+
const token = await getAuthToken();
|
|
107
114
|
const clients = createAdminRpcClients(baseURL);
|
|
108
|
-
const res = await clients.orders[':id'].$patch({ param: { id: orderId }, json: data }, authHeaders(
|
|
115
|
+
const res = await clients.orders[':id'].$patch({ param: { id: orderId }, json: data }, authHeaders(token));
|
|
109
116
|
if (!res.ok) {
|
|
110
117
|
throw new Error(`Failed to update order: ${res.statusText}`);
|
|
111
118
|
}
|
|
@@ -125,12 +132,13 @@ export function useUpdateOrder(orderId, options) {
|
|
|
125
132
|
* @param options - React Query mutation options
|
|
126
133
|
*/
|
|
127
134
|
export function useUpdateOrderStatus(orderId, options) {
|
|
128
|
-
const { baseURL,
|
|
135
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
129
136
|
const queryClient = useQueryClient();
|
|
130
137
|
return useMutation({
|
|
131
138
|
mutationFn: async (data) => {
|
|
139
|
+
const token = await getAuthToken();
|
|
132
140
|
const clients = createAdminRpcClients(baseURL);
|
|
133
|
-
const res = await clients.orders[':id'].status.$patch({ param: { id: orderId }, json: data }, authHeaders(
|
|
141
|
+
const res = await clients.orders[':id'].status.$patch({ param: { id: orderId }, json: data }, authHeaders(token));
|
|
134
142
|
if (!res.ok) {
|
|
135
143
|
throw new Error(`Failed to update order status: ${res.statusText}`);
|
|
136
144
|
}
|
|
@@ -150,12 +158,13 @@ export function useUpdateOrderStatus(orderId, options) {
|
|
|
150
158
|
* @param options - React Query mutation options
|
|
151
159
|
*/
|
|
152
160
|
export function useDeleteOrder(orderId, options) {
|
|
153
|
-
const { baseURL,
|
|
161
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
154
162
|
const queryClient = useQueryClient();
|
|
155
163
|
return useMutation({
|
|
156
164
|
mutationFn: async () => {
|
|
165
|
+
const token = await getAuthToken();
|
|
157
166
|
const clients = createAdminRpcClients(baseURL);
|
|
158
|
-
const res = await clients.orders[':id'].$delete({ param: { id: orderId } }, authHeaders(
|
|
167
|
+
const res = await clients.orders[':id'].$delete({ param: { id: orderId } }, authHeaders(token));
|
|
159
168
|
if (!res.ok) {
|
|
160
169
|
throw new Error(`Failed to delete order: ${res.statusText}`);
|
|
161
170
|
}
|
|
@@ -7,12 +7,13 @@ import { createAdminRpcClients, authHeaders } from '../../rpc-client';
|
|
|
7
7
|
import { queryKeys } from '../../utils/query-keys';
|
|
8
8
|
import { useApiConfig } from '../useApiConfig';
|
|
9
9
|
export function useListProducts(brandId, options) {
|
|
10
|
-
const { baseURL,
|
|
10
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
11
11
|
return useQueryUnwrapped({
|
|
12
12
|
queryKey: queryKeys.admin.products.list(brandId),
|
|
13
13
|
queryFn: async () => {
|
|
14
|
+
const token = await getAuthToken();
|
|
14
15
|
const clients = createAdminRpcClients(baseURL);
|
|
15
|
-
const res = await clients.products.index.$get(brandId ? { query: { brandId } } : {}, authHeaders(
|
|
16
|
+
const res = await clients.products.index.$get(brandId ? { query: { brandId } } : {}, authHeaders(token));
|
|
16
17
|
if (!res.ok)
|
|
17
18
|
throw new Error(`Failed to fetch products: ${res.statusText}`);
|
|
18
19
|
return res.json();
|
|
@@ -21,12 +22,13 @@ export function useListProducts(brandId, options) {
|
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
export function useGetProduct(productId, options) {
|
|
24
|
-
const { baseURL,
|
|
25
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
25
26
|
return useQueryUnwrapped({
|
|
26
27
|
queryKey: queryKeys.admin.products.detail(productId),
|
|
27
28
|
queryFn: async () => {
|
|
29
|
+
const token = await getAuthToken();
|
|
28
30
|
const clients = createAdminRpcClients(baseURL);
|
|
29
|
-
const res = await clients.products[':id'].$get({ param: { id: productId } }, authHeaders(
|
|
31
|
+
const res = await clients.products[':id'].$get({ param: { id: productId } }, authHeaders(token));
|
|
30
32
|
if (!res.ok)
|
|
31
33
|
throw new Error(`Failed to fetch product: ${res.statusText}`);
|
|
32
34
|
return res.json();
|
|
@@ -35,12 +37,13 @@ export function useGetProduct(productId, options) {
|
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
39
|
export function useCreateProduct(options) {
|
|
38
|
-
const { baseURL,
|
|
40
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
39
41
|
const queryClient = useQueryClient();
|
|
40
42
|
return useMutation({
|
|
41
43
|
mutationFn: async (data) => {
|
|
44
|
+
const token = await getAuthToken();
|
|
42
45
|
const clients = createAdminRpcClients(baseURL);
|
|
43
|
-
const res = await clients.products.index.$post({ json: data }, authHeaders(
|
|
46
|
+
const res = await clients.products.index.$post({ json: data }, authHeaders(token));
|
|
44
47
|
if (!res.ok)
|
|
45
48
|
throw new Error(`Failed to create product: ${res.statusText}`);
|
|
46
49
|
return res.json();
|
|
@@ -50,12 +53,13 @@ export function useCreateProduct(options) {
|
|
|
50
53
|
});
|
|
51
54
|
}
|
|
52
55
|
export function useUpdateProduct(productId, options) {
|
|
53
|
-
const { baseURL,
|
|
56
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
54
57
|
const queryClient = useQueryClient();
|
|
55
58
|
return useMutation({
|
|
56
59
|
mutationFn: async (data) => {
|
|
60
|
+
const token = await getAuthToken();
|
|
57
61
|
const clients = createAdminRpcClients(baseURL);
|
|
58
|
-
const res = await clients.products[':id'].$patch({ param: { id: productId }, json: data }, authHeaders(
|
|
62
|
+
const res = await clients.products[':id'].$patch({ param: { id: productId }, json: data }, authHeaders(token));
|
|
59
63
|
if (!res.ok)
|
|
60
64
|
throw new Error(`Failed to update product: ${res.statusText}`);
|
|
61
65
|
return res.json();
|
|
@@ -68,12 +72,13 @@ export function useUpdateProduct(productId, options) {
|
|
|
68
72
|
});
|
|
69
73
|
}
|
|
70
74
|
export function useDeleteProduct(productId, options) {
|
|
71
|
-
const { baseURL,
|
|
75
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
72
76
|
const queryClient = useQueryClient();
|
|
73
77
|
return useMutation({
|
|
74
78
|
mutationFn: async () => {
|
|
79
|
+
const token = await getAuthToken();
|
|
75
80
|
const clients = createAdminRpcClients(baseURL);
|
|
76
|
-
const res = await clients.products[':id'].$delete({ param: { id: productId } }, authHeaders(
|
|
81
|
+
const res = await clients.products[':id'].$delete({ param: { id: productId } }, authHeaders(token));
|
|
77
82
|
if (!res.ok)
|
|
78
83
|
throw new Error(`Failed to delete product: ${res.statusText}`);
|
|
79
84
|
return res.json();
|
|
@@ -9,12 +9,13 @@ import { useApiConfig } from '../useApiConfig';
|
|
|
9
9
|
* Hook to get dashboard statistics using admin RPC
|
|
10
10
|
*/
|
|
11
11
|
export function useGetStats(params, options) {
|
|
12
|
-
const { baseURL,
|
|
12
|
+
const { baseURL, getAuthToken } = useApiConfig();
|
|
13
13
|
return useQueryUnwrapped({
|
|
14
14
|
queryKey: queryKeys.admin.stats.overview(params?.brandId),
|
|
15
15
|
queryFn: async () => {
|
|
16
|
+
const token = await getAuthToken();
|
|
16
17
|
const clients = createAdminRpcClients(baseURL);
|
|
17
|
-
const res = await clients.stats.index.$get({ query: params }, authHeaders(
|
|
18
|
+
const res = await clients.stats.index.$get({ query: params }, authHeaders(token));
|
|
18
19
|
if (!res.ok)
|
|
19
20
|
throw new Error(`Failed to fetch statistics: ${res.statusText}`);
|
|
20
21
|
return res.json();
|