oa-componentbook 1.0.1-stage.434 → 1.0.1-stage.436

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.
@@ -58,7 +58,8 @@ function EntityOverviewLayout(_ref) {
58
58
  profileData,
59
59
  accordionData,
60
60
  drawer,
61
- modal
61
+ modal,
62
+ misc
62
63
  } = state !== null && state !== void 0 ? state : {};
63
64
  (0, _react.useEffect)(() => {
64
65
  init();
@@ -121,8 +122,90 @@ function EntityOverviewLayout(_ref) {
121
122
  placement: "bottomRight"
122
123
  });
123
124
  };
124
- const handleCloseDrawer = () => {
125
- init();
125
+ const handleCloseDrawer = async () => {
126
+ var _state$misc2, _state$misc3, _state$misc4;
127
+ // Get selected enterprise from session storage to ensure profile data reflects correct enterprise
128
+ const selectedEnterpriseFromStorage = JSON.parse(sessionStorage.getItem('selectedEnterprise') || 'null');
129
+ const enterpriseIdFromStorage = (selectedEnterpriseFromStorage === null || selectedEnterpriseFromStorage === void 0 ? void 0 : selectedEnterpriseFromStorage.value) || (selectedEnterpriseFromStorage === null || selectedEnterpriseFromStorage === void 0 ? void 0 : selectedEnterpriseFromStorage.enterpriseId) || (selectedEnterpriseFromStorage === null || selectedEnterpriseFromStorage === void 0 ? void 0 : selectedEnterpriseFromStorage.id);
130
+
131
+ // Update misc with enterpriseId from session storage
132
+ const currentMisc = _objectSpread(_objectSpread({}, (_state$misc2 = state === null || state === void 0 ? void 0 : state.misc) !== null && _state$misc2 !== void 0 ? _state$misc2 : {}), {}, {
133
+ enterpriseId: enterpriseIdFromStorage || (state === null || state === void 0 || (_state$misc3 = state.misc) === null || _state$misc3 === void 0 ? void 0 : _state$misc3.enterpriseId),
134
+ enterpriseData: selectedEnterpriseFromStorage || (state === null || state === void 0 || (_state$misc4 = state.misc) === null || _state$misc4 === void 0 ? void 0 : _state$misc4.enterpriseData)
135
+ });
136
+ dispatch({
137
+ type: _entityOverviewLayoutReducer.actionTypes.SET_LOADING,
138
+ payload: true
139
+ });
140
+ if (getInitialData) {
141
+ const {
142
+ error,
143
+ data
144
+ } = await (getInitialData === null || getInitialData === void 0 ? void 0 : getInitialData(_objectSpread({}, currentMisc)));
145
+ if (error) {
146
+ showErrorNotification(error);
147
+ const dynamicConfig = (0, _staticConfigResolver.default)(config, {});
148
+ // Update misc with enterpriseId from session storage
149
+ if (currentMisc) {
150
+ dynamicConfig.misc = currentMisc;
151
+ }
152
+ // Don't preserve profile data - let it be re-rendered from config with correct enterprise
153
+ // Don't preserve accordion data - use fresh data from API (or empty if error)
154
+ dispatch({
155
+ type: _entityOverviewLayoutReducer.actionTypes.INIT,
156
+ payload: dynamicConfig
157
+ });
158
+ } else {
159
+ const dynamicConfig = (0, _staticConfigResolver.default)(config, data !== null && data !== void 0 ? data : {});
160
+ // Update misc with enterpriseId from session storage
161
+ if (currentMisc) {
162
+ dynamicConfig.misc = currentMisc;
163
+ }
164
+ // Use fresh profile data from API response to reflect correct enterprise
165
+ if (data !== null && data !== void 0 && data.data) {
166
+ dispatch({
167
+ type: _entityOverviewLayoutReducer.actionTypes.UPDATE_PROFILE_DATA,
168
+ payload: data.data
169
+ });
170
+ }
171
+ // Use fresh accordion data from API response (includes newly added users)
172
+ // Check for both 'accordionData' and 'accordianData' (typo in API response)
173
+ const freshAccordionData = (data === null || data === void 0 ? void 0 : data.accordionData) || (data === null || data === void 0 ? void 0 : data.accordianData);
174
+ if (freshAccordionData) {
175
+ let accordionDataToUpdate;
176
+ if (Array.isArray(freshAccordionData)) {
177
+ accordionDataToUpdate = freshAccordionData;
178
+ } else if (freshAccordionData.data && Array.isArray(freshAccordionData.data)) {
179
+ accordionDataToUpdate = freshAccordionData.data;
180
+ } else {
181
+ accordionDataToUpdate = freshAccordionData;
182
+ }
183
+ // Update accordion data with fresh data from API
184
+ dispatch({
185
+ type: _entityOverviewLayoutReducer.actionTypes.UPDATE_ACCORDION_DATA,
186
+ payload: accordionDataToUpdate
187
+ });
188
+ }
189
+ dispatch({
190
+ type: _entityOverviewLayoutReducer.actionTypes.INIT,
191
+ payload: dynamicConfig
192
+ });
193
+ }
194
+ } else {
195
+ const dynamicConfig = (0, _staticConfigResolver.default)(config, {});
196
+ // Update misc with enterpriseId from session storage
197
+ if (currentMisc) {
198
+ dynamicConfig.misc = currentMisc;
199
+ }
200
+ dispatch({
201
+ type: _entityOverviewLayoutReducer.actionTypes.INIT,
202
+ payload: dynamicConfig
203
+ });
204
+ }
205
+ dispatch({
206
+ type: _entityOverviewLayoutReducer.actionTypes.SET_LOADING,
207
+ payload: false
208
+ });
126
209
  dispatch({
127
210
  type: _entityOverviewLayoutReducer.actionTypes.CLOSE_DRAWER
128
211
  });
@@ -140,14 +223,70 @@ function EntityOverviewLayout(_ref) {
140
223
  {
141
224
  (config === null || config === void 0 ? void 0 : config.storageType) == "sessionStorage" && (config === null || config === void 0 ? void 0 : config.storageKey) && sessionStorage.setItem(config === null || config === void 0 ? void 0 : config.storageKey, JSON.stringify(selectedData));
142
225
  }
226
+ // Always update 'selectedEnterprise' in sessionStorage to keep misc.enterpriseId in sync
227
+ if (selectedData) {
228
+ sessionStorage.setItem('selectedEnterprise', JSON.stringify(selectedData));
229
+ }
143
230
  showSuccessNotification(config === null || config === void 0 ? void 0 : config.successMessage);
144
231
  if (error) {
145
232
  showErrorNotification(error);
146
233
  } else {
234
+ // Update misc.enterpriseId to keep it in sync with selected enterprise
235
+ // Read from selectedData to match the sessionStorage structure
236
+ const enterpriseId = (selectedData === null || selectedData === void 0 ? void 0 : selectedData.value) || (selectedData === null || selectedData === void 0 ? void 0 : selectedData.enterpriseId) || (selectedData === null || selectedData === void 0 ? void 0 : selectedData.id) || selectedValue;
237
+ if (enterpriseId) {
238
+ dispatch({
239
+ type: _entityOverviewLayoutReducer.actionTypes.SET_MISC,
240
+ payload: _objectSpread(_objectSpread({}, state === null || state === void 0 ? void 0 : state.misc), {}, {
241
+ enterpriseId: enterpriseId,
242
+ enterpriseData: selectedData // Also update enterpriseData to match sessionStorage
243
+ })
244
+ });
245
+ }
147
246
  dispatch({
148
247
  type: _entityOverviewLayoutReducer.actionTypes.UPDATE_PROFILE_DATA,
149
248
  payload: selectedItem
150
249
  });
250
+ // Update accordion data if provided in the response
251
+ // Note: API returns 'accordianData' (typo) but we check for both
252
+ const accordionDataFromResponse = (data === null || data === void 0 ? void 0 : data.accordionData) || (data === null || data === void 0 ? void 0 : data.accordianData);
253
+
254
+ // Check if accordionDataFromResponse is an object with data array, or if it's directly an array
255
+ if (accordionDataFromResponse) {
256
+ let accordionDataToUpdate;
257
+ if (Array.isArray(accordionDataFromResponse)) {
258
+ // If it's directly an array, use it as is
259
+ accordionDataToUpdate = accordionDataFromResponse;
260
+ } else if (accordionDataFromResponse.data && Array.isArray(accordionDataFromResponse.data)) {
261
+ // If it's an object with a data property containing the array, extract the data array
262
+ accordionDataToUpdate = accordionDataFromResponse.data;
263
+ }
264
+ if (accordionDataToUpdate) {
265
+ dispatch({
266
+ type: _entityOverviewLayoutReducer.actionTypes.UPDATE_ACCORDION_DATA,
267
+ payload: accordionDataToUpdate
268
+ });
269
+ } else {
270
+ console.log('Accordion data structure not recognized:', accordionDataFromResponse);
271
+ }
272
+ } else {
273
+ if (getInitialData && config !== null && config !== void 0 && config.refreshAccordionOnSwitch) {
274
+ var _state$misc5;
275
+ // Optionally refresh accordion data by calling getInitialData again
276
+ const {
277
+ error: refreshError,
278
+ data: refreshData
279
+ } = await (getInitialData === null || getInitialData === void 0 ? void 0 : getInitialData(_objectSpread(_objectSpread({}, (_state$misc5 = state === null || state === void 0 ? void 0 : state.misc) !== null && _state$misc5 !== void 0 ? _state$misc5 : {}), {}, {
280
+ selectedValue
281
+ })));
282
+ if (!refreshError && refreshData !== null && refreshData !== void 0 && refreshData.accordionData) {
283
+ dispatch({
284
+ type: _entityOverviewLayoutReducer.actionTypes.UPDATE_ACCORDION_DATA,
285
+ payload: refreshData.accordionData
286
+ });
287
+ }
288
+ }
289
+ }
151
290
  }
152
291
  }
153
292
  };
@@ -255,7 +394,9 @@ function EntityOverviewLayout(_ref) {
255
394
  customPageModal: modal,
256
395
  addUserClick: addUserClick,
257
396
  deleteUserClick: deleteUserClick,
258
- editUserClick: editUserClick
397
+ editUserClick: editUserClick,
398
+ misc: misc,
399
+ drawer: drawer
259
400
  }))))));
260
401
  }
261
402
  EntityOverviewLayout.propTypes = {};
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.initialState = exports.entityOverviewLayoutReducer = exports.actionTypes = void 0;
7
+ require("core-js/modules/web.dom-collections.iterator.js");
7
8
  require("core-js/modules/es.symbol.description.js");
8
9
  var _staticConfigResolver = require("../../GenricLayOut/resolver/staticConfigResolver");
9
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -19,7 +20,8 @@ const actionTypes = exports.actionTypes = {
19
20
  SET_DRAWER: 'SET_DRAWER',
20
21
  TOGGLE_DRAWER: 'TOGGLE_DRAWER',
21
22
  CLOSE_DRAWER: 'CLOSE_DRAWER',
22
- UPDATE_PROFILE_DATA: 'UPDATE_PROFILE_DATA'
23
+ UPDATE_PROFILE_DATA: 'UPDATE_PROFILE_DATA',
24
+ UPDATE_ACCORDION_DATA: 'UPDATE_ACCORDION_DATA'
23
25
  };
24
26
  const initialState = exports.initialState = {};
25
27
  const entityOverviewLayoutReducer = (state, action) => {
@@ -38,6 +40,21 @@ const entityOverviewLayoutReducer = (state, action) => {
38
40
  return _objectSpread(_objectSpread({}, state), {}, {
39
41
  profileData: action.payload
40
42
  });
43
+ case actionTypes.UPDATE_ACCORDION_DATA:
44
+ {
45
+ var _state$accordionData$, _state$accordionData;
46
+ console.log('Reducer: Updating accordion data with payload:', action.payload);
47
+ const newAccordionData = _objectSpread(_objectSpread({}, (state === null || state === void 0 ? void 0 : state.accordionData) || {}), {}, {
48
+ // Preserve all existing accordionData properties
49
+ visible: (_state$accordionData$ = state === null || state === void 0 || (_state$accordionData = state.accordionData) === null || _state$accordionData === void 0 ? void 0 : _state$accordionData.visible) !== null && _state$accordionData$ !== void 0 ? _state$accordionData$ : true,
50
+ // Preserve visible property, default to true
51
+ data: Array.isArray(action.payload) ? [...action.payload] : action.payload // Ensure new array reference
52
+ });
53
+ console.log('Reducer: New accordion data:', newAccordionData);
54
+ return _objectSpread(_objectSpread({}, state), {}, {
55
+ accordionData: newAccordionData
56
+ });
57
+ }
41
58
  case actionTypes.SET_MISC:
42
59
  return _objectSpread(_objectSpread({}, state), {}, {
43
60
  misc: _objectSpread(_objectSpread({}, state.misc), action.payload)
@@ -452,7 +452,8 @@ function FormWidget(props) {
452
452
  initialData: (item === null || item === void 0 ? void 0 : item.value) || [],
453
453
  fields: item === null || item === void 0 ? void 0 : item.fields,
454
454
  disabled: (item === null || item === void 0 ? void 0 : item.disabled) || false,
455
- customPageModal: props === null || props === void 0 ? void 0 : props.customPageModal
455
+ customPageModal: props === null || props === void 0 ? void 0 : props.customPageModal,
456
+ misc: props === null || props === void 0 ? void 0 : props.misc
456
457
  }, props)));
457
458
  case "field":
458
459
  return renderFieldWidget(item);
@@ -5,9 +5,12 @@ require("core-js/modules/es.weak-map.js");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = UserManagementWidget;
8
+ exports.default = _default;
9
9
  require("core-js/modules/web.dom-collections.iterator.js");
10
10
  require("core-js/modules/es.promise.js");
11
+ require("core-js/modules/es.regexp.constructor.js");
12
+ require("core-js/modules/es.regexp.exec.js");
13
+ require("core-js/modules/es.regexp.to-string.js");
11
14
  var _react = _interopRequireWildcard(require("react"));
12
15
  var _antd = require("antd");
13
16
  var _EditOutlined = _interopRequireDefault(require("@material-ui/icons/EditOutlined"));
@@ -28,7 +31,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
28
31
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
32
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
30
33
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable */
31
- function UserManagementWidget(_ref) {
34
+ function _default(_ref) {
35
+ var _drawer$data, _activeDrawerData$mis;
32
36
  let {
33
37
  form,
34
38
  fieldName = "users",
@@ -39,7 +43,8 @@ function UserManagementWidget(_ref) {
39
43
  addUserClick,
40
44
  deleteUserClick,
41
45
  editUserClick,
42
- misc
46
+ misc,
47
+ drawer
43
48
  } = _ref;
44
49
  const finalFields = fields || [];
45
50
  const [editingUserId, setEditingUserId] = (0, _react.useState)(null);
@@ -88,6 +93,28 @@ function UserManagementWidget(_ref) {
88
93
  [fieldName]: defaultUsers
89
94
  });
90
95
  }, [initialData, fieldName, form]);
96
+
97
+ // Reset form state when drawer closes or opens to ensure fresh context
98
+ (0, _react.useEffect)(() => {
99
+ if (drawer && drawer.visible === false) {
100
+ // Reset adding/editing state when drawer closes
101
+ setAddingUser(false);
102
+ setEditingUserId(null);
103
+ setDeleteModalVisible(false);
104
+ setUserToDelete(null);
105
+
106
+ // Clear form fields
107
+ const clearData = {};
108
+ finalFields.forEach(field => {
109
+ clearData["".concat(fieldName, "_").concat(field.key)] = "";
110
+ });
111
+ form.setFieldsValue(clearData);
112
+ }
113
+ }, [drawer === null || drawer === void 0 ? void 0 : drawer.visible, form, fieldName, finalFields]);
114
+
115
+ // Access branchId dynamically from drawer data using active drawer key
116
+ const activeDrawerData = drawer === null || drawer === void 0 || (_drawer$data = drawer.data) === null || _drawer$data === void 0 ? void 0 : _drawer$data[drawer === null || drawer === void 0 ? void 0 : drawer.active];
117
+ const branchId = activeDrawerData === null || activeDrawerData === void 0 || (_activeDrawerData$mis = activeDrawerData.misc) === null || _activeDrawerData$mis === void 0 ? void 0 : _activeDrawerData$mis.branchId;
91
118
  const handleEdit = user => {
92
119
  setEditingUserId(user.id);
93
120
  setAddingUser(false);
@@ -127,7 +154,7 @@ function UserManagementWidget(_ref) {
127
154
  const {
128
155
  error,
129
156
  data
130
- } = await editUserClick(editingUserId, userData);
157
+ } = await editUserClick(editingUserId, userData, misc);
131
158
  if (error) {
132
159
  showErrorNotification(error);
133
160
  } else {
@@ -149,7 +176,7 @@ function UserManagementWidget(_ref) {
149
176
  const {
150
177
  error,
151
178
  data
152
- } = await addUserClick(userData, misc);
179
+ } = await addUserClick(userData, misc, branchId);
153
180
  if (error) {
154
181
  showErrorNotification(error);
155
182
  } else {
@@ -215,15 +242,38 @@ function UserManagementWidget(_ref) {
215
242
  };
216
243
  const canDelete = users.length > 1;
217
244
  const isEditing = editingUserId !== null || addingUser;
245
+
246
+ // Process rules to handle checkValidator structure (similar to FormWidget)
247
+ const processRules = rules => {
248
+ if (!rules || !Array.isArray(rules)) {
249
+ return rules;
250
+ }
251
+ return rules.map(r => {
252
+ // If rule has checkValidator, extract the nested rule object
253
+ if (r !== null && r !== void 0 && r.checkValidator && r !== null && r !== void 0 && r.rule) {
254
+ let processedRule = _objectSpread({}, r.rule);
255
+
256
+ // Handle pattern conversion if it's a string
257
+ if (processedRule.pattern && typeof processedRule.pattern === "string") {
258
+ processedRule.pattern = new RegExp(processedRule.pattern);
259
+ }
260
+ return processedRule;
261
+ }
262
+
263
+ // Return rule as-is if it doesn't have checkValidator structure
264
+ return r;
265
+ });
266
+ };
218
267
  const renderFormField = field => {
219
268
  var _field$options;
220
269
  const fieldNameWithPrefix = "".concat(fieldName, "_").concat(field.key);
270
+ const processedRules = processRules(field.rules);
221
271
  switch (field.widget || field.type) {
222
272
  case "input":
223
273
  return /*#__PURE__*/_react.default.createElement(_antd.Form.Item, {
224
274
  name: fieldNameWithPrefix,
225
275
  label: field.label,
226
- rules: field.rules,
276
+ rules: processedRules,
227
277
  style: {
228
278
  marginBottom: 16
229
279
  }
@@ -234,7 +284,7 @@ function UserManagementWidget(_ref) {
234
284
  return /*#__PURE__*/_react.default.createElement(_antd.Form.Item, {
235
285
  name: fieldNameWithPrefix,
236
286
  label: field.label,
237
- rules: field.rules,
287
+ rules: processedRules,
238
288
  style: {
239
289
  marginBottom: 16
240
290
  }
@@ -249,7 +299,7 @@ function UserManagementWidget(_ref) {
249
299
  return /*#__PURE__*/_react.default.createElement(_antd.Form.Item, {
250
300
  name: fieldNameWithPrefix,
251
301
  label: field.label,
252
- rules: field.rules,
302
+ rules: processedRules,
253
303
  style: {
254
304
  marginBottom: 16
255
305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oa-componentbook",
3
- "version": "1.0.1-stage.434",
3
+ "version": "1.0.1-stage.436",
4
4
  "private": false,
5
5
  "description": "Reusable components",
6
6
  "main": "build/index.js",