@appcorp/stellar-solutions-invoice-module 0.1.73 → 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 +542 -340
  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 -41
  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 +312 -240
  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 +431 -293
  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 -3
  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 +12 -11
  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;
@@ -311,107 +397,130 @@ var useInvoiceState = function () {
311
397
  var _a, _b;
312
398
  return (__assign(__assign({}, item), { price: (_a = item === null || item === void 0 ? void 0 : item.product) === null || _a === void 0 ? void 0 : _a.salePrice, id: item === null || item === void 0 ? void 0 : item.productId, quantity: item === null || item === void 0 ? void 0 : item.quantity, rowTotal: parseFloat((_b = item === null || item === void 0 ? void 0 : item.product) === null || _b === void 0 ? void 0 : _b.salePrice) * parseInt(item.quantity) }));
313
399
  });
314
- var updatedData = __assign(__assign(__assign(__assign({}, data), { 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) && {
315
- customer: __assign({}, data.customer),
316
- })), { servicesList: __spreadArray([], updatedServices, true).filter(function (item) { return item.name; }), productsList: __spreadArray([], updatedProducts, true).filter(function (item) { return item.id; }), companiesList: [__assign({}, data.company)] });
317
- if ((_c = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _c === void 0 ? void 0 : _c.name) {
318
- dispatch({
319
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
320
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER },
321
- });
322
- }
323
- if ((_d = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _d === void 0 ? void 0 : _d.firstName) {
324
- dispatch({
325
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
326
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER },
400
+ // Normalize currency: API may return currency id or code. Prefer storing id.
401
+ var normalizedCurrency_1 = data.currency;
402
+ if (normalizedCurrency_1) {
403
+ var foundById = (_b = currencies === null || currencies === void 0 ? void 0 : currencies.items) === null || _b === void 0 ? void 0 : _b.find(function (_a) {
404
+ var id = _a.id;
405
+ return id === normalizedCurrency_1;
327
406
  });
407
+ if (!foundById) {
408
+ var foundByCode = (_c = currencies === null || currencies === void 0 ? void 0 : currencies.items) === null || _c === void 0 ? void 0 : _c.find(function (_a) {
409
+ var code = _a.code;
410
+ return code === normalizedCurrency_1;
411
+ });
412
+ if (foundByCode)
413
+ normalizedCurrency_1 = foundByCode.id;
414
+ }
328
415
  }
329
- dispatch({
330
- type: actions_1.INVOICE_ACTION_TYPES.SET_FORM,
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) && {
417
+ customer: __assign({}, data.customer),
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,
331
421
  payload: { form: updatedData },
332
422
  });
333
423
  if ((_e = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _e === void 0 ? void 0 : _e.name) {
334
- dispatch({
335
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
336
- 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 },
337
431
  });
338
432
  }
339
- if ((_f = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _f === void 0 ? void 0 : _f.firstName) {
340
- dispatch({
341
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
342
- 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 },
343
441
  });
344
442
  }
345
443
  }
346
- }, [t, showErrorToast]);
444
+ }, [t, showErrorToast, currencies, context]);
347
445
  var deleteCallback = (0, react_1.useCallback)(function (_a) {
446
+ var _b;
348
447
  var data = _a.data, error = _a.error;
349
448
  if (error) {
350
449
  showErrorToast(tCommon("messagesNetworkError"));
351
450
  return;
352
451
  }
353
452
  if (data) {
453
+ (0, cache_1.invalidateInvoicesCache)();
354
454
  showSuccessToast(t("messagesInvoiceDeleted"));
355
- dispatch({ type: actions_1.INVOICE_ACTION_TYPES.RESET_FORM });
356
- listFetchNow();
455
+ context.dispatch({ type: exports.INVOICE_ACTION_TYPES.RESET_FORM });
456
+ (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
357
457
  }
358
- },
359
- // eslint-disable-next-line react-hooks/exhaustive-deps
360
- [t, tCommon, showErrorToast, showSuccessToast]);
458
+ }, [t, tCommon, showErrorToast, showSuccessToast, context]);
361
459
  // ---------------------------------------------------------------------------
362
460
  // Module Entity Hook
363
461
  // ---------------------------------------------------------------------------
364
- var _c = (0, util_functions_1.useModuleEntity)({
462
+ var _b = (0, util_functions_1.useModuleEntityV2)({
365
463
  byIdCallback: byIdCallback,
366
464
  byIdParams: byIdParams,
367
465
  deleteCallback: deleteCallback,
368
466
  deleteParams: deleteParams,
369
467
  listCallback: listCallback,
370
468
  listParams: listParams,
371
- listUrl: constants_1.INVOICE_API_ROUTES.INVOICES,
469
+ listUrl: constants_1.INVOICE_API_ROUTES.UNIT,
372
470
  searchQuery: debouncedQuery,
373
- unitByIdUrl: constants_1.INVOICE_API_ROUTES.INVOICE_BY_ID,
374
- unitUrl: constants_1.INVOICE_API_ROUTES.INVOICE,
471
+ unitByIdUrl: constants_1.INVOICE_API_ROUTES.UNIT,
472
+ unitUrl: constants_1.INVOICE_API_ROUTES.UNIT,
375
473
  updateCallback: updateCallback,
376
- updateDeps: [state],
377
- updateParams: __assign(__assign({}, updateParams), { mode: "Create" }),
378
- }), 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]);
379
480
  // ---------------------------------------------------------------------------
380
481
  // Effects
381
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.
382
522
  (0, react_1.useEffect)(function () {
383
- listFetchNow();
384
- // eslint-disable-next-line
385
- }, [debouncedQuery, state.currentPage, state.pageLimit]);
386
- (0, react_1.useEffect)(function () {
387
- (function () { return __awaiter(void 0, void 0, void 0, function () {
388
- var data;
389
- return __generator(this, function (_a) {
390
- switch (_a.label) {
391
- case 0: return [4 /*yield*/, (0, util_functions_1.fetchData)({
392
- url: constants_1.INVOICE_API_ROUTES.PRODUCTS,
393
- method: util_functions_1.API_METHODS.POST,
394
- body: JSON.stringify({
395
- searchQuery: debouncedProductList,
396
- pageLimit: 100,
397
- currentPage: 1,
398
- }),
399
- })];
400
- case 1:
401
- data = (_a.sent()).data;
402
- if (data === null || data === void 0 ? void 0 : data.items) {
403
- dispatch({
404
- type: actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST,
405
- payload: { list: data.items },
406
- });
407
- }
408
- return [2 /*return*/];
409
- }
410
- });
411
- }); })();
412
- }, [debouncedProductList]);
413
- (0, react_1.useEffect)(function () {
414
- if (state.drawer === types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER &&
523
+ if (state.invoiceMode === util_functions_1.QUOTE_INVOICE_MODE.CUSTOMER &&
415
524
  debouncedCustomer) {
416
525
  (function () { return __awaiter(void 0, void 0, void 0, function () {
417
526
  var data;
@@ -419,7 +528,7 @@ var useInvoiceState = function () {
419
528
  switch (_a.label) {
420
529
  case 0: return [4 /*yield*/, (0, util_functions_1.fetchData)({
421
530
  url: constants_1.INVOICE_API_ROUTES.CUSTOMER_BY_PHONE,
422
- method: util_functions_1.API_METHODS.POST,
531
+ method: util_functions_1.API_METHODS.GET,
423
532
  body: JSON.stringify({
424
533
  phone: debouncedCustomer,
425
534
  }),
@@ -427,9 +536,16 @@ var useInvoiceState = function () {
427
536
  case 1:
428
537
  data = (_a.sent()).data;
429
538
  if (data) {
430
- dispatch({
431
- type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER,
432
- 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 },
433
549
  });
434
550
  }
435
551
  return [2 /*return*/];
@@ -437,9 +553,34 @@ var useInvoiceState = function () {
437
553
  });
438
554
  }); })();
439
555
  }
440
- }, [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]);
441
582
  (0, react_1.useEffect)(function () {
442
- if (state.drawer === types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER &&
583
+ if (state.invoiceMode === util_functions_1.QUOTE_INVOICE_MODE.COMPANY &&
443
584
  debouncedCompanyList) {
444
585
  (function () { return __awaiter(void 0, void 0, void 0, function () {
445
586
  var data;
@@ -457,9 +598,9 @@ var useInvoiceState = function () {
457
598
  case 1:
458
599
  data = (_a.sent()).data;
459
600
  if (data === null || data === void 0 ? void 0 : data.items) {
460
- dispatch({
461
- type: actions_1.INVOICE_ACTION_TYPES.SET_COMPANIES_LIST,
462
- payload: { companiesList: data.items },
601
+ context.dispatch({
602
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
603
+ payload: { key: "companiesList", value: data.items },
463
604
  });
464
605
  }
465
606
  return [2 /*return*/];
@@ -467,7 +608,29 @@ var useInvoiceState = function () {
467
608
  });
468
609
  }); })();
469
610
  }
470
- }, [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]);
471
634
  (0, react_1.useEffect)(function () {
472
635
  (function () { return __awaiter(void 0, void 0, void 0, function () {
473
636
  var data;
@@ -487,9 +650,9 @@ var useInvoiceState = function () {
487
650
  case 1:
488
651
  data = (_a.sent()).data;
489
652
  if (data.items) {
490
- dispatch({
491
- type: actions_1.INVOICE_ACTION_TYPES.SET_TAXES,
492
- payload: { taxes: data.items },
653
+ context.dispatch({
654
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
655
+ payload: { key: "taxes", value: data.items },
493
656
  });
494
657
  }
495
658
  _a.label = 2;
@@ -497,24 +660,23 @@ var useInvoiceState = function () {
497
660
  }
498
661
  });
499
662
  }); })();
663
+ // eslint-disable-next-line react-hooks/exhaustive-deps
500
664
  }, [debouncedTaxList]);
501
665
  (0, react_1.useEffect)(function () {
502
- 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;
503
- dispatch({
504
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
505
- payload: {
506
- key: "total",
507
- value: total,
508
- },
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 },
509
670
  });
510
- dispatch({
511
- type: actions_1.INVOICE_ACTION_TYPES.SET_TAX,
512
- payload: { tax: tax },
671
+ context.dispatch({
672
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
673
+ payload: { key: "tax", value: tax },
513
674
  });
514
- dispatch({
515
- type: actions_1.INVOICE_ACTION_TYPES.SET_AFTER_DISCOUNT,
516
- payload: { afterDiscount: String(afterDiscount) },
675
+ context.dispatch({
676
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
677
+ payload: { key: "afterDiscount", value: String(afterDiscount) },
517
678
  });
679
+ // eslint-disable-next-line react-hooks/exhaustive-deps
518
680
  }, [state.discountUnit, state.discount, state.subTotal, state.taxRate]);
519
681
  // ---------------------------------------------------------------------------
520
682
  // Item Management Handlers
@@ -528,11 +690,11 @@ var useInvoiceState = function () {
528
690
  price: "",
529
691
  rowTotal: "",
530
692
  };
531
- dispatch({
532
- type: actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_SERVICE,
533
- 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) },
534
696
  });
535
- }, [state.servicesList]);
697
+ }, [context, state.serviceList]);
536
698
  var handleAddItemProduct = (0, react_1.useCallback)(function () {
537
699
  var newItem = {
538
700
  id: "",
@@ -541,39 +703,41 @@ var useInvoiceState = function () {
541
703
  quantity: "1",
542
704
  rowTotal: "",
543
705
  };
544
- dispatch({
545
- type: actions_1.INVOICE_ACTION_TYPES.ADD_ITEM_PRODUCT,
546
- 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) },
547
709
  });
548
- }, [state.productsList]);
710
+ }, [context, state.productList]);
549
711
  // ---------------------------------------------------------------------------
550
712
  // Drawer & Modal Handlers
551
713
  // ---------------------------------------------------------------------------
552
714
  var handleCreate = (0, react_1.useCallback)(function (text) {
553
- dispatch({
554
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
715
+ context.dispatch({
716
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
555
717
  payload: { key: "ref", value: (0, util_functions_1.generateRef)({ refLength: 5 }) },
556
718
  });
557
- if (text === "company") {
558
- dispatch({
559
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
560
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_COMPANY_FORM_DRAWER },
561
- });
562
- }
563
- if (text === "customer") {
564
- dispatch({
565
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
566
- payload: { drawer: types_1.INVOICE_DRAWER.INVOICE_CUSTOMER_FORM_DRAWER },
567
- });
568
- }
569
- }, []);
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]);
570
733
  // ---------------------------------------------------------------------------
571
734
  // CRUD Operation Handlers
572
735
  // ---------------------------------------------------------------------------
573
- var handleEdit = (0, react_1.useCallback)(function (id) {
574
- byIdFetchNow(undefined, {
736
+ var handleEdit = (0, react_1.useCallback)(function (row) {
737
+ var record = row;
738
+ byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, {
739
+ params: { id: record === null || record === void 0 ? void 0 : record.id },
575
740
  body: JSON.stringify({
576
- id: id,
577
741
  includeCompany: true,
578
742
  includeCustomer: true,
579
743
  includePayments: true,
@@ -583,116 +747,137 @@ var useInvoiceState = function () {
583
747
  });
584
748
  // eslint-disable-next-line react-hooks/exhaustive-deps
585
749
  }, []);
586
- var handleRecordPayment = (0, react_1.useCallback)(function (id) {
587
- (0, util_functions_1.setStorageValue)("paymentInvoiceId", 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
+ });
762
+ // eslint-disable-next-line react-hooks/exhaustive-deps
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);
588
767
  router.push("/erp/payment");
589
768
  }, [router]);
590
- var handleDelete = (0, react_1.useCallback)(function (id) {
769
+ var handleDelete = (0, react_1.useCallback)(function (row) {
770
+ var record = row;
591
771
  deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
592
- body: JSON.stringify({ id: id }),
772
+ params: { id: record === null || record === void 0 ? void 0 : record.id },
593
773
  });
594
- // eslint-disable-next-line react-hooks/exhaustive-deps
595
- }, []);
774
+ }, [deleteFetchNow]);
596
775
  // ---------------------------------------------------------------------------
597
776
  // Form Submission Handler
598
777
  // ---------------------------------------------------------------------------
599
778
  var handleSubmit = (0, react_1.useCallback)(function () {
600
- if (!state.servicesList[0].name && !state.productsList[0].id) {
601
- dispatch({
602
- 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,
603
782
  payload: { disableSaveButton: true },
604
783
  });
605
784
  return;
606
785
  }
607
- dispatch({
608
- type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
786
+ context.dispatch({
787
+ type: exports.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
609
788
  payload: { disableSaveButton: true },
610
789
  });
611
790
  (0, util_functions_1.validateForm)({
612
- params: __assign(__assign({}, updateParams), { currency: updateParams.currency || defaultCurrency.code, 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 }),
613
792
  schema: validate_1.formValid,
614
793
  successCallback: function () {
615
794
  updateFetchNow(undefined, {
616
- 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.code, 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 })),
617
796
  });
618
797
  },
619
798
  errorCallback: function (e) {
620
- dispatch({
621
- 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,
622
805
  payload: { errors: e },
623
806
  });
624
807
  },
625
808
  });
626
809
  }, [
810
+ context,
627
811
  updateFetchNow,
628
812
  updateParams,
629
813
  defaultCurrency,
630
- defaultTax,
631
- state.productsList,
632
- state.servicesList,
814
+ state.productList,
815
+ state.serviceList,
633
816
  ]);
634
817
  // ---------------------------------------------------------------------------
635
818
  // Form Change Handlers
636
819
  // ---------------------------------------------------------------------------
637
820
  var handleChange = (0, react_1.useCallback)(function (key, value) {
638
- if (key === "companyQuery") {
639
- dispatch({
640
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
641
- 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: {} },
642
833
  });
643
- return;
644
834
  }
645
- dispatch({
646
- type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
647
- payload: { disableSaveButton: false },
648
- });
649
- dispatch({
650
- type: actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS,
651
- });
652
- }, []);
835
+ }, [context]);
653
836
  var handleItemChangeServices = (0, react_1.useCallback)(function (_a) {
654
837
  var _b;
655
838
  var index = _a.index, key = _a.key, value = _a.value;
656
- dispatch({
657
- type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
839
+ context.dispatch({
840
+ type: exports.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
658
841
  payload: { disableSaveButton: false },
659
842
  });
660
- var updatedItems = __spreadArray([], state.servicesList, true);
843
+ var updatedItems = __spreadArray([], state.serviceList, true);
661
844
  updatedItems[index] = __assign(__assign({}, updatedItems[index]), (_b = {}, _b[key] = value, _b.mode = updatedItems[index].mode === "Create" ? "Create" : "Edit", _b));
662
845
  var quantity = parseFloat(updatedItems[index].quantity) || 0;
663
846
  var price = parseFloat(updatedItems[index].price) || 0;
664
847
  var rowTotal = (quantity * price).toFixed(2);
665
848
  updatedItems[index].rowTotal = rowTotal;
666
- var allProducts = state.productsList;
849
+ var allProducts = state.productList;
667
850
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(updatedItems, allProducts);
668
- dispatch({
669
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
851
+ context.dispatch({
852
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
670
853
  payload: { key: "subTotal", value: subtotal },
671
854
  });
672
- dispatch({
673
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
674
- payload: { key: "servicesList", value: updatedItems },
855
+ context.dispatch({
856
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
857
+ payload: { key: "serviceList", value: updatedItems },
675
858
  });
676
- }, [state.productsList, state.servicesList]);
859
+ }, [context, state.productList, state.serviceList]);
677
860
  var handleItemChangeProducts = (0, react_1.useCallback)(function (_a) {
678
861
  var _b, _c, _d;
679
862
  var _e;
680
863
  var index = _a.index, key = _a.key, value = _a.value;
681
- dispatch({
682
- type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
864
+ context.dispatch({
865
+ type: exports.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
683
866
  payload: { disableSaveButton: false },
684
867
  });
685
- var updatedItems = __spreadArray([], state.productsList, true);
868
+ var updatedItems = __spreadArray([], state.productList, true);
686
869
  if (key === "id" && typeof value === "string") {
687
- 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; });
688
871
  if (matchingProduct) {
689
872
  var quantity = parseFloat(String(updatedItems[index].quantity)) || 0;
690
- var rowTotal = (quantity * parseFloat(matchingProduct.salePrice)).toFixed(2);
691
- 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));
692
- 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;
693
878
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(allServices, updatedItems);
694
- dispatch({
695
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
879
+ context.dispatch({
880
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
696
881
  payload: { key: "subTotal", value: subtotal },
697
882
  });
698
883
  }
@@ -706,100 +891,106 @@ var useInvoiceState = function () {
706
891
  var price = parseFloat(updatedItems[index].price) || 0;
707
892
  var rowTotal = (quantity * price).toFixed(2);
708
893
  updatedItems[index] = __assign(__assign({}, updatedItems[index]), { rowTotal: rowTotal });
709
- var allServices = state.servicesList;
894
+ var allServices = state.serviceList;
710
895
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(allServices, updatedItems);
711
- dispatch({
712
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
896
+ context.dispatch({
897
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
713
898
  payload: { key: "subTotal", value: subtotal },
714
899
  });
715
900
  }
716
- dispatch({
717
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
718
- payload: { key: "productsList", value: updatedItems },
901
+ context.dispatch({
902
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
903
+ payload: { key: "productList", value: updatedItems },
719
904
  });
720
- }, [state.servicesList, state.productsList, state.getProducts]);
905
+ },
906
+ // eslint-disable-next-line react-hooks/exhaustive-deps
907
+ [context, state.serviceList, state.productList]);
721
908
  // ---------------------------------------------------------------------------
722
- // PAGINATION HANDLERS
909
+ // Pagination Handlers
723
910
  // ---------------------------------------------------------------------------
724
911
  var handleNextClick = (0, react_1.useCallback)(function () {
725
- dispatch({
726
- type: actions_1.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
912
+ context.dispatch({
913
+ type: exports.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
727
914
  payload: { currentPage: state.currentPage + 1 },
728
915
  });
729
- }, [state.currentPage]);
916
+ }, [context, state.currentPage]);
730
917
  var handlePreviousClick = (0, react_1.useCallback)(function () {
731
- dispatch({
732
- type: actions_1.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
918
+ context.dispatch({
919
+ type: exports.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
733
920
  payload: { currentPage: state.currentPage - 1 },
734
921
  });
735
- }, [state.currentPage]);
922
+ }, [context, state.currentPage]);
736
923
  var handlePageLimit = (0, react_1.useCallback)(function (k, value) {
737
924
  var val = __assign({}, value);
738
- dispatch({
739
- type: actions_1.INVOICE_ACTION_TYPES.SET_PAGE_LIMIT,
925
+ context.dispatch({
926
+ type: exports.INVOICE_ACTION_TYPES.SET_PAGE_LIMIT,
740
927
  payload: { pageLimit: Number(val.option) },
741
928
  });
742
- // Reset to page 1 when page limit changes
743
- dispatch({
744
- type: actions_1.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
929
+ context.dispatch({
930
+ type: exports.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE,
745
931
  payload: { currentPage: 1 },
746
932
  });
747
- }, []);
933
+ }, [context]);
748
934
  var searchOnChange = (0, react_1.useCallback)(function (k, v) {
749
- dispatch({
750
- type: actions_1.INVOICE_ACTION_TYPES.SET_SEARCH_QUERY,
935
+ context.dispatch({
936
+ type: exports.INVOICE_ACTION_TYPES.SET_SEARCH_QUERY,
751
937
  payload: { searchQuery: v },
752
938
  });
753
- }, []);
939
+ }, [context]);
754
940
  var clearSearch = (0, react_1.useCallback)(function () {
755
- dispatch({
756
- type: actions_1.INVOICE_ACTION_TYPES.SET_SEARCH_QUERY,
941
+ context.dispatch({
942
+ type: exports.INVOICE_ACTION_TYPES.SET_SEARCH_QUERY,
757
943
  payload: { searchQuery: "" },
758
944
  });
759
- }, []);
945
+ }, [context]);
760
946
  // ---------------------------------------------------------------------------
761
- // SEARCH HANDLERS
947
+ // Search Handlers
762
948
  // ---------------------------------------------------------------------------
763
949
  var handleTaxSearch = (0, react_1.useCallback)(function (searchQuery) {
764
- dispatch({
765
- type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
950
+ context.dispatch({
951
+ type: exports.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
766
952
  payload: { key: "taxQuery", value: searchQuery },
767
953
  });
768
- }, []);
954
+ }, [context]);
769
955
  // ---------------------------------------------------------------------------
770
- // DRAWER & MODAL HANDLERS
956
+ // Drawer & Modal Handlers
771
957
  // ---------------------------------------------------------------------------
772
958
  var closeDrawer = (0, react_1.useCallback)(function () {
773
- dispatch({
774
- type: actions_1.INVOICE_ACTION_TYPES.SET_DRAWER,
959
+ context.dispatch({
960
+ type: exports.INVOICE_ACTION_TYPES.SET_DRAWER,
775
961
  payload: { drawer: null },
776
962
  });
777
- dispatch({ type: actions_1.INVOICE_ACTION_TYPES.RESET_FORM });
778
- dispatch({ type: actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS });
779
- }, []);
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]);
780
969
  // ---------------------------------------------------------------------------
781
- // FORM HANDLERS
970
+ // Form Row Handlers
782
971
  // ---------------------------------------------------------------------------
783
972
  var handleDeleteServiceRow = (0, react_1.useCallback)(function (i) {
784
- if (state.servicesList.length > 1) {
785
- var res = state.servicesList.splice(i, 1);
786
- dispatch({
787
- type: actions_1.INVOICE_ACTION_TYPES.DELETE_ITEM_SERVICE,
788
- 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 },
789
979
  });
790
980
  }
791
- }, [state.servicesList]);
981
+ }, [context, state.serviceList]);
792
982
  var handleDeleteProductRow = (0, react_1.useCallback)(function (i) {
793
- if (state.productsList.length > 1) {
794
- var res = state.productsList.splice(i, 1);
795
- dispatch({
796
- type: actions_1.INVOICE_ACTION_TYPES.DELETE_ITEM_PRODUCT,
797
- 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 },
798
989
  });
799
990
  }
800
- }, [state.productsList]);
991
+ }, [context, state.productList]);
801
992
  // ---------------------------------------------------------------------------
802
- // TABLE ACTIONS
993
+ // Table Actions
803
994
  // ---------------------------------------------------------------------------
804
995
  var headerActions = (0, react_1.useMemo)(function () { return [
805
996
  {
@@ -816,42 +1007,53 @@ var useInvoiceState = function () {
816
1007
  },
817
1008
  ]; }, [handleCreate]);
818
1009
  var rowActions = (0, react_1.useMemo)(function () { return [
1010
+ {
1011
+ enabled: true,
1012
+ handleAction: handleView,
1013
+ label: "View",
1014
+ order: 1,
1015
+ },
819
1016
  {
820
1017
  enabled: true,
821
1018
  handleAction: handleEdit,
822
1019
  label: "Edit",
823
- order: 1,
1020
+ order: 2,
824
1021
  },
825
1022
  {
826
1023
  enabled: true,
827
1024
  handleAction: handleRecordPayment,
828
1025
  label: "Record payment",
829
- order: 2,
1026
+ order: 3,
830
1027
  },
831
1028
  {
832
1029
  enabled: true,
833
1030
  handleAction: handleDelete,
834
1031
  label: "Delete",
835
- order: 3,
1032
+ order: 4,
836
1033
  },
837
- ]; }, [handleEdit, handleRecordPayment, handleDelete]);
1034
+ ]; }, [handleEdit, handleRecordPayment, handleDelete, handleView]);
838
1035
  // ---------------------------------------------------------------------------
839
- // RETURN STATE
1036
+ // Return State (flat, backward-compatible + factory-compatible)
840
1037
  // ---------------------------------------------------------------------------
841
- 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 });
842
- };
843
- 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 }));
844
- var InvoiceStateContextProvider = function (_a) {
845
- var children = _a.children;
846
- var state = useInvoiceState();
847
- return (react_1.default.createElement(exports.InvoiceStateContext.Provider, { value: state }, children));
848
- };
849
- exports.InvoiceStateContextProvider = InvoiceStateContextProvider;
850
- var useInvoiceStateContext = function () {
851
- var state = (0, react_1.useContext)(exports.InvoiceStateContext);
852
- if (state === undefined) {
853
- throw new Error("useInvoiceStateContext must be used within an InvoiceContextProvider");
854
- }
855
- 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 });
856
1058
  };
857
- exports.useInvoiceStateContext = useInvoiceStateContext;
1059
+ exports.useInvoiceModule = useInvoiceModule;