@smartbills/react-hooks-sdk 0.0.2-alpha.44 → 0.0.2-alpha.46
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 +1447 -0
- package/dist/@types/index.d.ts.map +1 -0
- package/dist/cjs/apis/SBApiKeys.cjs +56 -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 +237 -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 +215 -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 +224 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/apis/SBApiKeys.mjs +56 -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 +228 -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 +204 -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 +5099 -0
- package/dist/umd/index.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useApiClient, useBusinessId } from '../../../context/ApiContext.mjs';
|
|
2
|
+
import { useQueryClient, useInfiniteQuery, useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { SBApiKeys } from '../../SBApiKeys.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to list balance transactions for a customer with infinite scrolling
|
|
7
|
+
* @param customerId - The customer ID
|
|
8
|
+
* @param request - The list request parameters
|
|
9
|
+
* @param options - Optional request options
|
|
10
|
+
* @param config - Optional axios request config
|
|
11
|
+
* @returns Query result containing the customer balance transactions
|
|
12
|
+
*/
|
|
13
|
+
const useListCustomerBalanceTransactionsInfiniteQuery = (customerId, 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 customer balance transaction operations");
|
|
22
|
+
}
|
|
23
|
+
return useInfiniteQuery({
|
|
24
|
+
initialPageParam: request.page || 1,
|
|
25
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Customers, customerId, SBApiKeys.CustomerBalanceTransactions, request, options],
|
|
26
|
+
queryFn: async ({
|
|
27
|
+
pageParam = 1
|
|
28
|
+
}) => {
|
|
29
|
+
return await client.businesses.customerBalanceTransactions.listAsync(businessId, customerId, {
|
|
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 && !!customerId
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Hook to get a specific balance transaction for a customer
|
|
45
|
+
* @param customerId - The customer ID
|
|
46
|
+
* @param transactionId - The balance transaction ID
|
|
47
|
+
* @param options - Optional request options
|
|
48
|
+
* @param config - Optional axios request config
|
|
49
|
+
* @returns Query result containing the customer balance transaction
|
|
50
|
+
*/
|
|
51
|
+
const useGetCustomerBalanceTransactionByIdQuery = (customerId, transactionId, options, config) => {
|
|
52
|
+
const client = useApiClient();
|
|
53
|
+
useQueryClient();
|
|
54
|
+
const businessId = useBusinessId();
|
|
55
|
+
if (!businessId) {
|
|
56
|
+
throw new Error("businessId is required for customer balance transaction operations");
|
|
57
|
+
}
|
|
58
|
+
return useQuery({
|
|
59
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Customers, customerId, SBApiKeys.CustomerBalanceTransactions, transactionId, options],
|
|
60
|
+
queryFn: async () => {
|
|
61
|
+
return await client.businesses.customerBalanceTransactions.getByIdAsync(businessId, customerId, transactionId, options, config);
|
|
62
|
+
},
|
|
63
|
+
enabled: !!businessId && !!customerId && !!transactionId
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { useGetCustomerBalanceTransactionByIdQuery, useListCustomerBalanceTransactionsInfiniteQuery };
|
|
68
|
+
//# sourceMappingURL=CustomerBalanceTransactionsAPI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomerBalanceTransactionsAPI.mjs","sources":["../../../../../src/apis/business/customers/CustomerBalanceTransactionsAPI.ts"],"sourcesContent":["import {\n\tSBList,\n\tSBRequestOptions,\n\tCustomerBalanceTransactionListRequest,\n\tSBCustomerBalanceTransaction,\n\tSBApiException,\n} from \"@smartbills/sdk\";\n\nimport { useApiClient } from \"@/context\";\nimport {\n\tQueryKey,\n\tuseInfiniteQuery,\n\tuseQuery,\n\tuseQueryClient,\n} from \"@tanstack/react-query\";\nimport { AxiosRequestConfig } from \"axios\";\nimport { SBApiKeys } from \"@/apis/SBApiKeys\";\nimport { useBusinessId } from \"@/context\";\n\n/**\n * Hook to list balance transactions for a customer with infinite scrolling\n * @param customerId - The customer ID\n * @param request - The list request parameters\n * @param options - Optional request options\n * @param config - Optional axios request config\n * @returns Query result containing the customer balance transactions\n */\nexport const useListCustomerBalanceTransactionsInfiniteQuery = (\n\tcustomerId: number,\n\trequest: CustomerBalanceTransactionListRequest = { page: 1, pageSize: 25 },\n\toptions?: SBRequestOptions,\n\tconfig?: AxiosRequestConfig<CustomerBalanceTransactionListRequest>,\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 customer balance transaction operations\",\n\t\t);\n\t}\n\n\treturn useInfiniteQuery<\n\t\tSBList<SBCustomerBalanceTransaction>,\n\t\tSBApiException,\n\t\tSBList<SBCustomerBalanceTransaction>,\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.Customers,\n\t\t\tcustomerId,\n\t\t\tSBApiKeys.CustomerBalanceTransactions,\n\t\t\trequest,\n\t\t\toptions,\n\t\t],\n\t\tqueryFn: async ({ pageParam = 1 }) => {\n\t\t\treturn await client.businesses.customerBalanceTransactions.listAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tcustomerId,\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 && !!customerId,\n\t});\n};\n\n/**\n * Hook to get a specific balance transaction for a customer\n * @param customerId - The customer ID\n * @param transactionId - The balance transaction ID\n * @param options - Optional request options\n * @param config - Optional axios request config\n * @returns Query result containing the customer balance transaction\n */\nexport const useGetCustomerBalanceTransactionByIdQuery = (\n\tcustomerId: number,\n\ttransactionId: 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(\n\t\t\t\"businessId is required for customer balance transaction operations\",\n\t\t);\n\t}\n\n\treturn useQuery<SBCustomerBalanceTransaction, SBApiException>({\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.Customers,\n\t\t\tcustomerId,\n\t\t\tSBApiKeys.CustomerBalanceTransactions,\n\t\t\ttransactionId,\n\t\t\toptions,\n\t\t],\n\t\tqueryFn: async () => {\n\t\t\treturn await client.businesses.customerBalanceTransactions.getByIdAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tcustomerId,\n\t\t\t\ttransactionId,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tenabled: !!businessId && !!customerId && !!transactionId,\n\t});\n};\n"],"names":["useListCustomerBalanceTransactionsInfiniteQuery","customerId","request","page","pageSize","options","config","client","useApiClient","useQueryClient","businessId","useBusinessId","Error","useInfiniteQuery","initialPageParam","queryKey","SBApiKeys","Businesses","Customers","CustomerBalanceTransactions","queryFn","pageParam","businesses","customerBalanceTransactions","listAsync","getNextPageParam","lastPage","pagination","currentPage","pageCount","undefined","enabled","useGetCustomerBalanceTransactionByIdQuery","transactionId","useQuery","getByIdAsync"],"mappings":";;;;AAmBA;;;;;;;AAOG;MACUA,+CAA+C,GAAGA,CAC9DC,UAAkB,EAClBC,OAAiD,GAAA;AAAEC,EAAAA,IAAI,EAAE,CAAC;AAAEC,EAAAA,QAAQ,EAAE;AAAE,CAAE,EAC1EC,OAA0B,EAC1BC,MAAkE,KAC/D;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,CACd,oEAAoE,CACpE;AACF;AAEA,EAAA,OAAOC,gBAAgB,CAMr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ACnBjB,UAAU,EACVe,SAAS,CAACG,2BAA2B,EACrCc,aAAa,EACb5B,OAAO,CACP;IACDe,OAAO,EAAE,YAAW;AACnB,MAAA,OAAO,MAAMb,MAAM,CAACe,UAAU,CAACC,2BAA2B,CAACY,YAAY,CACtEzB,UAAU,EACVT,UAAU,EACVgC,aAAa,EACb5B,OAAO,EACPC,MAAM,CACN;KACD;IACDyB,OAAO,EAAE,CAAC,CAACrB,UAAU,IAAI,CAAC,CAACT,UAAU,IAAI,CAAC,CAACgC;AAC3C,GAAA,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,170 @@
|
|
|
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 list a customer's payment methods with infinite query
|
|
7
|
+
* @param customerId - The customer ID
|
|
8
|
+
* @param request - Request parameters for listing payment methods
|
|
9
|
+
* @param options - Optional request options
|
|
10
|
+
* @param config - Optional axios request config
|
|
11
|
+
* @returns Infinite query result containing the customer's payment methods
|
|
12
|
+
*/
|
|
13
|
+
const useListCustomerPaymentMethodsInfiniteQuery = (customerId, 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 customer payment method operations");
|
|
22
|
+
}
|
|
23
|
+
return useInfiniteQuery({
|
|
24
|
+
initialPageParam: request.page || 1,
|
|
25
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Customers, customerId, SBApiKeys.CustomerPaymentMethods, request],
|
|
26
|
+
queryFn: async ({
|
|
27
|
+
pageParam = 1
|
|
28
|
+
}) => {
|
|
29
|
+
return await client.businesses.customerPaymentMethods.listAsync(businessId, customerId, {
|
|
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 && !!customerId
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Hook to get a specific payment method for a customer
|
|
45
|
+
* @param customerId - The customer ID
|
|
46
|
+
* @param id - The payment method ID
|
|
47
|
+
* @param options - Optional request options
|
|
48
|
+
* @param config - Optional axios request config
|
|
49
|
+
* @returns Query result containing the payment method
|
|
50
|
+
*/
|
|
51
|
+
const useGetCustomerPaymentMethodByIdQuery = (customerId, id, options, config) => {
|
|
52
|
+
const client = useApiClient();
|
|
53
|
+
useQueryClient();
|
|
54
|
+
const businessId = useBusinessId();
|
|
55
|
+
if (!businessId) {
|
|
56
|
+
throw new Error("businessId is required for customer payment method operations");
|
|
57
|
+
}
|
|
58
|
+
return useQuery({
|
|
59
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Customers, customerId, SBApiKeys.CustomerPaymentMethods, id, options],
|
|
60
|
+
queryFn: async () => {
|
|
61
|
+
return await client.businesses.customerPaymentMethods.getByIdAsync(businessId, customerId, id, options, config);
|
|
62
|
+
},
|
|
63
|
+
enabled: !!businessId && !!customerId
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Hook to create a customer payment method
|
|
68
|
+
* @returns Mutation function and state for creating payment methods
|
|
69
|
+
*/
|
|
70
|
+
const useCreateCustomerPaymentMethodMutation = () => {
|
|
71
|
+
const client = useApiClient();
|
|
72
|
+
const queryClient = useQueryClient();
|
|
73
|
+
const businessId = useBusinessId();
|
|
74
|
+
return useMutation({
|
|
75
|
+
mutationFn: async ({
|
|
76
|
+
customerId,
|
|
77
|
+
data,
|
|
78
|
+
options,
|
|
79
|
+
config
|
|
80
|
+
}) => {
|
|
81
|
+
if (!businessId) {
|
|
82
|
+
throw new Error("businessId is required for customer payment method operations");
|
|
83
|
+
}
|
|
84
|
+
return await client.businesses.customerPaymentMethods.createAsync(businessId, customerId, data, options, config);
|
|
85
|
+
},
|
|
86
|
+
onSuccess: (_, {
|
|
87
|
+
customerId
|
|
88
|
+
}) => {
|
|
89
|
+
if (businessId) {
|
|
90
|
+
queryClient.invalidateQueries({
|
|
91
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Customers, customerId, SBApiKeys.CustomerPaymentMethods]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Hook to update a customer payment method
|
|
99
|
+
* @returns Mutation function and state for updating payment methods
|
|
100
|
+
*/
|
|
101
|
+
const useUpdateCustomerPaymentMethodMutation = () => {
|
|
102
|
+
const client = useApiClient();
|
|
103
|
+
const queryClient = useQueryClient();
|
|
104
|
+
const businessId = useBusinessId();
|
|
105
|
+
return useMutation({
|
|
106
|
+
mutationFn: async ({
|
|
107
|
+
customerId,
|
|
108
|
+
id,
|
|
109
|
+
data,
|
|
110
|
+
options,
|
|
111
|
+
config
|
|
112
|
+
}) => {
|
|
113
|
+
if (!businessId) {
|
|
114
|
+
throw new Error("businessId is required for customer payment method operations");
|
|
115
|
+
}
|
|
116
|
+
return await client.businesses.customerPaymentMethods.updateAsync(businessId, customerId, id, data, options, config);
|
|
117
|
+
},
|
|
118
|
+
onSuccess: (_, {
|
|
119
|
+
customerId,
|
|
120
|
+
id
|
|
121
|
+
}) => {
|
|
122
|
+
if (businessId) {
|
|
123
|
+
queryClient.invalidateQueries({
|
|
124
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Customers, customerId, SBApiKeys.CustomerPaymentMethods]
|
|
125
|
+
});
|
|
126
|
+
queryClient.invalidateQueries({
|
|
127
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Customers, customerId, SBApiKeys.CustomerPaymentMethods, id]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Hook to delete a customer payment method
|
|
135
|
+
* @returns Mutation function and state for deleting payment methods
|
|
136
|
+
*/
|
|
137
|
+
const useDeleteCustomerPaymentMethodMutation = () => {
|
|
138
|
+
const client = useApiClient();
|
|
139
|
+
const queryClient = useQueryClient();
|
|
140
|
+
const businessId = useBusinessId();
|
|
141
|
+
return useMutation({
|
|
142
|
+
mutationFn: async ({
|
|
143
|
+
customerId,
|
|
144
|
+
id,
|
|
145
|
+
options,
|
|
146
|
+
config
|
|
147
|
+
}) => {
|
|
148
|
+
if (!businessId) {
|
|
149
|
+
throw new Error("businessId is required for customer payment method operations");
|
|
150
|
+
}
|
|
151
|
+
return await client.businesses.customerPaymentMethods.deleteAsync(businessId, customerId, id, options, config);
|
|
152
|
+
},
|
|
153
|
+
onSuccess: (_, {
|
|
154
|
+
customerId,
|
|
155
|
+
id
|
|
156
|
+
}) => {
|
|
157
|
+
if (businessId) {
|
|
158
|
+
queryClient.invalidateQueries({
|
|
159
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Customers, customerId, SBApiKeys.CustomerPaymentMethods]
|
|
160
|
+
});
|
|
161
|
+
queryClient.invalidateQueries({
|
|
162
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Customers, customerId, SBApiKeys.CustomerPaymentMethods, id]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export { useCreateCustomerPaymentMethodMutation, useDeleteCustomerPaymentMethodMutation, useGetCustomerPaymentMethodByIdQuery, useListCustomerPaymentMethodsInfiniteQuery, useUpdateCustomerPaymentMethodMutation };
|
|
170
|
+
//# sourceMappingURL=CustomerPaymentMethodsAPI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomerPaymentMethodsAPI.mjs","sources":["../../../../../src/apis/business/customers/CustomerPaymentMethodsAPI.ts"],"sourcesContent":["import {\n\tCustomerPaymentMethodListRequest,\n\tSBPaymentMethod,\n\tSBRequestOptions,\n\tSBList,\n\tCustomerPaymentMethodCreateRequest,\n\tCustomerPaymentMethodUpdateRequest,\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 { SBApiKeys } from \"@/apis/SBApiKeys\";\nimport { AxiosRequestConfig } from \"axios\";\nimport { useBusinessId } from \"@/context\";\n\n/**\n * Hook to list a customer's payment methods with infinite query\n * @param customerId - The customer ID\n * @param request - Request parameters for listing payment methods\n * @param options - Optional request options\n * @param config - Optional axios request config\n * @returns Infinite query result containing the customer's payment methods\n */\nexport const useListCustomerPaymentMethodsInfiniteQuery = (\n\tcustomerId: number,\n\trequest: CustomerPaymentMethodListRequest = { 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 customer payment method operations\",\n\t\t);\n\t}\n\n\treturn useInfiniteQuery<\n\t\tSBList<SBPaymentMethod>,\n\t\tSBApiException,\n\t\tSBList<SBPaymentMethod>,\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.Customers,\n\t\t\tcustomerId,\n\t\t\tSBApiKeys.CustomerPaymentMethods,\n\t\t\trequest,\n\t\t],\n\t\tqueryFn: async ({ pageParam = 1 }) => {\n\t\t\treturn await client.businesses.customerPaymentMethods.listAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tcustomerId,\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 && !!customerId,\n\t});\n};\n\n/**\n * Hook to get a specific payment method for a customer\n * @param customerId - The customer ID\n * @param id - The payment method ID\n * @param options - Optional request options\n * @param config - Optional axios request config\n * @returns Query result containing the payment method\n */\nexport const useGetCustomerPaymentMethodByIdQuery = (\n\tcustomerId: number,\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(\n\t\t\t\"businessId is required for customer payment method operations\",\n\t\t);\n\t}\n\n\treturn useQuery<SBPaymentMethod, SBApiException>({\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.Customers,\n\t\t\tcustomerId,\n\t\t\tSBApiKeys.CustomerPaymentMethods,\n\t\t\tid,\n\t\t\toptions,\n\t\t],\n\t\tqueryFn: async () => {\n\t\t\treturn await client.businesses.customerPaymentMethods.getByIdAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tcustomerId,\n\t\t\t\tid,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tenabled: !!businessId && !!customerId,\n\t});\n};\n\n/**\n * Hook to create a customer payment method\n * @returns Mutation function and state for creating payment methods\n */\nexport const useCreateCustomerPaymentMethodMutation = () => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBPaymentMethod,\n\t\tSBApiException,\n\t\t{\n\t\t\tcustomerId: number;\n\t\t\tdata: CustomerPaymentMethodCreateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ customerId, 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 customer payment method operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await client.businesses.customerPaymentMethods.createAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tcustomerId,\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: (_, { customerId }) => {\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.Customers,\n\t\t\t\t\t\tcustomerId,\n\t\t\t\t\t\tSBApiKeys.CustomerPaymentMethods,\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 a customer payment method\n * @returns Mutation function and state for updating payment methods\n */\nexport const useUpdateCustomerPaymentMethodMutation = () => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBPaymentMethod,\n\t\tSBApiException,\n\t\t{\n\t\t\tcustomerId: number;\n\t\t\tid: number;\n\t\t\tdata: CustomerPaymentMethodUpdateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ customerId, id, 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 customer payment method operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await client.businesses.customerPaymentMethods.updateAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tcustomerId,\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: (_, { customerId, 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.Customers,\n\t\t\t\t\t\tcustomerId,\n\t\t\t\t\t\tSBApiKeys.CustomerPaymentMethods,\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.Customers,\n\t\t\t\t\t\tcustomerId,\n\t\t\t\t\t\tSBApiKeys.CustomerPaymentMethods,\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\n/**\n * Hook to delete a customer payment method\n * @returns Mutation function and state for deleting payment methods\n */\nexport const useDeleteCustomerPaymentMethodMutation = () => {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBPaymentMethod,\n\t\tSBApiException,\n\t\t{\n\t\t\tcustomerId: number;\n\t\t\tid: number;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ customerId, 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 customer payment method operations\",\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await client.businesses.customerPaymentMethods.deleteAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tcustomerId,\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: (_, { customerId, 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.Customers,\n\t\t\t\t\t\tcustomerId,\n\t\t\t\t\t\tSBApiKeys.CustomerPaymentMethods,\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.Customers,\n\t\t\t\t\t\tcustomerId,\n\t\t\t\t\t\tSBApiKeys.CustomerPaymentMethods,\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":["useListCustomerPaymentMethodsInfiniteQuery","customerId","request","page","pageSize","options","config","client","useApiClient","useQueryClient","businessId","useBusinessId","Error","useInfiniteQuery","initialPageParam","queryKey","SBApiKeys","Businesses","Customers","CustomerPaymentMethods","queryFn","pageParam","businesses","customerPaymentMethods","listAsync","getNextPageParam","lastPage","pagination","currentPage","pageCount","undefined","enabled","useGetCustomerPaymentMethodByIdQuery","id","useQuery","getByIdAsync","useCreateCustomerPaymentMethodMutation","queryClient","useMutation","mutationFn","data","createAsync","onSuccess","_","invalidateQueries","useUpdateCustomerPaymentMethodMutation","updateAsync","useDeleteCustomerPaymentMethodMutation","deleteA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SAAS,CAACE,SAAS,EACnBjB,UAAU,EACVe,SAAS,CAACG,sBAAsB,EAChCc,EAAE;AAEH,SAAA,CAAC;AACH;AACD;AACA,GAAA,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,161 @@
|
|
|
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 departments using infinite query
|
|
7
|
+
* @param request - The pagination request parameters
|
|
8
|
+
* @param options - Optional request options
|
|
9
|
+
* @param config - Optional Axios request configuration
|
|
10
|
+
* @returns An infinite query result containing paginated departments data
|
|
11
|
+
*/
|
|
12
|
+
function useListDepartmentsInfiniteQuery(request = {
|
|
13
|
+
page: 1,
|
|
14
|
+
pageSize: 25
|
|
15
|
+
}, options, config) {
|
|
16
|
+
const client = useApiClient();
|
|
17
|
+
useQueryClient();
|
|
18
|
+
const businessId = useBusinessId();
|
|
19
|
+
if (!businessId) {
|
|
20
|
+
throw new Error("businessId is required for department operations");
|
|
21
|
+
}
|
|
22
|
+
return useInfiniteQuery({
|
|
23
|
+
initialPageParam: request.page || 1,
|
|
24
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments, request, options],
|
|
25
|
+
queryFn: async ({
|
|
26
|
+
pageParam
|
|
27
|
+
}) => {
|
|
28
|
+
return await client.businesses.departments.listAsync(businessId, {
|
|
29
|
+
...request,
|
|
30
|
+
page: pageParam
|
|
31
|
+
}, options, config);
|
|
32
|
+
},
|
|
33
|
+
getNextPageParam: lastPage => {
|
|
34
|
+
if (lastPage.pagination.currentPage < lastPage.pagination.pageCount) {
|
|
35
|
+
return lastPage.pagination.currentPage + 1;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
},
|
|
39
|
+
enabled: !!businessId
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Hook to fetch a list of departments
|
|
44
|
+
* @param request - The pagination request parameters
|
|
45
|
+
* @param options - Optional request options
|
|
46
|
+
* @param config - Optional Axios request configuration
|
|
47
|
+
* @returns A query result containing paginated departments data
|
|
48
|
+
*/
|
|
49
|
+
function useListDepartmentsQuery(request = {
|
|
50
|
+
page: 1,
|
|
51
|
+
pageSize: 25
|
|
52
|
+
}, options, config) {
|
|
53
|
+
const client = useApiClient();
|
|
54
|
+
useQueryClient();
|
|
55
|
+
const businessId = useBusinessId();
|
|
56
|
+
return useQuery({
|
|
57
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments, request],
|
|
58
|
+
queryFn: async () => {
|
|
59
|
+
return await client.businesses.departments.listAsync(businessId, request, options, config);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Hook to fetch a specific department by ID
|
|
65
|
+
* @param departmentId - The ID of the department to retrieve
|
|
66
|
+
* @param options - Optional request options
|
|
67
|
+
* @param config - Optional Axios request configuration
|
|
68
|
+
* @returns A query result containing the department data
|
|
69
|
+
*/
|
|
70
|
+
function useGetDepartmentByIdQuery(departmentId, options, config) {
|
|
71
|
+
const client = useApiClient();
|
|
72
|
+
useQueryClient();
|
|
73
|
+
const businessId = useBusinessId();
|
|
74
|
+
return useQuery({
|
|
75
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments, departmentId],
|
|
76
|
+
queryFn: async () => await client.businesses.departments.getByIdAsync(businessId, departmentId, options, config)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Hook to create a new department
|
|
81
|
+
* @returns A mutation function to create a department
|
|
82
|
+
*/
|
|
83
|
+
function useCreateDepartmentMutation() {
|
|
84
|
+
const client = useApiClient();
|
|
85
|
+
const queryClient = useQueryClient();
|
|
86
|
+
const businessId = useBusinessId();
|
|
87
|
+
return useMutation({
|
|
88
|
+
mutationFn: async ({
|
|
89
|
+
request,
|
|
90
|
+
options,
|
|
91
|
+
config
|
|
92
|
+
}) => {
|
|
93
|
+
return await client.businesses.departments.createAsync(businessId, request, options, config);
|
|
94
|
+
},
|
|
95
|
+
onSuccess: () => {
|
|
96
|
+
queryClient.invalidateQueries({
|
|
97
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Hook to update an existing department
|
|
104
|
+
* @returns A mutation function to update a department
|
|
105
|
+
*/
|
|
106
|
+
function useUpdateDepartmentMutation() {
|
|
107
|
+
const client = useApiClient();
|
|
108
|
+
const queryClient = useQueryClient();
|
|
109
|
+
const businessId = useBusinessId();
|
|
110
|
+
return useMutation({
|
|
111
|
+
mutationFn: async ({
|
|
112
|
+
departmentId,
|
|
113
|
+
request,
|
|
114
|
+
options,
|
|
115
|
+
config
|
|
116
|
+
}) => {
|
|
117
|
+
return await client.businesses.departments.updateAsync(businessId, departmentId, request, options, config);
|
|
118
|
+
},
|
|
119
|
+
onSuccess: (_, {
|
|
120
|
+
departmentId
|
|
121
|
+
}) => {
|
|
122
|
+
queryClient.invalidateQueries({
|
|
123
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments]
|
|
124
|
+
});
|
|
125
|
+
queryClient.invalidateQueries({
|
|
126
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments, departmentId]
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Hook to delete a department
|
|
133
|
+
* @returns A mutation function to delete a department
|
|
134
|
+
*/
|
|
135
|
+
function useDeleteDepartmentMutation() {
|
|
136
|
+
const client = useApiClient();
|
|
137
|
+
const queryClient = useQueryClient();
|
|
138
|
+
const businessId = useBusinessId();
|
|
139
|
+
return useMutation({
|
|
140
|
+
mutationFn: async ({
|
|
141
|
+
departmentId,
|
|
142
|
+
options,
|
|
143
|
+
config
|
|
144
|
+
}) => {
|
|
145
|
+
return await client.businesses.departments.deleteAsync(businessId, departmentId, options, config);
|
|
146
|
+
},
|
|
147
|
+
onSuccess: (_, {
|
|
148
|
+
departmentId
|
|
149
|
+
}) => {
|
|
150
|
+
queryClient.invalidateQueries({
|
|
151
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments]
|
|
152
|
+
});
|
|
153
|
+
queryClient.invalidateQueries({
|
|
154
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments, departmentId]
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { useCreateDepartmentMutation, useDeleteDepartmentMutation, useGetDepartmentByIdQuery, useListDepartmentsInfiniteQuery, useListDepartmentsQuery, useUpdateDepartmentMutation };
|
|
161
|
+
//# sourceMappingURL=DepartmentApi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DepartmentApi.mjs","sources":["../../../../../src/apis/business/departments/DepartmentApi.tsx"],"sourcesContent":["import {\n\tSBEntity,\n\tITimestamp,\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 { SBApiKeys } from \"@/apis/SBApiKeys\";\nimport { AxiosRequestConfig } from \"axios\";\nimport { useBusinessId } from \"@/context\";\n\n/**\n * NOTE: This API implementation assumes that the SDK has a departments service\n * which may still need to be implemented in the SDK. The implementation follows\n * the same pattern as the EmployeesAPI but requires the BusinessService to have\n * a departments property.\n */\n\n// Define Department interface based on SBEntity\ninterface SBDepartment extends SBEntity, ITimestamp {\n\tname: string;\n\tdescription?: string;\n\tbusinessId: number;\n}\n\n// Define request types\ninterface DepartmentCreateRequest {\n\tname: string;\n\tdescription?: string;\n}\n\ninterface DepartmentUpdateRequest {\n\tname?: string;\n\tdescription?: string;\n}\n\n/**\n * Hook to fetch a list of departments using infinite query\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 departments data\n */\nexport function useListDepartmentsInfiniteQuery(\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(\"businessId is required for department operations\");\n\t}\n\n\treturn useInfiniteQuery<\n\t\tSBList<SBDepartment>,\n\t\tSBApiException,\n\t\tSBList<SBDepartment>,\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.Departments,\n\t\t\trequest,\n\t\t\toptions,\n\t\t],\n\t\tqueryFn: async ({ pageParam }) => {\n\t\t\treturn await client.businesses.departments.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.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\n/**\n * Hook to fetch a list of departments\n * @param request - The pagination request parameters\n * @param options - Optional request options\n * @param config - Optional Axios request configuration\n * @returns A query result containing paginated departments data\n */\nexport function useListDepartmentsQuery(\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\treturn useQuery({\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.Departments,\n\t\t\trequest,\n\t\t],\n\t\tqueryFn: async () => {\n\t\t\treturn await client.businesses.departments.listAsync(\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});\n}\n\n/**\n * Hook to fetch a specific department by ID\n * @param departmentId - The ID of the department to retrieve\n * @param options - Optional request options\n * @param config - Optional Axios request configuration\n * @returns A query result containing the department data\n */\nexport function useGetDepartmentByIdQuery(\n\tdepartmentId: number,\n\toptions?: SBRequestOptions,\n\tconfig?: AxiosRequestConfig,\n) {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useQuery<SBDepartment, SBApiException>({\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.Departments,\n\t\t\tdepartmentId,\n\t\t],\n\t\tqueryFn: async () =>\n\t\t\tawait client.businesses.departments.getByIdAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tdepartmentId,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t),\n\t});\n}\n\n/**\n * Hook to create a new department\n * @returns A mutation function to create a department\n */\nexport function useCreateDepartmentMutation() {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBDepartment,\n\t\tSBApiException,\n\t\t{\n\t\t\trequest: DepartmentCreateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ request, options, config }) => {\n\t\t\treturn await client.businesses.departments.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\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.Departments,\n\t\t\t\t],\n\t\t\t});\n\t\t},\n\t});\n}\n\n/**\n * Hook to update an existing department\n * @returns A mutation function to update a department\n */\nexport function useUpdateDepartmentMutation() {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBDepartment,\n\t\tSBApiException,\n\t\t{\n\t\t\tdepartmentId: number;\n\t\t\trequest: DepartmentUpdateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ departmentId, request, options, config }) => {\n\t\t\treturn await client.businesses.departments.updateAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tdepartmentId,\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: (_, { departmentId }) => {\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.Departments,\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.Departments,\n\t\t\t\t\tdepartmentId,\n\t\t\t\t],\n\t\t\t});\n\t\t},\n\t});\n}\n\n/**\n * Hook to delete a department\n * @returns A mutation function to delete a department\n */\nexport function useDeleteDepartmentMutation() {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBDepartment,\n\t\tSBApiException,\n\t\t{\n\t\t\tdepartmentId: number;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ departmentId, options, config }) => {\n\t\t\treturn await client.businesses.departments.deleteAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tdepartmentId,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: (_, { departmentId }) => {\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.Departments,\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.Departments,\n\t\t\t\t\tdepartmentId,\n\t\t\t\t],\n\t\t\t});\n\t\t},\n\t});\n}\n"],"names":["useListDepartmentsInfiniteQuery","request","page","pageSize","options","config","client","useApiClient","useQueryClient","businessId","useBusinessId","Error","useInfiniteQuery","initialPageParam","queryKey","SBApiKeys","Businesses","Departments","queryFn","pageParam","businesses","departments","listAsync","getNextPageParam","lastPage","pagination","currentPage","pageCount","undefined","enabled","useListDepartmentsQuery","useQuery","useGetDepartmentByIdQuery","departmentId","getByIdAsync","useCreateDepartmentMutation","queryClient","useMutation","mutationFn","createAsync","onSuccess","invalidateQueries","useUpdateDepartmentMutation","updateAsync","_","useDeleteDepartmentMutation","deleteAsync"],"mappings":";;;;AA4CA;;;;;;AAMG;SACaA,+BAA+BA,CAC9CC,OAAgD,GAAA;AAAEC,EAAAA,IAAI,EAAE,CAAC;AAAEC,EAAAA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UAAU,GAAGC,aAAa,EAAE;AAElC,EAAA,OAAO2B,WAAW,CAQhB;IACDC,UAAU,EAAE,OAAO;MAAEL,YAAY;MAAE7B,OAAO;AAAEC,MAAAA;AAAQ,KAAA,KAAI;AACvD,MAAA,OAAO,MAAMC,MAAM,CAACc,UAAU,CAACC,WAAW,CAACyB,WAAW,CACrDrC,UAAU,EACVwB,YAAY,EACZ7B,OAAO,EACPC,MAAM,CACN;KACD;IACDmC,SAAS,EAAEA,CAACI,CAAC,EAAE;AAAEX,MAAAA;AAAY,KAAE,KAAI;MAClCG,WAAW,CAACK,iBAAiB,CAAC;QAC7B3B,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBP,UAAU,EACVM,SAAS,CAACE,WAAW;AAEtB,OAAA,CAAC;MACFmB,WAAW,CAACK,iBAAiB,CAAC;AAC7B3B,QAAAA,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBP,UAAU,EACVM,SAAS,CAACE,WAAW,EACrBgB,YAAY;AAEb,OAAA,CAAC;AACH;AACA,GAAA,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
* NOTE: This API implementation assumes that the SDK has a departments service
|
|
7
|
+
* which may still need to be implemented in the SDK. The implementation follows
|
|
8
|
+
* the same pattern as the EmployeesAPI but requires the BusinessService to have
|
|
9
|
+
* a departments property with an employees subproperty.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Hook to fetch a list of employees in a department using infinite query
|
|
13
|
+
* @param departmentId - The ID of the department
|
|
14
|
+
* @param request - The pagination request parameters
|
|
15
|
+
* @param options - Optional request options
|
|
16
|
+
* @param config - Optional Axios request configuration
|
|
17
|
+
* @returns An infinite query result containing paginated department employees data
|
|
18
|
+
*/
|
|
19
|
+
function useListDepartmentEmployeesInfiniteQuery(departmentId, request = {
|
|
20
|
+
page: 1,
|
|
21
|
+
pageSize: 25
|
|
22
|
+
}, options, config) {
|
|
23
|
+
const client = useApiClient();
|
|
24
|
+
useQueryClient();
|
|
25
|
+
const businessId = useBusinessId();
|
|
26
|
+
if (!businessId) {
|
|
27
|
+
throw new Error("businessId is required for department employee operations");
|
|
28
|
+
}
|
|
29
|
+
return useInfiniteQuery({
|
|
30
|
+
initialPageParam: request.page || 1,
|
|
31
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments, departmentId, SBApiKeys.Employees, request, options],
|
|
32
|
+
queryFn: async ({
|
|
33
|
+
pageParam
|
|
34
|
+
}) => {
|
|
35
|
+
return await client.businesses.departments.employees.listAsync(businessId, departmentId, {
|
|
36
|
+
...request,
|
|
37
|
+
page: pageParam
|
|
38
|
+
}, options, config);
|
|
39
|
+
},
|
|
40
|
+
getNextPageParam: lastPage => {
|
|
41
|
+
if (lastPage.pagination.currentPage < lastPage.pagination.pageCount) {
|
|
42
|
+
return lastPage.pagination.currentPage + 1;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
},
|
|
46
|
+
enabled: !!businessId && !!departmentId
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Hook to fetch a list of employees in a department
|
|
51
|
+
* @param departmentId - The ID of the department
|
|
52
|
+
* @param request - The pagination request parameters
|
|
53
|
+
* @param options - Optional request options
|
|
54
|
+
* @param config - Optional Axios request configuration
|
|
55
|
+
* @returns A query result containing paginated department employees data
|
|
56
|
+
*/
|
|
57
|
+
function useListDepartmentEmployeesQuery(departmentId, request = {
|
|
58
|
+
page: 1,
|
|
59
|
+
pageSize: 25
|
|
60
|
+
}, options, config) {
|
|
61
|
+
const client = useApiClient();
|
|
62
|
+
useQueryClient();
|
|
63
|
+
const businessId = useBusinessId();
|
|
64
|
+
return useQuery({
|
|
65
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments, departmentId, SBApiKeys.Employees, request],
|
|
66
|
+
queryFn: async () => {
|
|
67
|
+
return await client.businesses.departments.employees.listAsync(businessId, departmentId, request, options, config);
|
|
68
|
+
},
|
|
69
|
+
enabled: !!businessId && !!departmentId
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Hook to add an employee to a department
|
|
74
|
+
* @returns A mutation function to add an employee to a department
|
|
75
|
+
*/
|
|
76
|
+
function useAddEmployeeToDepartmentMutation() {
|
|
77
|
+
const client = useApiClient();
|
|
78
|
+
const queryClient = useQueryClient();
|
|
79
|
+
const businessId = useBusinessId();
|
|
80
|
+
return useMutation({
|
|
81
|
+
mutationFn: async ({
|
|
82
|
+
departmentId,
|
|
83
|
+
request,
|
|
84
|
+
options,
|
|
85
|
+
config
|
|
86
|
+
}) => {
|
|
87
|
+
return await client.businesses.departments.employees.createAsync(businessId, departmentId, request, options, config);
|
|
88
|
+
},
|
|
89
|
+
onSuccess: (_, {
|
|
90
|
+
departmentId
|
|
91
|
+
}) => {
|
|
92
|
+
queryClient.invalidateQueries({
|
|
93
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments, departmentId, SBApiKeys.Employees]
|
|
94
|
+
});
|
|
95
|
+
queryClient.invalidateQueries({
|
|
96
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Employees]
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Hook to remove an employee from a department
|
|
103
|
+
* @returns A mutation function to remove an employee from a department
|
|
104
|
+
*/
|
|
105
|
+
function useRemoveEmployeeFromDepartmentMutation() {
|
|
106
|
+
const client = useApiClient();
|
|
107
|
+
const queryClient = useQueryClient();
|
|
108
|
+
const businessId = useBusinessId();
|
|
109
|
+
return useMutation({
|
|
110
|
+
mutationFn: async ({
|
|
111
|
+
departmentId,
|
|
112
|
+
employeeId,
|
|
113
|
+
options,
|
|
114
|
+
config
|
|
115
|
+
}) => {
|
|
116
|
+
return await client.businesses.departments.employees.deleteAsync(businessId, departmentId, employeeId, options, config);
|
|
117
|
+
},
|
|
118
|
+
onSuccess: (_, {
|
|
119
|
+
departmentId
|
|
120
|
+
}) => {
|
|
121
|
+
queryClient.invalidateQueries({
|
|
122
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Departments, departmentId, SBApiKeys.Employees]
|
|
123
|
+
});
|
|
124
|
+
queryClient.invalidateQueries({
|
|
125
|
+
queryKey: [SBApiKeys.Businesses, businessId, SBApiKeys.Employees]
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { useAddEmployeeToDepartmentMutation, useListDepartmentEmployeesInfiniteQuery, useListDepartmentEmployeesQuery, useRemoveEmployeeFromDepartmentMutation };
|
|
132
|
+
//# sourceMappingURL=DepartmentEmployeesAPI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DepartmentEmployeesAPI.mjs","sources":["../../../../../../src/apis/business/departments/employees/DepartmentEmployeesAPI.tsx"],"sourcesContent":["import {\n\tSBDepartmentTeamMember,\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 { SBApiKeys } from \"@/apis/SBApiKeys\";\nimport { AxiosRequestConfig } from \"axios\";\nimport { useBusinessId } from \"@/context\";\nimport { DepartmentEmployeeCreateRequest } from \"@smartbills/sdk/dist/@types/services/businesses/departments/Employees/DepartmentEmployeeCreateRequest\";\n\n/**\n * NOTE: This API implementation assumes that the SDK has a departments service\n * which may still need to be implemented in the SDK. The implementation follows\n * the same pattern as the EmployeesAPI but requires the BusinessService to have\n * a departments property with an employees subproperty.\n */\n\n/**\n * Hook to fetch a list of employees in a department using infinite query\n * @param departmentId - The ID of the department\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 department employees data\n */\nexport function useListDepartmentEmployeesInfiniteQuery(\n\tdepartmentId: 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 department employee operations\",\n\t\t);\n\t}\n\n\treturn useInfiniteQuery<\n\t\tSBList<SBDepartmentTeamMember>,\n\t\tSBApiException,\n\t\tSBList<SBDepartmentTeamMember>,\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.Departments,\n\t\t\tdepartmentId,\n\t\t\tSBApiKeys.Employees,\n\t\t\trequest,\n\t\t\toptions,\n\t\t],\n\t\tqueryFn: async ({ pageParam }) => {\n\t\t\treturn await client.businesses.departments.employees.listAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tdepartmentId,\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 && !!departmentId,\n\t});\n}\n\n/**\n * Hook to fetch a list of employees in a department\n * @param departmentId - The ID of the department\n * @param request - The pagination request parameters\n * @param options - Optional request options\n * @param config - Optional Axios request configuration\n * @returns A query result containing paginated department employees data\n */\nexport function useListDepartmentEmployeesQuery(\n\tdepartmentId: 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\treturn useQuery({\n\t\tqueryKey: [\n\t\t\tSBApiKeys.Businesses,\n\t\t\tbusinessId,\n\t\t\tSBApiKeys.Departments,\n\t\t\tdepartmentId,\n\t\t\tSBApiKeys.Employees,\n\t\t\trequest,\n\t\t],\n\t\tqueryFn: async () => {\n\t\t\treturn await client.businesses.departments.employees.listAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tdepartmentId,\n\t\t\t\trequest,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tenabled: !!businessId && !!departmentId,\n\t});\n}\n\n/**\n * Hook to add an employee to a department\n * @returns A mutation function to add an employee to a department\n */\nexport function useAddEmployeeToDepartmentMutation() {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBDepartmentTeamMember,\n\t\tSBApiException,\n\t\t{\n\t\t\tdepartmentId: number;\n\t\t\trequest: DepartmentEmployeeCreateRequest;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ departmentId, request, options, config }) => {\n\t\t\treturn await client.businesses.departments.employees.createAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tdepartmentId,\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: (_, { departmentId }) => {\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.Departments,\n\t\t\t\t\tdepartmentId,\n\t\t\t\t\tSBApiKeys.Employees,\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.Employees,\n\t\t\t\t],\n\t\t\t});\n\t\t},\n\t});\n}\n\n/**\n * Hook to remove an employee from a department\n * @returns A mutation function to remove an employee from a department\n */\nexport function useRemoveEmployeeFromDepartmentMutation() {\n\tconst client = useApiClient();\n\tconst queryClient = useQueryClient();\n\tconst businessId = useBusinessId();\n\n\treturn useMutation<\n\t\tSBDepartmentTeamMember,\n\t\tSBApiException,\n\t\t{\n\t\t\tdepartmentId: number;\n\t\t\temployeeId: number;\n\t\t\toptions?: SBRequestOptions;\n\t\t\tconfig?: AxiosRequestConfig;\n\t\t}\n\t>({\n\t\tmutationFn: async ({ departmentId, employeeId, options, config }) => {\n\t\t\treturn await client.businesses.departments.employees.deleteAsync(\n\t\t\t\tbusinessId,\n\t\t\t\tdepartmentId,\n\t\t\t\temployeeId,\n\t\t\t\toptions,\n\t\t\t\tconfig,\n\t\t\t);\n\t\t},\n\t\tonSuccess: (_, { departmentId }) => {\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.Departments,\n\t\t\t\t\tdepartmentId,\n\t\t\t\t\tSBApiKeys.Employees,\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.Employees,\n\t\t\t\t],\n\t\t\t});\n\t\t},\n\t});\n}\n"],"names":["useListDepartmentEmployeesInfiniteQuery","departmentId","request","page","pageSize","options","config","client","useApiClient","useQueryClient","businessId","useBusinessId","Error","useInfiniteQuery","initialPageParam","queryKey","SBApiKeys","Businesses","Departments","Employees","queryFn","pageParam","businesses","departments","employees","listAsync","getNextPageParam","lastPage","pagination","currentPage","pageCount","undefined","enabled","useListDepartmentEmployeesQuery","useQuery","useAddEmployeeToDepartmentMutation","queryClient","useMutation","mutationFn","createAsync","onSuccess","_","invalidateQueries","useRemoveEmployeeFromDepartmentMutation","employeeId","deleteAsync"],"mappings":";;;;AAmBA;;;;;AAKG;AAEH;;;;;;;AAOG;SACaA,uCAAuCA,CACtDC,YAAoB,EACpBC,OAAA,GAAgD;AAAEC,EAAAA,IAAI,EAAE,CAAC;AAAEC,EAAAA,QAAQ,EAAE;CAAI,EACzEC,OAA0B,EAC1BC,MAA2B,EAAA;AAE3B,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,CACd,2DAA2D,CAC3D;AACF;AAEA,EAAA,OAAOC,gBAAgB,CAMrB;AACDC,IAAAA,gBAAgB,EAAEZ,OAAO,CAACC,IAAI,IAAI,CAAC;IACnCY,QAAQ,EAAE,CACTC,SAAS,CAACC,UAAU,EACpBP,UAAU,EACVM,SAAS,CAACE,WAAW,EACrBjB,YAAY,EACZe,SAAS,CAACG,SAAS,EACnBjB,OAAO,EACPG,OAAO,CACP;IACDe,OAAO,EAAE,OAAO;AAAEC,MAAAA;AAAS,KAAE,KAAI;AAChC,MAAA,OAAO,MAAMd,MAAM,CAACe,UAAU,CAACC,WAAW,CAACC,SAAS,CAACC,SAAS,CAC7Df,UAAU,EACVT,YAAY,EACZ;AAAE,QAAA,GAAGC,OAAO;AAAEC,QAAAA,IAAI,EAAEkB;AAAW,OAAA,EAC/BhB,OAAO,EACPC,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