@appcorp/stellar-solutions-invoice-module 0.1.74 → 0.1.75

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.
Files changed (89) hide show
  1. package/base-modules/invoice/add-service-product-section.d.ts +1 -5
  2. package/base-modules/invoice/add-service-product-section.js +3 -3
  3. package/base-modules/invoice/cache.d.ts +15 -0
  4. package/base-modules/invoice/cache.js +50 -0
  5. package/base-modules/invoice/calculate-subtotal.d.ts +6 -1
  6. package/base-modules/invoice/calculate-subtotal.js +2 -2
  7. package/base-modules/invoice/calculate-total.d.ts +1 -1
  8. package/base-modules/invoice/calculate-total.js +8 -8
  9. package/base-modules/invoice/company-form-section.d.ts +1 -5
  10. package/base-modules/invoice/company-form-section.js +25 -22
  11. package/base-modules/invoice/constants.d.ts +2 -3
  12. package/base-modules/invoice/constants.js +2 -3
  13. package/base-modules/invoice/context.d.ts +556 -20
  14. package/base-modules/invoice/context.js +530 -342
  15. package/base-modules/invoice/customer-form-section.d.ts +1 -5
  16. package/base-modules/invoice/customer-form-section.js +25 -9
  17. package/base-modules/invoice/form.d.ts +1 -5
  18. package/base-modules/invoice/form.js +9 -9
  19. package/base-modules/invoice/page.d.ts +8 -0
  20. package/base-modules/invoice/page.js +171 -0
  21. package/base-modules/invoice/pricing-form-section.d.ts +1 -5
  22. package/base-modules/invoice/pricing-form-section.js +16 -11
  23. package/base-modules/invoice/products-form-section.d.ts +1 -5
  24. package/base-modules/invoice/products-form-section.js +49 -40
  25. package/base-modules/invoice/services-form-section.d.ts +1 -5
  26. package/base-modules/invoice/services-form-section.js +10 -9
  27. package/base-modules/invoice/validate.d.ts +83 -25
  28. package/base-modules/invoice/validate.js +4 -4
  29. package/base-modules/payment/cache.d.ts +15 -0
  30. package/base-modules/payment/cache.js +52 -0
  31. package/base-modules/payment/constants.d.ts +1 -14
  32. package/base-modules/payment/constants.js +2 -15
  33. package/base-modules/payment/context.d.ts +214 -48
  34. package/base-modules/payment/context.js +266 -237
  35. package/base-modules/payment/drawer.d.ts +0 -6
  36. package/base-modules/payment/drawer.js +89 -44
  37. package/base-modules/payment/form.js +3 -2
  38. package/base-modules/payment/{payment.js → page.js} +2 -5
  39. package/base-modules/payment/types.d.ts +0 -85
  40. package/base-modules/payment/types.js +74 -21
  41. package/base-modules/payment/validate.d.ts +12 -0
  42. package/base-modules/payment/validate.js +19 -8
  43. package/base-modules/payment/view.d.ts +1 -5
  44. package/base-modules/payment/view.js +4 -3
  45. package/base-modules/quote/add-service-product-section.js +1 -1
  46. package/base-modules/quote/cache.d.ts +15 -0
  47. package/base-modules/quote/cache.js +50 -0
  48. package/base-modules/quote/company-form-section.d.ts +1 -1
  49. package/base-modules/quote/company-form-section.js +14 -12
  50. package/base-modules/quote/constants.js +1 -0
  51. package/base-modules/quote/context.d.ts +656 -46
  52. package/base-modules/quote/context.js +413 -289
  53. package/base-modules/quote/customer-form-section.d.ts +1 -1
  54. package/base-modules/quote/customer-form-section.js +24 -9
  55. package/base-modules/quote/form.d.ts +1 -5
  56. package/base-modules/quote/form.js +8 -9
  57. package/base-modules/quote/page.d.ts +8 -0
  58. package/base-modules/quote/page.js +163 -0
  59. package/base-modules/quote/pricing-form-section.js +9 -8
  60. package/base-modules/quote/products-form-section.js +2 -2
  61. package/base-modules/quote/services-form-section.js +1 -1
  62. package/base-modules/quote/types.d.ts +0 -127
  63. package/base-modules/quote/types.js +92 -35
  64. package/base-modules/quote/validate.d.ts +82 -25
  65. package/base-modules/quote/validate.js +3 -4
  66. package/package.json +8 -8
  67. package/base-modules/invoice/actions.d.ts +0 -215
  68. package/base-modules/invoice/actions.js +0 -38
  69. package/base-modules/invoice/drawer.d.ts +0 -13
  70. package/base-modules/invoice/drawer.js +0 -46
  71. package/base-modules/invoice/invoice.d.ts +0 -8
  72. package/base-modules/invoice/invoice.js +0 -69
  73. package/base-modules/invoice/reducer.d.ts +0 -4
  74. package/base-modules/invoice/reducer.js +0 -180
  75. package/base-modules/invoice/types.d.ts +0 -211
  76. package/base-modules/invoice/types.js +0 -43
  77. package/base-modules/payment/actions.d.ts +0 -203
  78. package/base-modules/payment/actions.js +0 -50
  79. package/base-modules/payment/reducer.d.ts +0 -29
  80. package/base-modules/payment/reducer.js +0 -215
  81. package/base-modules/quote/actions.d.ts +0 -215
  82. package/base-modules/quote/actions.js +0 -38
  83. package/base-modules/quote/drawer.d.ts +0 -13
  84. package/base-modules/quote/drawer.js +0 -46
  85. package/base-modules/quote/quote.d.ts +0 -8
  86. package/base-modules/quote/quote.js +0 -69
  87. package/base-modules/quote/reducer.d.ts +0 -4
  88. package/base-modules/quote/reducer.js +0 -181
  89. /package/base-modules/payment/{payment.d.ts → page.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Invoice State Context
2
+ * Invoice State Context - Using Generic Module Factory
3
3
  *
4
4
  * This module provides comprehensive state management for the Invoice feature including:
5
5
  * - CRUD operations (create, read, update, delete)
@@ -15,28 +15,25 @@
15
15
  * - Theme-aware toast notifications
16
16
  *
17
17
  * Organization:
18
- * - Types & Interfaces
19
- * - Main Hook (useInvoiceState)
20
- * - State & Core Hooks
21
- * - Theme Support
18
+ * - Module Configuration & Factory Setup
19
+ * - Enhanced Invoice Hook (useInvoiceModule)
20
+ * - State via factory context
22
21
  * - Toast Helpers
23
22
  * - Debounced Values
24
23
  * - Tax & Currency Defaults
25
24
  * - API Parameters (memoized)
26
- * - API Callbacks (with error handling)
25
+ * - API Callbacks
27
26
  * - Module Entity Hook
28
- * - Effects (list refresh, defaults, calculations)
27
+ * - Effects (list refresh, calculations)
28
+ * - Item Management Handlers
29
29
  * - Drawer & Modal Handlers
30
30
  * - CRUD Operation Handlers
31
31
  * - Form Handlers (products, services, pricing)
32
- * - Calculation Handlers
33
32
  * - Pagination Handlers
34
33
  * - Search Handlers
35
34
  * - Table Actions (memoized)
36
35
  * - Return State
37
- * - Context Setup
38
- * - Provider Component
39
- * - Custom Hook
36
+ * - Backward-Compatible Exports
40
37
  */
41
38
  "use client";
42
39
  "use strict";
@@ -51,39 +48,6 @@ var __assign = (this && this.__assign) || function () {
51
48
  };
52
49
  return __assign.apply(this, arguments);
53
50
  };
54
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
55
- if (k2 === undefined) k2 = k;
56
- var desc = Object.getOwnPropertyDescriptor(m, k);
57
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
58
- desc = { enumerable: true, get: function() { return m[k]; } };
59
- }
60
- Object.defineProperty(o, k2, desc);
61
- }) : (function(o, m, k, k2) {
62
- if (k2 === undefined) k2 = k;
63
- o[k2] = m[k];
64
- }));
65
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
66
- Object.defineProperty(o, "default", { enumerable: true, value: v });
67
- }) : function(o, v) {
68
- o["default"] = v;
69
- });
70
- var __importStar = (this && this.__importStar) || (function () {
71
- var ownKeys = function(o) {
72
- ownKeys = Object.getOwnPropertyNames || function (o) {
73
- var ar = [];
74
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
75
- return ar;
76
- };
77
- return ownKeys(o);
78
- };
79
- return function (mod) {
80
- if (mod && mod.__esModule) return mod;
81
- var result = {};
82
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
83
- __setModuleDefault(result, mod);
84
- return result;
85
- };
86
- })();
87
51
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
88
52
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
89
53
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -129,38 +93,163 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
129
93
  }
130
94
  return to.concat(ar || Array.prototype.slice.call(from));
131
95
  };
96
+ var _a;
132
97
  Object.defineProperty(exports, "__esModule", { value: true });
133
- exports.useInvoiceStateContext = exports.InvoiceStateContextProvider = exports.InvoiceStateContext = void 0;
134
- var react_1 = __importStar(require("react"));
98
+ exports.useInvoiceModule = exports.initialInvoiceState = exports.INVOICE_ACTION_TYPES = exports.invoiceModuleConfig = exports.useInvoiceCoreContext = exports.InvoiceProvider = exports.invoiceReducer = void 0;
99
+ var react_1 = require("react");
100
+ var date_fns_1 = require("date-fns");
135
101
  var next_themes_1 = require("next-themes");
136
102
  var next_intl_1 = require("next-intl");
137
103
  var util_functions_1 = require("@react-pakistan/util-functions");
104
+ var generic_module_factory_1 = require("@react-pakistan/util-functions/factory/generic-module-factory");
105
+ var generic_component_factory_1 = require("@react-pakistan/util-functions/factory/generic-component-factory");
138
106
  var toast_utils_1 = require("@appcorp/shadcn/lib/toast-utils");
139
- var actions_1 = require("./actions");
107
+ // import { CompanyBE } from "@appcorp/stellar-solutions-company-module/base-modules/company/types";
108
+ // import { CustomerTypeBE } from "@appcorp/stellar-solutions-company-module/base-modules/customer/types";
109
+ // import { ContactTypeBE } from "@appcorp/stellar-solutions-company-module/base-modules/contact/types";
110
+ // import { ProductTypeBE } from "@appcorp/stellar-solutions-product-module/base-modules/product/types";
111
+ // import { TaxTypeBE } from "@appcorp/stellar-solutions-modules/global-modules/preferences/types";
140
112
  var constants_1 = require("./constants");
141
- var reducer_1 = require("./reducer");
142
- var types_1 = require("./types");
113
+ // import {
114
+ // DISCOUNT_UNIT,
115
+ // INVOICE_DRAWER,
116
+ // INVOICE_MODE,
117
+ // INVOICE_STATUS,
118
+ // PaymentTypeBE,
119
+ // Product,
120
+ // QUOTE_INVOICE_CATEGORY,
121
+ // QUOTE_STATUS,
122
+ // QuoteInvoiceTypeBE,
123
+ // QuoteInvoiceTypeFE,
124
+ // Service,
125
+ // } from "./types";
126
+ var cache_1 = require("./cache");
143
127
  var validate_1 = require("./validate");
144
128
  var calculate_subtotal_1 = require("./calculate-subtotal");
145
129
  var calculate_total_1 = require("./calculate-total");
146
- var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/tax/context");
147
- var context_2 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
148
130
  var navigation_1 = require("../../i18n/navigation");
131
+ var cache_2 = require("@appcorp/stellar-solutions-modules/global-modules/currency/cache");
132
+ var cache_3 = require("@appcorp/stellar-solutions-product-module/base-modules/product/cache");
133
+ // ============================================================================
134
+ // MODULE CONFIGURATION
135
+ // ============================================================================
136
+ var invoiceConfig = {
137
+ name: "Invoice",
138
+ displayName: "Invoice",
139
+ initialState: {
140
+ // List Data
141
+ items: [],
142
+ count: 0,
143
+ // Search & Pagination
144
+ currentPage: 1,
145
+ pageLimit: constants_1.pageLimit,
146
+ searchQuery: "",
147
+ // UI State
148
+ disableSaveButton: false,
149
+ drawer: null,
150
+ invoiceMode: null,
151
+ modal: null,
152
+ loading: true,
153
+ // Form Fields
154
+ afterDiscount: 0,
155
+ category: util_functions_1.QUOTE_INVOICE_CATEGORY.INVOICE,
156
+ companiesList: [],
157
+ companyId: "",
158
+ companyQuery: "",
159
+ contactsList: [],
160
+ countryQuery: "",
161
+ currency: "",
162
+ customerId: "",
163
+ date: new Date().toISOString(),
164
+ discount: 0,
165
+ discountUnit: util_functions_1.DISCOUNT_UNIT.FIXED_VALUE,
166
+ errors: {},
167
+ expiryDate: (0, date_fns_1.addDays)(new Date(), 7).toISOString(),
168
+ // getProducts: [],
169
+ id: "",
170
+ invoiceStatus: util_functions_1.INVOICE_STATUS.UNPAID,
171
+ mode: "Create",
172
+ netTotal: "",
173
+ note: "",
174
+ payments: [],
175
+ // products: [],
176
+ productQuery: "",
177
+ productList: [
178
+ {
179
+ id: "",
180
+ mode: "Create",
181
+ price: "",
182
+ quantity: "1",
183
+ rowTotal: "",
184
+ },
185
+ ],
186
+ quoteStatus: util_functions_1.QUOTE_STATUS.DRAFT,
187
+ ref: "",
188
+ serviceList: [
189
+ {
190
+ description: "",
191
+ mode: "Create",
192
+ name: "",
193
+ price: "",
194
+ quantity: "1",
195
+ rowTotal: "",
196
+ },
197
+ ],
198
+ // services: [],
199
+ subTotal: "",
200
+ tax: "",
201
+ taxQuery: "",
202
+ taxRate: "",
203
+ taxes: [],
204
+ total: "",
205
+ customer: {
206
+ address: "",
207
+ city: "",
208
+ country: "",
209
+ createdAt: "",
210
+ email: "",
211
+ firstName: "",
212
+ id: "",
213
+ lastName: "",
214
+ phone: "",
215
+ quotesInvoices: [],
216
+ updatedAt: "",
217
+ },
218
+ company: {
219
+ contacts: [],
220
+ country: "",
221
+ createdAt: "",
222
+ email: "",
223
+ id: "",
224
+ name: "",
225
+ phone: "",
226
+ quotesInvoices: [],
227
+ updatedAt: "",
228
+ website: "",
229
+ },
230
+ },
231
+ drawerTypes: __assign({}, generic_component_factory_1.DRAWER_TYPES),
232
+ };
149
233
  // ============================================================================
150
- // MAIN HOOK
234
+ // CREATE INVOICE MODULE
151
235
  // ============================================================================
152
- var useInvoiceState = function () {
236
+ exports.invoiceReducer = (_a = (0, generic_module_factory_1.createGenericModule)(invoiceConfig), _a.reducer), exports.InvoiceProvider = _a.Provider, exports.useInvoiceCoreContext = _a.useContext, exports.invoiceModuleConfig = _a.config, exports.INVOICE_ACTION_TYPES = _a.actionTypes, exports.initialInvoiceState = _a.initialState;
237
+ var useInvoiceModule = function () {
153
238
  var _a;
154
239
  // ---------------------------------------------------------------------------
155
- // State & Core Hooks
240
+ // State via factory context
156
241
  // ---------------------------------------------------------------------------
157
- var _b = (0, react_1.useReducer)(reducer_1.invoiceReducer, reducer_1.initialInvoiceState), state = _b[0], dispatch = _b[1];
242
+ var context = (0, exports.useInvoiceCoreContext)();
243
+ var state = context.state;
158
244
  var t = (0, next_intl_1.useTranslations)("invoice");
159
245
  var tCommon = (0, next_intl_1.useTranslations)("common");
160
246
  var theme = (0, next_themes_1.useTheme)().theme;
161
- var taxes = (0, context_1.useTaxStateContext)().taxes;
162
- var currencies = (0, context_2.usePreferenceStateContext)().currencies;
247
+ // const taxModule = useTaxModule();
248
+ // const taxes = taxModule.state.items;
249
+ var currencies = (0, cache_2.getCachedCurrenciesSync)();
250
+ var cachedProducts = (0, cache_3.getCachedProductsSync)();
163
251
  var router = (0, navigation_1.useRouter)();
252
+ var listFetchNowRef = (0, react_1.useRef)(null);
164
253
  // ---------------------------------------------------------------------------
165
254
  // Toast Helpers
166
255
  // ---------------------------------------------------------------------------
@@ -182,30 +271,26 @@ var useInvoiceState = function () {
182
271
  // Debounced Values
183
272
  // ---------------------------------------------------------------------------
184
273
  var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
185
- var debouncedProductList = (0, util_functions_1.useDebounce)(state.productQuery, 800);
274
+ // debouncedProductList removed products sourced from getCachedProductsSync()
186
275
  var debouncedCustomer = (0, util_functions_1.useDebounce)((_a = state === null || state === void 0 ? void 0 : state.customer) === null || _a === void 0 ? void 0 : _a.phone, 800);
187
276
  var debouncedTaxList = (0, util_functions_1.useDebounce)(state.taxQuery, 800);
188
277
  var debouncedCompanyList = (0, util_functions_1.useDebounce)(state.companyQuery, 800);
189
278
  // ---------------------------------------------------------------------------
190
279
  // Tax & Currency Defaults
191
280
  // ---------------------------------------------------------------------------
192
- var defaultTax = (0, react_1.useMemo)(function () {
193
- return taxes.filter(function (_a) {
194
- var isDefault = _a.isDefault;
195
- return isDefault;
196
- })[0];
197
- }, [taxes]);
198
281
  var defaultCurrency = (0, react_1.useMemo)(function () {
199
- return currencies.filter(function (_a) {
282
+ var _a, _b;
283
+ return (((_a = currencies === null || currencies === void 0 ? void 0 : currencies.items) === null || _a === void 0 ? void 0 : _a.find(function (_a) {
200
284
  var isDefault = _a.isDefault;
201
285
  return isDefault;
202
- })[0];
286
+ })) ||
287
+ ((_b = currencies === null || currencies === void 0 ? void 0 : currencies.items) === null || _b === void 0 ? void 0 : _b[0]));
203
288
  }, [currencies]);
204
289
  // ---------------------------------------------------------------------------
205
- // API PARAMETERS
290
+ // API Parameters
206
291
  // ---------------------------------------------------------------------------
207
292
  var listParams = (0, react_1.useMemo)(function () { return ({
208
- category: types_1.QUOTE_INVOICE_CATEGORY.INVOICE,
293
+ category: util_functions_1.QUOTE_INVOICE_CATEGORY.INVOICE,
209
294
  currentPage: state.currentPage,
210
295
  includeCompany: true,
211
296
  includeCustomer: true,
@@ -213,88 +298,89 @@ var useInvoiceState = function () {
213
298
  searchQuery: state.searchQuery,
214
299
  }); }, [state.currentPage, state.pageLimit, state.searchQuery]);
215
300
  var updateParams = (0, react_1.useMemo)(function () {
216
- var _a, _b, _c, _d, _e, _f, _g, _h;
301
+ var _a, _b, _c, _d, _e, _f, _g;
217
302
  return ({
218
303
  category: state.category,
219
304
  companyId: state.companyId,
220
305
  currency: state.currency,
221
306
  customerId: state.customerId,
222
- date: state.date,
223
- discount: (_a = state === null || state === void 0 ? void 0 : state.discount) === null || _a === void 0 ? void 0 : _a.trim(),
307
+ date: new Date(state.date),
308
+ discount: state === null || state === void 0 ? void 0 : state.discount,
224
309
  discountUnit: state.discountUnit,
225
310
  drawer: state.drawer,
226
- expiryDate: state.expiryDate,
311
+ expiryDate: new Date(state.expiryDate),
227
312
  id: state.id,
228
313
  invoiceStatus: state.invoiceStatus,
229
314
  mode: state.mode,
230
315
  note: state.note.trim(),
231
- productsList: state.productsList.filter(function (_a) {
316
+ productList: state.productList.filter(function (_a) {
232
317
  var id = _a.id;
233
318
  return id;
234
319
  }),
235
320
  quoteStatus: state.quoteStatus,
236
321
  ref: state.ref,
237
- servicesList: state.servicesList.filter(function (_a) {
322
+ serviceList: state.serviceList.filter(function (_a) {
238
323
  var name = _a.name;
239
324
  return name;
240
325
  }),
241
- subTotal: state.subTotal,
242
- taxRate: state.taxRate,
243
- total: state.total,
244
- phone: (_b = state.customer) === null || _b === void 0 ? void 0 : _b.phone,
245
- firstName: (_c = state.customer) === null || _c === void 0 ? void 0 : _c.firstName,
246
- lastName: (_d = state.customer) === null || _d === void 0 ? void 0 : _d.lastName,
247
- email: (_e = state.customer) === null || _e === void 0 ? void 0 : _e.email,
248
- address: (_f = state.customer) === null || _f === void 0 ? void 0 : _f.address,
249
- city: (_g = state.customer) === null || _g === void 0 ? void 0 : _g.city,
250
- country: (_h = state.customer) === null || _h === void 0 ? void 0 : _h.country,
326
+ subTotal: Number(state.subTotal),
327
+ taxRate: Number(state.taxRate),
328
+ total: Number(state.total),
329
+ invoiceMode: state.invoiceMode,
330
+ phone: (_a = state.customer) === null || _a === void 0 ? void 0 : _a.phone,
331
+ firstName: (_b = state.customer) === null || _b === void 0 ? void 0 : _b.firstName,
332
+ lastName: (_c = state.customer) === null || _c === void 0 ? void 0 : _c.lastName,
333
+ email: (_d = state.customer) === null || _d === void 0 ? void 0 : _d.email,
334
+ address: (_e = state.customer) === null || _e === void 0 ? void 0 : _e.address,
335
+ city: (_f = state.customer) === null || _f === void 0 ? void 0 : _f.city,
336
+ country: (_g = state.customer) === null || _g === void 0 ? void 0 : _g.country,
251
337
  });
252
338
  }, [state]);
253
339
  var byIdParams = (0, react_1.useMemo)(function () { return ({ id: state.id }); }, [state.id]);
254
340
  var deleteParams = (0, react_1.useMemo)(function () { return ({ id: state.id }); }, [state.id]);
255
341
  // ---------------------------------------------------------------------------
256
- // API CALLBACKS
342
+ // API Callbacks
257
343
  // ---------------------------------------------------------------------------
258
344
  var listCallback = (0, react_1.useCallback)(function (_a) {
345
+ var _b;
259
346
  var data = _a.data, error = _a.error;
260
347
  if (error) {
261
348
  showErrorToast(tCommon("messagesNetworkError"));
262
349
  return;
263
350
  }
264
351
  if (data === null || data === void 0 ? void 0 : data.items) {
265
- dispatch({
266
- type: actions_1.INVOICE_ACTION_TYPES.SET_INVOICES,
267
- payload: { invoices: data.items },
268
- });
269
- dispatch({
270
- type: actions_1.INVOICE_ACTION_TYPES.SET_COUNT,
271
- payload: { count: data === null || data === void 0 ? void 0 : data.count },
352
+ context.dispatch({
353
+ type: exports.INVOICE_ACTION_TYPES.SET_ITEMS,
354
+ payload: { items: data.items, count: (_b = data === null || data === void 0 ? void 0 : data.count) !== null && _b !== void 0 ? _b : 0 },
272
355
  });
273
356
  }
274
357
  },
275
358
  // eslint-disable-next-line react-hooks/exhaustive-deps
276
359
  [showErrorToast]);
277
360
  var updateCallback = (0, react_1.useCallback)(function (_a) {
361
+ var _b;
278
362
  var data = _a.data, error = _a.error;
279
363
  if (error) {
280
364
  showErrorToast(tCommon("messagesNetworkError"));
281
365
  return;
282
366
  }
283
367
  if (data) {
368
+ (0, cache_1.invalidateInvoicesCache)();
284
369
  showSuccessToast(state.mode === "Edit"
285
370
  ? t("messagesInvoiceUpdated")
286
371
  : t("messagesInvoiceCreated"));
287
- dispatch({ type: actions_1.INVOICE_ACTION_TYPES.RESET_FORM });
288
- dispatch({ type: actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS });
289
- listFetchNow();
290
- dispatch({
291
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
372
+ context.dispatch({ type: exports.INVOICE_ACTION_TYPES.RESET_FORM });
373
+ context.dispatch({
374
+ type: exports.INVOICE_ACTION_TYPES.SET_ERRORS,
375
+ payload: { errors: {} },
376
+ });
377
+ context.dispatch({
378
+ type: exports.INVOICE_ACTION_TYPES.SET_DRAWER,
292
379
  payload: { drawer: null },
293
380
  });
381
+ (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
294
382
  }
295
- },
296
- // eslint-disable-next-line react-hooks/exhaustive-deps
297
- [t, tCommon, state.mode, showErrorToast, showSuccessToast]);
383
+ }, [t, tCommon, state.mode, showErrorToast, showSuccessToast, context]);
298
384
  var byIdCallback = (0, react_1.useCallback)(function (_a) {
299
385
  var _b, _c, _d, _e, _f;
300
386
  var data = _a.data, error = _a.error;
@@ -314,12 +400,12 @@ var useInvoiceState = function () {
314
400
  // Normalize currency: API may return currency id or code. Prefer storing id.
315
401
  var normalizedCurrency_1 = data.currency;
316
402
  if (normalizedCurrency_1) {
317
- var foundById = currencies.find(function (_a) {
403
+ var foundById = (_b = currencies === null || currencies === void 0 ? void 0 : currencies.items) === null || _b === void 0 ? void 0 : _b.find(function (_a) {
318
404
  var id = _a.id;
319
405
  return id === normalizedCurrency_1;
320
406
  });
321
407
  if (!foundById) {
322
- var foundByCode = currencies.find(function (_a) {
408
+ var foundByCode = (_c = currencies === null || currencies === void 0 ? void 0 : currencies.items) === null || _c === void 0 ? void 0 : _c.find(function (_a) {
323
409
  var code = _a.code;
324
410
  return code === normalizedCurrency_1;
325
411
  });
@@ -327,107 +413,114 @@ var useInvoiceState = function () {
327
413
  normalizedCurrency_1 = foundByCode.id;
328
414
  }
329
415
  }
330
- var updatedData = __assign(__assign(__assign(__assign(__assign({}, data), (normalizedCurrency_1 && { currency: normalizedCurrency_1 })), { mode: "Edit", companyId: (data === null || data === void 0 ? void 0 : data.companyId) || "", customerId: (data === null || data === void 0 ? void 0 : data.customerId) || "" }), (((_b = data === null || data === void 0 ? void 0 : data.customer) === null || _b === void 0 ? void 0 : _b.id) && {
416
+ var updatedData = __assign(__assign(__assign(__assign(__assign({}, data), (normalizedCurrency_1 && { currency: normalizedCurrency_1 })), { mode: "Edit", companyId: (data === null || data === void 0 ? void 0 : data.companyId) || "", customerId: (data === null || data === void 0 ? void 0 : data.customerId) || "" }), (((_d = data === null || data === void 0 ? void 0 : data.customer) === null || _d === void 0 ? void 0 : _d.id) && {
331
417
  customer: __assign({}, data.customer),
332
- })), { servicesList: __spreadArray([], updatedServices, true).filter(function (item) { return item.name; }), productsList: __spreadArray([], updatedProducts, true).filter(function (item) { return item.id; }), companiesList: [__assign({}, data.company)] });
333
- if ((_c = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _c === void 0 ? void 0 : _c.name) {
334
- dispatch({
335
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
336
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER },
337
- });
338
- }
339
- if ((_d = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _d === void 0 ? void 0 : _d.firstName) {
340
- dispatch({
341
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
342
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER },
343
- });
344
- }
345
- dispatch({
346
- type: actions_1.INVOICE_ACTION_TYPES.SET_FORM,
418
+ })), { serviceList: __spreadArray([], updatedServices, true).filter(function (item) { return item.name; }), productList: __spreadArray([], updatedProducts, true).filter(function (item) { return item.id; }), companiesList: data.company ? [__assign({}, data.company)] : [] });
419
+ context.dispatch({
420
+ type: exports.INVOICE_ACTION_TYPES.SET_FORM_DATA,
347
421
  payload: { form: updatedData },
348
422
  });
349
423
  if ((_e = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _e === void 0 ? void 0 : _e.name) {
350
- dispatch({
351
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
352
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER },
424
+ context.dispatch({
425
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
426
+ payload: { key: "invoiceMode", value: util_functions_1.QUOTE_INVOICE_MODE.COMPANY },
427
+ });
428
+ context.dispatch({
429
+ type: exports.INVOICE_ACTION_TYPES.SET_DRAWER,
430
+ payload: { drawer: invoiceConfig.drawerTypes.FORM_DRAWER },
353
431
  });
354
432
  }
355
- if ((_f = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _f === void 0 ? void 0 : _f.firstName) {
356
- dispatch({
357
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
358
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER },
433
+ else if ((_f = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _f === void 0 ? void 0 : _f.firstName) {
434
+ context.dispatch({
435
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
436
+ payload: { key: "invoiceMode", value: util_functions_1.QUOTE_INVOICE_MODE.CUSTOMER },
437
+ });
438
+ context.dispatch({
439
+ type: exports.INVOICE_ACTION_TYPES.SET_DRAWER,
440
+ payload: { drawer: invoiceConfig.drawerTypes.FORM_DRAWER },
359
441
  });
360
442
  }
361
443
  }
362
- }, [t, showErrorToast, currencies]);
444
+ }, [t, showErrorToast, currencies, context]);
363
445
  var deleteCallback = (0, react_1.useCallback)(function (_a) {
446
+ var _b;
364
447
  var data = _a.data, error = _a.error;
365
448
  if (error) {
366
449
  showErrorToast(tCommon("messagesNetworkError"));
367
450
  return;
368
451
  }
369
452
  if (data) {
453
+ (0, cache_1.invalidateInvoicesCache)();
370
454
  showSuccessToast(t("messagesInvoiceDeleted"));
371
- dispatch({ type: actions_1.INVOICE_ACTION_TYPES.RESET_FORM });
372
- listFetchNow();
455
+ context.dispatch({ type: exports.INVOICE_ACTION_TYPES.RESET_FORM });
456
+ (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
373
457
  }
374
- },
375
- // eslint-disable-next-line react-hooks/exhaustive-deps
376
- [t, tCommon, showErrorToast, showSuccessToast]);
458
+ }, [t, tCommon, showErrorToast, showSuccessToast, context]);
377
459
  // ---------------------------------------------------------------------------
378
460
  // Module Entity Hook
379
461
  // ---------------------------------------------------------------------------
380
- var _c = (0, util_functions_1.useModuleEntity)({
462
+ var _b = (0, util_functions_1.useModuleEntityV2)({
381
463
  byIdCallback: byIdCallback,
382
464
  byIdParams: byIdParams,
383
465
  deleteCallback: deleteCallback,
384
466
  deleteParams: deleteParams,
385
467
  listCallback: listCallback,
386
468
  listParams: listParams,
387
- listUrl: constants_1.INVOICE_API_ROUTES.INVOICES,
469
+ listUrl: constants_1.INVOICE_API_ROUTES.UNIT,
388
470
  searchQuery: debouncedQuery,
389
- unitByIdUrl: constants_1.INVOICE_API_ROUTES.INVOICE_BY_ID,
390
- unitUrl: constants_1.INVOICE_API_ROUTES.INVOICE,
471
+ unitByIdUrl: constants_1.INVOICE_API_ROUTES.UNIT,
472
+ unitUrl: constants_1.INVOICE_API_ROUTES.UNIT,
391
473
  updateCallback: updateCallback,
392
- updateDeps: [state],
393
- updateParams: __assign(__assign({}, updateParams), { mode: "Create" }),
394
- }), byIdError = _c.byIdError, byIdFetchNow = _c.byIdFetchNow, byIdLoading = _c.byIdLoading, deleteError = _c.deleteError, deleteFetchNow = _c.deleteFetchNow, deleteLoading = _c.deleteLoading, listError = _c.listError, listFetchNow = _c.listFetchNow, listLoading = _c.listLoading, updateError = _c.updateError, updateFetchNow = _c.updateFetchNow, updateLoading = _c.updateLoading;
474
+ updateParams: updateParams,
475
+ }), byIdFetchNow = _b.byIdFetchNow, deleteFetchNow = _b.deleteFetchNow, listError = _b.listError, listFetchNow = _b.listFetchNow, listLoading = _b.listLoading, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
476
+ // Keep ref in sync with the latest listFetchNow so callbacks can use it
477
+ (0, react_1.useEffect)(function () {
478
+ listFetchNowRef.current = listFetchNow;
479
+ }, [listFetchNow]);
395
480
  // ---------------------------------------------------------------------------
396
481
  // Effects
397
482
  // ---------------------------------------------------------------------------
483
+ // useEffect(() => {
484
+ // (async () => {
485
+ // try {
486
+ // const { count, items } = await getCachedInvoices({
487
+ // params: listParams,
488
+ // });
489
+ // context.dispatch({
490
+ // type: INVOICE_ACTION_TYPES.SET_ITEMS,
491
+ // payload: { items: items || [], count: count || 0 },
492
+ // });
493
+ // } catch {
494
+ // generateThemeToast({
495
+ // description: t("messagesNetworkError"),
496
+ // variant: TOAST_VARIANT.ERROR,
497
+ // });
498
+ // }
499
+ // })();
500
+ // }, [context, listParams, t]);
501
+ // useEffect(() => {
502
+ // (async () => {
503
+ // const { data } = await fetchData({
504
+ // url: INVOICE_API_ROUTES.PRODUCT,
505
+ // method: API_METHODS.GET,
506
+ // body: JSON.stringify({
507
+ // searchQuery: debouncedProductList,
508
+ // pageLimit: 100,
509
+ // currentPage: 1,
510
+ // }),
511
+ // });
512
+ // if (data?.items) {
513
+ // context.dispatch({
514
+ // type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
515
+ // payload: { key: "getProducts", value: data.items },
516
+ // });
517
+ // }
518
+ // })();
519
+ // }, [context, debouncedProductList]);
520
+ // Product list is sourced from getCachedProductsSync() in the form section -
521
+ // no separate fetch needed.
398
522
  (0, react_1.useEffect)(function () {
399
- listFetchNow();
400
- // eslint-disable-next-line
401
- }, [debouncedQuery, state.currentPage, state.pageLimit]);
402
- (0, react_1.useEffect)(function () {
403
- (function () { return __awaiter(void 0, void 0, void 0, function () {
404
- var data;
405
- return __generator(this, function (_a) {
406
- switch (_a.label) {
407
- case 0: return [4 /*yield*/, (0, util_functions_1.fetchData)({
408
- url: constants_1.INVOICE_API_ROUTES.PRODUCTS,
409
- method: util_functions_1.API_METHODS.POST,
410
- body: JSON.stringify({
411
- searchQuery: debouncedProductList,
412
- pageLimit: 100,
413
- currentPage: 1,
414
- }),
415
- })];
416
- case 1:
417
- data = (_a.sent()).data;
418
- if (data === null || data === void 0 ? void 0 : data.items) {
419
- dispatch({
420
- type: actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST,
421
- payload: { list: data.items },
422
- });
423
- }
424
- return [2 /*return*/];
425
- }
426
- });
427
- }); })();
428
- }, [debouncedProductList]);
429
- (0, react_1.useEffect)(function () {
430
- if (state.drawer === types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER &&
523
+ if (state.invoiceMode === util_functions_1.QUOTE_INVOICE_MODE.CUSTOMER &&
431
524
  debouncedCustomer) {
432
525
  (function () { return __awaiter(void 0, void 0, void 0, function () {
433
526
  var data;
@@ -435,7 +528,7 @@ var useInvoiceState = function () {
435
528
  switch (_a.label) {
436
529
  case 0: return [4 /*yield*/, (0, util_functions_1.fetchData)({
437
530
  url: constants_1.INVOICE_API_ROUTES.CUSTOMER_BY_PHONE,
438
- method: util_functions_1.API_METHODS.POST,
531
+ method: util_functions_1.API_METHODS.GET,
439
532
  body: JSON.stringify({
440
533
  phone: debouncedCustomer,
441
534
  }),
@@ -443,9 +536,16 @@ var useInvoiceState = function () {
443
536
  case 1:
444
537
  data = (_a.sent()).data;
445
538
  if (data) {
446
- dispatch({
447
- type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER,
448
- payload: { customer: __assign({}, data), customerId: data.id },
539
+ context.dispatch({
540
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
541
+ payload: {
542
+ key: "customer",
543
+ value: __assign(__assign({}, state.customer), data),
544
+ },
545
+ });
546
+ context.dispatch({
547
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
548
+ payload: { key: "customerId", value: data.id },
449
549
  });
450
550
  }
451
551
  return [2 /*return*/];
@@ -453,9 +553,34 @@ var useInvoiceState = function () {
453
553
  });
454
554
  }); })();
455
555
  }
456
- }, [debouncedCustomer, state.drawer]);
556
+ // eslint-disable-next-line react-hooks/exhaustive-deps
557
+ }, [debouncedCustomer, state.invoiceMode]);
558
+ // useEffect(() => {
559
+ // if (
560
+ // state.invoiceMode === QUOTE_INVOICE_MODE.COMPANY &&
561
+ // debouncedCompanyList
562
+ // ) {
563
+ // (async () => {
564
+ // const { data } = await fetchData({
565
+ // url: INVOICE_API_ROUTES.COMPANIES,
566
+ // method: API_METHODS.POST,
567
+ // body: JSON.stringify({
568
+ // searchQuery: debouncedCompanyList,
569
+ // pageLimit: 100,
570
+ // currentPage: 1,
571
+ // }),
572
+ // });
573
+ // if (data?.items) {
574
+ // context.dispatch({
575
+ // type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
576
+ // payload: { key: "companiesList", value: data.items },
577
+ // });
578
+ // }
579
+ // })();
580
+ // }
581
+ // }, [debouncedCompanyList, state.invoiceMode, context]);
457
582
  (0, react_1.useEffect)(function () {
458
- if (state.drawer === types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER &&
583
+ if (state.invoiceMode === util_functions_1.QUOTE_INVOICE_MODE.COMPANY &&
459
584
  debouncedCompanyList) {
460
585
  (function () { return __awaiter(void 0, void 0, void 0, function () {
461
586
  var data;
@@ -473,9 +598,9 @@ var useInvoiceState = function () {
473
598
  case 1:
474
599
  data = (_a.sent()).data;
475
600
  if (data === null || data === void 0 ? void 0 : data.items) {
476
- dispatch({
477
- type: actions_1.INVOICE_ACTION_TYPES.SET_COMPANIES_LIST,
478
- payload: { companiesList: data.items },
601
+ context.dispatch({
602
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
603
+ payload: { key: "companiesList", value: data.items },
479
604
  });
480
605
  }
481
606
  return [2 /*return*/];
@@ -483,7 +608,29 @@ var useInvoiceState = function () {
483
608
  });
484
609
  }); })();
485
610
  }
486
- }, [debouncedCompanyList, state.drawer]);
611
+ // eslint-disable-next-line react-hooks/exhaustive-deps
612
+ }, [debouncedCompanyList, state.invoiceMode]);
613
+ // useEffect(() => {
614
+ // (async () => {
615
+ // if (debouncedTaxList) {
616
+ // const { data } = await fetchData({
617
+ // url: INVOICE_API_ROUTES.TAXES,
618
+ // method: API_METHODS.POST,
619
+ // body: JSON.stringify({
620
+ // searchQuery: debouncedTaxList,
621
+ // pageLimit: 100,
622
+ // currentPage: 1,
623
+ // }),
624
+ // });
625
+ // if (data.items) {
626
+ // context.dispatch({
627
+ // type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
628
+ // payload: { key: "taxes", value: data.items },
629
+ // });
630
+ // }
631
+ // }
632
+ // })();
633
+ // }, [debouncedTaxList, context]);
487
634
  (0, react_1.useEffect)(function () {
488
635
  (function () { return __awaiter(void 0, void 0, void 0, function () {
489
636
  var data;
@@ -503,9 +650,9 @@ var useInvoiceState = function () {
503
650
  case 1:
504
651
  data = (_a.sent()).data;
505
652
  if (data.items) {
506
- dispatch({
507
- type: actions_1.INVOICE_ACTION_TYPES.SET_TAXES,
508
- payload: { taxes: data.items },
653
+ context.dispatch({
654
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
655
+ payload: { key: "taxes", value: data.items },
509
656
  });
510
657
  }
511
658
  _a.label = 2;
@@ -513,24 +660,23 @@ var useInvoiceState = function () {
513
660
  }
514
661
  });
515
662
  }); })();
663
+ // eslint-disable-next-line react-hooks/exhaustive-deps
516
664
  }, [debouncedTaxList]);
517
665
  (0, react_1.useEffect)(function () {
518
- var _a = (0, calculate_total_1.calculateTotal)(state.subTotal, state.taxRate, state.discountUnit, state.discount || "0"), afterDiscount = _a.afterDiscount, tax = _a.tax, total = _a.total;
519
- dispatch({
520
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
521
- payload: {
522
- key: "total",
523
- value: total,
524
- },
666
+ var _a = (0, calculate_total_1.calculateTotal)(context.state.subTotal, context.state.taxRate, context.state.discountUnit, String(context.state.discount) || "0"), afterDiscount = _a.afterDiscount, tax = _a.tax, total = _a.total;
667
+ context.dispatch({
668
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
669
+ payload: { key: "total", value: total },
525
670
  });
526
- dispatch({
527
- type: actions_1.INVOICE_ACTION_TYPES.SET_TAX,
528
- payload: { tax: tax },
671
+ context.dispatch({
672
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
673
+ payload: { key: "tax", value: tax },
529
674
  });
530
- dispatch({
531
- type: actions_1.INVOICE_ACTION_TYPES.SET_AFTER_DISCOUNT,
532
- payload: { afterDiscount: String(afterDiscount) },
675
+ context.dispatch({
676
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
677
+ payload: { key: "afterDiscount", value: String(afterDiscount) },
533
678
  });
679
+ // eslint-disable-next-line react-hooks/exhaustive-deps
534
680
  }, [state.discountUnit, state.discount, state.subTotal, state.taxRate]);
535
681
  // ---------------------------------------------------------------------------
536
682
  // Item Management Handlers
@@ -544,11 +690,11 @@ var useInvoiceState = function () {
544
690
  price: "",
545
691
  rowTotal: "",
546
692
  };
547
- dispatch({
548
- type: actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_SERVICE,
549
- payload: { servicesList: __spreadArray(__spreadArray([], state.servicesList, true), [newItem], false) },
693
+ context.dispatch({
694
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
695
+ payload: { key: "serviceList", value: __spreadArray(__spreadArray([], state.serviceList, true), [newItem], false) },
550
696
  });
551
- }, [state.servicesList]);
697
+ }, [context, state.serviceList]);
552
698
  var handleAddItemProduct = (0, react_1.useCallback)(function () {
553
699
  var newItem = {
554
700
  id: "",
@@ -557,38 +703,40 @@ var useInvoiceState = function () {
557
703
  quantity: "1",
558
704
  rowTotal: "",
559
705
  };
560
- dispatch({
561
- type: actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_PRODUCT,
562
- payload: { productsList: __spreadArray(__spreadArray([], state.productsList, true), [newItem], false) },
706
+ context.dispatch({
707
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
708
+ payload: { key: "productList", value: __spreadArray(__spreadArray([], state.productList, true), [newItem], false) },
563
709
  });
564
- }, [state.productsList]);
710
+ }, [context, state.productList]);
565
711
  // ---------------------------------------------------------------------------
566
712
  // Drawer & Modal Handlers
567
713
  // ---------------------------------------------------------------------------
568
714
  var handleCreate = (0, react_1.useCallback)(function (text) {
569
- dispatch({
570
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
715
+ context.dispatch({
716
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
571
717
  payload: { key: "ref", value: (0, util_functions_1.generateRef)({ refLength: 5 }) },
572
718
  });
573
- if (text === "company") {
574
- dispatch({
575
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
576
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER },
577
- });
578
- }
579
- if (text === "customer") {
580
- dispatch({
581
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
582
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER },
583
- });
584
- }
585
- }, []);
719
+ context.dispatch({
720
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
721
+ payload: {
722
+ key: "invoiceMode",
723
+ value: text === "company"
724
+ ? util_functions_1.QUOTE_INVOICE_MODE.COMPANY
725
+ : util_functions_1.QUOTE_INVOICE_MODE.CUSTOMER,
726
+ },
727
+ });
728
+ context.dispatch({
729
+ type: exports.INVOICE_ACTION_TYPES.SET_DRAWER,
730
+ payload: { drawer: invoiceConfig.drawerTypes.FORM_DRAWER },
731
+ });
732
+ }, [context]);
586
733
  // ---------------------------------------------------------------------------
587
734
  // CRUD Operation Handlers
588
735
  // ---------------------------------------------------------------------------
589
- var handleEdit = (0, react_1.useCallback)(function (id) {
736
+ var handleEdit = (0, react_1.useCallback)(function (row) {
737
+ var record = row;
590
738
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, {
591
- params: { id: id },
739
+ params: { id: record === null || record === void 0 ? void 0 : record.id },
592
740
  body: JSON.stringify({
593
741
  includeCompany: true,
594
742
  includeCustomer: true,
@@ -599,114 +747,137 @@ var useInvoiceState = function () {
599
747
  });
600
748
  // eslint-disable-next-line react-hooks/exhaustive-deps
601
749
  }, []);
602
- var handleRecordPayment = (0, react_1.useCallback)(function (id) {
603
- (0, util_functions_1.setStorageValue)("paymentInvoiceId", id);
604
- router.push("/erp/payment");
605
- }, [router]);
606
- var handleDelete = (0, react_1.useCallback)(function (id) {
607
- deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, { params: { id: id } });
750
+ var handleView = (0, react_1.useCallback)(function (row) {
751
+ var record = row;
752
+ byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, {
753
+ params: { id: record === null || record === void 0 ? void 0 : record.id },
754
+ body: JSON.stringify({
755
+ includeCompany: true,
756
+ includeCustomer: true,
757
+ includePayments: true,
758
+ includeProducts: true,
759
+ includeServices: true,
760
+ }),
761
+ });
608
762
  // eslint-disable-next-line react-hooks/exhaustive-deps
609
763
  }, []);
764
+ var handleRecordPayment = (0, react_1.useCallback)(function (row) {
765
+ var record = row;
766
+ (0, util_functions_1.setStorageValue)("paymentInvoiceId", record === null || record === void 0 ? void 0 : record.id);
767
+ router.push("/erp/payment");
768
+ }, [router]);
769
+ var handleDelete = (0, react_1.useCallback)(function (row) {
770
+ var record = row;
771
+ deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
772
+ params: { id: record === null || record === void 0 ? void 0 : record.id },
773
+ });
774
+ }, [deleteFetchNow]);
610
775
  // ---------------------------------------------------------------------------
611
776
  // Form Submission Handler
612
777
  // ---------------------------------------------------------------------------
613
778
  var handleSubmit = (0, react_1.useCallback)(function () {
614
- if (!state.servicesList[0].name && !state.productsList[0].id) {
615
- dispatch({
616
- type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
779
+ if (!state.serviceList[0].name && !state.productList[0].id) {
780
+ context.dispatch({
781
+ type: exports.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
617
782
  payload: { disableSaveButton: true },
618
783
  });
619
784
  return;
620
785
  }
621
- dispatch({
622
- type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
786
+ context.dispatch({
787
+ type: exports.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
623
788
  payload: { disableSaveButton: true },
624
789
  });
625
790
  (0, util_functions_1.validateForm)({
626
- params: __assign(__assign({}, updateParams), { currency: updateParams.currency || defaultCurrency.id, taxRate: updateParams.taxRate || defaultTax.taxRate }),
791
+ params: __assign(__assign({}, updateParams), { currency: updateParams.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id) || "", taxRate: updateParams.taxRate }),
627
792
  schema: validate_1.formValid,
628
793
  successCallback: function () {
629
794
  updateFetchNow(undefined, {
630
- body: JSON.stringify(__assign(__assign({}, updateParams), { products: state.productsList.filter(function (item) { return item.id; }), services: state.servicesList.filter(function (item) { return item.name; }), currency: updateParams.currency || defaultCurrency.id, taxRate: updateParams.taxRate || defaultTax.taxRate })),
795
+ body: JSON.stringify(__assign(__assign({}, updateParams), { products: state.productList.filter(function (item) { return item.id; }), services: state.serviceList.filter(function (item) { return item.name; }), currency: updateParams.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id) || "", taxRate: updateParams.taxRate })),
631
796
  });
632
797
  },
633
798
  errorCallback: function (e) {
634
- dispatch({
635
- type: actions_1.INVOICE_ACTION_TYPES.SET_ERRORS,
799
+ context.dispatch({
800
+ type: exports.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
801
+ payload: { disableSaveButton: false },
802
+ });
803
+ context.dispatch({
804
+ type: exports.INVOICE_ACTION_TYPES.SET_ERRORS,
636
805
  payload: { errors: e },
637
806
  });
638
807
  },
639
808
  });
640
809
  }, [
810
+ context,
641
811
  updateFetchNow,
642
812
  updateParams,
643
813
  defaultCurrency,
644
- defaultTax,
645
- state.productsList,
646
- state.servicesList,
814
+ state.productList,
815
+ state.serviceList,
647
816
  ]);
648
817
  // ---------------------------------------------------------------------------
649
818
  // Form Change Handlers
650
819
  // ---------------------------------------------------------------------------
651
820
  var handleChange = (0, react_1.useCallback)(function (key, value) {
652
- if (key === "companyQuery") {
653
- dispatch({
654
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
655
- payload: { key: key, value: value },
821
+ context.dispatch({
822
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
823
+ payload: { key: key, value: value },
824
+ });
825
+ if (key !== "companyQuery") {
826
+ context.dispatch({
827
+ type: exports.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
828
+ payload: { disableSaveButton: false },
829
+ });
830
+ context.dispatch({
831
+ type: exports.INVOICE_ACTION_TYPES.SET_ERRORS,
832
+ payload: { errors: {} },
656
833
  });
657
- return;
658
834
  }
659
- dispatch({
660
- type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
661
- payload: { disableSaveButton: false },
662
- });
663
- dispatch({
664
- type: actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS,
665
- });
666
- }, []);
835
+ }, [context]);
667
836
  var handleItemChangeServices = (0, react_1.useCallback)(function (_a) {
668
837
  var _b;
669
838
  var index = _a.index, key = _a.key, value = _a.value;
670
- dispatch({
671
- type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
839
+ context.dispatch({
840
+ type: exports.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
672
841
  payload: { disableSaveButton: false },
673
842
  });
674
- var updatedItems = __spreadArray([], state.servicesList, true);
843
+ var updatedItems = __spreadArray([], state.serviceList, true);
675
844
  updatedItems[index] = __assign(__assign({}, updatedItems[index]), (_b = {}, _b[key] = value, _b.mode = updatedItems[index].mode === "Create" ? "Create" : "Edit", _b));
676
845
  var quantity = parseFloat(updatedItems[index].quantity) || 0;
677
846
  var price = parseFloat(updatedItems[index].price) || 0;
678
847
  var rowTotal = (quantity * price).toFixed(2);
679
848
  updatedItems[index].rowTotal = rowTotal;
680
- var allProducts = state.productsList;
849
+ var allProducts = state.productList;
681
850
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(updatedItems, allProducts);
682
- dispatch({
683
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
851
+ context.dispatch({
852
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
684
853
  payload: { key: "subTotal", value: subtotal },
685
854
  });
686
- dispatch({
687
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
688
- payload: { key: "servicesList", value: updatedItems },
855
+ context.dispatch({
856
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
857
+ payload: { key: "serviceList", value: updatedItems },
689
858
  });
690
- }, [state.productsList, state.servicesList]);
859
+ }, [context, state.productList, state.serviceList]);
691
860
  var handleItemChangeProducts = (0, react_1.useCallback)(function (_a) {
692
861
  var _b, _c, _d;
693
862
  var _e;
694
863
  var index = _a.index, key = _a.key, value = _a.value;
695
- dispatch({
696
- type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
864
+ context.dispatch({
865
+ type: exports.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
697
866
  payload: { disableSaveButton: false },
698
867
  });
699
- var updatedItems = __spreadArray([], state.productsList, true);
868
+ var updatedItems = __spreadArray([], state.productList, true);
700
869
  if (key === "id" && typeof value === "string") {
701
- var matchingProduct = (_e = state.getProducts) === null || _e === void 0 ? void 0 : _e.find(function (product) { return product.id === value; });
870
+ var matchingProduct = (_e = cachedProducts === null || cachedProducts === void 0 ? void 0 : cachedProducts.items) === null || _e === void 0 ? void 0 : _e.find(function (product) { return product.id === value; });
702
871
  if (matchingProduct) {
703
872
  var quantity = parseFloat(String(updatedItems[index].quantity)) || 0;
704
- var rowTotal = (quantity * parseFloat(matchingProduct.salePrice)).toFixed(2);
705
- updatedItems[index] = __assign(__assign({}, updatedItems[index]), (_b = {}, _b[key] = value, _b.price = matchingProduct.salePrice, _b.mode = updatedItems[index].mode === "Create" ? "Create" : "Edit", _b.rowTotal = rowTotal, _b));
706
- var allServices = state.servicesList;
873
+ var rowTotal = (quantity * Number(matchingProduct.price))
874
+ .toFixed(2)
875
+ .toString();
876
+ updatedItems[index] = __assign(__assign({}, updatedItems[index]), (_b = {}, _b[key] = value, _b.price = String(matchingProduct.price), _b.mode = updatedItems[index].mode === "Create" ? "Create" : "Edit", _b.rowTotal = rowTotal, _b));
877
+ var allServices = state.serviceList;
707
878
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(allServices, updatedItems);
708
- dispatch({
709
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
879
+ context.dispatch({
880
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
710
881
  payload: { key: "subTotal", value: subtotal },
711
882
  });
712
883
  }
@@ -720,100 +891,106 @@ var useInvoiceState = function () {
720
891
  var price = parseFloat(updatedItems[index].price) || 0;
721
892
  var rowTotal = (quantity * price).toFixed(2);
722
893
  updatedItems[index] = __assign(__assign({}, updatedItems[index]), { rowTotal: rowTotal });
723
- var allServices = state.servicesList;
894
+ var allServices = state.serviceList;
724
895
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(allServices, updatedItems);
725
- dispatch({
726
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
896
+ context.dispatch({
897
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
727
898
  payload: { key: "subTotal", value: subtotal },
728
899
  });
729
900
  }
730
- dispatch({
731
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
732
- payload: { key: "productsList", value: updatedItems },
901
+ context.dispatch({
902
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
903
+ payload: { key: "productList", value: updatedItems },
733
904
  });
734
- }, [state.servicesList, state.productsList, state.getProducts]);
905
+ },
906
+ // eslint-disable-next-line react-hooks/exhaustive-deps
907
+ [context, state.serviceList, state.productList]);
735
908
  // ---------------------------------------------------------------------------
736
- // PAGINATION HANDLERS
909
+ // Pagination Handlers
737
910
  // ---------------------------------------------------------------------------
738
911
  var handleNextClick = (0, react_1.useCallback)(function () {
739
- dispatch({
740
- type: actions_1.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
912
+ context.dispatch({
913
+ type: exports.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
741
914
  payload: { currentPage: state.currentPage + 1 },
742
915
  });
743
- }, [state.currentPage]);
916
+ }, [context, state.currentPage]);
744
917
  var handlePreviousClick = (0, react_1.useCallback)(function () {
745
- dispatch({
746
- type: actions_1.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
918
+ context.dispatch({
919
+ type: exports.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
747
920
  payload: { currentPage: state.currentPage - 1 },
748
921
  });
749
- }, [state.currentPage]);
922
+ }, [context, state.currentPage]);
750
923
  var handlePageLimit = (0, react_1.useCallback)(function (k, value) {
751
924
  var val = __assign({}, value);
752
- dispatch({
753
- type: actions_1.INVOICE_ACTION_TYPES.SET_PAGE_LIMIT,
925
+ context.dispatch({
926
+ type: exports.INVOICE_ACTION_TYPES.SET_PAGE_LIMIT,
754
927
  payload: { pageLimit: Number(val.option) },
755
928
  });
756
- // Reset to page 1 when page limit changes
757
- dispatch({
758
- type: actions_1.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
929
+ context.dispatch({
930
+ type: exports.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
759
931
  payload: { currentPage: 1 },
760
932
  });
761
- }, []);
933
+ }, [context]);
762
934
  var searchOnChange = (0, react_1.useCallback)(function (k, v) {
763
- dispatch({
764
- type: actions_1.INVOICE_ACTION_TYPES.SET_SEARCH_QUERY,
935
+ context.dispatch({
936
+ type: exports.INVOICE_ACTION_TYPES.SET_SEARCH_QUERY,
765
937
  payload: { searchQuery: v },
766
938
  });
767
- }, []);
939
+ }, [context]);
768
940
  var clearSearch = (0, react_1.useCallback)(function () {
769
- dispatch({
770
- type: actions_1.INVOICE_ACTION_TYPES.SET_SEARCH_QUERY,
941
+ context.dispatch({
942
+ type: exports.INVOICE_ACTION_TYPES.SET_SEARCH_QUERY,
771
943
  payload: { searchQuery: "" },
772
944
  });
773
- }, []);
945
+ }, [context]);
774
946
  // ---------------------------------------------------------------------------
775
- // SEARCH HANDLERS
947
+ // Search Handlers
776
948
  // ---------------------------------------------------------------------------
777
949
  var handleTaxSearch = (0, react_1.useCallback)(function (searchQuery) {
778
- dispatch({
779
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
950
+ context.dispatch({
951
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
780
952
  payload: { key: "taxQuery", value: searchQuery },
781
953
  });
782
- }, []);
954
+ }, [context]);
783
955
  // ---------------------------------------------------------------------------
784
- // DRAWER & MODAL HANDLERS
956
+ // Drawer & Modal Handlers
785
957
  // ---------------------------------------------------------------------------
786
958
  var closeDrawer = (0, react_1.useCallback)(function () {
787
- dispatch({
788
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
959
+ context.dispatch({
960
+ type: exports.INVOICE_ACTION_TYPES.SET_DRAWER,
789
961
  payload: { drawer: null },
790
962
  });
791
- dispatch({ type: actions_1.INVOICE_ACTION_TYPES.RESET_FORM });
792
- dispatch({ type: actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS });
793
- }, []);
963
+ context.dispatch({ type: exports.INVOICE_ACTION_TYPES.RESET_FORM });
964
+ context.dispatch({
965
+ type: exports.INVOICE_ACTION_TYPES.SET_ERRORS,
966
+ payload: { errors: {} },
967
+ });
968
+ }, [context]);
794
969
  // ---------------------------------------------------------------------------
795
- // FORM HANDLERS
970
+ // Form Row Handlers
796
971
  // ---------------------------------------------------------------------------
797
972
  var handleDeleteServiceRow = (0, react_1.useCallback)(function (i) {
798
- if (state.servicesList.length > 1) {
799
- var res = state.servicesList.splice(i, 1);
800
- dispatch({
801
- type: actions_1.INVOICE_ACTION_TYPES.DELETE_ITEM_SERVICE,
802
- payload: { servicesList: __spreadArray([], res, true) },
973
+ if (state.serviceList.length > 1) {
974
+ var updatedList = __spreadArray([], state.serviceList, true);
975
+ updatedList.splice(i, 1);
976
+ context.dispatch({
977
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
978
+ payload: { key: "serviceList", value: updatedList },
803
979
  });
804
980
  }
805
- }, [state.servicesList]);
981
+ }, [context, state.serviceList]);
806
982
  var handleDeleteProductRow = (0, react_1.useCallback)(function (i) {
807
- if (state.productsList.length > 1) {
808
- var res = state.productsList.splice(i, 1);
809
- dispatch({
810
- type: actions_1.INVOICE_ACTION_TYPES.DELETE_ITEM_PRODUCT,
811
- payload: { productsList: __spreadArray([], res, true) },
983
+ if (state.productList.length > 1) {
984
+ var updatedList = __spreadArray([], state.productList, true);
985
+ updatedList.splice(i, 1);
986
+ context.dispatch({
987
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
988
+ payload: { key: "productList", value: updatedList },
812
989
  });
813
990
  }
814
- }, [state.productsList]);
991
+ }, [context, state.productList]);
815
992
  // ---------------------------------------------------------------------------
816
- // TABLE ACTIONS
993
+ // Table Actions
817
994
  // ---------------------------------------------------------------------------
818
995
  var headerActions = (0, react_1.useMemo)(function () { return [
819
996
  {
@@ -830,42 +1007,53 @@ var useInvoiceState = function () {
830
1007
  },
831
1008
  ]; }, [handleCreate]);
832
1009
  var rowActions = (0, react_1.useMemo)(function () { return [
1010
+ {
1011
+ enabled: true,
1012
+ handleAction: handleView,
1013
+ label: "View",
1014
+ order: 1,
1015
+ },
833
1016
  {
834
1017
  enabled: true,
835
1018
  handleAction: handleEdit,
836
1019
  label: "Edit",
837
- order: 1,
1020
+ order: 2,
838
1021
  },
839
1022
  {
840
1023
  enabled: true,
841
1024
  handleAction: handleRecordPayment,
842
1025
  label: "Record payment",
843
- order: 2,
1026
+ order: 3,
844
1027
  },
845
1028
  {
846
1029
  enabled: true,
847
1030
  handleAction: handleDelete,
848
1031
  label: "Delete",
849
- order: 3,
1032
+ order: 4,
850
1033
  },
851
- ]; }, [handleEdit, handleRecordPayment, handleDelete]);
1034
+ ]; }, [handleEdit, handleRecordPayment, handleDelete, handleView]);
852
1035
  // ---------------------------------------------------------------------------
853
- // RETURN STATE
1036
+ // Return State (flat, backward-compatible + factory-compatible)
854
1037
  // ---------------------------------------------------------------------------
855
- return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, handleAddItemProduct: handleAddItemProduct, handleAddItemService: handleAddItemService, handleChange: handleChange, handleDeleteProductRow: handleDeleteProductRow, handleDeleteServiceRow: handleDeleteServiceRow, handleItemChangeProducts: handleItemChangeProducts, handleItemChangeServices: handleItemChangeServices, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, handleTaxSearch: handleTaxSearch, updateError: updateError, updateLoading: updateLoading });
856
- };
857
- exports.InvoiceStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialInvoiceState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, handleAddItemProduct: function () { return void 0; }, handleAddItemService: function () { return void 0; }, handleChange: function () { return void 0; }, handleDeleteProductRow: function () { return void 0; }, handleDeleteServiceRow: function () { return void 0; }, handleItemChangeProducts: function () { return void 0; }, handleItemChangeServices: function () { return void 0; }, handleNextClick: function () { return void 0; }, handlePageLimit: function () { return void 0; }, handlePreviousClick: function () { return void 0; }, handleSubmit: function () { return void 0; }, headerActions: [], listError: undefined, listFetchNow: function () { return void 0; }, listLoading: false, rowActions: [], searchOnChange: function () { return void 0; }, handleTaxSearch: function () { return void 0; }, updateError: undefined, updateLoading: false }));
858
- var InvoiceStateContextProvider = function (_a) {
859
- var children = _a.children;
860
- var state = useInvoiceState();
861
- return (react_1.default.createElement(exports.InvoiceStateContext.Provider, { value: state }, children));
862
- };
863
- exports.InvoiceStateContextProvider = InvoiceStateContextProvider;
864
- var useInvoiceStateContext = function () {
865
- var state = (0, react_1.useContext)(exports.InvoiceStateContext);
866
- if (state === undefined) {
867
- throw new Error("useInvoiceStateContext must be used within an InvoiceContextProvider");
868
- }
869
- return state;
1038
+ return __assign(__assign({}, context), { clearSearch: clearSearch, closeDrawer: closeDrawer, handleAddItemProduct: handleAddItemProduct, handleAddItemService: handleAddItemService, handleChange: handleChange, handleCloseDrawer: closeDrawer, handleCreate: handleCreate, handleDelete: handleDelete, handleDeleteProductRow: handleDeleteProductRow, handleDeleteServiceRow: handleDeleteServiceRow, handleEdit: handleEdit, handleItemChangeProducts: handleItemChangeProducts, handleItemChangeServices: handleItemChangeServices, handleNextClick: handleNextClick, handlePageChange: function (page) {
1039
+ context.dispatch({
1040
+ type: exports.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
1041
+ payload: { currentPage: page },
1042
+ });
1043
+ }, handlePageLimit: handlePageLimit, handlePageLimitChange: function (limit) {
1044
+ context.dispatch({
1045
+ type: exports.INVOICE_ACTION_TYPES.SET_PAGE_LIMIT,
1046
+ payload: { pageLimit: limit },
1047
+ });
1048
+ context.dispatch({
1049
+ type: exports.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
1050
+ payload: { currentPage: 1 },
1051
+ });
1052
+ }, handlePreviousClick: handlePreviousClick, handleRecordPayment: handleRecordPayment, handleSearch: function (query) {
1053
+ context.dispatch({
1054
+ type: exports.INVOICE_ACTION_TYPES.SET_SEARCH_QUERY,
1055
+ payload: { searchQuery: query },
1056
+ });
1057
+ }, handleSubmit: handleSubmit, handleTaxSearch: handleTaxSearch, handleView: handleView, headerActions: headerActions, rowActions: rowActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, updateLoading: updateLoading, searchOnChange: searchOnChange });
870
1058
  };
871
- exports.useInvoiceStateContext = useInvoiceStateContext;
1059
+ exports.useInvoiceModule = useInvoiceModule;