@banch0u/core-project-test-repository 2.2.2 → 2.2.3

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.
@@ -290,7 +290,7 @@ var QuestionnairesSidebar = function QuestionnairesSidebar(_ref) {
290
290
  {
291
291
  key: "subtypes",
292
292
  //delete the "/" at the start of string
293
- label: "Müqavilə alt növü",
293
+ label: "Müqavilənin predmeti",
294
294
  link: QUESTIONNAIRES_CONTRACTTYPESSUBTYPES
295
295
  },
296
296
  // ---- generated sidebar item by questionnaireGenerator: ContractTypesSubtypes ----
@@ -305,7 +305,7 @@ var QuestionnairesSidebar = function QuestionnairesSidebar(_ref) {
305
305
 
306
306
  {
307
307
  key: "routelocations",
308
- //delete the "/" at the start of string
308
+ //delete the "/" at the start of string
309
309
  label: "Göndərilən yerlər",
310
310
  link: QUESTIONNAIRES_ROUTELOCATIONS
311
311
  },
@@ -313,8 +313,8 @@ var QuestionnairesSidebar = function QuestionnairesSidebar(_ref) {
313
313
 
314
314
  {
315
315
  key: "internalstructures",
316
- //delete the "/" at the start of string
317
- label: "Daxili Strukturlar",
316
+ //delete the "/" at the start of string
317
+ label: "Şablon strukturlar",
318
318
  link: QUESTIONNAIRES_INTERNALSTRUCTURE
319
319
  }
320
320
  // ---- generated sidebar item by questionnaireGenerator: InternalStructure ----
@@ -11,7 +11,7 @@ export var getStreetColumns = function getStreetColumns(onEditClick, onDelete, o
11
11
  ellipsis: true,
12
12
  width: 35
13
13
  }, {
14
- title: "Müqavilə alt növü",
14
+ title: "Müqavilənin predmeti",
15
15
  dataIndex: "name",
16
16
  width: innerW,
17
17
  disabled: true,
@@ -205,7 +205,7 @@ var QuestionnairesContractTypesSubtypesContent = function QuestionnairesContract
205
205
  className: style.content
206
206
  }, /*#__PURE__*/React.createElement("div", {
207
207
  className: style.table_header
208
- }, /*#__PURE__*/React.createElement("h2", null, "M\xFCqavil\u0259 alt n\xF6v\xFC"), /*#__PURE__*/React.createElement("div", {
208
+ }, /*#__PURE__*/React.createElement("h2", null, "M\xFCqavil\u0259nin predmeti"), /*#__PURE__*/React.createElement("div", {
209
209
  className: style.buttons
210
210
  }, /*#__PURE__*/React.createElement(Select, {
211
211
  size: "sm",
@@ -21,12 +21,6 @@ export var getStreetColumns = function getStreetColumns(onEditClick, onDelete, d
21
21
  width: innerW,
22
22
  disabled: false,
23
23
  ellipsis: true
24
- }, {
25
- title: "Daxili Struktur",
26
- dataIndex: "internalStructure",
27
- width: innerW,
28
- disabled: false,
29
- ellipsis: true
30
24
  }, {
31
25
  title: "",
32
26
  key: "actions",
@@ -1,7 +1,10 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
+ 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; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
8
  import React from "react";
6
9
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
7
10
  import Cookies from "js-cookie";
@@ -30,12 +33,111 @@ import Input from "../../../components/Input";
30
33
  var Content = Layout.Content;
31
34
  var Item = Form.Item;
32
35
  var Option = AntdSelect.Option;
36
+
37
+ /**
38
+ * Helpers
39
+ */
40
+ var toNumSafe = function toNumSafe(v) {
41
+ return v === null || v === undefined || v === "" ? NaN : Number(v);
42
+ };
43
+ var deriveFlowPriorityFromRank = function deriveFlowPriorityFromRank(rank) {
44
+ var r = toNumSafe(rank);
45
+ if (Number.isNaN(r)) return undefined;
46
+ if (r === -1 || r === 0 || r === 1 || r === 2) return r;
47
+ if (r >= 3) return 3;
48
+ return undefined;
49
+ };
50
+
51
+ /**
52
+ * ✅ EDIT NORMALIZATION (flowPriority-first)
53
+ */
54
+ var normalizeForEdit = function normalizeForEdit(row) {
55
+ var fpNum = toNumSafe(row === null || row === void 0 ? void 0 : row.flowPriority);
56
+ if (!Number.isNaN(fpNum) && [-1, 0, 1, 2, 3].includes(fpNum)) {
57
+ if (fpNum === 3) {
58
+ var _rankNum = toNumSafe(row === null || row === void 0 ? void 0 : row.rank);
59
+ return _objectSpread(_objectSpread({}, row), {}, {
60
+ flowPriority: 3,
61
+ rank: Number.isNaN(_rankNum) ? undefined : _rankNum
62
+ });
63
+ }
64
+ return _objectSpread(_objectSpread({}, row), {}, {
65
+ flowPriority: fpNum,
66
+ rank: undefined
67
+ });
68
+ }
69
+ var rankNum = toNumSafe(row === null || row === void 0 ? void 0 : row.rank);
70
+ if (Number.isNaN(rankNum)) {
71
+ var fp = row === null || row === void 0 ? void 0 : row.flowPriority;
72
+ return _objectSpread(_objectSpread({}, row), {}, {
73
+ flowPriority: fp === -1 || fp === 0 || fp === 1 || fp === 2 || fp === 3 ? fp : undefined,
74
+ rank: undefined
75
+ });
76
+ }
77
+ if (rankNum === -1) return _objectSpread(_objectSpread({}, row), {}, {
78
+ flowPriority: -1,
79
+ rank: undefined
80
+ });
81
+ if (rankNum === 0 || rankNum === 1 || rankNum === 2) return _objectSpread(_objectSpread({}, row), {}, {
82
+ flowPriority: rankNum,
83
+ rank: undefined
84
+ });
85
+ return _objectSpread(_objectSpread({}, row), {}, {
86
+ flowPriority: 3,
87
+ rank: rankNum
88
+ });
89
+ };
90
+
91
+ /**
92
+ * ✅ PAYLOAD BUILD (SEND BOTH rank + flowPriority)
93
+ */
94
+ var buildPayloadFromForm = function buildPayloadFromForm(id, values) {
95
+ var flowPriority = Number(values === null || values === void 0 ? void 0 : values.flowPriority);
96
+ var base = _objectSpread(_objectSpread({}, id ? {
97
+ id: id
98
+ } : {}), {}, {
99
+ responsiblePersonId: values === null || values === void 0 ? void 0 : values.responsiblePersonId,
100
+ internalStructureId: values === null || values === void 0 ? void 0 : values.internalStructureId,
101
+ // ✅ will come from top select
102
+ flowPriority: flowPriority
103
+ });
104
+ if (flowPriority === -1) return _objectSpread(_objectSpread({}, base), {}, {
105
+ rank: -1
106
+ });
107
+ if (flowPriority === 0 || flowPriority === 1 || flowPriority === 2) return _objectSpread(_objectSpread({}, base), {}, {
108
+ rank: flowPriority
109
+ });
110
+ return _objectSpread(_objectSpread({}, base), {}, {
111
+ rank: Number(values === null || values === void 0 ? void 0 : values.rank)
112
+ });
113
+ };
114
+ var resolveRankFromValues = function resolveRankFromValues(values) {
115
+ var fp = Number(values === null || values === void 0 ? void 0 : values.flowPriority);
116
+ if (fp === -1) return -1;
117
+ if (fp === 0 || fp === 1 || fp === 2) return fp;
118
+ return Number(values === null || values === void 0 ? void 0 : values.rank);
119
+ };
120
+
121
+ // ✅ for priority labels (only 0/1 unique now; 2 can be multiple)
122
+ var PRIORITY_LABEL = {
123
+ 0: "Sənəd yaradan",
124
+ 1: "Birinci baxan"
125
+ };
33
126
  var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultAgreementPlansContent() {
127
+ var _query$internalStruct;
34
128
  var _useState = useState(null),
35
129
  _useState2 = _slicedToArray(_useState, 2),
36
130
  innerW = _useState2[0],
37
131
  setInnerW = _useState2[1];
38
- var ref = useRef();
132
+
133
+ // ✅ modal ref
134
+ var modalRef = useRef();
135
+
136
+ // ✅ capture FormModal's internal antd form so we can set field errors on submit
137
+ var modalFormRef = useRef(null);
138
+
139
+ // ✅ default internalStructure init only once
140
+ var didInitInternalStructure = useRef(false);
39
141
  var dispatch = useDispatch();
40
142
  var _useState3 = useState(0),
41
143
  _useState4 = _slicedToArray(_useState3, 2),
@@ -49,6 +151,8 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
49
151
  _useState8 = _slicedToArray(_useState7, 2),
50
152
  size = _useState8[0],
51
153
  setSize = _useState8[1];
154
+
155
+ // ✅ query will get internalStructureId default after internalStructureAll loads
52
156
  var _useState9 = useState({
53
157
  name: ""
54
158
  }),
@@ -69,7 +173,6 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
69
173
  var internalStructureAll = useSelector(function (state) {
70
174
  return state.questionnaire.internalStructureAll;
71
175
  });
72
- console.log(internalStructureAll);
73
176
  var contractUsersAll = useSelector(function (state) {
74
177
  return state.employees.contractUsersAll;
75
178
  });
@@ -78,81 +181,262 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
78
181
  editingRecord = _useState12[0],
79
182
  setEditingRecord = _useState12[1];
80
183
  var paginationLength = setPaginationLength(DefaultAgreementPlans === null || DefaultAgreementPlans === void 0 ? void 0 : DefaultAgreementPlans.count, DefaultAgreementPlans === null || DefaultAgreementPlans === void 0 ? void 0 : DefaultAgreementPlans.size);
184
+
185
+ // ✅ build table data (current page)
186
+ var data = useMemo(function () {
187
+ if (!(DefaultAgreementPlans !== null && DefaultAgreementPlans !== void 0 && DefaultAgreementPlans.items)) return [];
188
+ return DefaultAgreementPlans.items.map(function (dataObj, i) {
189
+ var _dataObj$responsibleP, _dataObj$responsibleP2, _dataObj$internalStru, _dataObj$internalStru2;
190
+ return {
191
+ num: (DefaultAgreementPlans === null || DefaultAgreementPlans === void 0 ? void 0 : DefaultAgreementPlans.size) * (DefaultAgreementPlans === null || DefaultAgreementPlans === void 0 ? void 0 : DefaultAgreementPlans.page) + i + 1 - (DefaultAgreementPlans === null || DefaultAgreementPlans === void 0 ? void 0 : DefaultAgreementPlans.size),
192
+ id: dataObj === null || dataObj === void 0 ? void 0 : dataObj.id,
193
+ responsiblePerson: dataObj === null || dataObj === void 0 || (_dataObj$responsibleP = dataObj.responsiblePerson) === null || _dataObj$responsibleP === void 0 ? void 0 : _dataObj$responsibleP.fullName,
194
+ responsiblePersonId: dataObj === null || dataObj === void 0 || (_dataObj$responsibleP2 = dataObj.responsiblePerson) === null || _dataObj$responsibleP2 === void 0 ? void 0 : _dataObj$responsibleP2.id,
195
+ flowPriority: dataObj === null || dataObj === void 0 ? void 0 : dataObj.flowPriority,
196
+ rank: dataObj === null || dataObj === void 0 ? void 0 : dataObj.rank,
197
+ internalStructure: dataObj === null || dataObj === void 0 || (_dataObj$internalStru = dataObj.internalStructure) === null || _dataObj$internalStru === void 0 ? void 0 : _dataObj$internalStru.text,
198
+ internalStructureId: dataObj === null || dataObj === void 0 || (_dataObj$internalStru2 = dataObj.internalStructure) === null || _dataObj$internalStru2 === void 0 ? void 0 : _dataObj$internalStru2.id,
199
+ className: "rowClassName1"
200
+ };
201
+ });
202
+ }, [DefaultAgreementPlans]);
203
+
204
+ /**
205
+ * ✅ rows used for validation:
206
+ * - prefer DefaultAgreementPlansAll if exists (covers all pages)
207
+ * - fallback to current page `data`
208
+ */
209
+ var rowsForValidation = useMemo(function () {
210
+ var list = Array.isArray(DefaultAgreementPlansAll) && DefaultAgreementPlansAll.length ? DefaultAgreementPlansAll : data;
211
+ if (list === data) return data;
212
+ return list.map(function (item) {
213
+ var _ref, _item$flowPriority, _item$responsiblePers, _item$responsiblePers2, _item$internalStructu, _item$internalStructu2;
214
+ var rank = item === null || item === void 0 ? void 0 : item.rank;
215
+ var fp = (_ref = (_item$flowPriority = item === null || item === void 0 ? void 0 : item.flowPriority) !== null && _item$flowPriority !== void 0 ? _item$flowPriority : item === null || item === void 0 ? void 0 : item.flowpriority) !== null && _ref !== void 0 ? _ref : deriveFlowPriorityFromRank(rank);
216
+ return {
217
+ id: item === null || item === void 0 ? void 0 : item.id,
218
+ responsiblePersonId: (_item$responsiblePers = item === null || item === void 0 ? void 0 : item.responsiblePersonId) !== null && _item$responsiblePers !== void 0 ? _item$responsiblePers : item === null || item === void 0 || (_item$responsiblePers2 = item.responsiblePerson) === null || _item$responsiblePers2 === void 0 ? void 0 : _item$responsiblePers2.id,
219
+ internalStructureId: (_item$internalStructu = item === null || item === void 0 ? void 0 : item.internalStructureId) !== null && _item$internalStructu !== void 0 ? _item$internalStructu : item === null || item === void 0 || (_item$internalStructu2 = item.internalStructure) === null || _item$internalStructu2 === void 0 ? void 0 : _item$internalStructu2.id,
220
+ rank: rank,
221
+ flowPriority: fp
222
+ };
223
+ });
224
+ }, [DefaultAgreementPlansAll, data]);
225
+
226
+ // ✅ IMPORTANT: Filter should not wipe internalStructureId; merge patches into query
227
+ var setQueryMerge = useCallback(function (patchOrUpdater) {
228
+ setQuery(function (prev) {
229
+ var patch = typeof patchOrUpdater === "function" ? patchOrUpdater(prev) : patchOrUpdater;
230
+ return _objectSpread(_objectSpread({}, prev), patch || {});
231
+ });
232
+ }, []);
233
+
234
+ // ✅ top select change => set query.internalStructureId
235
+ var handleInternalStructureChange = useCallback(function (value) {
236
+ setPage(1);
237
+ setQuery(function (prev) {
238
+ return _objectSpread(_objectSpread({}, prev), {}, {
239
+ internalStructureId: value
240
+ });
241
+ });
242
+ }, []);
243
+
244
+ // ✅ set default internalStructureId = internalStructureAll[0].id (ONLY ONCE)
245
+ useEffect(function () {
246
+ var _internalStructureAll;
247
+ if (didInitInternalStructure.current) return;
248
+ var firstId = internalStructureAll === null || internalStructureAll === void 0 || (_internalStructureAll = internalStructureAll[0]) === null || _internalStructureAll === void 0 ? void 0 : _internalStructureAll.id;
249
+ if (firstId !== undefined && firstId !== null) {
250
+ didInitInternalStructure.current = true;
251
+ setPage(1);
252
+ setQuery(function (prev) {
253
+ return _objectSpread(_objectSpread({}, prev), {}, {
254
+ internalStructureId: firstId
255
+ });
256
+ });
257
+ }
258
+ }, [internalStructureAll]);
259
+
260
+ // ✅ window width once
261
+ useEffect(function () {
262
+ if (window.innerWidth >= 1900) setInnerW(210);else setInnerW(155);
263
+ }, []);
264
+
265
+ // ✅ fetch lists separately
266
+ useEffect(function () {
267
+ dispatch(getDefaultAgreementPlansAll("onlyactive"));
268
+ dispatch(getInternalStructureAll("onlyactive"));
269
+ }, [dispatch, DefaultAgreementPlansRender]);
270
+
271
+ // ✅ NOW fetch paged data ONLY when internalStructureId exists
272
+ useEffect(function () {
273
+ if ((query === null || query === void 0 ? void 0 : query.internalStructureId) === undefined || (query === null || query === void 0 ? void 0 : query.internalStructureId) === null) return;
274
+ var req = {
275
+ page: page,
276
+ size: size,
277
+ query: query,
278
+ visibility: "nondeleted"
279
+ };
280
+ dispatch(getDefaultAgreementPlans(req));
281
+ }, [dispatch, page, size, query, DefaultAgreementPlansRender]);
282
+ useEffect(function () {
283
+ dispatch(getContractUsersAll());
284
+ }, [dispatch]);
285
+
286
+ // ✅ throw helper: duplicate same person in same structure
287
+ var throwDuplicateError = useCallback(function () {
288
+ var errMsg = "Bu məsul şəxs bu struktur üçün artıq təyin olunub!";
289
+ if (modalFormRef.current) {
290
+ modalFormRef.current.setFields([{
291
+ name: "responsiblePersonId",
292
+ errors: [errMsg]
293
+ }]);
294
+ }
295
+ throw new Error(errMsg);
296
+ }, []);
297
+
298
+ // ✅ throw helper: priority already taken in this internalStructure (ONLY for 0/1 now)
299
+ var throwPriorityTakenError = useCallback(function (priority01) {
300
+ var label = (PRIORITY_LABEL === null || PRIORITY_LABEL === void 0 ? void 0 : PRIORITY_LABEL[priority01]) || "Prioritet ".concat(priority01);
301
+ var errMsg = "Bu strukturda art\u0131q \"".concat(label, "\" prioriteti t\u0259yin olunub!");
302
+ if (modalFormRef.current) {
303
+ modalFormRef.current.setFields([{
304
+ name: "flowPriority",
305
+ errors: [errMsg]
306
+ }]);
307
+ }
308
+ throw new Error(errMsg);
309
+ }, []);
310
+
311
+ // ✅ validation 1: same person cannot be in same structure twice
312
+ var hasDuplicatePersonInStructure = useCallback(function (personId, structureId, ignoreId) {
313
+ if (!personId || !structureId) return false;
314
+ var p = Number(personId);
315
+ var s = Number(structureId);
316
+ return rowsForValidation.some(function (row) {
317
+ if (ignoreId && Number(row === null || row === void 0 ? void 0 : row.id) === Number(ignoreId)) return false;
318
+ return Number(row === null || row === void 0 ? void 0 : row.responsiblePersonId) === p && Number(row === null || row === void 0 ? void 0 : row.internalStructureId) === s;
319
+ });
320
+ }, [rowsForValidation]);
321
+
322
+ /**
323
+ * ✅ validation 2 (UPDATED):
324
+ * each internalStructure can have ONLY ONE flowPriority 0/1
325
+ * ✅ flowPriority (or rank) = 2 can be MULTIPLE
326
+ * flowPriority 3 can be multiple
327
+ */
328
+ var hasPriority01TakenInStructure = useCallback(function (structureId, priority01, ignoreId) {
329
+ if (!structureId && structureId !== 0) return false;
330
+ var s = Number(structureId);
331
+ var p = Number(priority01);
332
+ if (!(p === 0 || p === 1)) return false;
333
+ return rowsForValidation.some(function (row) {
334
+ var _row$flowPriority;
335
+ if (ignoreId && Number(row === null || row === void 0 ? void 0 : row.id) === Number(ignoreId)) return false;
336
+ var rowFp = toNumSafe((_row$flowPriority = row === null || row === void 0 ? void 0 : row.flowPriority) !== null && _row$flowPriority !== void 0 ? _row$flowPriority : deriveFlowPriorityFromRank(row === null || row === void 0 ? void 0 : row.rank));
337
+ return Number(row === null || row === void 0 ? void 0 : row.internalStructureId) === s && rowFp === p;
338
+ });
339
+ }, [rowsForValidation]);
81
340
  var onSubmit = useCallback(/*#__PURE__*/function () {
82
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(data) {
341
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(values) {
342
+ var fpCandidate, internalStructureId, payload;
83
343
  return _regeneratorRuntime.wrap(function _callee$(_context) {
84
344
  while (1) switch (_context.prev = _context.next) {
85
345
  case 0:
86
- dispatch(addDefaultAgreementPlans(data));
346
+ fpCandidate = Number(values === null || values === void 0 ? void 0 : values.flowPriority);
347
+ resolveRankFromValues(values);
348
+ internalStructureId = query === null || query === void 0 ? void 0 : query.internalStructureId; // ✅ 1) block duplicate person+structure (structure comes from top select)
349
+ if (hasDuplicatePersonInStructure(values === null || values === void 0 ? void 0 : values.responsiblePersonId, internalStructureId, null)) {
350
+ throwDuplicateError();
351
+ }
352
+
353
+ // ✅ 2) block if flowPriority 0/1 already exists in this structure
354
+ if (fpCandidate === 0 || fpCandidate === 1) {
355
+ if (hasPriority01TakenInStructure(internalStructureId, fpCandidate, null)) {
356
+ throwPriorityTakenError(fpCandidate);
357
+ }
358
+ }
359
+
360
+ // ✅ inject internalStructureId from top select into payload
361
+ payload = buildPayloadFromForm(null, _objectSpread(_objectSpread({}, values), {}, {
362
+ internalStructureId: internalStructureId
363
+ }));
364
+ dispatch(addDefaultAgreementPlans(payload));
87
365
  setEditingRecord(null);
88
- case 2:
366
+ case 8:
89
367
  case "end":
90
368
  return _context.stop();
91
369
  }
92
370
  }, _callee);
93
371
  }));
94
372
  return function (_x) {
95
- return _ref.apply(this, arguments);
373
+ return _ref2.apply(this, arguments);
96
374
  };
97
- }(), [dispatch]);
98
- var onEdit = useCallback(function (id, record) {
99
- var data = {
100
- id: id,
101
- responsiblePersonId: record === null || record === void 0 ? void 0 : record.responsiblePersonId,
102
- flowPriority: record === null || record === void 0 ? void 0 : record.flowPriority,
103
- // ✅ include it for edit
104
- rank: record === null || record === void 0 ? void 0 : record.rank,
105
- internalStructureId: record === null || record === void 0 ? void 0 : record.internalStructureId
375
+ }(), [dispatch, query === null || query === void 0 ? void 0 : query.internalStructureId, hasDuplicatePersonInStructure, hasPriority01TakenInStructure, throwDuplicateError, throwPriorityTakenError]);
376
+ var onEdit = useCallback(/*#__PURE__*/function () {
377
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(editId, values) {
378
+ var fpCandidate, internalStructureId, payload;
379
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
380
+ while (1) switch (_context2.prev = _context2.next) {
381
+ case 0:
382
+ fpCandidate = Number(values === null || values === void 0 ? void 0 : values.flowPriority);
383
+ resolveRankFromValues(values);
384
+ internalStructureId = query === null || query === void 0 ? void 0 : query.internalStructureId; // ✅ 1) block duplicate person+structure (ignore self)
385
+ if (hasDuplicatePersonInStructure(values === null || values === void 0 ? void 0 : values.responsiblePersonId, internalStructureId, editId)) {
386
+ throwDuplicateError();
387
+ }
388
+
389
+ // ✅ 2) block if flowPriority 0/1 already exists in this structure (ignore self)
390
+ if (fpCandidate === 0 || fpCandidate === 1) {
391
+ if (hasPriority01TakenInStructure(internalStructureId, fpCandidate, editId)) {
392
+ throwPriorityTakenError(fpCandidate);
393
+ }
394
+ }
395
+
396
+ // ✅ inject internalStructureId from top select into payload
397
+ payload = buildPayloadFromForm(editId, _objectSpread(_objectSpread({}, values), {}, {
398
+ internalStructureId: internalStructureId
399
+ }));
400
+ dispatch(editDefaultAgreementPlans(payload));
401
+ setEditingRecord(null);
402
+ case 8:
403
+ case "end":
404
+ return _context2.stop();
405
+ }
406
+ }, _callee2);
407
+ }));
408
+ return function (_x2, _x3) {
409
+ return _ref3.apply(this, arguments);
106
410
  };
107
- dispatch(editDefaultAgreementPlans(data));
108
- setEditingRecord(null);
109
- }, [dispatch]);
411
+ }(), [dispatch, query === null || query === void 0 ? void 0 : query.internalStructureId, hasDuplicatePersonInStructure, hasPriority01TakenInStructure, throwDuplicateError, throwPriorityTakenError]);
110
412
  var closeOnViewModal = useCallback(function () {
111
413
  dispatch(setViewModalVisible(false));
112
414
  }, [dispatch]);
113
415
  var onClickModal = function onClickModal() {
114
- var _ref$current;
115
- setEditingRecord(null); // RESET
116
- ref === null || ref === void 0 || (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.open();
416
+ var _modalRef$current;
417
+ setEditingRecord(null);
418
+ modalRef === null || modalRef === void 0 || (_modalRef$current = modalRef.current) === null || _modalRef$current === void 0 || _modalRef$current.open();
117
419
  };
118
- var onEditClick = useCallback(function (data) {
119
- var _ref$current2;
120
- setEditingRecord(data); // store editing record
121
- ref === null || ref === void 0 || (_ref$current2 = ref.current) === null || _ref$current2 === void 0 || _ref$current2.setEdit(data); // keep existing modal functionality
122
- }, []);
123
- var onDelete = useCallback(function (id) {
124
- setId(id);
125
- }, []);
126
- var handleColumnToggle = function handleColumnToggle(checked, dataIndex) {
127
- setSelectedColumns(function (prevSelected) {
128
- if (checked) {
129
- return [].concat(_toConsumableArray(prevSelected), [dataIndex]);
130
- } else {
131
- return prevSelected.filter(function (col) {
132
- return col !== dataIndex;
420
+
421
+ // ✅ when clicking edit, also sync top select to that row's structure
422
+ var onEditClick = useCallback(function (row) {
423
+ var _modalRef$current2;
424
+ var normalized = normalizeForEdit(row);
425
+ var rowStructureId = normalized === null || normalized === void 0 ? void 0 : normalized.internalStructureId;
426
+ if (rowStructureId !== undefined && rowStructureId !== null && rowStructureId !== (query === null || query === void 0 ? void 0 : query.internalStructureId)) {
427
+ setPage(1);
428
+ setQuery(function (prev) {
429
+ return _objectSpread(_objectSpread({}, prev), {}, {
430
+ internalStructureId: rowStructureId
133
431
  });
134
- }
135
- });
136
- };
137
- var data = [];
138
- if (DefaultAgreementPlans !== null && DefaultAgreementPlans !== void 0 && DefaultAgreementPlans.items) {
139
- var _DefaultAgreementPlan;
140
- data = DefaultAgreementPlans === null || DefaultAgreementPlans === void 0 || (_DefaultAgreementPlan = DefaultAgreementPlans.items) === null || _DefaultAgreementPlan === void 0 ? void 0 : _DefaultAgreementPlan.map(function (dataObj, i) {
141
- var _dataObj$responsibleP, _dataObj$internalStru, _dataObj$internalStru2;
142
- return {
143
- num: (DefaultAgreementPlans === null || DefaultAgreementPlans === void 0 ? void 0 : DefaultAgreementPlans.size) * (DefaultAgreementPlans === null || DefaultAgreementPlans === void 0 ? void 0 : DefaultAgreementPlans.page) + i + 1 - (DefaultAgreementPlans === null || DefaultAgreementPlans === void 0 ? void 0 : DefaultAgreementPlans.size),
144
- id: dataObj === null || dataObj === void 0 ? void 0 : dataObj.id,
145
- responsiblePerson: dataObj === null || dataObj === void 0 ? void 0 : dataObj.responsiblePerson.fullName,
146
- responsiblePersonId: dataObj === null || dataObj === void 0 || (_dataObj$responsibleP = dataObj.responsiblePerson) === null || _dataObj$responsibleP === void 0 ? void 0 : _dataObj$responsibleP.id,
147
- flowPriority: dataObj === null || dataObj === void 0 ? void 0 : dataObj.flowPriority,
148
- // ✅ so edit modal knows what to show
149
- rank: dataObj === null || dataObj === void 0 ? void 0 : dataObj.rank,
150
- internalStructure: dataObj === null || dataObj === void 0 || (_dataObj$internalStru = dataObj.internalStructure) === null || _dataObj$internalStru === void 0 ? void 0 : _dataObj$internalStru.text,
151
- internalStructureId: dataObj === null || dataObj === void 0 || (_dataObj$internalStru2 = dataObj.internalStructure) === null || _dataObj$internalStru2 === void 0 ? void 0 : _dataObj$internalStru2.id,
152
- className: "rowClassName1"
153
- };
154
- });
155
- }
432
+ });
433
+ }
434
+ setEditingRecord(normalized);
435
+ modalRef === null || modalRef === void 0 || (_modalRef$current2 = modalRef.current) === null || _modalRef$current2 === void 0 || _modalRef$current2.setEdit(normalized);
436
+ }, [query === null || query === void 0 ? void 0 : query.internalStructureId]);
437
+ var onDelete = useCallback(function (deleteId) {
438
+ setId(deleteId);
439
+ }, []);
156
440
  var columns = useMemo(function () {
157
441
  return getStreetColumns(onEditClick, onDelete, dispatch);
158
442
  }, [onEditClick, onDelete, dispatch]);
@@ -162,37 +446,20 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
162
446
  _useState14 = _slicedToArray(_useState13, 2),
163
447
  selectedColumns = _useState14[0],
164
448
  setSelectedColumns = _useState14[1];
165
- useEffect(function () {
166
- if (window.innerWidth >= 1900) {
167
- setInnerW(210);
168
- } else {
169
- setInnerW(155);
170
- }
171
- var data = {
172
- page: page,
173
- size: size,
174
- query: query,
175
- visibility: "nondeleted"
176
- };
177
- dispatch(getDefaultAgreementPlans(data));
178
- dispatch(getDefaultAgreementPlansAll("onlyactive"));
179
- dispatch(getInternalStructureAll("onlyactive"));
180
- }, [dispatch, page, DefaultAgreementPlansRender, query, size]);
181
- useEffect(function () {
182
- dispatch(getContractUsersAll());
183
- }, [dispatch]);
449
+ var handleColumnToggle = function handleColumnToggle(checked, dataIndex) {
450
+ setSelectedColumns(function (prevSelected) {
451
+ if (checked) return [].concat(_toConsumableArray(prevSelected), [dataIndex]);
452
+ return prevSelected.filter(function (col) {
453
+ return col !== dataIndex;
454
+ });
455
+ });
456
+ };
184
457
  var updateSize = function updateSize(newSize) {
185
458
  setSize(newSize);
186
459
  Cookies.set("pagination-size-questionnaire-defaultagreementplans", JSON.stringify(newSize), {
187
460
  expires: 7
188
461
  });
189
462
  };
190
- var assignedIds = useMemo(function () {
191
- return DefaultAgreementPlansAll === null || DefaultAgreementPlansAll === void 0 ? void 0 : DefaultAgreementPlansAll.map(function (item) {
192
- var _item$responsiblePers;
193
- return (_item$responsiblePers = item.responsiblePerson) === null || _item$responsiblePers === void 0 ? void 0 : _item$responsiblePers.id;
194
- });
195
- }, [DefaultAgreementPlansAll]);
196
463
  return /*#__PURE__*/React.createElement(React.Fragment, null, loading ? /*#__PURE__*/React.createElement(Loading, null) : null, /*#__PURE__*/React.createElement(Layout, {
197
464
  className: style.layout
198
465
  }, /*#__PURE__*/React.createElement(Content, {
@@ -205,7 +472,8 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
205
472
  }, /*#__PURE__*/React.createElement(PlusIcon, null), " Soraq\xE7a \u0259lav\u0259 et"), /*#__PURE__*/React.createElement(Filter, {
206
473
  columns: columns,
207
474
  selectedColumns: selectedColumns,
208
- setQuery: setQuery,
475
+ setQuery: setQueryMerge // ✅ merge (doesn't remove internalStructureId)
476
+ ,
209
477
  disabledElementCount: 3,
210
478
  setPage: setPage
211
479
  }))), /*#__PURE__*/React.createElement(Layout, {
@@ -216,7 +484,17 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
216
484
  className: style.table_header
217
485
  }, /*#__PURE__*/React.createElement("h2", null, "\u015Eablon raz\u0131la\u015Fma sxemi"), /*#__PURE__*/React.createElement("div", {
218
486
  className: style.buttons
219
- }, /*#__PURE__*/React.createElement(ColSort, {
487
+ }, /*#__PURE__*/React.createElement(Select, {
488
+ width: 250,
489
+ size: "sm",
490
+ value: (_query$internalStruct = query === null || query === void 0 ? void 0 : query.internalStructureId) !== null && _query$internalStruct !== void 0 ? _query$internalStruct : undefined,
491
+ onChange: handleInternalStructureChange
492
+ }, internalStructureAll === null || internalStructureAll === void 0 ? void 0 : internalStructureAll.map(function (item) {
493
+ return /*#__PURE__*/React.createElement(Option, {
494
+ key: item.id,
495
+ value: item.id
496
+ }, item.name);
497
+ })), /*#__PURE__*/React.createElement(ColSort, {
220
498
  columns: columns,
221
499
  selectedColumns: selectedColumns,
222
500
  handleColumnToggle: handleColumnToggle
@@ -237,7 +515,10 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
237
515
  page: page,
238
516
  onChange: setPage
239
517
  })), /*#__PURE__*/React.createElement(FormModal, {
240
- ref: ref,
518
+ ref: modalRef,
519
+ customForm: function customForm(f) {
520
+ modalFormRef.current = f;
521
+ },
241
522
  width: 454,
242
523
  title: "Yeni soraqça yaratma",
243
524
  titleEdit: "Soraqça redaktə etmə",
@@ -248,13 +529,15 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
248
529
  className: "absolute",
249
530
  centered: false
250
531
  }, /*#__PURE__*/React.createElement(Item, {
532
+ name: "responsiblePersonId",
533
+ label: "Məsul şəxs",
251
534
  rules: [{
252
535
  required: true,
253
536
  message: ""
254
- }],
255
- name: "responsiblePersonId",
256
- label: "Məsul şəxs"
257
- }, /*#__PURE__*/React.createElement(Select, null, contractUsersAll === null || contractUsersAll === void 0 ? void 0 : contractUsersAll.map(function (item) {
537
+ }]
538
+ }, /*#__PURE__*/React.createElement(Select, {
539
+ size: "md"
540
+ }, contractUsersAll === null || contractUsersAll === void 0 ? void 0 : contractUsersAll.map(function (item) {
258
541
  return /*#__PURE__*/React.createElement(Option, {
259
542
  key: item.id,
260
543
  value: item.id
@@ -281,8 +564,8 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
281
564
  shouldUpdate: function shouldUpdate(prev, cur) {
282
565
  return prev.flowPriority !== cur.flowPriority;
283
566
  }
284
- }, function (_ref2) {
285
- var getFieldValue = _ref2.getFieldValue;
567
+ }, function (_ref4) {
568
+ var getFieldValue = _ref4.getFieldValue;
286
569
  var flowPriority = getFieldValue("flowPriority");
287
570
  if (flowPriority !== 3) return null;
288
571
  return /*#__PURE__*/React.createElement(Item, {
@@ -290,38 +573,52 @@ var QuestionnairesDefaultAgreementPlansContent = function QuestionnairesDefaultA
290
573
  name: "rank",
291
574
  label: "Qrup \u2116",
292
575
  rules: [{
293
- required: false,
576
+ required: true,
294
577
  message: ""
295
578
  }, {
296
- validator: function validator(_, value) {
297
- if (!value) return Promise.resolve();
298
- var numericValue = Number(value);
299
- if (numericValue !== 1) return Promise.resolve();
300
- var existsRank1 = DefaultAgreementPlansAll === null || DefaultAgreementPlansAll === void 0 ? void 0 : DefaultAgreementPlansAll.some(function (item) {
301
- return item.rank === 1 && (!editingRecord || item.id !== editingRecord.id);
302
- });
303
- return existsRank1 ? Promise.reject("Yalnız bir qrup 1 ola bilər!") : Promise.resolve();
304
- }
579
+ validator: function () {
580
+ var _validator = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_, value) {
581
+ var numericValue;
582
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
583
+ while (1) switch (_context3.prev = _context3.next) {
584
+ case 0:
585
+ if (!(value === undefined || value === null || value === "")) {
586
+ _context3.next = 2;
587
+ break;
588
+ }
589
+ throw new Error("");
590
+ case 2:
591
+ numericValue = Number(value);
592
+ if (!Number.isNaN(numericValue)) {
593
+ _context3.next = 5;
594
+ break;
595
+ }
596
+ throw new Error("");
597
+ case 5:
598
+ if (!(numericValue < 3)) {
599
+ _context3.next = 7;
600
+ break;
601
+ }
602
+ throw new Error("Qrup № 3-dən kiçik ola bilməz!");
603
+ case 7:
604
+ return _context3.abrupt("return", true);
605
+ case 8:
606
+ case "end":
607
+ return _context3.stop();
608
+ }
609
+ }, _callee3);
610
+ }));
611
+ function validator(_x4, _x5) {
612
+ return _validator.apply(this, arguments);
613
+ }
614
+ return validator;
615
+ }()
305
616
  }]
306
617
  }, /*#__PURE__*/React.createElement(Input, {
307
618
  type: "number",
308
619
  size: "md"
309
620
  }));
310
- }), /*#__PURE__*/React.createElement(Item, {
311
- rules: [{
312
- required: true,
313
- message: ""
314
- }],
315
- name: "internalStructureId",
316
- label: "Daxili Struktur"
317
- }, /*#__PURE__*/React.createElement(Select, {
318
- size: "md"
319
- }, internalStructureAll === null || internalStructureAll === void 0 ? void 0 : internalStructureAll.map(function (item) {
320
- return /*#__PURE__*/React.createElement(Option, {
321
- key: item.id,
322
- value: item.id
323
- }, item.name);
324
- })))), /*#__PURE__*/React.createElement(DeleteModal, {
621
+ })), /*#__PURE__*/React.createElement(DeleteModal, {
325
622
  onCancel: function onCancel() {
326
623
  return dispatch(setDeleteModalVisible(false));
327
624
  },
@@ -11,7 +11,7 @@ export var getStreetColumns = function getStreetColumns(onEditClick, onDelete, o
11
11
  ellipsis: true,
12
12
  width: 35
13
13
  }, {
14
- title: "Daxili Strukturlar",
14
+ title: "Şablon strukturlar",
15
15
  dataIndex: "name",
16
16
  width: innerW,
17
17
  disabled: true,
@@ -178,7 +178,7 @@ var QuestionnairesInternalStructureContent = function QuestionnairesInternalStru
178
178
  className: style.content
179
179
  }, /*#__PURE__*/React.createElement("div", {
180
180
  className: style.table_header
181
- }, /*#__PURE__*/React.createElement("h2", null, "Daxili Strukturlar"), /*#__PURE__*/React.createElement("div", {
181
+ }, /*#__PURE__*/React.createElement("h2", null, "\u015Eablon strukturlar"), /*#__PURE__*/React.createElement("div", {
182
182
  className: style.buttons
183
183
  }, /*#__PURE__*/React.createElement(ColSort, {
184
184
  columns: columns,
@@ -8141,7 +8141,7 @@ _defineProperty(Services, "getDefaultAgreementPlans", /*#__PURE__*/function () {
8141
8141
  while (1) switch (_context429.prev = _context429.next) {
8142
8142
  case 0:
8143
8143
  _context429.next = 2;
8144
- return api.get("/defaultagreementplans/".concat(size, "/page/").concat(page, "?visibility=").concat(visibility, "&name=").concat(query === null || query === void 0 ? void 0 : query.name));
8144
+ return api.get("/defaultagreementplans/".concat(size, "/page/").concat(page, "?visibility=").concat(visibility, "&name=").concat(query === null || query === void 0 ? void 0 : query.name, "&internalStructureId=").concat(query === null || query === void 0 ? void 0 : query.internalStructureId));
8145
8145
  case 2:
8146
8146
  response = _context429.sent;
8147
8147
  return _context429.abrupt("return", response === null || response === void 0 ? void 0 : response.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banch0u/core-project-test-repository",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "Shared core features for all projects",
5
5
  "main": "dist/index.js",
6
6
  "files": [