@smartbills/react-hooks-sdk 0.0.2-alpha.44 → 0.0.2-alpha.45
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/@types/index.d.ts +1424 -0
- package/dist/@types/index.d.ts.map +1 -0
- package/dist/cjs/apis/SBApiKeys.cjs +55 -0
- package/dist/cjs/apis/SBApiKeys.cjs.map +1 -0
- package/dist/cjs/apis/api-logs/LogsAPI.cjs +42 -0
- package/dist/cjs/apis/api-logs/LogsAPI.cjs.map +1 -0
- package/dist/cjs/apis/attachments/AttachmentsAPI.cjs +147 -0
- package/dist/cjs/apis/attachments/AttachmentsAPI.cjs.map +1 -0
- package/dist/cjs/apis/banks/accounts/BankAccountAPI.cjs +88 -0
- package/dist/cjs/apis/banks/accounts/BankAccountAPI.cjs.map +1 -0
- package/dist/cjs/apis/banks/bank-institutions/BankInstitutionsAPI.cjs +58 -0
- package/dist/cjs/apis/banks/bank-institutions/BankInstitutionsAPI.cjs.map +1 -0
- package/dist/cjs/apis/banks/bank-transactions/BankTransactionAPI.cjs +57 -0
- package/dist/cjs/apis/banks/bank-transactions/BankTransactionAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/BusinessAPI.cjs +172 -0
- package/dist/cjs/apis/business/BusinessAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/customers/CustomerAPI.cjs +161 -0
- package/dist/cjs/apis/business/customers/CustomerAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/customers/CustomerBalanceTransactionsAPI.cjs +71 -0
- package/dist/cjs/apis/business/customers/CustomerBalanceTransactionsAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/customers/CustomerPaymentMethodsAPI.cjs +176 -0
- package/dist/cjs/apis/business/customers/CustomerPaymentMethodsAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/departments/DepartmentApi.cjs +168 -0
- package/dist/cjs/apis/business/departments/DepartmentApi.cjs.map +1 -0
- package/dist/cjs/apis/business/departments/employees/DepartmentEmployeesAPI.cjs +137 -0
- package/dist/cjs/apis/business/departments/employees/DepartmentEmployeesAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/fees/FeesAPI.cjs +167 -0
- package/dist/cjs/apis/business/fees/FeesAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/locations/LocationsAPI.cjs +133 -0
- package/dist/cjs/apis/business/locations/LocationsAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/products/ProductsAPI.cjs +184 -0
- package/dist/cjs/apis/business/products/ProductsAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/products/images/ProductImagesAPI.cjs +195 -0
- package/dist/cjs/apis/business/products/images/ProductImagesAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/products/modifiers/ModifiersAPI.cjs +169 -0
- package/dist/cjs/apis/business/products/modifiers/ModifiersAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/products/options/ProductOptionsAPI.cjs +183 -0
- package/dist/cjs/apis/business/products/options/ProductOptionsAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/products/variants/ProductVariantsAPI.cjs +185 -0
- package/dist/cjs/apis/business/products/variants/ProductVariantsAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/promo-codes/PromoCodesAPI.cjs +139 -0
- package/dist/cjs/apis/business/promo-codes/PromoCodesAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/reviews/ReviewsAPI.cjs +143 -0
- package/dist/cjs/apis/business/reviews/ReviewsAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/tables/TablesAPI.cjs +75 -0
- package/dist/cjs/apis/business/tables/TablesAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/taxes/TaxesAPI.cjs +140 -0
- package/dist/cjs/apis/business/taxes/TaxesAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/team/TeamMemberInvitationsAPI.cjs +161 -0
- package/dist/cjs/apis/business/team/TeamMemberInvitationsAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/team/TeamMembersAPI.cjs +93 -0
- package/dist/cjs/apis/business/team/TeamMembersAPI.cjs.map +1 -0
- package/dist/cjs/apis/business/vendors/VendorsAPI.cjs +239 -0
- package/dist/cjs/apis/business/vendors/VendorsAPI.cjs.map +1 -0
- package/dist/cjs/apis/documents/DocumentsAPI.cjs +87 -0
- package/dist/cjs/apis/documents/DocumentsAPI.cjs.map +1 -0
- package/dist/cjs/apis/expenses/ExpensesAPI.cjs +62 -0
- package/dist/cjs/apis/expenses/ExpensesAPI.cjs.map +1 -0
- package/dist/cjs/apis/friends/FriendsAPI.cjs +150 -0
- package/dist/cjs/apis/friends/FriendsAPI.cjs.map +1 -0
- package/dist/cjs/apis/integrations/IntegrationsAPI.cjs +55 -0
- package/dist/cjs/apis/integrations/IntegrationsAPI.cjs.map +1 -0
- package/dist/cjs/apis/invoices/InvoicesAPI.cjs +168 -0
- package/dist/cjs/apis/invoices/InvoicesAPI.cjs.map +1 -0
- package/dist/cjs/apis/loyalty/LoyaltyProgramAPI.cjs +484 -0
- package/dist/cjs/apis/loyalty/LoyaltyProgramAPI.cjs.map +1 -0
- package/dist/cjs/apis/notifications/NotificationAPI.cjs +103 -0
- package/dist/cjs/apis/notifications/NotificationAPI.cjs.map +1 -0
- package/dist/cjs/apis/payment-methods/PaymentMethodsAPI.cjs +125 -0
- package/dist/cjs/apis/payment-methods/PaymentMethodsAPI.cjs.map +1 -0
- package/dist/cjs/apis/receipts/ReceiptAPI.cjs +135 -0
- package/dist/cjs/apis/receipts/ReceiptAPI.cjs.map +1 -0
- package/dist/cjs/apis/user/UserAPI.cjs +130 -0
- package/dist/cjs/apis/user/UserAPI.cjs.map +1 -0
- package/dist/cjs/apis/vendors/VendorsAPI.cjs +171 -0
- package/dist/cjs/apis/vendors/VendorsAPI.cjs.map +1 -0
- package/dist/cjs/context/ApiContext.cjs +94 -0
- package/dist/cjs/context/ApiContext.cjs.map +1 -0
- package/dist/cjs/index.cjs +222 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/apis/SBApiKeys.mjs +55 -0
- package/dist/esm/apis/SBApiKeys.mjs.map +1 -0
- package/dist/esm/apis/api-logs/LogsAPI.mjs +39 -0
- package/dist/esm/apis/api-logs/LogsAPI.mjs.map +1 -0
- package/dist/esm/apis/attachments/AttachmentsAPI.mjs +142 -0
- package/dist/esm/apis/attachments/AttachmentsAPI.mjs.map +1 -0
- package/dist/esm/apis/banks/accounts/BankAccountAPI.mjs +84 -0
- package/dist/esm/apis/banks/accounts/BankAccountAPI.mjs.map +1 -0
- package/dist/esm/apis/banks/bank-institutions/BankInstitutionsAPI.mjs +55 -0
- package/dist/esm/apis/banks/bank-institutions/BankInstitutionsAPI.mjs.map +1 -0
- package/dist/esm/apis/banks/bank-transactions/BankTransactionAPI.mjs +54 -0
- package/dist/esm/apis/banks/bank-transactions/BankTransactionAPI.mjs.map +1 -0
- package/dist/esm/apis/business/BusinessAPI.mjs +165 -0
- package/dist/esm/apis/business/BusinessAPI.mjs.map +1 -0
- package/dist/esm/apis/business/customers/CustomerAPI.mjs +155 -0
- package/dist/esm/apis/business/customers/CustomerAPI.mjs.map +1 -0
- package/dist/esm/apis/business/customers/CustomerBalanceTransactionsAPI.mjs +68 -0
- package/dist/esm/apis/business/customers/CustomerBalanceTransactionsAPI.mjs.map +1 -0
- package/dist/esm/apis/business/customers/CustomerPaymentMethodsAPI.mjs +170 -0
- package/dist/esm/apis/business/customers/CustomerPaymentMethodsAPI.mjs.map +1 -0
- package/dist/esm/apis/business/departments/DepartmentApi.mjs +161 -0
- package/dist/esm/apis/business/departments/DepartmentApi.mjs.map +1 -0
- package/dist/esm/apis/business/departments/employees/DepartmentEmployeesAPI.mjs +132 -0
- package/dist/esm/apis/business/departments/employees/DepartmentEmployeesAPI.mjs.map +1 -0
- package/dist/esm/apis/business/fees/FeesAPI.mjs +161 -0
- package/dist/esm/apis/business/fees/FeesAPI.mjs.map +1 -0
- package/dist/esm/apis/business/locations/LocationsAPI.mjs +127 -0
- package/dist/esm/apis/business/locations/LocationsAPI.mjs.map +1 -0
- package/dist/esm/apis/business/products/ProductsAPI.mjs +177 -0
- package/dist/esm/apis/business/products/ProductsAPI.mjs.map +1 -0
- package/dist/esm/apis/business/products/images/ProductImagesAPI.mjs +188 -0
- package/dist/esm/apis/business/products/images/ProductImagesAPI.mjs.map +1 -0
- package/dist/esm/apis/business/products/modifiers/ModifiersAPI.mjs +163 -0
- package/dist/esm/apis/business/products/modifiers/ModifiersAPI.mjs.map +1 -0
- package/dist/esm/apis/business/products/options/ProductOptionsAPI.mjs +177 -0
- package/dist/esm/apis/business/products/options/ProductOptionsAPI.mjs.map +1 -0
- package/dist/esm/apis/business/products/variants/ProductVariantsAPI.mjs +179 -0
- package/dist/esm/apis/business/products/variants/ProductVariantsAPI.mjs.map +1 -0
- package/dist/esm/apis/business/promo-codes/PromoCodesAPI.mjs +133 -0
- package/dist/esm/apis/business/promo-codes/PromoCodesAPI.mjs.map +1 -0
- package/dist/esm/apis/business/reviews/ReviewsAPI.mjs +137 -0
- package/dist/esm/apis/business/reviews/ReviewsAPI.mjs.map +1 -0
- package/dist/esm/apis/business/tables/TablesAPI.mjs +70 -0
- package/dist/esm/apis/business/tables/TablesAPI.mjs.map +1 -0
- package/dist/esm/apis/business/taxes/TaxesAPI.mjs +134 -0
- package/dist/esm/apis/business/taxes/TaxesAPI.mjs.map +1 -0
- package/dist/esm/apis/business/team/TeamMemberInvitationsAPI.mjs +153 -0
- package/dist/esm/apis/business/team/TeamMemberInvitationsAPI.mjs.map +1 -0
- package/dist/esm/apis/business/team/TeamMembersAPI.mjs +88 -0
- package/dist/esm/apis/business/team/TeamMembersAPI.mjs.map +1 -0
- package/dist/esm/apis/business/vendors/VendorsAPI.mjs +230 -0
- package/dist/esm/apis/business/vendors/VendorsAPI.mjs.map +1 -0
- package/dist/esm/apis/documents/DocumentsAPI.mjs +82 -0
- package/dist/esm/apis/documents/DocumentsAPI.mjs.map +1 -0
- package/dist/esm/apis/expenses/ExpensesAPI.mjs +58 -0
- package/dist/esm/apis/expenses/ExpensesAPI.mjs.map +1 -0
- package/dist/esm/apis/friends/FriendsAPI.mjs +144 -0
- package/dist/esm/apis/friends/FriendsAPI.mjs.map +1 -0
- package/dist/esm/apis/integrations/IntegrationsAPI.mjs +52 -0
- package/dist/esm/apis/integrations/IntegrationsAPI.mjs.map +1 -0
- package/dist/esm/apis/invoices/InvoicesAPI.mjs +161 -0
- package/dist/esm/apis/invoices/InvoicesAPI.mjs.map +1 -0
- package/dist/esm/apis/loyalty/LoyaltyProgramAPI.mjs +482 -0
- package/dist/esm/apis/loyalty/LoyaltyProgramAPI.mjs.map +1 -0
- package/dist/esm/apis/notifications/NotificationAPI.mjs +98 -0
- package/dist/esm/apis/notifications/NotificationAPI.mjs.map +1 -0
- package/dist/esm/apis/payment-methods/PaymentMethodsAPI.mjs +117 -0
- package/dist/esm/apis/payment-methods/PaymentMethodsAPI.mjs.map +1 -0
- package/dist/esm/apis/receipts/ReceiptAPI.mjs +129 -0
- package/dist/esm/apis/receipts/ReceiptAPI.mjs.map +1 -0
- package/dist/esm/apis/user/UserAPI.mjs +123 -0
- package/dist/esm/apis/user/UserAPI.mjs.map +1 -0
- package/dist/esm/apis/vendors/VendorsAPI.mjs +162 -0
- package/dist/esm/apis/vendors/VendorsAPI.mjs.map +1 -0
- package/dist/esm/context/ApiContext.mjs +86 -0
- package/dist/esm/context/ApiContext.mjs.map +1 -0
- package/dist/esm/index.mjs +39 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/umd/index.js +5056 -0
- package/dist/umd/index.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { useApiClient, useBusinessId } from '../../../../context/ApiContext.mjs';
|
|
2
|
+
import { useQueryClient, useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
3
|
+
import { SBApiKeys } from '../../../SBApiKeys.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to fetch a list of product variants for a specific product using infinite query
|
|
7
|
+
* @param productId - The ID of the product
|
|
8
|
+
* @param request - The pagination request parameters
|
|
9
|
+
* @param options - Optional request options
|
|
10
|
+
* @param config - Optional Axios request configuration
|
|
11
|
+
* @returns An infinite query result containing paginated product variants data
|
|
12
|
+
*/
|
|
13
|
+
function useListProductVariantsInfiniteQuery(productId, request = {
|
|
14
|
+
page: 1,
|
|
15
|
+
pageSize: 25
|
|
16
|
+
}, options, config) {
|
|
17
|
+
const client = useApiClient();
|
|
18
|
+
useQueryClient();
|
|
19
|
+
const businessId = useBusinessId();
|
|
20
|
+
if (!businessId) {
|
|
21
|
+
throw new Error("businessId is required for product variant operations");
|
|
22
|
+
}
|
|
23
|
+
return useInfiniteQuery({
|
|
24
|
+
initialPageParam: request.page || 1,
|
|
25
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId, SBApiKeys.ProductVariants, request],
|
|
26
|
+
queryFn: async ({
|
|
27
|
+
pageParam = 1
|
|
28
|
+
}) => {
|
|
29
|
+
return await client.businesses.productVariants.listAsync(businessId, productId, {
|
|
30
|
+
...request,
|
|
31
|
+
page: pageParam
|
|
32
|
+
}, options, config);
|
|
33
|
+
},
|
|
34
|
+
getNextPageParam: lastPage => {
|
|
35
|
+
if (lastPage.pagination.currentPage < lastPage.pagination.pageCount) {
|
|
36
|
+
return lastPage.pagination.currentPage + 1;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
},
|
|
40
|
+
enabled: !!businessId && !!productId
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Hook to fetch a specific product variant by ID
|
|
45
|
+
* @param productId - The ID of the product
|
|
46
|
+
* @param variantId - The ID of the product variant to retrieve
|
|
47
|
+
* @param options - Optional request options
|
|
48
|
+
* @param config - Optional Axios request configuration
|
|
49
|
+
* @returns A query result containing the product variant data
|
|
50
|
+
*/
|
|
51
|
+
function useGetProductVariantByIdQuery(productId, variantId, options, config) {
|
|
52
|
+
const client = useApiClient();
|
|
53
|
+
useQueryClient();
|
|
54
|
+
const businessId = useBusinessId();
|
|
55
|
+
return useQuery({
|
|
56
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId, SBApiKeys.ProductVariants, variantId],
|
|
57
|
+
queryFn: async () => {
|
|
58
|
+
if (!businessId) {
|
|
59
|
+
throw new Error("businessId is required for product variant operations");
|
|
60
|
+
}
|
|
61
|
+
return await client.businesses.productVariants.getByIdAsync(businessId, productId, variantId, options, config);
|
|
62
|
+
},
|
|
63
|
+
enabled: !!businessId && !!productId && !!variantId
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Hook to create a new product variant
|
|
68
|
+
* @returns A mutation function to create a product variant
|
|
69
|
+
*/
|
|
70
|
+
function useCreateProductVariantMutation() {
|
|
71
|
+
const client = useApiClient();
|
|
72
|
+
const queryClient = useQueryClient();
|
|
73
|
+
const businessId = useBusinessId();
|
|
74
|
+
return useMutation({
|
|
75
|
+
mutationFn: async ({
|
|
76
|
+
productId,
|
|
77
|
+
data,
|
|
78
|
+
options,
|
|
79
|
+
config
|
|
80
|
+
}) => {
|
|
81
|
+
if (!businessId) {
|
|
82
|
+
throw new Error("businessId is required for product variant operations");
|
|
83
|
+
}
|
|
84
|
+
return await client.businesses.productVariants.createAsync(businessId, productId, data, options, config);
|
|
85
|
+
},
|
|
86
|
+
onSuccess: (_, {
|
|
87
|
+
productId
|
|
88
|
+
}) => {
|
|
89
|
+
if (businessId) {
|
|
90
|
+
queryClient.invalidateQueries({
|
|
91
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId, SBApiKeys.ProductVariants]
|
|
92
|
+
});
|
|
93
|
+
queryClient.invalidateQueries({
|
|
94
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Hook to update an existing product variant
|
|
102
|
+
* @returns A mutation function to update a product variant
|
|
103
|
+
*/
|
|
104
|
+
function useUpdateProductVariantMutation() {
|
|
105
|
+
const client = useApiClient();
|
|
106
|
+
const queryClient = useQueryClient();
|
|
107
|
+
const businessId = useBusinessId();
|
|
108
|
+
return useMutation({
|
|
109
|
+
mutationFn: async ({
|
|
110
|
+
productId,
|
|
111
|
+
variantId,
|
|
112
|
+
data,
|
|
113
|
+
options,
|
|
114
|
+
config
|
|
115
|
+
}) => {
|
|
116
|
+
if (!businessId) {
|
|
117
|
+
throw new Error("businessId is required for product variant operations");
|
|
118
|
+
}
|
|
119
|
+
return await client.businesses.productVariants.updateAsync(businessId, productId, variantId, data, options, config);
|
|
120
|
+
},
|
|
121
|
+
onSuccess: (_, {
|
|
122
|
+
productId,
|
|
123
|
+
variantId
|
|
124
|
+
}) => {
|
|
125
|
+
if (businessId) {
|
|
126
|
+
queryClient.invalidateQueries({
|
|
127
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId, SBApiKeys.ProductVariants]
|
|
128
|
+
});
|
|
129
|
+
queryClient.invalidateQueries({
|
|
130
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId, SBApiKeys.ProductVariants, variantId]
|
|
131
|
+
});
|
|
132
|
+
queryClient.invalidateQueries({
|
|
133
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId]
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Hook to delete a product variant
|
|
141
|
+
* @returns A mutation function to delete a product variant
|
|
142
|
+
*/
|
|
143
|
+
function useDeleteProductVariantMutation() {
|
|
144
|
+
const client = useApiClient();
|
|
145
|
+
const queryClient = useQueryClient();
|
|
146
|
+
const businessId = useBusinessId();
|
|
147
|
+
return useMutation({
|
|
148
|
+
mutationFn: async ({
|
|
149
|
+
productId,
|
|
150
|
+
variantId,
|
|
151
|
+
options,
|
|
152
|
+
config
|
|
153
|
+
}) => {
|
|
154
|
+
if (!businessId) {
|
|
155
|
+
throw new Error("businessId is required for product variant operations");
|
|
156
|
+
}
|
|
157
|
+
return await client.businesses.productVariants.deleteAsync(businessId, productId, variantId, options, config);
|
|
158
|
+
},
|
|
159
|
+
onSuccess: (_, {
|
|
160
|
+
productId,
|
|
161
|
+
variantId
|
|
162
|
+
}) => {
|
|
163
|
+
if (businessId) {
|
|
164
|
+
queryClient.invalidateQueries({
|
|
165
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId, SBApiKeys.ProductVariants]
|
|
166
|
+
});
|
|
167
|
+
queryClient.invalidateQueries({
|
|
168
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId, SBApiKeys.ProductVariants, variantId]
|
|
169
|
+
});
|
|
170
|
+
queryClient.invalidateQueries({
|
|
171
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Products, productId]
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { useCreateProductVariantMutation, useDeleteProductVariantMutation, useGetProductVariantByIdQuery, useListProductVariantsInfiniteQuery, useUpdateProductVariantMutation };
|
|
179
|
+
//# sourceMappingURL=ProductVariantsAPI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProductVariantsAPI.mjs","sources":["../../../../../../src/apis/business/products/variants/ProductVariantsAPI.tsx"],"sourcesContent":["import {\n\tSBRequestOptions,\n\tSBProductVariant,\n\tProductVariantCreateRequest,\n\tProductVariantUpdateRequest,\n\tSBList,\n\tSBApiException,\n} from \"@smartbills/sdk\";\nimport { useApiClient } from \"@/context\";\nimport { useQueryClient } from \"@tanstack/react-query\";\nimport {\n\tQueryKey,\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n} from \"@tanstack/react-query\";\nimport { AxiosRequestConfig } from \"axios\";\nimport { useBusinessId } from \"@/context\";\nimport { SBApiKeys } from \"@/apis/SBApiKeys\";\n\n/**\n * Hook to fetch a list of product variants for a specific product using infinite query\n * @param productId - The ID of the product\n * @param request - The pagination request parameters\n * @param options - Optional request options\n * @param config - Optional Axios request configuration\n * @returns An infinite query result containing paginated product variants data\n */\nexport function useListProductVariantsInfiniteQuery(\n\tproductId: number,\n\trequest: { page?: number; pageSize?: number } = { page: 1, pageSize: 25 },\n\toptions?: SBRequestOptions,\n\tconfig?: AxiosRequestConfig,\n) {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\tif (!businessId) {\n\t\tthrow new Error(\n\t\t\t\"businessId is required for product variant operations\",\n\t\t);\n\t}\n\n\treturn useInfiniteQuery<\n\t\tSBList<SBProductVariant>,\n\t\tSBApiException,\n\t\tSBList<SBProductVariant>,\n\t\tQueryKey,\n\t\tnumber\n\t>({\n\t\tinitialPageParam: request.page || 1,\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.Products,\n\t\t\tproductId,\n\t\t\tSBApiKeys.ProductVariants,\n\t\t\trequest,\n\t\t],\n\t\tqueryFn: async ({ pageParam = 1 }) => {\n\t\t\treturn await client.businesses.productVariants.listAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tproductId,\n\t\t\t\t{ ...request, page: pageParam },\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tgetNextPageParam: (lastPage) => {\n\t\t\tif (\n\t\t\t\tlastPage.pagination.currentPage < lastPage.pagination.pageCount\n\t\t\t) {\n\t\t\t\treturn lastPage.pagination.currentPage + 1;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t\tenabled: !!businessId && !!productId,\n\t});\n}\n\n/**\n * Hook to fetch a specific product variant by ID\n * @param productId - The ID of the product\n * @param variantId - The ID of the product variant to retrieve\n * @param options - Optional request options\n * @param config - Optional Axios request configuration\n * @returns A query result containing the product variant data\n */\nexport function useGetProductVariantByIdQuery(\n\tproductId: number,\n\tvariantId: number,\n\toptions?: SBRequestOptions,\n\tconfig?: AxiosRequestConfig,\n) {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useQuery<SBProductVariant, SBApiException>({\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.Products,\n\t\t\tproductId,\n\t\t\tSBApiKeys.ProductVariants,\n\t\t\tvariantId,\n\t\t],\n\t\tqueryFn: async () => {\n\t\t\tif (!businessId) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"businessId is required for product variant operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await client.businesses.productVariants.getByIdAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tproductId,\n\t\t\t\tvariantId,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tenabled: !!businessId && !!productId && !!variantId,\n\t});\n}\n\n/**\n * Hook to create a new product variant\n * @returns A mutation function to create a product variant\n */\nexport function useCreateProductVariantMutation() {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBProductVariant,\n\t\tSBApiException,\n\t\t{\n\t\t\tproductId: number;\n\t\t\tdata: ProductVariantCreateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ productId, data, options, config }) => {\n\t\t\tif (!businessId) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"businessId is required for product variant operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await client.businesses.productVariants.createAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tproductId,\n\t\t\t\tdata,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: (_, { productId }) => {\n\t\t\tif (businessId) {\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.Products,\n\t\t\t\t\t\tproductId,\n\t\t\t\t\t\tSBApiKeys.ProductVariants,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.Products,\n\t\t\t\t\t\tproductId,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t});\n}\n\n/**\n * Hook to update an existing product variant\n * @returns A mutation function to update a product variant\n */\nexport function useUpdateProductVariantMutation() {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBProductVariant,\n\t\tSBApiException,\n\t\t{\n\t\t\tproductId: number;\n\t\t\tvariantId: number;\n\t\t\tdata: ProductVariantUpdateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ productId, variantId, data, options, config }) => {\n\t\t\tif (!businessId) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"businessId is required for product variant operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await client.businesses.productVariants.updateAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tproductId,\n\t\t\t\tvariantId,\n\t\t\t\tdata,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: (_, { productId, variantId }) => {\n\t\t\tif (businessId) {\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.Products,\n\t\t\t\t\t\tproductId,\n\t\t\t\t\t\tSBApiKeys.ProductVariants,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.Products,\n\t\t\t\t\t\tproductId,\n\t\t\t\t\t\tSBApiKeys.ProductVariants,\n\t\t\t\t\t\tvariantId,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.Products,\n\t\t\t\t\t\tproductId,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t});\n}\n\n/**\n * Hook to delete a product variant\n * @returns A mutation function to delete a product variant\n */\nexport function useDeleteProductVariantMutation() {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBProductVariant,\n\t\tSBApiException,\n\t\t{\n\t\t\tproductId: number;\n\t\t\tvariantId: number;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ productId, variantId, options, config }) => {\n\t\t\tif (!businessId) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"businessId is required for product variant operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await client.businesses.productVariants.deleteAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tproductId,\n\t\t\t\tvariantId,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: (_, { productId, variantId }) => {\n\t\t\tif (businessId) {\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.Products,\n\t\t\t\t\t\tproductId,\n\t\t\t\t\t\tSBApiKeys.ProductVariants,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.Products,\n\t\t\t\t\t\tproductId,\n\t\t\t\t\t\tSBApiKeys.ProductVariants,\n\t\t\t\t\t\tvariantId,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.Products,\n\t\t\t\t\t\tproductId,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t});\n}\n"],"names":["useListProductVariantsInfiniteQuery","productId","request","page","pageSize","options","config","client","useApiClient","useQueryClient","businessId","useBusinessId","Error","useInfiniteQuery","initialPageParam","queryKey","SBApiKeys","Businesses","Products","ProductVariants","queryFn","pageParam","businesses","productVariants","listAsync","getNextPageParam","lastPage","pagination","currentPage","pageCount","undefined","enabled","useGetProductVariantByIdQuery","variantId","useQuery","getByIdAsync","useCreateProductVariantMutation","queryClient","useMutation","mutationFn","data","createAsync","onSuccess","_","invalidateQueries","useUpdateProductVariantMutation","updateAsync","useDeleteProductVariantMutation","deleteAsync"],"mappings":";;;;AAoBA;;;;;;;AAOG;SACaA,mCAAmCA,CAClDC,SAAiB,EACjBC,OAAA,GAAgD;AAAEC,EAAAA,IAAI,EAAE,CAAC;AAAEC,EAAAA,QAAQ,EAAE;CAAI,EACzEC,OAA0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,iBAAiB,CAAC;AAC7B7B,UAAAA,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBP,UAAU,EACVM,SAAS,CAACE,QAAQ,EAClBjB,SAAS,EACTe,SAAS,CAACG,eAAe,EACzBc,SAAS;AAEV,SAAA,CAAC;QACFI,WAAW,CAACO,iBAAiB,CAAC;AAC7B7B,UAAAA,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBP,UAAU,EACVM,SAAS,CAACE,QAAQ,EAClBjB,SAAS;AAEV,SAAA,CAAC;AACH;AACD;AACA,GAAA,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { useApiClient, useBusinessId } from '../../../context/ApiContext.mjs';
|
|
2
|
+
import { useQueryClient, useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
3
|
+
import { SBApiKeys } from '../../SBApiKeys.mjs';
|
|
4
|
+
|
|
5
|
+
const useListPromoCodes = (request = {
|
|
6
|
+
page: 1,
|
|
7
|
+
pageSize: 25
|
|
8
|
+
}, options, config) => {
|
|
9
|
+
const client = useApiClient();
|
|
10
|
+
useQueryClient();
|
|
11
|
+
const businessId = useBusinessId();
|
|
12
|
+
if (!businessId) {
|
|
13
|
+
throw new Error("businessId is required for promo code operations");
|
|
14
|
+
}
|
|
15
|
+
return useInfiniteQuery({
|
|
16
|
+
initialPageParam: request.page || 1,
|
|
17
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.PromoCodes, request, options],
|
|
18
|
+
queryFn: async ({
|
|
19
|
+
pageParam = 1
|
|
20
|
+
}) => {
|
|
21
|
+
return await client.businesses.promoCodes.listAsync(businessId, {
|
|
22
|
+
...request,
|
|
23
|
+
page: pageParam
|
|
24
|
+
}, options, config);
|
|
25
|
+
},
|
|
26
|
+
getNextPageParam: lastPage => {
|
|
27
|
+
if (lastPage.pagination && lastPage.pagination.currentPage < lastPage.pagination.pageCount) {
|
|
28
|
+
return lastPage.pagination.currentPage + 1;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
},
|
|
32
|
+
enabled: !!businessId
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const useGetPromoCodeById = (id, options, config) => {
|
|
36
|
+
const client = useApiClient();
|
|
37
|
+
useQueryClient();
|
|
38
|
+
const businessId = useBusinessId();
|
|
39
|
+
if (!businessId) {
|
|
40
|
+
throw new Error("businessId is required for promo code operations");
|
|
41
|
+
}
|
|
42
|
+
return useQuery({
|
|
43
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.PromoCodes, id, options],
|
|
44
|
+
queryFn: async () => await client.businesses.promoCodes.getByIdAsync(businessId, id, options, config),
|
|
45
|
+
enabled: !!businessId
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const useCreatePromoCodeMutation = () => {
|
|
49
|
+
const client = useApiClient();
|
|
50
|
+
const queryClient = useQueryClient();
|
|
51
|
+
const businessId = useBusinessId();
|
|
52
|
+
return useMutation({
|
|
53
|
+
mutationFn: async ({
|
|
54
|
+
request,
|
|
55
|
+
options,
|
|
56
|
+
config
|
|
57
|
+
}) => {
|
|
58
|
+
if (!businessId) {
|
|
59
|
+
throw new Error("businessId is required for promo code operations");
|
|
60
|
+
}
|
|
61
|
+
return await client.businesses.promoCodes.createAsync(businessId, request, options, config);
|
|
62
|
+
},
|
|
63
|
+
onSuccess: () => {
|
|
64
|
+
if (businessId) {
|
|
65
|
+
queryClient.invalidateQueries({
|
|
66
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.PromoCodes]
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const useUpdatePromoCodeMutation = () => {
|
|
73
|
+
const client = useApiClient();
|
|
74
|
+
const queryClient = useQueryClient();
|
|
75
|
+
const businessId = useBusinessId();
|
|
76
|
+
return useMutation({
|
|
77
|
+
mutationFn: async ({
|
|
78
|
+
id,
|
|
79
|
+
request,
|
|
80
|
+
options,
|
|
81
|
+
config
|
|
82
|
+
}) => {
|
|
83
|
+
if (!businessId) {
|
|
84
|
+
throw new Error("businessId is required for promo code operations");
|
|
85
|
+
}
|
|
86
|
+
return await client.businesses.promoCodes.updateAsync(businessId, id, request, options, config);
|
|
87
|
+
},
|
|
88
|
+
onSuccess: (_, {
|
|
89
|
+
id
|
|
90
|
+
}) => {
|
|
91
|
+
if (businessId) {
|
|
92
|
+
queryClient.invalidateQueries({
|
|
93
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.PromoCodes]
|
|
94
|
+
});
|
|
95
|
+
queryClient.invalidateQueries({
|
|
96
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.PromoCodes, id]
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const useDeletePromoCodeMutation = () => {
|
|
103
|
+
const client = useApiClient();
|
|
104
|
+
const queryClient = useQueryClient();
|
|
105
|
+
const businessId = useBusinessId();
|
|
106
|
+
return useMutation({
|
|
107
|
+
mutationFn: async ({
|
|
108
|
+
id,
|
|
109
|
+
options,
|
|
110
|
+
config
|
|
111
|
+
}) => {
|
|
112
|
+
if (!businessId) {
|
|
113
|
+
throw new Error("businessId is required for promo code operations");
|
|
114
|
+
}
|
|
115
|
+
await client.businesses.promoCodes.deleteAsync(businessId, id, options, config);
|
|
116
|
+
},
|
|
117
|
+
onSuccess: (_, {
|
|
118
|
+
id
|
|
119
|
+
}) => {
|
|
120
|
+
if (businessId) {
|
|
121
|
+
queryClient.invalidateQueries({
|
|
122
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.PromoCodes]
|
|
123
|
+
});
|
|
124
|
+
queryClient.invalidateQueries({
|
|
125
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.PromoCodes, id]
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export { useCreatePromoCodeMutation, useDeletePromoCodeMutation, useGetPromoCodeById, useListPromoCodes, useUpdatePromoCodeMutation };
|
|
133
|
+
//# sourceMappingURL=PromoCodesAPI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromoCodesAPI.mjs","sources":["../../../../../src/apis/business/promo-codes/PromoCodesAPI.tsx"],"sourcesContent":["import {\n\tPromoCodeCreateRequest,\n\tPromoCodeListRequest,\n\tPromoCodeUpdateRequest,\n\tSBPromoCode,\n\tSBRequestOptions,\n\tSBApiException,\n\tSBList,\n} from \"@smartbills/sdk\";\nimport { useApiClient } from \"@/context\";\nimport { useQueryClient } from \"@tanstack/react-query\";\nimport {\n\tQueryKey,\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n} from \"@tanstack/react-query\";\nimport { AxiosRequestConfig } from \"axios\";\nimport { SBApiKeys } from \"../../SBApiKeys\";\nimport { useBusinessId } from \"@/context\";\n\nexport const useListPromoCodes = (\n\trequest: PromoCodeListRequest = { page: 1, pageSize: 25 },\n\toptions?: SBRequestOptions,\n\tconfig?: AxiosRequestConfig<PromoCodeListRequest>,\n) => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\tif (!businessId) {\n\t\tthrow new Error(\"businessId is required for promo code operations\");\n\t}\n\n\treturn useInfiniteQuery<\n\t\tSBList<SBPromoCode>,\n\t\tSBApiException,\n\t\tSBList<SBPromoCode>,\n\t\tQueryKey,\n\t\tnumber\n\t>({\n\t\tinitialPageParam: request.page || 1,\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.PromoCodes,\n\t\t\trequest,\n\t\t\toptions,\n\t\t],\n\t\tqueryFn: async ({ pageParam = 1 }) => {\n\t\t\treturn await client.businesses.promoCodes.listAsync(\n\t\t\t\tbusinessId,\n\t\t\t\t{ ...request, page: pageParam },\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tgetNextPageParam: (lastPage) => {\n\t\t\tif (\n\t\t\t\tlastPage.pagination &&\n\t\t\t\tlastPage.pagination.currentPage < lastPage.pagination.pageCount\n\t\t\t) {\n\t\t\t\treturn lastPage.pagination.currentPage + 1;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t\tenabled: !!businessId,\n\t});\n};\n\nexport const useGetPromoCodeById = (\n\tid: number,\n\toptions?: SBRequestOptions,\n\tconfig?: AxiosRequestConfig,\n) => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\tif (!businessId) {\n\t\tthrow new Error(\"businessId is required for promo code operations\");\n\t}\n\n\treturn useQuery<SBPromoCode, SBApiException>({\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.PromoCodes,\n\t\t\tid,\n\t\t\toptions,\n\t\t],\n\t\tqueryFn: async () =>\n\t\t\tawait client.businesses.promoCodes.getByIdAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tid,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t),\n\t\tenabled: !!businessId,\n\t});\n};\n\nexport const useCreatePromoCodeMutation = () => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBPromoCode,\n\t\tSBApiException,\n\t\t{\n\t\t\trequest: PromoCodeCreateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig<PromoCodeCreateRequest>;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ request, options, config }) => {\n\t\t\tif (!businessId) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"businessId is required for promo code operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await client.businesses.promoCodes.createAsync(\n\t\t\t\tbusinessId,\n\t\t\t\trequest,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: () => {\n\t\t\tif (businessId) {\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.PromoCodes,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t});\n};\n\nexport const useUpdatePromoCodeMutation = () => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBPromoCode,\n\t\tSBApiException,\n\t\t{\n\t\t\tid: number;\n\t\t\trequest: PromoCodeUpdateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig<PromoCodeUpdateRequest>;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ id, request, options, config }) => {\n\t\t\tif (!businessId) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"businessId is required for promo code operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await client.businesses.promoCodes.updateAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tid,\n\t\t\t\trequest,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: (_, { id }) => {\n\t\t\tif (businessId) {\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.PromoCodes,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.PromoCodes,\n\t\t\t\t\t\tid,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t});\n};\n\nexport const useDeletePromoCodeMutation = () => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tvoid,\n\t\tSBApiException,\n\t\t{\n\t\t\tid: number;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ id, options, config }) => {\n\t\t\tif (!businessId) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"businessId is required for promo code operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait client.businesses.promoCodes.deleteAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tid,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: (_, { id }) => {\n\t\t\tif (businessId) {\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.PromoCodes,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tqueryClient.invalidateQueries({\n\t\t\t\t\tqueryKey: [\n\t\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\t\tbusinessId,\n\t\t\t\t\t\tSBApiKeys.PromoCodes,\n\t\t\t\t\t\tid,\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t});\n};\n"],"names":["useListPromoCodes","request","page","pageSize","options","config","client","useApiClient","useQueryClient","businessId","useBusinessId","Error","useInfiniteQuery","initialPageParam","queryKey","SBApiKeys","Businesses","PromoCodes","queryFn","pageParam","businesses","promoCodes","listAsync","getNextPageParam","lastPage","pagination","currentPage","pageCount","undefined","enabled","useGetPromoCodeById","id","useQuery","getByIdAsync","useCreatePromoCodeMutation","queryClient","useMutation","mutationFn","createAsync","onSuccess","invalidateQueries","useUpdatePromoCodeMutation","updateAsync","_","useDeletePromoCodeMutation","deleteAsync"],"mappings":";;;;AAqBaA,MAAAA,iBAAiB,GAAGA,CAChCC,OAAgC,GAAA;AAAEC,EAAAA,IAAI,EAAE,CAAC;AAAEC,EAAAA,QAAQ,EAAE;AAAI,CAAA,EACzDC,OAA0B,EAC1BC,MAAiD,KAC9C;AACH,EAAA,MAAMC,MAAM,GAAGC,YAAY,EAAE;AAC7B,EAAoBC,cAAc;AAClC,EAAA,MAAMC,UAAU,GAAGC,aAAa,EAAE;EAElC,IAAI,CAACD,UAAU,EAAE;AAChB,IAAA,MAAM,IAAIE,KAAK,CAAC,kDAAkD,CAAC;AACpE;AAEA,EAAA,OAAOC,gBAAgB,CAMrB;AACDC,IAAAA,gBAAgB,EAAEZ,OAAO,CAACC,IAAI,IAAI,CAAC;AACnCY,IAAAA,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBP,UAAU,EACVM,SAAS,CAACE,UAAU,EACpBhB,OAAO,EACPG,OAAO,CACP;IACDc,OAAO,EAAE,OAAO;AAAEC,MAAAA,SAAS,GAAG;AAAG,KAAA,KAAI;MACpC,OAAO,MAAMb,MAAM,CAACc,UAAU,CAACC,UAAU,CAACC,SAAS,CAClDb,UAAU,EACV;AAAE,QAAA,GAAGR,OAAO;AAAEC,QAAAA,IAAI,EAAEiB;AAAS,OAAE,EAC/Bf,OAAO,EACPC,MAAM,CACN;KACD;IACDkB,gBAAgB,EAAGC,QAAQ,IAAI;AAC9B,MAAA,IACCA,QAAQ,CAACC,UAAU,IACnBD,QAAQ,CAACC,UAAU,CAACC,WAAW,GAAGF,QAAQ,CAACC,UAAU,CAACE,SAAS,EAC9D;AACD,QAAA,OAAOH,QAAQ,CAACC,UAAU,CAACC,WAAW,GAAG,CAAC;AAC3C;AACA,MAAA,OAAOE,SAAS;KAChB;IACDC,OAAO,EAAE,CAAC,CAACpB;AACX,GAAA,CAAC;AACH;AAEO,MAAMqB,mBA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AAE;AAElC,EAAA,OAAO0B,WAAW,CAQhB;IACDC,UAAU,EAAE,OAAO;MAAEN,EAAE;MAAE3B,OAAO;AAAEC,MAAAA;AAAQ,KAAA,KAAI;MAC7C,IAAI,CAACI,UAAU,EAAE;AAChB,QAAA,MAAM,IAAIE,KAAK,CACd,kDAAkD,CAClD;AACF;AACA,MAAA,MAAML,MAAM,CAACc,UAAU,CAACC,UAAU,CAACwB,WAAW,CAC7CpC,UAAU,EACVsB,EAAE,EACF3B,OAAO,EACPC,MAAM,CACN;KACD;IACDkC,SAAS,EAAEA,CAACI,CAAC,EAAE;AAAEZ,MAAAA;AAAE,KAAE,KAAI;AACxB,MAAA,IAAItB,UAAU,EAAE;QACf0B,WAAW,CAACK,iBAAiB,CAAC;UAC7B1B,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBP,UAAU,EACVM,SAAS,CAACE,UAAU;AAErB,SAAA,CAAC;QACFkB,WAAW,CAACK,iBAAiB,CAAC;AAC7B1B,UAAAA,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBP,UAAU,EACVM,SAAS,CAACE,UAAU,EACpBc,EAAE;AAEH,SAAA,CAAC;AACH;AACD;AACA,GAAA,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { useQueryClient, useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { useApiClient, useBusinessId } from '../../../context/ApiContext.mjs';
|
|
3
|
+
import { SBApiKeys } from '../../SBApiKeys.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook for listing reviews with infinite pagination
|
|
7
|
+
* @param request - Request parameters for listing reviews
|
|
8
|
+
* @param options - Optional request options
|
|
9
|
+
* @param config - Optional Axios request configuration
|
|
10
|
+
* @returns Infinite query result for implementing infinite scrolling with reviews data
|
|
11
|
+
*/
|
|
12
|
+
const useListReviewsInfiniteQuery = (request = {
|
|
13
|
+
page: 1,
|
|
14
|
+
pageSize: 25
|
|
15
|
+
}, options, config) => {
|
|
16
|
+
const client = useApiClient();
|
|
17
|
+
useQueryClient();
|
|
18
|
+
const businessId = useBusinessId();
|
|
19
|
+
return useInfiniteQuery({
|
|
20
|
+
initialPageParam: request.page || 1,
|
|
21
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.BusinessReviews, request, options],
|
|
22
|
+
queryFn: async ({
|
|
23
|
+
pageParam = 1
|
|
24
|
+
}) => {
|
|
25
|
+
const paginatedRequest = {
|
|
26
|
+
...request,
|
|
27
|
+
page: pageParam
|
|
28
|
+
};
|
|
29
|
+
return await client.businesses.reviews.listAsync(businessId, paginatedRequest, options, config);
|
|
30
|
+
},
|
|
31
|
+
getNextPageParam: lastPage => {
|
|
32
|
+
if (lastPage.pagination && lastPage.pagination.currentPage < lastPage.pagination.pageCount) {
|
|
33
|
+
return lastPage.pagination.currentPage + 1;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Hook for retrieving a review by ID
|
|
41
|
+
* @param id - The ID of the review to retrieve
|
|
42
|
+
* @param options - Optional request options
|
|
43
|
+
* @param config - Optional Axios request configuration
|
|
44
|
+
* @returns Query result containing the review data
|
|
45
|
+
*/
|
|
46
|
+
const useGetReviewByIdQuery = (id, options, config) => {
|
|
47
|
+
const client = useApiClient();
|
|
48
|
+
useQueryClient();
|
|
49
|
+
const businessId = useBusinessId();
|
|
50
|
+
return useQuery({
|
|
51
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.BusinessReviews, id, options],
|
|
52
|
+
queryFn: async () => await client.businesses.reviews.getByIdAsync(businessId, id, options, config)
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Hook for creating a new review
|
|
57
|
+
* @returns Mutation function for creating reviews
|
|
58
|
+
*/
|
|
59
|
+
const useCreateReviewMutation = () => {
|
|
60
|
+
const client = useApiClient();
|
|
61
|
+
const queryClient = useQueryClient();
|
|
62
|
+
const businessId = useBusinessId();
|
|
63
|
+
return useMutation({
|
|
64
|
+
mutationFn: async ({
|
|
65
|
+
data,
|
|
66
|
+
options,
|
|
67
|
+
config
|
|
68
|
+
}) => {
|
|
69
|
+
return await client.businesses.reviews.createAsync(businessId, data, options, config);
|
|
70
|
+
},
|
|
71
|
+
onSuccess: () => {
|
|
72
|
+
queryClient.invalidateQueries({
|
|
73
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.BusinessReviews]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Hook for updating an existing review
|
|
80
|
+
* @returns Mutation function for updating reviews
|
|
81
|
+
*/
|
|
82
|
+
const useUpdateReviewMutation = () => {
|
|
83
|
+
const client = useApiClient();
|
|
84
|
+
const queryClient = useQueryClient();
|
|
85
|
+
const businessId = useBusinessId();
|
|
86
|
+
return useMutation({
|
|
87
|
+
mutationFn: async ({
|
|
88
|
+
id,
|
|
89
|
+
data,
|
|
90
|
+
options,
|
|
91
|
+
config
|
|
92
|
+
}) => {
|
|
93
|
+
return await client.businesses.reviews.updateAsync(businessId, id, data, options, config);
|
|
94
|
+
},
|
|
95
|
+
onSuccess: (_, {
|
|
96
|
+
id
|
|
97
|
+
}) => {
|
|
98
|
+
queryClient.invalidateQueries({
|
|
99
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.BusinessReviews]
|
|
100
|
+
});
|
|
101
|
+
queryClient.invalidateQueries({
|
|
102
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.BusinessReviews, id]
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Hook for deleting a review
|
|
109
|
+
* @returns Mutation function for deleting reviews
|
|
110
|
+
*/
|
|
111
|
+
const useDeleteReviewMutation = () => {
|
|
112
|
+
const client = useApiClient();
|
|
113
|
+
const queryClient = useQueryClient();
|
|
114
|
+
const businessId = useBusinessId();
|
|
115
|
+
return useMutation({
|
|
116
|
+
mutationFn: async ({
|
|
117
|
+
id,
|
|
118
|
+
options,
|
|
119
|
+
config
|
|
120
|
+
}) => {
|
|
121
|
+
await client.businesses.reviews.deleteAsync(businessId, id, options, config);
|
|
122
|
+
},
|
|
123
|
+
onSuccess: (_, {
|
|
124
|
+
id
|
|
125
|
+
}) => {
|
|
126
|
+
queryClient.invalidateQueries({
|
|
127
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.BusinessReviews]
|
|
128
|
+
});
|
|
129
|
+
queryClient.removeQueries({
|
|
130
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.BusinessReviews, id]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export { useCreateReviewMutation, useDeleteReviewMutation, useGetReviewByIdQuery, useListReviewsInfiniteQuery, useUpdateReviewMutation };
|
|
137
|
+
//# sourceMappingURL=ReviewsAPI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReviewsAPI.mjs","sources":["../../../../../src/apis/business/reviews/ReviewsAPI.tsx"],"sourcesContent":["import {\n\tSBList,\n\tBusinessReviewCreateRequest,\n\tBusinessReviewUpdateRequest,\n\tSBBusinessReview,\n\tSBApiException,\n\tSBRequestOptions,\n} from \"@smartbills/sdk\";\nimport {\n\tInfiniteData,\n\tQueryKey,\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n} from \"@tanstack/react-query\";\nimport { useApiClient } from \"@/context\";\nimport { useQueryClient } from \"@tanstack/react-query\";\nimport { AxiosRequestConfig } from \"axios\";\nimport { SBApiKeys } from \"@/apis/SBApiKeys\";\nimport { useBusinessId } from \"@/context\";\n\n/**\n * Hook for listing reviews with infinite pagination\n * @param request - Request parameters for listing reviews\n * @param options - Optional request options\n * @param config - Optional Axios request configuration\n * @returns Infinite query result for implementing infinite scrolling with reviews data\n */\nexport const useListReviewsInfiniteQuery = (\n\trequest: { page?: number; pageSize?: number } = { page: 1, pageSize: 25 },\n\toptions?: SBRequestOptions,\n\tconfig?: AxiosRequestConfig,\n) => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\treturn useInfiniteQuery<\n\t\tSBList<SBBusinessReview>,\n\t\tSBApiException,\n\t\tInfiniteData<SBList<SBBusinessReview>>,\n\t\tQueryKey,\n\t\tnumber\n\t>({\n\t\tinitialPageParam: request.page || 1,\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.BusinessReviews,\n\t\t\trequest,\n\t\t\toptions,\n\t\t],\n\t\tqueryFn: async ({ pageParam = 1 }) => {\n\t\t\tconst paginatedRequest = { ...request, page: pageParam };\n\t\t\treturn await client.businesses.reviews.listAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tpaginatedRequest,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tgetNextPageParam: (lastPage) => {\n\t\t\tif (\n\t\t\t\tlastPage.pagination &&\n\t\t\t\tlastPage.pagination.currentPage < lastPage.pagination.pageCount\n\t\t\t) {\n\t\t\t\treturn lastPage.pagination.currentPage + 1;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t});\n};\n\n/**\n * Hook for retrieving a review by ID\n * @param id - The ID of the review to retrieve\n * @param options - Optional request options\n * @param config - Optional Axios request configuration\n * @returns Query result containing the review data\n */\nexport const useGetReviewByIdQuery = (\n\tid: number,\n\toptions?: SBRequestOptions,\n\tconfig?: AxiosRequestConfig,\n) => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\treturn useQuery<SBBusinessReview, SBApiException>({\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.BusinessReviews,\n\t\t\tid,\n\t\t\toptions,\n\t\t],\n\t\tqueryFn: async () =>\n\t\t\tawait client.businesses.reviews.getByIdAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tid,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t),\n\t});\n};\n\n/**\n * Hook for creating a new review\n * @returns Mutation function for creating reviews\n */\nexport const useCreateReviewMutation = () => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\treturn useMutation<\n\t\tSBBusinessReview,\n\t\tSBApiException,\n\t\t{\n\t\t\tdata: BusinessReviewCreateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig<BusinessReviewCreateRequest>;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ data, options, config }) => {\n\t\t\treturn await client.businesses.reviews.createAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tdata,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: () => {\n\t\t\tqueryClient.invalidateQueries({\n\t\t\t\tqueryKey: [\n\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\tbusinessId,\n\t\t\t\t\tSBApiKeys.BusinessReviews,\n\t\t\t\t],\n\t\t\t});\n\t\t},\n\t});\n};\n\n/**\n * Hook for updating an existing review\n * @returns Mutation function for updating reviews\n */\nexport const useUpdateReviewMutation = () => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\treturn useMutation<\n\t\tSBBusinessReview,\n\t\tSBApiException,\n\t\t{\n\t\t\tid: number;\n\t\t\tdata: BusinessReviewUpdateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig<BusinessReviewUpdateRequest>;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ id, data, options, config }) => {\n\t\t\treturn await client.businesses.reviews.updateAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tid,\n\t\t\t\tdata,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: (_, { id }) => {\n\t\t\tqueryClient.invalidateQueries({\n\t\t\t\tqueryKey: [\n\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\tbusinessId,\n\t\t\t\t\tSBApiKeys.BusinessReviews,\n\t\t\t\t],\n\t\t\t});\n\t\t\tqueryClient.invalidateQueries({\n\t\t\t\tqueryKey: [\n\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\tbusinessId,\n\t\t\t\t\tSBApiKeys.BusinessReviews,\n\t\t\t\t\tid,\n\t\t\t\t],\n\t\t\t});\n\t\t},\n\t});\n};\n\n/**\n * Hook for deleting a review\n * @returns Mutation function for deleting reviews\n */\nexport const useDeleteReviewMutation = () => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\treturn useMutation<\n\t\tvoid,\n\t\tSBApiException,\n\t\t{\n\t\t\tid: number;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ id, options, config }) => {\n\t\t\tawait client.businesses.reviews.deleteAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tid,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: (_, { id }) => {\n\t\t\tqueryClient.invalidateQueries({\n\t\t\t\tqueryKey: [\n\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\tbusinessId,\n\t\t\t\t\tSBApiKeys.BusinessReviews,\n\t\t\t\t],\n\t\t\t});\n\t\t\tqueryClient.removeQueries({\n\t\t\t\tqueryKey: [\n\t\t\t\t\tSBApiKeys.Businesses,\n\t\t\t\t\tbusinessId,\n\t\t\t\t\tSBApiKeys.BusinessReviews,\n\t\t\t\t\tid,\n\t\t\t\t],\n\t\t\t});\n\t\t},\n\t});\n};\n"],"names":["useListReviewsInfiniteQuery","request","page","pageSize","options","config","client","useApiClient","useQueryClient","businessId","useBusinessId","useInfiniteQuery","initialPageParam","queryKey","SBApiKeys","Businesses","BusinessReviews","queryFn","pageParam","paginatedRequest","businesses","reviews","listAsync","getNextPageParam","lastPage","pagination","currentPage","pageCount","undefined","useGetReviewByIdQuery","id","useQuery","getByIdAsync","useCreateReviewMutation","queryClient","useMutation","mutationFn","data","createAsync","onSuccess","invalidateQueries","useUpdateReviewMutation","updateAsync","_","useDeleteReviewMutation","deleteAsync","removeQueries"],"mappings":";;;;AAqBA;;;;;;AAMG;AACUA,MAAAA,2BAA2B,GAAGA,CAC1CC,OAAgD,GAAA;AAAEC,EAAAA,IAAI,EAAE,CAAC;AAAEC,EAAAA,QAAQ,EAAE;AAAI,CAAA,EACzEC,OAA0B,EAC1BC,MAA2B,KACxB;AACH,EAAA,MAAMC,MAAM,GAAGC,YAAY,EAAE;AAC7B,EAAoBC,cAAc;AAClC,EAAA,MAAMC,UAAU,GAAGC,aAAa,EAAE;AAClC,EAAA,OAAOC,gBAAgB,CAMrB;AACDC,IAAAA,gBAAgB,EAAEX,OAAO,CAACC,IAAI,IAAI,CAAC;AACnCW,IAAAA,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBN,UAAU,EACVK,SAAS,CAACE,eAAe,EACzBf,OAAO,EACPG,OAAO,CACP;IACDa,OAAO,EAAE,OAAO;AAAEC,MAAAA,SAAS,GAAG;AAAG,KAAA,KAAI;AACpC,MAAA,MAAMC,gBAAgB,GAAG;AAAE,QAAA,GAAGlB,OAAO;AAAEC,QAAAA,IAAI,EAAEgB;OAAW;AACxD,MAAA,OAAO,MAAMZ,MAAM,CAACc,UAAU,CAACC,OAAO,CAACC,SAAS,CAC/Cb,UAAU,EACVU,gBAAgB,EAChBf,OAAO,EACPC,MAAM,CACN;KACD;IACDkB,gBAAgB,EAAGC,QAAQ,IAAI;AAC9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DC,UAAU,EAAE,OAAO;MAAEN,EAAE;MAAE1B,OAAO;AAAEC,MAAAA;AAAQ,KAAA,KAAI;AAC7C,MAAA,MAAMC,MAAM,CAACc,UAAU,CAACC,OAAO,CAACwB,WAAW,CAC1CpC,UAAU,EACVqB,EAAE,EACF1B,OAAO,EACPC,MAAM,CACN;KACD;IACDkC,SAAS,EAAEA,CAACI,CAAC,EAAE;AAAEb,MAAAA;AAAE,KAAE,KAAI;MACxBI,WAAW,CAACM,iBAAiB,CAAC;QAC7B3B,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBN,UAAU,EACVK,SAAS,CAACE,eAAe;AAE1B,OAAA,CAAC;MACFkB,WAAW,CAACY,aAAa,CAAC;AACzBjC,QAAAA,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBN,UAAU,EACVK,SAAS,CAACE,eAAe,EACzBc,EAAE;AAEH,OAAA,CAAC;AACH;AACA,GAAA,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useApiClient, useBusinessId } from '../../../context/ApiContext.mjs';
|
|
2
|
+
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
3
|
+
import { SBApiKeys } from '../../SBApiKeys.mjs';
|
|
4
|
+
|
|
5
|
+
function useTablesQuery() {
|
|
6
|
+
const client = useApiClient();
|
|
7
|
+
const businessId = useBusinessId();
|
|
8
|
+
return useQuery({
|
|
9
|
+
queryKey: [SBApiKeys.Tables, businessId],
|
|
10
|
+
queryFn: async () => {
|
|
11
|
+
return await client.tables.getAllAsync(businessId);
|
|
12
|
+
},
|
|
13
|
+
enabled: !!businessId
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function useTableByIdQuery(tableId) {
|
|
17
|
+
const client = useApiClient();
|
|
18
|
+
const businessId = useBusinessId();
|
|
19
|
+
return useQuery({
|
|
20
|
+
queryKey: [SBApiKeys.Tables, businessId, tableId],
|
|
21
|
+
queryFn: async () => {
|
|
22
|
+
return await client.tables.getByIdAsync(businessId, tableId);
|
|
23
|
+
},
|
|
24
|
+
enabled: !!businessId && !!tableId
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function useCreateTableMutation() {
|
|
28
|
+
const client = useApiClient();
|
|
29
|
+
const businessId = useBusinessId();
|
|
30
|
+
const queryClient = useQueryClient();
|
|
31
|
+
return useMutation({
|
|
32
|
+
mutationFn: async ({
|
|
33
|
+
data,
|
|
34
|
+
options,
|
|
35
|
+
config
|
|
36
|
+
}) => {
|
|
37
|
+
return await client.tables.createAsync(businessId, data, options, config);
|
|
38
|
+
},
|
|
39
|
+
onSuccess: () => {
|
|
40
|
+
queryClient.invalidateQueries({
|
|
41
|
+
queryKey: [SBApiKeys.Tables, businessId]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function useUpdateTableMutation(tableId) {
|
|
47
|
+
const client = useApiClient();
|
|
48
|
+
const businessId = useBusinessId();
|
|
49
|
+
const queryClient = useQueryClient();
|
|
50
|
+
return useMutation({
|
|
51
|
+
mutationFn: async ({
|
|
52
|
+
data,
|
|
53
|
+
options,
|
|
54
|
+
config
|
|
55
|
+
}) => {
|
|
56
|
+
return await client.tables.updateAsync(businessId, tableId, data, options, config);
|
|
57
|
+
},
|
|
58
|
+
onSuccess: () => {
|
|
59
|
+
queryClient.invalidateQueries({
|
|
60
|
+
queryKey: [SBApiKeys.Tables, businessId]
|
|
61
|
+
});
|
|
62
|
+
queryClient.invalidateQueries({
|
|
63
|
+
queryKey: [SBApiKeys.Tables, businessId, tableId]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { useCreateTableMutation, useTableByIdQuery, useTablesQuery, useUpdateTableMutation };
|
|
70
|
+
//# sourceMappingURL=TablesAPI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TablesAPI.mjs","sources":["../../../../../src/apis/business/tables/TablesAPI.tsx"],"sourcesContent":["import {\n\tSBTable,\n\tTableCreateRequest,\n\tTableUpdateRequest,\n\tSBApiException,\n\tSBRequestOptions,\n} from \"@smartbills/sdk\";\nimport { useApiClient, useBusinessId } from \"@/context\";\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { AxiosRequestConfig } from \"axios\";\nimport { SBApiKeys } from \"@/apis/SBApiKeys\";\n\nexport function useTablesQuery() {\n\tconst client = useApiClient();\n\tconst businessId = useBusinessId();\n\treturn useQuery<SBTable[], SBApiException>({\n\t\tqueryKey: [SBApiKeys.Tables, businessId],\n\t\tqueryFn: async () => {\n\t\t\treturn await client.tables.getAllAsync(businessId);\n\t\t},\n\t\tenabled: !!businessId,\n\t});\n}\n\nexport function useTableByIdQuery(tableId: number) {\n\tconst client = useApiClient();\n\tconst businessId = useBusinessId();\n\treturn useQuery<SBTable, SBApiException>({\n\t\tqueryKey: [SBApiKeys.Tables, businessId, tableId],\n\t\tqueryFn: async () => {\n\t\t\treturn await client.tables.getByIdAsync(businessId, tableId);\n\t\t},\n\t\tenabled: !!businessId && !!tableId,\n\t});\n}\n\nexport function useCreateTableMutation() {\n\tconst client = useApiClient();\n\tconst businessId = useBusinessId();\n\tconst queryClient = useQueryClient();\n\treturn useMutation<\n\t\tSBTable,\n\t\tSBApiException,\n\t\t{\n\t\t\tdata: TableCreateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ data, options, config }) => {\n\t\t\treturn await client.tables.createAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tdata,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: () => {\n\t\t\tqueryClient.invalidateQueries({\n\t\t\t\tqueryKey: [SBApiKeys.Tables, businessId],\n\t\t\t});\n\t\t},\n\t});\n}\n\nexport function useUpdateTableMutation(tableId: number) {\n\tconst client = useApiClient();\n\tconst businessId = useBusinessId();\n\tconst queryClient = useQueryClient();\n\treturn useMutation<\n\t\tSBTable,\n\t\tSBApiException,\n\t\t{\n\t\t\tdata: TableUpdateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ data, options, config }) => {\n\t\t\treturn await client.tables.updateAsync(\n\t\t\t\tbusinessId,\n\t\t\t\ttableId,\n\t\t\t\tdata,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: () => {\n\t\t\tqueryClient.invalidateQueries({\n\t\t\t\tqueryKey: [SBApiKeys.Tables, businessId],\n\t\t\t});\n\t\t\tqueryClient.invalidateQueries({\n\t\t\t\tqueryKey: [SBApiKeys.Tables, businessId, tableId],\n\t\t\t});\n\t\t},\n\t});\n}\n"],"names":["useTablesQuery","client","useApiClient","businessId","useBusinessId","useQuery","queryKey","SBApiKeys","Tables","queryFn","tables","getAllAsync","enabled","useTableByIdQuery","tableId","getByIdAsync","useCreateTableMutation","queryClient","useQueryClient","useMutation","mutationFn","data","options","config","createAsync","onSuccess","invalidateQueries","useUpdateTableMutation","updateAsync"],"mappings":";;;;SAYgBA,cAAcA,GAAA;AAC7B,EAAA,MAAMC,MAAM,GAAGC,YAAY,EAAE;AAC7B,EAAA,MAAMC,UAAU,GAAGC,aAAa,EAAE;AAClC,EAAA,OAAOC,QAAQ,CAA4B;AAC1CC,IAAAA,QAAQ,EAAE,CAACC,SAAS,CAACC,MAAM,EAAEL,UAAU,CAAC;IACxCM,OAAO,EAAE,YAAW;MACnB,OAAO,MAAMR,MAAM,CAACS,MAAM,CAACC,WAAW,CAACR,UAAU,CAAC;KAClD;IACDS,OAAO,EAAE,CAAC,CAACT;AACX,GAAA,CAAC;AACH;AAEM,SAAUU,iBAAiBA,CAACC,OAAe,EAAA;AAChD,EAAA,MAAMb,MAAM,GAAGC,YAAY,EAAE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