@appcorp/stellar-solutions-invoice-module 0.1.1

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 (76) hide show
  1. package/README.md +36 -0
  2. package/base-modules/invoice/actions.d.ts +134 -0
  3. package/base-modules/invoice/actions.js +29 -0
  4. package/base-modules/invoice/add-service-product-section.d.ts +2 -0
  5. package/base-modules/invoice/add-service-product-section.js +21 -0
  6. package/base-modules/invoice/calculate-subtotal.d.ts +2 -0
  7. package/base-modules/invoice/calculate-subtotal.js +20 -0
  8. package/base-modules/invoice/constants.d.ts +42 -0
  9. package/base-modules/invoice/constants.js +450 -0
  10. package/base-modules/invoice/context.d.ts +10 -0
  11. package/base-modules/invoice/context.js +661 -0
  12. package/base-modules/invoice/drawer.d.ts +8 -0
  13. package/base-modules/invoice/drawer.js +19 -0
  14. package/base-modules/invoice/form.d.ts +8 -0
  15. package/base-modules/invoice/form.js +67 -0
  16. package/base-modules/invoice/invoice.d.ts +10 -0
  17. package/base-modules/invoice/invoice.js +90 -0
  18. package/base-modules/invoice/pricing-form-elements.d.ts +3 -0
  19. package/base-modules/invoice/pricing-form-elements.js +41 -0
  20. package/base-modules/invoice/pricing-form-section.d.ts +2 -0
  21. package/base-modules/invoice/pricing-form-section.js +20 -0
  22. package/base-modules/invoice/products-form-elements.d.ts +4 -0
  23. package/base-modules/invoice/products-form-elements.js +41 -0
  24. package/base-modules/invoice/products-form-section.d.ts +2 -0
  25. package/base-modules/invoice/products-form-section.js +17 -0
  26. package/base-modules/invoice/reducer.d.ts +4 -0
  27. package/base-modules/invoice/reducer.js +138 -0
  28. package/base-modules/invoice/services-form-elements.d.ts +4 -0
  29. package/base-modules/invoice/services-form-elements.js +41 -0
  30. package/base-modules/invoice/services-form-section.d.ts +2 -0
  31. package/base-modules/invoice/services-form-section.js +17 -0
  32. package/base-modules/invoice/types.d.ts +163 -0
  33. package/base-modules/invoice/types.js +40 -0
  34. package/base-modules/invoice/validate.d.ts +36 -0
  35. package/base-modules/invoice/validate.js +17 -0
  36. package/base-modules/product/actions.d.ts +113 -0
  37. package/base-modules/product/actions.js +22 -0
  38. package/base-modules/product/constants.d.ts +33 -0
  39. package/base-modules/product/constants.js +204 -0
  40. package/base-modules/product/context.d.ts +10 -0
  41. package/base-modules/product/context.js +557 -0
  42. package/base-modules/product/drawer.d.ts +8 -0
  43. package/base-modules/product/drawer.js +19 -0
  44. package/base-modules/product/form-elements.d.ts +2 -0
  45. package/base-modules/product/form-elements.js +41 -0
  46. package/base-modules/product/form.d.ts +8 -0
  47. package/base-modules/product/form.js +107 -0
  48. package/base-modules/product/product.d.ts +10 -0
  49. package/base-modules/product/product.js +80 -0
  50. package/base-modules/product/reducer.d.ts +4 -0
  51. package/base-modules/product/reducer.js +88 -0
  52. package/base-modules/product/types.d.ts +87 -0
  53. package/base-modules/product/types.js +28 -0
  54. package/base-modules/product/validate.d.ts +36 -0
  55. package/base-modules/product/validate.js +17 -0
  56. package/base-modules/product-category/actions.d.ts +90 -0
  57. package/base-modules/product-category/actions.js +19 -0
  58. package/base-modules/product-category/constants.d.ts +28 -0
  59. package/base-modules/product-category/constants.js +74 -0
  60. package/base-modules/product-category/context.d.ts +10 -0
  61. package/base-modules/product-category/context.js +390 -0
  62. package/base-modules/product-category/drawer.d.ts +8 -0
  63. package/base-modules/product-category/drawer.js +19 -0
  64. package/base-modules/product-category/form-elements.d.ts +2 -0
  65. package/base-modules/product-category/form-elements.js +41 -0
  66. package/base-modules/product-category/form.d.ts +8 -0
  67. package/base-modules/product-category/form.js +81 -0
  68. package/base-modules/product-category/product-category.d.ts +10 -0
  69. package/base-modules/product-category/product-category.js +53 -0
  70. package/base-modules/product-category/reducer.d.ts +4 -0
  71. package/base-modules/product-category/reducer.js +73 -0
  72. package/base-modules/product-category/types.d.ts +59 -0
  73. package/base-modules/product-category/types.js +11 -0
  74. package/base-modules/product-category/validate.d.ts +12 -0
  75. package/base-modules/product-category/validate.js +11 -0
  76. package/package.json +60 -0
@@ -0,0 +1,74 @@
1
+ 'use client';
2
+ "use strict";
3
+ var _a;
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.formInfo = exports.messages = exports.tableBodyCols = exports.PRODUCT_CATEGORY_API_ROUTES = exports.staticFormElements = exports.DEFAULT_RANGES = exports.pageLimit = void 0;
6
+ var form_schema_1 = require("@appcorp/app-corp-vista/utils/form-schema");
7
+ var vista_table_type_1 = require("@appcorp/app-corp-vista/type/vista-table-type");
8
+ exports.pageLimit = Number(process.env.NEXT_PUBLIC_PAGE_LIMIT);
9
+ exports.DEFAULT_RANGES = {
10
+ totalRange: [10, 3000],
11
+ };
12
+ exports.staticFormElements = (_a = {},
13
+ _a[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_INPUT_V1] = [
14
+ {
15
+ enabled: true,
16
+ error: '',
17
+ handleOnChange: function () { return void 0; },
18
+ id: 'name',
19
+ label: 'formLabelName',
20
+ order: 1,
21
+ placeholder: 'Name goes here...',
22
+ required: true,
23
+ type: 'text',
24
+ value: '',
25
+ },
26
+ ],
27
+ _a[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_AREA_V1] = [
28
+ {
29
+ enabled: true,
30
+ error: '',
31
+ handleOnChange: function () { return void 0; },
32
+ id: 'description',
33
+ label: 'formLabelDescription',
34
+ order: 2,
35
+ placeholder: 'Description goes here...',
36
+ value: '',
37
+ },
38
+ ],
39
+ _a);
40
+ exports.PRODUCT_CATEGORY_API_ROUTES = {
41
+ PRODUCT_CATEGORIES: '/api/product-categories',
42
+ PRODUCT_CATEGORY: '/api/product-category',
43
+ PRODUCT_CATEGORY_BY_ID: '/api/product-category/product-category-by-id',
44
+ };
45
+ exports.tableBodyCols = [
46
+ {
47
+ componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.ID,
48
+ key: 'id',
49
+ },
50
+ {
51
+ componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.BOLD_TEXT,
52
+ key: 'name',
53
+ },
54
+ {
55
+ componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.TEXT,
56
+ key: 'description',
57
+ },
58
+ {
59
+ componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.CREATED_UPDATED_AT,
60
+ },
61
+ {
62
+ componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.ACTIONS,
63
+ },
64
+ {
65
+ componentType: vista_table_type_1.VISTA_TABLE_CELL_TYPE.MULTIPLE_TEXT_LINES,
66
+ key: [],
67
+ },
68
+ ];
69
+ exports.messages = {
70
+ name: 'Product category name is required',
71
+ success: 'Operation successful!',
72
+ error: 'Error occurred, please try again.',
73
+ };
74
+ exports.formInfo = {};
@@ -0,0 +1,10 @@
1
+ import React, { FC, ReactNode } from 'react';
2
+ import { ProductCategoryContextType, ProductCategoryState } from './types';
3
+ type State = ProductCategoryContextType & ProductCategoryState;
4
+ interface StateProviderProps {
5
+ children: ReactNode;
6
+ }
7
+ export declare const ProductCategoryStateContext: React.Context<State>;
8
+ export declare const ProductCategoryStateContextProvider: FC<StateProviderProps>;
9
+ export declare const useProductCategoryStateContext: () => State;
10
+ export {};
@@ -0,0 +1,390 @@
1
+ 'use client';
2
+ "use strict";
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
48
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
49
+ return new (P || (P = Promise))(function (resolve, reject) {
50
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
51
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
52
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
53
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
54
+ });
55
+ };
56
+ var __generator = (this && this.__generator) || function (thisArg, body) {
57
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
58
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
59
+ function verb(n) { return function (v) { return step([n, v]); }; }
60
+ function step(op) {
61
+ if (f) throw new TypeError("Generator is already executing.");
62
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
63
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
+ if (y = 0, t) op = [op[0] & 2, t.value];
65
+ switch (op[0]) {
66
+ case 0: case 1: t = op; break;
67
+ case 4: _.label++; return { value: op[1], done: false };
68
+ case 5: _.label++; y = op[1]; op = [0]; continue;
69
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
70
+ default:
71
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
72
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
73
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
74
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
75
+ if (t[2]) _.ops.pop();
76
+ _.trys.pop(); continue;
77
+ }
78
+ op = body.call(thisArg, _);
79
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
80
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
81
+ }
82
+ };
83
+ Object.defineProperty(exports, "__esModule", { value: true });
84
+ exports.useProductCategoryStateContext = exports.ProductCategoryStateContextProvider = exports.ProductCategoryStateContext = void 0;
85
+ var react_1 = __importStar(require("react"));
86
+ var util_functions_1 = require("@react-pakistan/util-functions");
87
+ var form_schema_1 = require("@appcorp/app-corp-vista/utils/form-schema");
88
+ var vista_notification_type_1 = require("@appcorp/app-corp-vista/type/vista-notification-type");
89
+ var actions_1 = require("./actions");
90
+ var constants_1 = require("./constants");
91
+ var reducer_1 = require("./reducer");
92
+ var types_1 = require("./types");
93
+ var validate_1 = require("./validate");
94
+ var generate_toast_1 = require("@appcorp/app-corp-vista/utils/generate-toast");
95
+ var useProductCategoryState = function () {
96
+ var _a = (0, react_1.useReducer)(reducer_1.productCategoryReducer, reducer_1.initialProductCategoryState), state = _a[0], dispatch = _a[1];
97
+ var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
98
+ var listParams = {
99
+ currentPage: state.currentPage,
100
+ pageLimit: state.pageLimit,
101
+ searchQuery: state.searchQuery,
102
+ };
103
+ var listCallback = function (_a) {
104
+ var data = _a.data, error = _a.error;
105
+ if (error) {
106
+ (0, generate_toast_1.generateToast)({
107
+ description: constants_1.messages.error,
108
+ variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
109
+ });
110
+ }
111
+ if (data === null || data === void 0 ? void 0 : data.items) {
112
+ dispatch({
113
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_PRODUCT_CATEGORIES,
114
+ payload: { productCategories: data.items },
115
+ });
116
+ dispatch({
117
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_COUNT,
118
+ payload: { count: data === null || data === void 0 ? void 0 : data.count },
119
+ });
120
+ }
121
+ };
122
+ var updateParams = (0, react_1.useMemo)(function () { return ({
123
+ description: state.description,
124
+ id: state.id,
125
+ name: state.name,
126
+ }); }, [state]);
127
+ var updateCallback = function (_a) {
128
+ var data = _a.data, error = _a.error;
129
+ if (error) {
130
+ (0, generate_toast_1.generateToast)({
131
+ description: constants_1.messages.error,
132
+ variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
133
+ });
134
+ }
135
+ if (data) {
136
+ (0, generate_toast_1.generateToast)({
137
+ description: constants_1.messages.success,
138
+ variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
139
+ });
140
+ dispatch({
141
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.RESET_FORM,
142
+ });
143
+ listFetchNow();
144
+ dispatch({
145
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_DRAWER,
146
+ payload: { drawer: null },
147
+ });
148
+ }
149
+ };
150
+ var byIdParams = {
151
+ id: state.id,
152
+ };
153
+ var byIdCallback = function (_a) {
154
+ var data = _a.data, error = _a.error;
155
+ if (error) {
156
+ (0, generate_toast_1.generateToast)({
157
+ description: constants_1.messages.error,
158
+ variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
159
+ });
160
+ }
161
+ if (data) {
162
+ dispatch({
163
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_FORM,
164
+ payload: { form: data },
165
+ });
166
+ dispatch({
167
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_DRAWER,
168
+ payload: { drawer: types_1.PRODUCT_CATEGORY_DRAWER.PRODUCT_CATEGORY_FORM_DRAWER },
169
+ });
170
+ }
171
+ };
172
+ var deleteParams = {
173
+ id: state.id,
174
+ };
175
+ var deleteCallback = function (_a) {
176
+ var data = _a.data, error = _a.error;
177
+ if (error) {
178
+ (0, generate_toast_1.generateToast)({
179
+ description: constants_1.messages.error,
180
+ variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
181
+ });
182
+ }
183
+ if (data) {
184
+ (0, generate_toast_1.generateToast)({
185
+ description: constants_1.messages.success,
186
+ variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
187
+ });
188
+ dispatch({
189
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.RESET_FORM,
190
+ });
191
+ listFetchNow();
192
+ }
193
+ };
194
+ var _b = (0, util_functions_1.useModuleEntity)({
195
+ byIdCallback: byIdCallback,
196
+ byIdParams: byIdParams,
197
+ deleteCallback: deleteCallback,
198
+ deleteParams: deleteParams,
199
+ listCallback: listCallback,
200
+ listParams: listParams,
201
+ listUrl: constants_1.PRODUCT_CATEGORY_API_ROUTES.PRODUCT_CATEGORIES,
202
+ searchQuery: debouncedQuery,
203
+ unitByIdUrl: constants_1.PRODUCT_CATEGORY_API_ROUTES.PRODUCT_CATEGORY_BY_ID,
204
+ unitUrl: constants_1.PRODUCT_CATEGORY_API_ROUTES.PRODUCT_CATEGORY,
205
+ updateCallback: updateCallback,
206
+ updateDeps: [state],
207
+ updateParams: updateParams,
208
+ }), 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;
209
+ (0, react_1.useEffect)(function () {
210
+ listFetchNow();
211
+ // eslint-disable-next-line
212
+ }, [
213
+ debouncedQuery,
214
+ state.currentPage,
215
+ state.pageLimit,
216
+ ]);
217
+ var handleCreate = function () {
218
+ dispatch({
219
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_DRAWER,
220
+ payload: { drawer: types_1.PRODUCT_CATEGORY_DRAWER.PRODUCT_CATEGORY_FORM_DRAWER },
221
+ });
222
+ };
223
+ var handleEdit = function (id) {
224
+ byIdFetchNow(undefined, {
225
+ body: JSON.stringify({ id: id }),
226
+ });
227
+ };
228
+ var handleDelete = function (id) {
229
+ deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
230
+ body: JSON.stringify({ id: id }),
231
+ });
232
+ };
233
+ var handleSubmit = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
234
+ var validationResult, validationErrors_1;
235
+ return __generator(this, function (_a) {
236
+ dispatch({
237
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
238
+ payload: { disableSaveButton: true },
239
+ });
240
+ try {
241
+ validationResult = validate_1.formValidation === null || validate_1.formValidation === void 0 ? void 0 : validate_1.formValidation.safeParse(__assign({}, updateParams));
242
+ if (validationResult === null || validationResult === void 0 ? void 0 : validationResult.error) {
243
+ validationErrors_1 = {};
244
+ validationResult === null || validationResult === void 0 ? void 0 : validationResult.error.errors.forEach(function (err) {
245
+ validationErrors_1[err.path[0]] = err.message;
246
+ });
247
+ dispatch({
248
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_ERRORS,
249
+ payload: validationErrors_1,
250
+ });
251
+ }
252
+ if (validationResult === null || validationResult === void 0 ? void 0 : validationResult.success) {
253
+ updateFetchNow(undefined, {
254
+ body: JSON.stringify(__assign({}, updateParams)),
255
+ });
256
+ }
257
+ // eslint-disable-next-line
258
+ }
259
+ catch (err) {
260
+ (0, generate_toast_1.generateToast)({
261
+ description: constants_1.messages.error,
262
+ variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
263
+ });
264
+ }
265
+ dispatch({
266
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.RESET_FORM,
267
+ });
268
+ dispatch({
269
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.CLEAR_ERRORS,
270
+ });
271
+ return [2 /*return*/];
272
+ });
273
+ }); }, [updateFetchNow, updateParams]);
274
+ var handleChange = function (key, value) {
275
+ dispatch({
276
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_INPUT_FIELD,
277
+ payload: { key: key, value: String(value).trim(), },
278
+ });
279
+ dispatch({
280
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
281
+ payload: { disableSaveButton: false },
282
+ });
283
+ dispatch({
284
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.CLEAR_ERRORS,
285
+ });
286
+ };
287
+ var handleNextClick = function () {
288
+ dispatch({
289
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_CURRENT_PAGE,
290
+ payload: { currentPage: state.currentPage + 1 },
291
+ });
292
+ };
293
+ var handlePreviousClick = function () {
294
+ dispatch({
295
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_CURRENT_PAGE,
296
+ payload: { currentPage: state.currentPage - 1 },
297
+ });
298
+ };
299
+ var handlePageLimit = function (node, value) {
300
+ dispatch({
301
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_PAGE_LIMIT,
302
+ payload: { pageLimit: Number(value.option) },
303
+ });
304
+ };
305
+ var searchOnChange = function (k, v) {
306
+ dispatch({
307
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_SEARCH_QUERY,
308
+ payload: { searchQuery: v },
309
+ });
310
+ };
311
+ var clearSearch = function () {
312
+ dispatch({
313
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_SEARCH_QUERY,
314
+ payload: { searchQuery: '' },
315
+ });
316
+ };
317
+ var closeDrawer = function () {
318
+ dispatch({
319
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.SET_DRAWER,
320
+ payload: { drawer: null },
321
+ });
322
+ dispatch({
323
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.RESET_FORM,
324
+ });
325
+ dispatch({
326
+ type: actions_1.PRODUCT_CATEGORY_ACTION_TYPES.CLEAR_ERRORS,
327
+ });
328
+ };
329
+ var dynamicFormElements = (0, react_1.useMemo)(function () {
330
+ var _a, _b;
331
+ var elements = __assign({}, constants_1.staticFormElements);
332
+ var textInputElements = (_a = elements[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_INPUT_V1]) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.order - b.order; });
333
+ if (textInputElements) {
334
+ textInputElements === null || textInputElements === void 0 ? void 0 : textInputElements.map(function (_a, i) {
335
+ var id = _a.id;
336
+ textInputElements[i].value = state[id];
337
+ textInputElements[i].handleOnChange = handleChange;
338
+ textInputElements[i].error = state.errors[id];
339
+ });
340
+ }
341
+ var textAreaElements = (_b = elements[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_AREA_V1]) === null || _b === void 0 ? void 0 : _b.sort(function (a, b) { return a.order - b.order; });
342
+ if (textAreaElements) {
343
+ textAreaElements === null || textAreaElements === void 0 ? void 0 : textAreaElements.forEach(function (_a, i) {
344
+ var id = _a.id;
345
+ textAreaElements[i].value = state[id];
346
+ textAreaElements[i].handleOnChange = handleChange;
347
+ textAreaElements[i].error = state.errors.description;
348
+ });
349
+ }
350
+ return elements;
351
+ }, [state]);
352
+ var headerActions = [
353
+ {
354
+ enabled: true,
355
+ handleOnClick: handleCreate,
356
+ label: 'Add Item',
357
+ order: 1,
358
+ },
359
+ ];
360
+ var rowActions = [
361
+ {
362
+ enabled: true,
363
+ handleAction: function (id) { return handleEdit(id); },
364
+ label: 'Edit',
365
+ order: 1,
366
+ },
367
+ {
368
+ enabled: true,
369
+ handleAction: function (id) { return handleDelete(id); },
370
+ label: 'Delete',
371
+ order: 2,
372
+ },
373
+ ];
374
+ return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, dynamicFormElements: dynamicFormElements, handleChange: handleChange, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading });
375
+ };
376
+ exports.ProductCategoryStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialProductCategoryState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, dynamicFormElements: {}, handleChange: 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; }, updateError: undefined, updateLoading: false }));
377
+ var ProductCategoryStateContextProvider = function (_a) {
378
+ var children = _a.children;
379
+ var state = useProductCategoryState();
380
+ return (react_1.default.createElement(exports.ProductCategoryStateContext.Provider, { value: state }, children));
381
+ };
382
+ exports.ProductCategoryStateContextProvider = ProductCategoryStateContextProvider;
383
+ var useProductCategoryStateContext = function () {
384
+ var state = (0, react_1.useContext)(exports.ProductCategoryStateContext);
385
+ if (state === undefined) {
386
+ throw new Error('useProductCategoryStateContext must be used within an ProductCategoryContextProvider');
387
+ }
388
+ return state;
389
+ };
390
+ exports.useProductCategoryStateContext = useProductCategoryStateContext;
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ interface Props {
3
+ translationMap: {
4
+ [key: string]: string;
5
+ };
6
+ }
7
+ export declare const Drawer: FC<Props>;
8
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Drawer = void 0;
7
+ var react_1 = __importDefault(require("react"));
8
+ var vista_drawer_v1_1 = require("@appcorp/app-corp-vista/molecules/vista-drawer-v1/vista-drawer-v1");
9
+ var vista_drawer_type_1 = require("@appcorp/app-corp-vista/type/vista-drawer-type");
10
+ var vista_button_type_1 = require("@appcorp/app-corp-vista/type/vista-button-type");
11
+ var context_1 = require("./context");
12
+ var form_1 = require("./form");
13
+ var Drawer = function (_a) {
14
+ var translationMap = _a.translationMap;
15
+ var _b = (0, context_1.useProductCategoryStateContext)(), 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.MD, title: 'Product Category' },
17
+ react_1.default.createElement(form_1.ProductCategoryForm, { translationMap: translationMap })));
18
+ };
19
+ exports.Drawer = Drawer;
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const renderProductCategoryFormElements: (elementProps: Record<string, any>) => React.JSX.Element;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.renderProductCategoryFormElements = void 0;
19
+ var react_1 = __importDefault(require("react"));
20
+ var form_schema_1 = require("@appcorp/app-corp-vista/utils/form-schema");
21
+ var renderProductCategoryFormElements = function (elementProps) {
22
+ var _a;
23
+ var elementsArray = (_a = Object.entries(form_schema_1.vistaFormSchema)
24
+ .flatMap(function (_a) {
25
+ var _b, _c;
26
+ var key = _a[0], config = _a[1];
27
+ var Component = config;
28
+ return (_c = (_b = (elementProps[key] || [])) === null || _b === void 0 ? void 0 : _b.filter(function (props) { return props.enabled; })) === null || _c === void 0 ? void 0 : _c.map(function (props) { return ({
29
+ Component: Component,
30
+ key: key,
31
+ order: props.order,
32
+ props: props,
33
+ }); });
34
+ })) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.order - b.order; });
35
+ return (react_1.default.createElement("div", { className: "grid grid-cols-1 gap-4" }, elementsArray === null || elementsArray === void 0 ? void 0 : elementsArray.map(function (_a, index) {
36
+ var key = _a.key, Component = _a.Component, props = _a.props;
37
+ return (react_1.default.createElement("div", { key: "".concat(key, "-").concat(index) },
38
+ react_1.default.createElement(Component, __assign({}, props))));
39
+ })));
40
+ };
41
+ exports.renderProductCategoryFormElements = renderProductCategoryFormElements;
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ interface Props {
3
+ translationMap: {
4
+ [key: string]: string;
5
+ };
6
+ }
7
+ export declare const ProductCategoryForm: FC<Props>;
8
+ export {};
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.ProductCategoryForm = void 0;
48
+ var react_1 = __importStar(require("react"));
49
+ var form_schema_1 = require("@appcorp/app-corp-vista/utils/form-schema");
50
+ var context_1 = require("./context");
51
+ var form_elements_1 = require("./form-elements");
52
+ var ProductCategoryForm = function (_a) {
53
+ var translationMap = _a.translationMap;
54
+ var dynamicFormElements = (0, context_1.useProductCategoryStateContext)().dynamicFormElements;
55
+ var updated = (0, react_1.useMemo)(function () {
56
+ var _a, _b;
57
+ var elements = __assign({}, dynamicFormElements);
58
+ var textInputElements = (_a = elements[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_INPUT_V1]) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.order - b.order; });
59
+ if (textInputElements) {
60
+ textInputElements === null || textInputElements === void 0 ? void 0 : textInputElements.forEach(function (_a, i) {
61
+ var label = _a.label;
62
+ if (translationMap[label] === undefined)
63
+ return label;
64
+ textInputElements[i].label = translationMap[label];
65
+ });
66
+ }
67
+ var textAreaElements = (_b = elements[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_AREA_V1]) === null || _b === void 0 ? void 0 : _b.sort(function (a, b) { return a.order - b.order; });
68
+ if (textAreaElements) {
69
+ textAreaElements === null || textAreaElements === void 0 ? void 0 : textAreaElements.forEach(function (_a, i) {
70
+ var label = _a.label;
71
+ if (translationMap[label] === undefined)
72
+ return label;
73
+ textAreaElements[i].label = translationMap[label];
74
+ });
75
+ }
76
+ return elements;
77
+ // eslint-disable-next-line
78
+ }, []);
79
+ return react_1.default.createElement(react_1.default.Fragment, null, (0, form_elements_1.renderProductCategoryFormElements)(updated));
80
+ };
81
+ exports.ProductCategoryForm = ProductCategoryForm;
@@ -0,0 +1,10 @@
1
+ import "slick-carousel/slick/slick.css";
2
+ import "slick-carousel/slick/slick-theme.css";
3
+ import { FC } from 'react';
4
+ interface Props {
5
+ params: Promise<{
6
+ locale: 'en' | 'ur';
7
+ }>;
8
+ }
9
+ export declare const ProductCategoryPage: FC<Props>;
10
+ export {};