@appcorp/stellar-solutions-invoice-module 0.1.29 → 0.1.31

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.
@@ -38,13 +38,26 @@ export declare const tableBodyCols: ({
38
38
  key?: undefined;
39
39
  expression?: undefined;
40
40
  })[];
41
- export declare const messages: {
42
- buyPrice: string;
41
+ export declare const validationErrors: {
42
+ companyId: string;
43
+ ref: string;
44
+ status: string;
45
+ date: string;
46
+ expiryDate: string;
47
+ note: string;
43
48
  currency: string;
44
- error: string;
45
- name: string;
46
- productCategoryId: string;
47
- quantity: string;
48
- salePrice: string;
49
- success: string;
49
+ total: string;
50
+ subTotal: string;
51
+ taxRate: string;
52
+ services: {
53
+ name: string;
54
+ description: string;
55
+ quantity: string;
56
+ price: string;
57
+ total: string;
58
+ };
59
+ products: {
60
+ id: string;
61
+ quantity: string;
62
+ };
50
63
  };
@@ -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.messages = 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.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;
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");
@@ -228,7 +228,7 @@ exports.staticCustomerSection = (_b = {},
228
228
  exports.staticPricingSection = (_c = {},
229
229
  _c[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_INPUT_V1] = [
230
230
  {
231
- disabled: true,
231
+ disabled: false,
232
232
  enabled: true,
233
233
  error: '',
234
234
  handleOnChange: function () { return void 0; },
@@ -236,6 +236,7 @@ exports.staticPricingSection = (_c = {},
236
236
  label: 'Sub Total',
237
237
  order: 1,
238
238
  placeholder: '0.00',
239
+ readOnly: true,
239
240
  required: false,
240
241
  type: 'text',
241
242
  value: '',
@@ -550,13 +551,26 @@ exports.tableBodyCols = [
550
551
  componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.ACTIONS,
551
552
  },
552
553
  ];
553
- exports.messages = {
554
- buyPrice: 'Buy Price should be more than 1 unit',
555
- currency: 'Please select a currency unit for this product',
556
- error: 'Error occurred, please try again',
557
- name: 'Product category name is required',
558
- productCategoryId: 'Product Category Id is required',
559
- quantity: 'Quantity should be more than 1 unit',
560
- salePrice: 'Sale Price should be more than 1 unit',
561
- success: 'Operation successful!',
554
+ exports.validationErrors = {
555
+ companyId: 'Please select Company',
556
+ ref: 'Please enter ref',
557
+ status: 'Please select status',
558
+ date: 'Please select date',
559
+ expiryDate: 'Please select expire date',
560
+ note: 'Please enter a note',
561
+ currency: 'Please select currency',
562
+ total: 'Please enter net total',
563
+ subTotal: 'Please enter sub total',
564
+ taxRate: 'Please enter tax value',
565
+ services: {
566
+ name: 'Item is required',
567
+ description: 'Description is required',
568
+ quantity: 'Quantity is required',
569
+ price: 'Price is required',
570
+ total: 'Total price is required',
571
+ },
572
+ products: {
573
+ id: 'Please select a product',
574
+ quantity: 'Please enter Quantity',
575
+ },
562
576
  };
@@ -113,6 +113,7 @@ var useInvoiceState = function () {
113
113
  var companies = (0, context_2.useCompanyStateContext)().companies;
114
114
  var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
115
115
  var listParams = {
116
+ category: types_1.QUOTE_INVOICE.INVOICE,
116
117
  currentPage: state.currentPage,
117
118
  pageLimit: state.pageLimit,
118
119
  searchQuery: state.searchQuery,
@@ -122,7 +123,7 @@ var useInvoiceState = function () {
122
123
  if (error) {
123
124
  (0, generate_toast_1.generateToast)({
124
125
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
125
- description: constants_1.messages.error,
126
+ description: constants_1.toastErrors.fetchInvoiceError,
126
127
  });
127
128
  }
128
129
  if (data === null || data === void 0 ? void 0 : data.items) {
@@ -147,6 +148,7 @@ var useInvoiceState = function () {
147
148
  expiryDate: state.expiryDate,
148
149
  id: state.id,
149
150
  invoiceStatus: state.invoiceStatus,
151
+ mode: state.mode,
150
152
  note: state.note,
151
153
  products: state.products,
152
154
  quoteStatus: state.quoteStatus,
@@ -155,19 +157,18 @@ var useInvoiceState = function () {
155
157
  subTotal: state.subTotal,
156
158
  taxRate: state.taxRate,
157
159
  total: state.total,
158
- mode: state.mode,
159
160
  }); }, [state]);
160
161
  var updateCallback = function (_a) {
161
162
  var data = _a.data, error = _a.error;
162
163
  if (error) {
163
164
  (0, generate_toast_1.generateToast)({
164
- description: constants_1.messages.error,
165
+ description: constants_1.toastErrors.networkError,
165
166
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
166
167
  });
167
168
  }
168
169
  if (data) {
169
170
  (0, generate_toast_1.generateToast)({
170
- description: constants_1.messages.success,
171
+ description: constants_1.toastErrors.networkError,
171
172
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
172
173
  });
173
174
  dispatch({
@@ -184,15 +185,32 @@ var useInvoiceState = function () {
184
185
  id: state.id,
185
186
  };
186
187
  var byIdCallback = function (_a) {
188
+ var _b, _c;
187
189
  var data = _a.data, error = _a.error;
188
190
  if (error) {
189
191
  (0, generate_toast_1.generateToast)({
190
- description: constants_1.messages.error,
192
+ description: constants_1.toastErrors.networkError,
191
193
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
192
194
  });
193
195
  }
194
196
  if (data) {
195
- var updatedData = __assign(__assign(__assign(__assign({}, data), (!data.description && { description: '' })), (!data.ref && { ref: '' })), (!data.image && { image: [] }));
197
+ var updatedServices = __spreadArray([], data.services, true).map(function (item) {
198
+ delete item.quoteInvoiceId;
199
+ return (__assign(__assign({}, item), { rowTotal: Number(item.quantity) * Number(item.price) }));
200
+ });
201
+ var updatedData = __assign(__assign({}, data), { mode: 'Edit', companyId: data.company.id, services: __spreadArray([], updatedServices, true) });
202
+ if ((_b = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _b === void 0 ? void 0 : _b.name) {
203
+ dispatch({
204
+ type: actions_1.INVOICE_ACTION_TYPES.SET_FORM_TO_RENDER,
205
+ payload: { formToRender: 'company' },
206
+ });
207
+ }
208
+ if ((_c = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _c === void 0 ? void 0 : _c.name) {
209
+ dispatch({
210
+ type: actions_1.INVOICE_ACTION_TYPES.SET_FORM_TO_RENDER,
211
+ payload: { formToRender: 'customer' },
212
+ });
213
+ }
196
214
  dispatch({
197
215
  type: actions_1.INVOICE_ACTION_TYPES.SET_FORM,
198
216
  payload: { form: updatedData },
@@ -210,13 +228,13 @@ var useInvoiceState = function () {
210
228
  var data = _a.data, error = _a.error;
211
229
  if (error) {
212
230
  (0, generate_toast_1.generateToast)({
213
- description: constants_1.messages.error,
231
+ description: constants_1.toastErrors.networkError,
214
232
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
215
233
  });
216
234
  }
217
235
  if (data) {
218
236
  (0, generate_toast_1.generateToast)({
219
- description: constants_1.messages.success,
237
+ description: constants_1.toastErrors.networkError,
220
238
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
221
239
  });
222
240
  dispatch({
@@ -334,33 +352,6 @@ var useInvoiceState = function () {
334
352
  body: JSON.stringify({ id: id }),
335
353
  });
336
354
  };
337
- // const handleUploadImage = useCallback(async () => {
338
- // const urls: string[] = [];
339
- // if (state?.images?.some((u) => u.startsWith('blob:'))) {
340
- // await Promise.all(state.images.map(async (url) => {
341
- // const blob = await fetch(url).then((r) => r.blob());
342
- // const webpBlob = await blobToWebP(blob, { quality: 1 });
343
- // const { data } = await uploadBlobToPublicSupabase({
344
- // blob: webpBlob,
345
- // supabase: supabaseClient,
346
- // fileRef: `products/${uuidv4()}.webp`,
347
- // contentType: 'image/webp',
348
- // upsert: true,
349
- // });
350
- // if (data) {
351
- // urls.push(`${supabasePublicStorageUrl}/${data.path}`);
352
- // }
353
- // return urls;
354
- // }));
355
- // }
356
- // if (urls.length) {
357
- // dispatch({
358
- // type: INVOICE_ACTION_TYPES.SET_INPUT_FIELD,
359
- // payload: { key: 'images', value: urls },
360
- // });
361
- // }
362
- // return urls;
363
- // }, [state.images]);
364
355
  var handleSubmit = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
365
356
  var validationResult, validationErrors_1;
366
357
  return __generator(this, function (_a) {
@@ -388,7 +379,7 @@ var useInvoiceState = function () {
388
379
  }
389
380
  catch (_b) {
390
381
  (0, generate_toast_1.generateToast)({
391
- description: constants_1.messages.error,
382
+ description: constants_1.toastErrors.networkError,
392
383
  variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
393
384
  });
394
385
  }
@@ -83,7 +83,7 @@ var InvoicePage = function () {
83
83
  ];
84
84
  var totalPagePerRecord = (0, util_functions_1.calculatePages)(count, pageLimit);
85
85
  return (react_1.default.createElement(react_1.default.Fragment, null,
86
- react_1.default.createElement(vista_table_v1_1.VistaTableV1, { currentPage: count, isNextDisabled: (0, util_functions_1.isNextButtonDisabled)(currentPage, totalPagePerRecord), isPreviousDisabled: (0, util_functions_1.isPreviousButtonDisabled)(currentPage), handleNextOnClick: handleNextClick, handlePreviousOnClick: handlePreviousClick, tableDescription: t('subTitle'), tableHeading: t('title'), totalPages: totalPagePerRecord, headerActions: headerActions, handleOnSelect: function () { return handlePageLimit; }, selectKey1: "label", nodeSelectKey: "pageLimit", selectedItem: { label: String(pageLimit) }, listOptions: (0, util_functions_1.getAvailablePageLimits)(count), searchEnabled: true, searchValue: searchQuery, searchPlaceholder: "Enter ID or Name...", searchDisabled: false, searchId: "inventory-search", handleSearchInput: searchOnChange, loading: listLoading, pageLimit: pageLimit, rowActions: rowActions, tableBodyCols: constants_1.tableBodyCols, tableBodyRows: invoices, tableHeadItems: tableHeadItems }),
86
+ react_1.default.createElement(vista_table_v1_1.VistaTableV1, { currentPage: count, handleNextOnClick: handleNextClick, handleOnSelect: handlePageLimit, handlePreviousOnClick: handlePreviousClick, handleSearchInput: searchOnChange, headerActions: headerActions, isNextDisabled: (0, util_functions_1.isNextButtonDisabled)(currentPage, totalPagePerRecord), isPreviousDisabled: (0, util_functions_1.isPreviousButtonDisabled)(currentPage), listOptions: (0, util_functions_1.getAvailablePageLimits)(count), loading: listLoading, nodeSelectKey: "pageLimit", pageLimit: pageLimit, rowActions: rowActions, searchDisabled: false, searchEnabled: true, searchId: "inventory-search", searchPlaceholder: "Enter ID or Name...", searchValue: searchQuery, selectKey1: "option", selectedItem: { option: String(pageLimit) }, tableBodyCols: constants_1.tableBodyCols, tableBodyRows: invoices, tableDescription: t('subTitle'), tableHeadItems: tableHeadItems, tableHeading: t('title'), totalPages: totalPagePerRecord }),
87
87
  react_1.default.createElement(drawer_1.Drawer, { translationMap: translationMap }),
88
88
  react_1.default.createElement(generate_toast_1.VistaToaster, null)));
89
89
  };
@@ -1,36 +1,84 @@
1
1
  import { z } from 'zod';
2
2
  export declare const formValidation: z.ZodObject<{
3
- buyPrice: z.ZodString;
3
+ companyId: z.ZodOptional<z.ZodString>;
4
+ ref: z.ZodString;
5
+ date: z.ZodString;
6
+ expiryDate: z.ZodString;
7
+ note: z.ZodOptional<z.ZodString>;
4
8
  currency: z.ZodString;
5
- description: z.ZodOptional<z.ZodString>;
6
- images: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
7
- name: z.ZodString;
8
- product: z.ZodOptional<z.ZodString>;
9
- productCategoryId: z.ZodString;
10
- quantity: z.ZodString;
11
- ref: z.ZodOptional<z.ZodString>;
12
- salePrice: z.ZodString;
9
+ total: z.ZodString;
10
+ subTotal: z.ZodString;
11
+ taxRate: z.ZodString;
12
+ services: z.ZodArray<z.ZodObject<{
13
+ name: z.ZodOptional<z.ZodString>;
14
+ description: z.ZodOptional<z.ZodString>;
15
+ quantity: z.ZodOptional<z.ZodString>;
16
+ price: z.ZodOptional<z.ZodString>;
17
+ total: z.ZodOptional<z.ZodString>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ quantity?: string | undefined;
20
+ price?: string | undefined;
21
+ name?: string | undefined;
22
+ description?: string | undefined;
23
+ total?: string | undefined;
24
+ }, {
25
+ quantity?: string | undefined;
26
+ price?: string | undefined;
27
+ name?: string | undefined;
28
+ description?: string | undefined;
29
+ total?: string | undefined;
30
+ }>, "many">;
31
+ products: z.ZodArray<z.ZodObject<{
32
+ productId: z.ZodOptional<z.ZodString>;
33
+ quantity: z.ZodOptional<z.ZodNumber>;
34
+ }, "strip", z.ZodTypeAny, {
35
+ productId?: string | undefined;
36
+ quantity?: number | undefined;
37
+ }, {
38
+ productId?: string | undefined;
39
+ quantity?: number | undefined;
40
+ }>, "many">;
13
41
  }, "strip", z.ZodTypeAny, {
14
- quantity: string;
15
- name: string;
16
42
  currency: string;
17
- buyPrice: string;
18
- productCategoryId: string;
19
- salePrice: string;
20
- description?: string | undefined;
21
- ref?: string | undefined;
22
- images?: string[] | undefined;
23
- product?: string | undefined;
43
+ date: string;
44
+ expiryDate: string;
45
+ products: {
46
+ productId?: string | undefined;
47
+ quantity?: number | undefined;
48
+ }[];
49
+ ref: string;
50
+ services: {
51
+ quantity?: string | undefined;
52
+ price?: string | undefined;
53
+ name?: string | undefined;
54
+ description?: string | undefined;
55
+ total?: string | undefined;
56
+ }[];
57
+ subTotal: string;
58
+ taxRate: string;
59
+ total: string;
60
+ companyId?: string | undefined;
61
+ note?: string | undefined;
24
62
  }, {
25
- quantity: string;
26
- name: string;
27
63
  currency: string;
28
- buyPrice: string;
29
- productCategoryId: string;
30
- salePrice: string;
31
- description?: string | undefined;
32
- ref?: string | undefined;
33
- images?: string[] | undefined;
34
- product?: string | undefined;
64
+ date: string;
65
+ expiryDate: string;
66
+ products: {
67
+ productId?: string | undefined;
68
+ quantity?: number | undefined;
69
+ }[];
70
+ ref: string;
71
+ services: {
72
+ quantity?: string | undefined;
73
+ price?: string | undefined;
74
+ name?: string | undefined;
75
+ description?: string | undefined;
76
+ total?: string | undefined;
77
+ }[];
78
+ subTotal: string;
79
+ taxRate: string;
80
+ total: string;
81
+ companyId?: string | undefined;
82
+ note?: string | undefined;
35
83
  }>;
36
- export type ProductCategoryFormValidate = z.infer<typeof formValidation>;
84
+ export type InvoiceFormValidate = z.infer<typeof formValidation>;
@@ -3,15 +3,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formValidation = void 0;
4
4
  var zod_1 = require("zod");
5
5
  var constants_1 = require("./constants");
6
- exports.formValidation = zod_1.z.object({
7
- buyPrice: zod_1.z.string(),
8
- currency: zod_1.z.string().nonempty(constants_1.messages.currency),
6
+ var services = zod_1.z.object({
7
+ name: zod_1.z.string().optional(),
8
+ // .nonempty(formErrors[DASHBOARD_DRAWERS_FORMS.INVOICE].itemsData.name),
9
9
  description: zod_1.z.string().optional(),
10
- images: zod_1.z.array(zod_1.z.string()).optional(),
11
- name: zod_1.z.string().nonempty(constants_1.messages.name),
12
- product: zod_1.z.string().optional(),
13
- productCategoryId: zod_1.z.string().nonempty(constants_1.messages.productCategoryId),
14
- quantity: zod_1.z.string(),
15
- ref: zod_1.z.string().optional(),
16
- salePrice: zod_1.z.string(),
10
+ quantity: zod_1.z.string().optional(),
11
+ // .nonempty(formErrors[DASHBOARD_DRAWERS_FORMS.INVOICE].itemsData.quantity),
12
+ price: zod_1.z.string().optional(),
13
+ // .nonempty(formErrors[DASHBOARD_DRAWERS_FORMS.INVOICE].itemsData.price),
14
+ total: zod_1.z.string().optional(),
15
+ // .nonempty(formErrors[DASHBOARD_DRAWERS_FORMS.INVOICE].itemsData.total),
16
+ });
17
+ var products = zod_1.z.object({
18
+ productId: zod_1.z.string().optional(),
19
+ // .nonempty(validationErrors.products.id),
20
+ quantity: zod_1.z.number().optional(),
21
+ // .min(
22
+ // 1,
23
+ // formErrors[DASHBOARD_DRAWERS_FORMS.INVOICE].products.productQuantity,
24
+ // ),
25
+ });
26
+ exports.formValidation = zod_1.z.object({
27
+ companyId: zod_1.z.string().optional(),
28
+ ref: zod_1.z.string().nonempty(constants_1.validationErrors.ref),
29
+ // invoiceStatus: z
30
+ // .string()
31
+ // .nonempty(formErrors[DASHBOARD_DRAWERS_FORMS.INVOICE].status),
32
+ date: zod_1.z.string().nonempty(constants_1.validationErrors.date),
33
+ expiryDate: zod_1.z
34
+ .string()
35
+ .nonempty(constants_1.validationErrors.expiryDate),
36
+ note: zod_1.z.string().optional(),
37
+ currency: zod_1.z
38
+ .string()
39
+ .nonempty(constants_1.validationErrors.currency),
40
+ total: zod_1.z.string().nonempty(constants_1.validationErrors.total),
41
+ subTotal: zod_1.z
42
+ .string()
43
+ .nonempty(constants_1.validationErrors.subTotal),
44
+ taxRate: zod_1.z
45
+ .string()
46
+ .nonempty(constants_1.validationErrors.taxRate),
47
+ services: zod_1.z.array(services),
48
+ products: zod_1.z.array(products),
17
49
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/stellar-solutions-invoice-module",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "scripts": {
5
5
  "build": "yarn clean && yarn build:ts && cp package.json lib && cp README.md lib",
6
6
  "build:next": "next build",