@appcorp/stellar-solutions-invoice-module 0.1.52 → 0.1.54

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.
@@ -1,5 +1,5 @@
1
1
  import { ProductTypeBE } from '@appcorp/stellar-solutions-product-module/base-modules/product/types';
2
- import { DISCOUNT_UNIT, INVOICE_DRAWER, InvoiceState, QuoteInvoiceTypeBE, Product, Service } from './types';
2
+ import { DISCOUNT_UNIT, INVOICE_DRAWER, InvoiceState, QuoteInvoiceTypeBE, Product, Service, INVOICE_MODAL } from './types';
3
3
  import { TaxTypeBE } from '@appcorp/stellar-solutions-modules/global-modules/preferences/types';
4
4
  import { CompanyTypeBE } from '@appcorp/stellar-solutions-company-module/base-modules/company/types';
5
5
  import { CustomerTypeBE } from '@appcorp/stellar-solutions-company-module/base-modules/customer/types';
@@ -12,9 +12,12 @@ export declare enum INVOICE_ACTION_TYPES {
12
12
  RESET_FORM = "RESET_FORM",
13
13
  SET_AFTER_DISCOUNT = "SET_AFTER_DISCOUNT",
14
14
  SET_BUTTON_DISABLE = "SET_BUTTON_DISABLE",
15
+ SET_COMPANIES_LIST = "SET_COMPANIES_LIST",
15
16
  SET_COUNT = "SET_COUNT",
16
17
  SET_CURRENT_PAGE = "SET_CURRENT_PAGE",
18
+ SET_CUSTOMER = "SET_CUSTOMER",
17
19
  SET_CUSTOMER_DATA = "SET_CUSTOMER_DATA",
20
+ SET_CUSTOMER_FORM = "SET_CUSTOMER_FORM",
18
21
  SET_DISABLE_SAVE_BUTTON = "SET_DISABLE_SAVE_BUTTON",
19
22
  SET_DISCOUNT_UNIT = "SET_DISCOUNT_UNIT",
20
23
  SET_DRAWER = "SET_DRAWER",
@@ -26,15 +29,13 @@ export declare enum INVOICE_ACTION_TYPES {
26
29
  SET_INVOICES = "SET_INVOICES",
27
30
  SET_INVOICE_FORM = "SET_INVOICE_FORM",
28
31
  SET_IS_INVOICE_API_SUCCESS = "SET_IS_INVOICE_API_SUCCESS",
32
+ SET_MODAL = "SET_MODAL",
29
33
  SET_PAGE_LIMIT = "SET_PAGE_LIMIT",
34
+ SET_PRODUCTS_LIST = "SET_PRODUCTS_LIST",
30
35
  SET_SEARCH_QUERY = "SET_SEARCH_QUERY",
31
36
  SET_SKELTON_LOADING = "SET_SKELTON_LOADING",
32
37
  SET_TAX = "SET_TAX",
33
- SET_PRODUCTS_LIST = "SET_PRODUCTS_LIST",
34
- SET_COMPANIES_LIST = "SET_COMPANIES_LIST",
35
- SET_CUSTOMER = "SET_CUSTOMER",
36
- SET_TAXES = "SET_TAXES",
37
- SET_CUSTOMER_FORM = "SET_CUSTOMER_FORM"
38
+ SET_TAXES = "SET_TAXES"
38
39
  }
39
40
  export type InvoiceUpdateFieldAction = {
40
41
  type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD;
@@ -205,4 +206,10 @@ export type InvoiceSetTaxesAction = {
205
206
  taxes: TaxTypeBE[];
206
207
  };
207
208
  };
208
- export type InvoiceActions = InvoiceAddItemProductAction | InvoiceAddItemServiceAction | InvoiceResetErrorAction | InvoiceDeleteItemProductAction | InvoiceDeleteItemServiceAction | InvoiceResetFormAction | InvoiceSetButtonDisableAction | InvoiceSetCurrentPageAction | InvoiceSetCustomerDataAction | InvoiceSetDiscountUnitAction | InvoiceSetErrorsAction | InvoiceSetFormLoadingAction | InvoiceSetInvoicesAction | InvoiceSetInvoiceFormAction | InvoiceSetIsInvoiceApiSuccessAction | InvoiceSetMaxPageLimitAction | InvoiceSetSearchQueryAction | InvoiceUpdateFieldAction | InvoiceToggleLoadingAction | InvoiceSetDrawerAction | InvoiceSetCountAction | InvoiceSetFormAction | InvoiceSetAfterDiscountAction | InvoiceSetTaxAction | InvoiceSetFormToRenderAction | InvoiceSetProductsListAction | InvoiceSetCustomerAction | InvoiceSetTaxesAction | InvoiceSetCustomerFormAction | InvoiceSetCompaniesListAction;
209
+ export type InvoiceSetModalAction = {
210
+ type: INVOICE_ACTION_TYPES.SET_MODAL;
211
+ payload: {
212
+ modal: INVOICE_MODAL;
213
+ };
214
+ };
215
+ export type InvoiceActions = InvoiceAddItemProductAction | InvoiceAddItemServiceAction | InvoiceResetErrorAction | InvoiceDeleteItemProductAction | InvoiceDeleteItemServiceAction | InvoiceResetFormAction | InvoiceSetButtonDisableAction | InvoiceSetCurrentPageAction | InvoiceSetCustomerDataAction | InvoiceSetDiscountUnitAction | InvoiceSetErrorsAction | InvoiceSetFormLoadingAction | InvoiceSetInvoicesAction | InvoiceSetInvoiceFormAction | InvoiceSetIsInvoiceApiSuccessAction | InvoiceSetMaxPageLimitAction | InvoiceSetSearchQueryAction | InvoiceUpdateFieldAction | InvoiceToggleLoadingAction | InvoiceSetDrawerAction | InvoiceSetCountAction | InvoiceSetFormAction | InvoiceSetAfterDiscountAction | InvoiceSetTaxAction | InvoiceSetFormToRenderAction | InvoiceSetProductsListAction | InvoiceSetCustomerAction | InvoiceSetTaxesAction | InvoiceSetCustomerFormAction | InvoiceSetCompaniesListAction | InvoiceSetModalAction;
@@ -11,9 +11,12 @@ var INVOICE_ACTION_TYPES;
11
11
  INVOICE_ACTION_TYPES["RESET_FORM"] = "RESET_FORM";
12
12
  INVOICE_ACTION_TYPES["SET_AFTER_DISCOUNT"] = "SET_AFTER_DISCOUNT";
13
13
  INVOICE_ACTION_TYPES["SET_BUTTON_DISABLE"] = "SET_BUTTON_DISABLE";
14
+ INVOICE_ACTION_TYPES["SET_COMPANIES_LIST"] = "SET_COMPANIES_LIST";
14
15
  INVOICE_ACTION_TYPES["SET_COUNT"] = "SET_COUNT";
15
16
  INVOICE_ACTION_TYPES["SET_CURRENT_PAGE"] = "SET_CURRENT_PAGE";
17
+ INVOICE_ACTION_TYPES["SET_CUSTOMER"] = "SET_CUSTOMER";
16
18
  INVOICE_ACTION_TYPES["SET_CUSTOMER_DATA"] = "SET_CUSTOMER_DATA";
19
+ INVOICE_ACTION_TYPES["SET_CUSTOMER_FORM"] = "SET_CUSTOMER_FORM";
17
20
  INVOICE_ACTION_TYPES["SET_DISABLE_SAVE_BUTTON"] = "SET_DISABLE_SAVE_BUTTON";
18
21
  INVOICE_ACTION_TYPES["SET_DISCOUNT_UNIT"] = "SET_DISCOUNT_UNIT";
19
22
  INVOICE_ACTION_TYPES["SET_DRAWER"] = "SET_DRAWER";
@@ -25,13 +28,11 @@ var INVOICE_ACTION_TYPES;
25
28
  INVOICE_ACTION_TYPES["SET_INVOICES"] = "SET_INVOICES";
26
29
  INVOICE_ACTION_TYPES["SET_INVOICE_FORM"] = "SET_INVOICE_FORM";
27
30
  INVOICE_ACTION_TYPES["SET_IS_INVOICE_API_SUCCESS"] = "SET_IS_INVOICE_API_SUCCESS";
31
+ INVOICE_ACTION_TYPES["SET_MODAL"] = "SET_MODAL";
28
32
  INVOICE_ACTION_TYPES["SET_PAGE_LIMIT"] = "SET_PAGE_LIMIT";
33
+ INVOICE_ACTION_TYPES["SET_PRODUCTS_LIST"] = "SET_PRODUCTS_LIST";
29
34
  INVOICE_ACTION_TYPES["SET_SEARCH_QUERY"] = "SET_SEARCH_QUERY";
30
35
  INVOICE_ACTION_TYPES["SET_SKELTON_LOADING"] = "SET_SKELTON_LOADING";
31
36
  INVOICE_ACTION_TYPES["SET_TAX"] = "SET_TAX";
32
- INVOICE_ACTION_TYPES["SET_PRODUCTS_LIST"] = "SET_PRODUCTS_LIST";
33
- INVOICE_ACTION_TYPES["SET_COMPANIES_LIST"] = "SET_COMPANIES_LIST";
34
- INVOICE_ACTION_TYPES["SET_CUSTOMER"] = "SET_CUSTOMER";
35
37
  INVOICE_ACTION_TYPES["SET_TAXES"] = "SET_TAXES";
36
- INVOICE_ACTION_TYPES["SET_CUSTOMER_FORM"] = "SET_CUSTOMER_FORM";
37
38
  })(INVOICE_ACTION_TYPES || (exports.INVOICE_ACTION_TYPES = INVOICE_ACTION_TYPES = {}));
@@ -3,14 +3,6 @@ import { VISTA_TABLE_CELL_TYPE } from '@appcorp/app-corp-vista/type/vista-table-
3
3
  export declare const pageLimit: number;
4
4
  export declare const handleSplitId: (value: string) => string[];
5
5
  export declare const changeActionsMap: Record<string, (val: string | number | number[]) => string | number | number[]>;
6
- export declare const toastErrors: {
7
- fetchInvoiceError: string;
8
- submitFormError: string;
9
- networkError: string;
10
- genericError: string;
11
- validationError: string;
12
- formSubmittedSuccess: string;
13
- };
14
6
  export declare const staticCompanySection: VistaFormElements;
15
7
  export declare const staticCustomerSection: VistaFormElements;
16
8
  export declare const staticPricingSection: VistaFormElements;
@@ -50,6 +42,10 @@ export declare const tableBodyCols: ({
50
42
  key?: undefined;
51
43
  expression?: undefined;
52
44
  })[];
45
+ export declare const networkMessages: {
46
+ error: string;
47
+ success: string;
48
+ };
53
49
  export declare const validationErrors: {
54
50
  companyId: string;
55
51
  ref: string;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  var _a, _b, _c, _d, _e;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.validationErrors = exports.tableBodyCols = exports.INVOICE_API_ROUTES = exports.staticProductSection = exports.staticServiceSection = exports.staticPricingSection = exports.staticCustomerSection = exports.staticCompanySection = exports.toastErrors = exports.changeActionsMap = exports.handleSplitId = exports.pageLimit = void 0;
7
+ exports.validationErrors = exports.networkMessages = exports.tableBodyCols = exports.INVOICE_API_ROUTES = exports.staticProductSection = exports.staticServiceSection = exports.staticPricingSection = exports.staticCustomerSection = exports.staticCompanySection = exports.changeActionsMap = exports.handleSplitId = exports.pageLimit = void 0;
8
8
  var react_1 = __importDefault(require("react"));
9
9
  var util_functions_1 = require("@react-pakistan/util-functions");
10
10
  var form_schema_1 = require("@appcorp/app-corp-vista/utils/form-schema");
@@ -20,14 +20,6 @@ exports.handleSplitId = handleSplitId;
20
20
  exports.changeActionsMap = {
21
21
  companyId: function (val) { return (0, exports.handleSplitId)(val)[1]; },
22
22
  };
23
- exports.toastErrors = {
24
- fetchInvoiceError: 'Error Fetching Invoice',
25
- submitFormError: 'Error Submitting Form',
26
- networkError: 'Network Error Occurred',
27
- genericError: 'Something Went Wrong',
28
- validationError: 'Validation Failed',
29
- formSubmittedSuccess: 'Form Submitted Successfully',
30
- };
31
23
  exports.staticCompanySection = (_a = {},
32
24
  _a[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_INPUT_V1] = [
33
25
  {
@@ -568,6 +560,10 @@ exports.tableBodyCols = [
568
560
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.ACTIONS,
569
561
  },
570
562
  ];
563
+ exports.networkMessages = {
564
+ error: 'Error occurred, please, try again',
565
+ success: 'Operation successful!',
566
+ };
571
567
  exports.validationErrors = {
572
568
  companyId: 'Please select Company',
573
569
  ref: 'Please enter ref',
@@ -108,12 +108,13 @@ var util_functions_2 = require("@react-pakistan/util-functions");
108
108
  var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/tax/context");
109
109
  var context_2 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
110
110
  var useInvoiceState = function () {
111
- var _a = (0, react_1.useReducer)(reducer_1.invoiceReducer, reducer_1.initialInvoiceState), state = _a[0], dispatch = _a[1];
111
+ var _a;
112
+ var _b = (0, react_1.useReducer)(reducer_1.invoiceReducer, reducer_1.initialInvoiceState), state = _b[0], dispatch = _b[1];
112
113
  var taxes = (0, context_1.useTaxStateContext)().taxes;
113
114
  var currencies = (0, context_2.usePreferenceStateContext)().currencies;
114
115
  var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
115
116
  var debouncedProductList = (0, util_functions_1.useDebounce)(state.productQuery, 800);
116
- var debouncedCustomer = (0, util_functions_1.useDebounce)(state.phone, 800);
117
+ 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);
117
118
  var debouncedTaxList = (0, util_functions_1.useDebounce)(state.taxQuery, 800);
118
119
  var debouncedCompanyList = (0, util_functions_1.useDebounce)(state.companyQuery, 800);
119
120
  var defaultTax = (0, react_1.useMemo)(function () {
@@ -139,7 +140,7 @@ var useInvoiceState = function () {
139
140
  if (error) {
140
141
  (0, generate_toast_1.generateToast)({
141
142
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
142
- description: constants_1.toastErrors.fetchInvoiceError,
143
+ description: constants_1.networkMessages.error,
143
144
  });
144
145
  }
145
146
  if (data === null || data === void 0 ? void 0 : data.items) {
@@ -168,7 +169,6 @@ var useInvoiceState = function () {
168
169
  invoiceStatus: state.invoiceStatus,
169
170
  mode: state.mode,
170
171
  note: state.note.trim(),
171
- phone: state.phone,
172
172
  products: state.products,
173
173
  quoteStatus: state.quoteStatus,
174
174
  ref: state.ref,
@@ -182,13 +182,13 @@ var useInvoiceState = function () {
182
182
  var data = _a.data, error = _a.error;
183
183
  if (error) {
184
184
  (0, generate_toast_1.generateToast)({
185
- description: constants_1.toastErrors.networkError,
185
+ description: constants_1.networkMessages.error,
186
186
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
187
187
  });
188
188
  }
189
189
  if (data) {
190
190
  (0, generate_toast_1.generateToast)({
191
- description: constants_1.toastErrors.networkError,
191
+ description: constants_1.networkMessages.success,
192
192
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
193
193
  });
194
194
  dispatch({
@@ -212,7 +212,7 @@ var useInvoiceState = function () {
212
212
  var data = _a.data, error = _a.error;
213
213
  if (error) {
214
214
  (0, generate_toast_1.generateToast)({
215
- description: constants_1.toastErrors.networkError,
215
+ description: constants_1.networkMessages.error,
216
216
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
217
217
  });
218
218
  }
@@ -262,13 +262,13 @@ var useInvoiceState = function () {
262
262
  var data = _a.data, error = _a.error;
263
263
  if (error) {
264
264
  (0, generate_toast_1.generateToast)({
265
- description: constants_1.toastErrors.networkError,
265
+ description: constants_1.networkMessages.error,
266
266
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
267
267
  });
268
268
  }
269
269
  if (data) {
270
270
  (0, generate_toast_1.generateToast)({
271
- description: constants_1.toastErrors.networkError,
271
+ description: constants_1.networkMessages.success,
272
272
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
273
273
  });
274
274
  dispatch({
@@ -277,7 +277,7 @@ var useInvoiceState = function () {
277
277
  listFetchNow();
278
278
  }
279
279
  };
280
- var _b = (0, util_functions_1.useModuleEntity)({
280
+ var _c = (0, util_functions_1.useModuleEntity)({
281
281
  byIdCallback: byIdCallback,
282
282
  byIdParams: byIdParams,
283
283
  deleteCallback: deleteCallback,
@@ -291,7 +291,7 @@ var useInvoiceState = function () {
291
291
  updateCallback: updateCallback,
292
292
  updateDeps: [state],
293
293
  updateParams: __assign(__assign({}, updateParams), { mode: 'Create' }),
294
- }), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError, listFetchNow = _b.listFetchNow, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
294
+ }), 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;
295
295
  (0, react_1.useEffect)(function () {
296
296
  listFetchNow();
297
297
  // eslint-disable-next-line
@@ -501,7 +501,7 @@ var useInvoiceState = function () {
501
501
  schema: validate_1.formValidation,
502
502
  successCallback: function () {
503
503
  updateFetchNow(undefined, {
504
- body: JSON.stringify(__assign(__assign({}, updateParams), { products: state.getProducts.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 })),
504
+ 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 })),
505
505
  });
506
506
  },
507
507
  errorCallback: function (e) {
@@ -511,8 +511,8 @@ var useInvoiceState = function () {
511
511
  });
512
512
  },
513
513
  });
514
- }, [updateFetchNow, updateParams, defaultCurrency, defaultTax, state.getProducts, state.servicesList]);
515
- var handleChange = (0, react_1.useCallback)(function (key, value) {
514
+ }, [updateFetchNow, updateParams, defaultCurrency, defaultTax, state.productsList, state.servicesList]);
515
+ var handleCustomerChange = (0, react_1.useCallback)(function (key, value) {
516
516
  var _a;
517
517
  if (key === 'phone') {
518
518
  var formattedNumber = (_a = (0, util_functions_1.formatPhone)(value)) === null || _a === void 0 ? void 0 : _a.international;
@@ -522,6 +522,19 @@ var useInvoiceState = function () {
522
522
  });
523
523
  return;
524
524
  }
525
+ dispatch({
526
+ type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM,
527
+ payload: { key: key, value: value },
528
+ });
529
+ dispatch({
530
+ type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
531
+ payload: { disableSaveButton: false },
532
+ });
533
+ dispatch({
534
+ type: actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS,
535
+ });
536
+ }, []);
537
+ var handleChange = (0, react_1.useCallback)(function (key, value) {
525
538
  if (key === 'companyQuery') {
526
539
  dispatch({
527
540
  type: actions_1.INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
@@ -529,10 +542,6 @@ var useInvoiceState = function () {
529
542
  });
530
543
  return;
531
544
  }
532
- dispatch({
533
- type: actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM,
534
- payload: { key: key, value: String(value) },
535
- });
536
545
  dispatch({
537
546
  type: actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
538
547
  payload: { disableSaveButton: false },
@@ -753,7 +762,7 @@ var useInvoiceState = function () {
753
762
  var _b;
754
763
  var id = _a.id;
755
764
  textInputElements[i].error = state.errors[id];
756
- textInputElements[i].handleOnChange = handleChange;
765
+ textInputElements[i].handleOnChange = handleCustomerChange;
757
766
  textInputElements[i].value = (_b = state === null || state === void 0 ? void 0 : state.customer) === null || _b === void 0 ? void 0 : _b[id];
758
767
  });
759
768
  }
@@ -763,15 +772,15 @@ var useInvoiceState = function () {
763
772
  comboboxElements[0].listItems = util_functions_2.countriesTimeZones;
764
773
  comboboxElements[0].query = state.countryQuery;
765
774
  comboboxElements[0].handleOnChange = handleSelectChange;
766
- comboboxElements[0].handleInputOnChange = handleChange;
767
- comboboxElements[0].handleOnBlur = handleChange;
775
+ comboboxElements[0].handleInputOnChange = handleCustomerChange;
776
+ comboboxElements[0].handleOnBlur = handleCustomerChange;
768
777
  comboboxElements[1].selectedItem = { code: state.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.code) };
769
778
  comboboxElements[1].listItems = currencies;
770
779
  comboboxElements[1].handleOnChange = handleSelectChange;
771
- comboboxElements[1].handleInputOnChange = handleChange;
780
+ comboboxElements[1].handleInputOnChange = handleCustomerChange;
772
781
  }
773
782
  return elements;
774
- }, [state, handleChange, currencies, defaultCurrency]);
783
+ }, [state, currencies, handleCustomerChange, defaultCurrency]);
775
784
  var dynamicPricingFormElements = (0, react_1.useMemo)(function () {
776
785
  var _a, _b, _c, _d, _e, _f;
777
786
  var elements = __assign({}, constants_1.staticPricingSection);
@@ -13,7 +13,7 @@ var form_1 = require("./form");
13
13
  var Drawer = function (_a) {
14
14
  var translationMap = _a.translationMap;
15
15
  var _b = (0, context_1.useInvoiceStateContext)(), closeDrawer = _b.closeDrawer, disableSaveButton = _b.disableSaveButton, drawer = _b.drawer, handleSubmit = _b.handleSubmit;
16
- return (react_1.default.createElement(vista_drawer_v1_1.VistaDrawerV1, { cancelLabel: "Cancel", cancelRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, cancelSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, handleCancelOnClick: closeDrawer, handleSaveOnClick: handleSubmit, handleSetIsOpen: closeDrawer, isOpen: !!drawer, saveDisabled: disableSaveButton, saveLabel: 'Save', saveRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, saveSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, size: vista_drawer_type_1.VISTA_DRAWER_SIZE.XL, title: 'Product' },
16
+ return (react_1.default.createElement(vista_drawer_v1_1.VistaDrawerV1, { cancelLabel: "Cancel", cancelRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, cancelSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, handleCancelOnClick: closeDrawer, handleSaveOnClick: handleSubmit, handleSetIsOpen: closeDrawer, isOpen: !!drawer, saveDisabled: disableSaveButton, saveLabel: 'Save', saveRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, saveSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, size: vista_drawer_type_1.VISTA_DRAWER_SIZE.XL, title: 'Invoice' },
17
17
  react_1.default.createElement(form_1.InvoiceForm, { translationMap: translationMap })));
18
18
  };
19
19
  exports.Drawer = Drawer;
@@ -27,7 +27,7 @@ var ProductsSection = function () {
27
27
  var _a = (0, context_1.useInvoiceStateContext)(), handleChange = _a.handleChange, handleDeleteServiceRow = _a.handleDeleteServiceRow, handleItemChangeProducts = _a.handleItemChangeProducts, productsList = _a.productsList, getProducts = _a.getProducts;
28
28
  return (react_1.default.createElement("div", { className: "flex flex-col gap-4" },
29
29
  react_1.default.createElement(vista_vertical_divider_v4_1.VistaVerticalDividerV4, { label: "Products" }),
30
- productsList.map(function (row, index) { return (react_1.default.createElement("div", { key: index, className: 'grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] items-end justify-between gap-4' },
30
+ productsList.length > 0 && (productsList === null || productsList === void 0 ? void 0 : productsList.map(function (row, index) { return (react_1.default.createElement("div", { key: index, className: 'grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] items-end justify-between gap-4' },
31
31
  react_1.default.createElement("div", { className: 'col-span-2' },
32
32
  react_1.default.createElement(vista_combobox_v1_1.VistaComboboxV1, { handleOnChange: function (k, v) {
33
33
  var val = __assign({}, v);
@@ -37,9 +37,9 @@ var ProductsSection = function () {
37
37
  value: val.id,
38
38
  });
39
39
  }, handleOnBlur: handleChange, handleInputOnChange: handleChange, label: "Product", listItems: getProducts, nodeQueryKey: 'productQuery', nodeSelectKey: 'id', query: '', selectKey1: 'name', selectedItem: { id: productsList[index].id } })),
40
- react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'quantity', label: 'Quantity', placeholder: '1', value: String(productsList[index].quantity), type: 'text' }),
40
+ react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'quantity', label: 'Quantity', placeholder: '1', value: String(productsList[index].quantity), type: 'number' }),
41
41
  react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'price', label: 'Price', placeholder: '0.00', value: productsList[index].price, type: 'number' }),
42
42
  react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeProducts({ index: index, key: k, value: v }); }, id: 'rowTotal', label: 'Row Total', placeholder: '0.00', value: productsList[index].rowTotal, type: 'number', readOnly: true }),
43
- react_1.default.createElement(vista_button_v1_1.VistaButtonV1, { className: 'flex justify-center items-end', handleOnClick: function () { return handleDeleteServiceRow(index); }, icon: react_1.default.createElement(solid_1.TrashIcon, { className: "size-6" }), variant: vista_button_type_1.VISTA_BUTTON_VARIANT.ICON }))); })));
43
+ react_1.default.createElement(vista_button_v1_1.VistaButtonV1, { className: 'flex justify-center items-end', handleOnClick: function () { return handleDeleteServiceRow(index); }, icon: react_1.default.createElement(solid_1.TrashIcon, { className: "size-6" }), variant: vista_button_type_1.VISTA_BUTTON_VARIANT.ICON }))); }))));
44
44
  };
45
45
  exports.ProductsSection = ProductsSection;
@@ -55,7 +55,9 @@ exports.initialInvoiceState = {
55
55
  discount: '0',
56
56
  discountUnit: types_1.DISCOUNT_UNIT.FIXED_VALUE,
57
57
  drawer: null,
58
- errors: {},
58
+ errors: {
59
+ phone: 'Phone number is not well formatted',
60
+ },
59
61
  expiryDate: (0, date_fns_1.addDays)(new Date(), 7).toISOString(),
60
62
  id: '',
61
63
  invoiceStatus: types_1.INVOICE_STATUS.UNPAID,
@@ -68,7 +70,6 @@ exports.initialInvoiceState = {
68
70
  note: '',
69
71
  pageLimit: constants_1.pageLimit,
70
72
  payments: [],
71
- phone: '',
72
73
  companiesList: [],
73
74
  productQuery: '',
74
75
  quoteStatus: types_1.QUOTE_STATUS.DRAFT,
@@ -119,7 +120,11 @@ function invoiceReducer(state, action) {
119
120
  case actions_1.INVOICE_ACTION_TYPES.RESET_ERRORS:
120
121
  return __assign(__assign({}, state), { errors: {} });
121
122
  case actions_1.INVOICE_ACTION_TYPES.RESET_FORM:
122
- return __assign({}, state);
123
+ return __assign(__assign(__assign(__assign({}, state), (state.customer && ({
124
+ customer: __assign({}, exports.initialInvoiceState.customer),
125
+ }))), (state.company && ({
126
+ company: __assign({}, exports.initialInvoiceState.company),
127
+ }))), { productsList: __assign({}, exports.initialInvoiceState.productsList), servicesList: __assign({}, exports.initialInvoiceState.servicesList), subTotal: exports.initialInvoiceState.subTotal, discount: exports.initialInvoiceState.discount, discountUnit: exports.initialInvoiceState.discountUnit, afterDiscount: exports.initialInvoiceState.afterDiscount, tax: exports.initialInvoiceState.tax, total: exports.initialInvoiceState.total, category: exports.initialInvoiceState.category, companyId: exports.initialInvoiceState.companyId, companyQuery: exports.initialInvoiceState.companyQuery, countryQuery: exports.initialInvoiceState.companyQuery, currency: exports.initialInvoiceState.currency, contactsList: exports.initialInvoiceState.contactsList, customerId: exports.initialInvoiceState.customerId, date: exports.initialInvoiceState.date, disableSaveButton: exports.initialInvoiceState.disableSaveButton, expiryDate: exports.initialInvoiceState.expiryDate, id: exports.initialInvoiceState.id, invoiceStatus: exports.initialInvoiceState.invoiceStatus, loading: exports.initialInvoiceState.loading, getProducts: exports.initialInvoiceState.getProducts, mode: exports.initialInvoiceState.mode, netTotal: exports.initialInvoiceState.netTotal, note: exports.initialInvoiceState.note, payments: exports.initialInvoiceState.payments, companiesList: exports.initialInvoiceState.companiesList, productQuery: exports.initialInvoiceState.productQuery, taxRate: exports.initialInvoiceState.taxRate, taxQuery: exports.initialInvoiceState.taxQuery, taxes: exports.initialInvoiceState.taxes });
123
128
  case actions_1.INVOICE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON:
124
129
  return __assign(__assign({}, state), { disableSaveButton: action.payload.disableSaveButton });
125
130
  case actions_1.INVOICE_ACTION_TYPES.SET_CURRENT_PAGE:
@@ -140,11 +145,8 @@ function invoiceReducer(state, action) {
140
145
  return __assign(__assign({}, state), action.payload.form);
141
146
  case actions_1.INVOICE_ACTION_TYPES.SET_DRAWER:
142
147
  return __assign(__assign({}, state), { drawer: action.payload.drawer });
143
- // case INVOICE_ACTION_TYPES.SET_MODAL:
144
- // return {
145
- // ...state,
146
- // modal: action.payload.modal,
147
- // };
148
+ case actions_1.INVOICE_ACTION_TYPES.SET_MODAL:
149
+ return __assign(__assign({}, state), { modal: action.payload.modal });
148
150
  case actions_1.INVOICE_ACTION_TYPES.SET_DISCOUNT_UNIT:
149
151
  return __assign(__assign({}, state), { discountUnit: action.payload.discountUnit });
150
152
  case actions_1.INVOICE_ACTION_TYPES.SET_AFTER_DISCOUNT:
@@ -162,7 +164,7 @@ function invoiceReducer(state, action) {
162
164
  case actions_1.INVOICE_ACTION_TYPES.SET_PRODUCTS_LIST:
163
165
  return __assign(__assign({}, state), { getProducts: __spreadArray([], action.payload.list, true) });
164
166
  case actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER:
165
- return __assign(__assign({}, state), { customerId: state.customerId, customer: __assign(__assign({}, state.customer), action.payload.customer) });
167
+ return __assign(__assign({}, state), { customerId: action.payload.customerId, customer: __assign(__assign({}, state.customer), action.payload.customer) });
166
168
  case actions_1.INVOICE_ACTION_TYPES.SET_CUSTOMER_FORM:
167
169
  return __assign(__assign({}, state), (state.customer && ({
168
170
  customer: __assign(__assign({}, state.customer), (_b = {}, _b[action.payload.key] = action.payload.value, _b)),
@@ -15,12 +15,12 @@ var ServicesSection = function () {
15
15
  var _a = (0, context_1.useInvoiceStateContext)(), servicesList = _a.servicesList, handleItemChangeServices = _a.handleItemChangeServices, handleDeleteServiceRow = _a.handleDeleteServiceRow;
16
16
  return (react_1.default.createElement("div", { className: "flex flex-col gap-4" },
17
17
  react_1.default.createElement(vista_vertical_divider_v4_1.VistaVerticalDividerV4, { label: "Services" }),
18
- servicesList.map(function (row, index) { return (react_1.default.createElement("div", { key: index, className: 'grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] items-end justify-between gap-4' },
18
+ servicesList.length > 0 && (servicesList === null || servicesList === void 0 ? void 0 : servicesList.map(function (row, index) { return (react_1.default.createElement("div", { key: index, className: 'grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] items-end justify-between gap-4' },
19
19
  react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'name', label: 'Service Name', placeholder: 'Service Name', value: servicesList[index].name, type: 'text' }),
20
20
  react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'description', label: 'Service Description', placeholder: 'Service Description', value: servicesList[index].description, type: 'text' }),
21
21
  react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'quantity', label: 'Quantity', placeholder: '1', value: servicesList[index].quantity, type: 'number' }),
22
22
  react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'price', label: 'Price', placeholder: '0.00', value: servicesList[index].price, type: 'number' }),
23
23
  react_1.default.createElement(vista_text_input_v1_1.VistaTextInputV1, { handleOnChange: function (k, v) { return handleItemChangeServices({ index: index, key: k, value: v }); }, id: 'rowTotal', label: 'Row Total', placeholder: '0.00', value: servicesList[index].rowTotal, type: 'number', readOnly: true }),
24
- react_1.default.createElement(vista_button_v1_1.VistaButtonV1, { className: 'flex justify-center items-end', handleOnClick: function () { return handleDeleteServiceRow(index); }, icon: react_1.default.createElement(solid_1.TrashIcon, { className: "size-6" }), variant: vista_button_type_1.VISTA_BUTTON_VARIANT.ICON }))); })));
24
+ react_1.default.createElement(vista_button_v1_1.VistaButtonV1, { className: 'flex justify-center items-end', handleOnClick: function () { return handleDeleteServiceRow(index); }, icon: react_1.default.createElement(solid_1.TrashIcon, { className: "size-6" }), variant: vista_button_type_1.VISTA_BUTTON_VARIANT.ICON }))); }))));
25
25
  };
26
26
  exports.ServicesSection = ServicesSection;
@@ -136,20 +136,19 @@ export interface InvoiceState extends Omit<QuoteInvoiceTypeBE, 'createdAt' | 'up
136
136
  count: number;
137
137
  countryQuery: string;
138
138
  currentPage: number;
139
- customer?: CustomerTypeBE;
140
139
  customerId?: string;
141
140
  disableSaveButton: boolean;
142
141
  drawer: null | INVOICE_DRAWER;
143
142
  errors: {
144
143
  [key: string]: string;
145
144
  };
145
+ getProducts: ProductTypeBE[];
146
146
  invoices: QuoteInvoiceTypeBE[];
147
147
  loading: boolean;
148
- modal: null | PRODUCT_MODAL;
148
+ modal: null | INVOICE_MODAL;
149
149
  mode: 'Create' | 'Edit';
150
150
  netTotal: string;
151
151
  pageLimit: number;
152
- phone: string;
153
152
  productQuery: string;
154
153
  productsList: Product[];
155
154
  searchQuery: string;
@@ -157,7 +156,6 @@ export interface InvoiceState extends Omit<QuoteInvoiceTypeBE, 'createdAt' | 'up
157
156
  tax: string;
158
157
  taxQuery: string;
159
158
  taxes: TaxTypeBE[];
160
- getProducts: ProductTypeBE[];
161
159
  }
162
160
  export interface FetchInvoicesArgs {
163
161
  currentPage: number;
@@ -168,7 +166,7 @@ export declare enum INVOICE_DRAWER {
168
166
  INVOICE_COMPANY_FORM_DRAWER = "INVOICE_COMPANY_FORM_DRAWER",
169
167
  INVOICE_CUSTOMER_FORM_DRAWER = "INVOICE_CUSTOMER_FORM_DRAWER"
170
168
  }
171
- export declare enum PRODUCT_MODAL {
169
+ export declare enum INVOICE_MODAL {
172
170
  DUMMY = "DUMMY"
173
171
  }
174
172
  export declare enum QUOTE_INVOICE_CATEGORY {
@@ -1,19 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DISCOUNT_UNIT = exports.QUOTE_STATUS = exports.INVOICE_STATUS = exports.QUOTE_INVOICE_CATEGORY = exports.PRODUCT_MODAL = exports.INVOICE_DRAWER = exports.PAYMENT_TYPE = exports.PAYMENT_MODE = void 0;
4
- // export interface CustomerTypeBE {
5
- // address?: string;
6
- // city: string;
7
- // country: string;
8
- // createdAt: string;
9
- // email?: string;
10
- // firstName: string;
11
- // id: string;
12
- // invoices?: InvoiceTypeBE[];
13
- // lastName: string;
14
- // phone: string;
15
- // updatedAt: string;
16
- // }
3
+ exports.DISCOUNT_UNIT = exports.QUOTE_STATUS = exports.INVOICE_STATUS = exports.QUOTE_INVOICE_CATEGORY = exports.INVOICE_MODAL = exports.INVOICE_DRAWER = exports.PAYMENT_TYPE = exports.PAYMENT_MODE = void 0;
17
4
  var PAYMENT_MODE;
18
5
  (function (PAYMENT_MODE) {
19
6
  })(PAYMENT_MODE || (exports.PAYMENT_MODE = PAYMENT_MODE = {}));
@@ -27,10 +14,10 @@ var INVOICE_DRAWER;
27
14
  INVOICE_DRAWER["INVOICE_COMPANY_FORM_DRAWER"] = "INVOICE_COMPANY_FORM_DRAWER";
28
15
  INVOICE_DRAWER["INVOICE_CUSTOMER_FORM_DRAWER"] = "INVOICE_CUSTOMER_FORM_DRAWER";
29
16
  })(INVOICE_DRAWER || (exports.INVOICE_DRAWER = INVOICE_DRAWER = {}));
30
- var PRODUCT_MODAL;
31
- (function (PRODUCT_MODAL) {
32
- PRODUCT_MODAL["DUMMY"] = "DUMMY";
33
- })(PRODUCT_MODAL || (exports.PRODUCT_MODAL = PRODUCT_MODAL = {}));
17
+ var INVOICE_MODAL;
18
+ (function (INVOICE_MODAL) {
19
+ INVOICE_MODAL["DUMMY"] = "DUMMY";
20
+ })(INVOICE_MODAL || (exports.INVOICE_MODAL = INVOICE_MODAL = {}));
34
21
  var QUOTE_INVOICE_CATEGORY;
35
22
  (function (QUOTE_INVOICE_CATEGORY) {
36
23
  QUOTE_INVOICE_CATEGORY["QUOTE"] = "QUOTE";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-invoice-module",
3
- "version": "0.1.52",
3
+ "version": "0.1.54",
4
4
  "scripts": {
5
5
  "build": "yarn clean && yarn build:ts && cp package.json lib && cp README.md lib && cp yarn.lock lib",
6
6
  "build:next": "next build",
@@ -17,14 +17,14 @@
17
17
  "upgrade": "ncu -u"
18
18
  },
19
19
  "devDependencies": {
20
- "@appcorp/app-corp-vista": "^0.3.0",
20
+ "@appcorp/app-corp-vista": "^0.3.6",
21
21
  "@appcorp/stellar-solutions-company-module": "^0.1.31",
22
- "@appcorp/stellar-solutions-modules": "^0.1.30",
23
- "@appcorp/stellar-solutions-product-module": "^0.2.7",
22
+ "@appcorp/stellar-solutions-modules": "^0.1.31",
23
+ "@appcorp/stellar-solutions-product-module": "^0.2.9",
24
24
  "@eslint/eslintrc": "^3",
25
25
  "@headlessui/react": "^2",
26
26
  "@heroicons/react": "^2",
27
- "@react-pakistan/util-functions": "^1.24.41",
27
+ "@react-pakistan/util-functions": "^1.24.48",
28
28
  "@supabase/supabase-js": "^2",
29
29
  "@tailwindcss/forms": "^0.5.10",
30
30
  "@tailwindcss/postcss": "^4",
File without changes
@@ -1,32 +0,0 @@
1
- // /* eslint-disable */
2
- // import React from 'react';
3
- // import { vistaFormSchema } from '@appcorp/app-corp-vista/utils/form-schema';
4
- // import { VistaFormElements } from '@appcorp/app-corp-vista/type/vista-form-elements';
5
- // import { Product } from './types';
6
- // export const renderProductsFormElements = (
7
- // elementProps: VistaFormElements,
8
- // row: Product,
9
- // ) => {
10
- // const elementsArray = Object.entries(vistaFormSchema)
11
- // .flatMap(([key, config]) => {
12
- // const Component = config;
13
- // return (elementProps[key as keyof VistaFormElements] || [])
14
- // ?.filter((props: any) => props.enabled)
15
- // ?.map((props: any) => ({
16
- // Component,
17
- // key,
18
- // order: props.order,
19
- // props,
20
- // }));
21
- // })
22
- // ?.sort((a, b) => a.order - b.order);
23
- // return (
24
- // <div className="grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] gap-4">
25
- // {elementsArray?.map(({ key, Component, props }, index) => (
26
- // <div key={`${key}-${index}`} className={props.className}>
27
- // <Component {...props} {...row} />
28
- // </div>
29
- // ))}
30
- // </div>
31
- // );
32
- // };
File without changes
@@ -1,38 +0,0 @@
1
- // /* eslint-disable */
2
- // import React from 'react';
3
- // import { vistaFormSchema } from '@appcorp/app-corp-vista/utils/form-schema';
4
- // import { Service } from './types';
5
- // import { VistaFormElements } from '@appcorp/app-corp-vista/type/vista-form-elements';
6
- // export const renderServicesFormElements = (
7
- // elementProps: VistaFormElements,
8
- // row: Service,
9
- // ) => {
10
- // const elementsArray = Object.entries(vistaFormSchema)
11
- // .flatMap(([key, config]) => {
12
- // const Component = config;
13
- // return (elementProps[key as keyof VistaFormElements] || [])
14
- // ?.filter((props: any) => props.enabled)
15
- // ?.map((props: any) => ({
16
- // Component,
17
- // key,
18
- // order: props.order,
19
- // props,
20
- // }));
21
- // })
22
- // ?.sort((a, b) => a.order - b.order);
23
- // return (
24
- // <div className="grid grid-cols-[17.5%_17.5%_17.5%_17.5%_17.5%_auto] gap-4">
25
- // {elementsArray?.map(({ key, Component, props }, index) => {
26
- // // console.log('_>>', props);
27
- // return (
28
- // <div key={`${key}-${index}`} className={props.className}>
29
- // <Component
30
- // {...props}
31
- // {...row}
32
- // value={row[props.id as keyof Service]}
33
- // />
34
- // </div>
35
- // )})}
36
- // </div>
37
- // );
38
- // };