@isettingkit/business-rules 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,5 @@
1
- import { IInputStatus } from '@isettingkit/input';
2
1
  import { IRuleDecision } from '@isettingkit/input';
3
2
  import { JSX as JSX_2 } from 'react/jsx-runtime';
4
- import { ValueDataType } from '@isettingkit/input';
5
- import { ValueHowToSetUp } from '@isettingkit/input';
6
3
 
7
4
  export declare const BusinessRuleCard: (props: IBusinessRuleCard) => JSX_2.Element;
8
5
 
@@ -16,37 +13,10 @@ export declare interface IBusinessRuleCard {
16
13
  }
17
14
 
18
15
  export declare interface IBusinessRuleView {
19
- decision: IRuleDecision_2;
16
+ decision: IRuleDecision;
20
17
  textValues: IRulesFormTextValues;
21
18
  }
22
19
 
23
- declare interface ICondition {
24
- description: string;
25
- valueUse: (typeof ValueHowToSetUp)[keyof typeof ValueHowToSetUp];
26
- name: string;
27
- value?: string | string[] | number | IValue | undefined;
28
- dataType: (typeof ValueDataType)[keyof typeof ValueDataType];
29
- }
30
-
31
- declare interface IDecision {
32
- description: string;
33
- endDate?: Date;
34
- valueUse: (typeof ValueHowToSetUp)[keyof typeof ValueHowToSetUp];
35
- name: string;
36
- value?: string | string[] | number | IValue | undefined;
37
- startDate?: Date;
38
- dataType: (typeof ValueDataType)[keyof typeof ValueDataType];
39
- }
40
-
41
- declare interface IRuleDecision_2 {
42
- id?: string;
43
- conditions?: ICondition[];
44
- decision?: IDecision;
45
- decisions?: IDecision[];
46
- startDate?: Date;
47
- endDate?: Date;
48
- }
49
-
50
20
  export declare interface IRulesForm {
51
21
  id: string;
52
22
  decision: IRuleDecision;
@@ -74,20 +44,6 @@ declare interface IRulesFormTextValues {
74
44
  termStart: string;
75
45
  }
76
46
 
77
- declare interface IValue {
78
- list?: string[];
79
- listSelected?: string[];
80
- labelFrom?: string;
81
- labelTo?: string;
82
- from?: number | string | Date;
83
- to?: number | string | Date;
84
- value?: string | number;
85
- messageFrom?: string;
86
- messageTo?: string;
87
- statusFrom?: IInputStatus;
88
- statusTo?: IInputStatus;
89
- }
90
-
91
47
  export declare const RulesForm: (prop: IRulesForm) => JSX_2.Element;
92
48
 
93
49
  export { }
package/dist/index.es.js CHANGED
@@ -1,93 +1,93 @@
1
- import { jsxs as m, jsx as n, Fragment as j } from "react/jsx-runtime";
1
+ import { jsxs as h, jsx as n, Fragment as F } from "react/jsx-runtime";
2
2
  import { useFormik as Q } from "formik";
3
- import { useState as y, useEffect as q } from "react";
4
- import { Divider as E } from "@inubekit/divider";
3
+ import { useState as x, useEffect as P } from "react";
4
+ import { Divider as V } from "@inubekit/divider";
5
5
  import { Stack as o } from "@inubekit/stack";
6
- import { Text as x } from "@inubekit/text";
6
+ import { Text as y } from "@inubekit/text";
7
7
  import { Toggle as $ } from "@inubekit/toggle";
8
- import { ValueHowToSetUp as f, DecisionConditionRenderer as L, ValueDataType as U } from "@isettingkit/input";
9
- import { Textarea as P } from "@inubekit/textarea";
10
- import { Date as z } from "@inubekit/date";
11
- import { Checkbox as Z } from "@inubekit/checkbox";
12
- import { Button as M } from "@inubekit/button";
13
- import { object as B, string as F, number as H } from "yup";
14
- import { DecisionViewConditionRenderer as V } from "@isettingkit/view";
15
- import { MdOutlineRemoveRedEye as J, MdOutlineDelete as K } from "react-icons/md";
16
- import { Icon as I } from "@inubekit/icon";
17
- import { inube as W } from "@inubekit/foundations";
8
+ import { ValueHowToSetUp as f, ValueDataType as R, DecisionConditionRenderer as L } from "@isettingkit/input";
9
+ import { Textarea as Z } from "@inubekit/textarea";
10
+ import { Date as M } from "@inubekit/date";
11
+ import { Checkbox as J } from "@inubekit/checkbox";
12
+ import { Button as z } from "@inubekit/button";
13
+ import { object as B, string as I, number as j, mixed as H } from "yup";
14
+ import { DecisionViewConditionRenderer as A } from "@isettingkit/view";
15
+ import { MdOutlineRemoveRedEye as K, MdOutlineDelete as W } from "react-icons/md";
16
+ import { Icon as N } from "@inubekit/icon";
17
+ import { inube as X } from "@inubekit/foundations";
18
18
  import G from "styled-components";
19
- const X = (t) => {
19
+ const Y = (t) => {
20
20
  const {
21
21
  label: e,
22
22
  labelText: a,
23
23
  onHandleChange: i,
24
- placeholder: c,
25
- required: g,
26
- value: l = ""
27
- } = t, [d, b] = y(l);
28
- return /* @__PURE__ */ m(o, { direction: "column", margin: "10px 4px", children: [
29
- /* @__PURE__ */ n(x, { size: "large", appearance: "gray", weight: "bold", margin: "10px 0", children: a }),
24
+ placeholder: l,
25
+ required: s,
26
+ value: m = ""
27
+ } = t, [u, b] = x(m);
28
+ return /* @__PURE__ */ h(o, { direction: "column", margin: "10px 4px", children: [
29
+ /* @__PURE__ */ n(y, { size: "large", appearance: "gray", weight: "bold", margin: "10px 0", children: a }),
30
30
  /* @__PURE__ */ n(o, { margin: "10px 0", children: /* @__PURE__ */ n(
31
- P,
31
+ Z,
32
32
  {
33
33
  id: "reasonChange",
34
34
  label: e,
35
- onChange: (p) => {
36
- b(p.target.value), i(p);
35
+ onChange: (g) => {
36
+ b(g.target.value), i(g);
37
37
  },
38
- placeholder: c,
39
- required: g,
40
- value: d,
38
+ placeholder: l,
39
+ required: s,
40
+ value: u,
41
41
  maxLength: 120,
42
42
  fullwidth: !0
43
43
  }
44
44
  ) })
45
45
  ] });
46
- }, Y = (t) => {
46
+ }, ee = (t) => {
47
47
  const {
48
48
  checked: e,
49
49
  children: a,
50
50
  handleToggleChange: i,
51
- id: c,
52
- labelToggle: g,
53
- name: l,
54
- valueToggle: d = ""
55
- } = t, [b, C] = y(e), p = (v) => {
51
+ id: l,
52
+ labelToggle: s,
53
+ name: m,
54
+ valueToggle: u = ""
55
+ } = t, [b, C] = x(e), g = (v) => {
56
56
  C(v.target.checked), i(v);
57
57
  };
58
- return q(() => {
58
+ return P(() => {
59
59
  C(e);
60
- }, [e]), /* @__PURE__ */ m(j, { children: [
60
+ }, [e]), /* @__PURE__ */ h(F, { children: [
61
61
  /* @__PURE__ */ n(o, { children: /* @__PURE__ */ n(
62
62
  $,
63
63
  {
64
64
  checked: b,
65
- id: c,
65
+ id: l,
66
66
  margin: "10px",
67
- name: l,
68
- onChange: p,
67
+ name: m,
68
+ onChange: g,
69
69
  size: "small",
70
- value: d,
71
- children: /* @__PURE__ */ n(x, { size: "medium", type: "label", weight: "bold", children: g })
70
+ value: u,
71
+ children: /* @__PURE__ */ n(y, { size: "medium", type: "label", weight: "bold", children: s })
72
72
  }
73
73
  ) }),
74
- b && /* @__PURE__ */ n(j, { children: a })
74
+ b && /* @__PURE__ */ n(F, { children: a })
75
75
  ] });
76
- }, ee = (t) => {
76
+ }, ne = (t) => {
77
77
  const {
78
78
  onHandleStartChange: e,
79
79
  onHandleEndChange: a,
80
80
  labelStart: i,
81
- labelEnd: c,
82
- checkedClosed: g = !1,
83
- required: l = !1,
84
- valueStart: d = "",
81
+ labelEnd: l,
82
+ checkedClosed: s = !1,
83
+ required: m = !1,
84
+ valueStart: u = "",
85
85
  valueEnd: b = ""
86
- } = t, [C, p] = y(g), [v, k] = y(d), [T, D] = y(b);
87
- return /* @__PURE__ */ m(j, { children: [
88
- /* @__PURE__ */ m(o, { direction: "row", justifyContent: "space-between", margin: "10px 0", children: [
86
+ } = t, [C, g] = x(s), [v, E] = x(u), [D, T] = x(b);
87
+ return /* @__PURE__ */ h(F, { children: [
88
+ /* @__PURE__ */ h(o, { direction: "row", justifyContent: "space-between", margin: "10px 0", children: [
89
89
  /* @__PURE__ */ n(o, { children: /* @__PURE__ */ n(
90
- x,
90
+ y,
91
91
  {
92
92
  appearance: "gray",
93
93
  margin: "10px 0",
@@ -105,11 +105,11 @@ const X = (t) => {
105
105
  wrap: "wrap",
106
106
  gap: "4px",
107
107
  children: /* @__PURE__ */ n(
108
- Z,
108
+ J,
109
109
  {
110
110
  label: "Cerrada",
111
- onChange: ({ target: s }) => {
112
- p(s.checked);
111
+ onChange: ({ target: d }) => {
112
+ g(d.checked);
113
113
  },
114
114
  checked: C,
115
115
  value: ""
@@ -118,138 +118,157 @@ const X = (t) => {
118
118
  }
119
119
  )
120
120
  ] }),
121
- /* @__PURE__ */ m(o, { justifyContent: "space-between", gap: "24px", children: [
121
+ /* @__PURE__ */ h(o, { justifyContent: "space-between", gap: "24px", children: [
122
122
  /* @__PURE__ */ n(o, { width: "189px", children: /* @__PURE__ */ n(
123
- z,
123
+ M,
124
124
  {
125
125
  id: "dateStart",
126
126
  label: i,
127
- onChange: (s) => {
128
- k(s.target.value), e(s);
127
+ onChange: (d) => {
128
+ E(d.target.value), e(d);
129
129
  },
130
130
  value: v,
131
- required: l,
131
+ required: m,
132
132
  size: "compact"
133
133
  }
134
134
  ) }),
135
135
  C && /* @__PURE__ */ n(o, { width: "189px", children: /* @__PURE__ */ n(
136
- z,
136
+ M,
137
137
  {
138
138
  id: "dateEnd",
139
- label: c,
140
- onChange: (s) => {
141
- D(s.target.value), a(s);
139
+ label: l,
140
+ onChange: (d) => {
141
+ T(d.target.value), a(d);
142
142
  },
143
- value: T,
144
- required: l,
143
+ value: D,
144
+ required: m,
145
145
  size: "compact"
146
146
  }
147
147
  ) })
148
148
  ] })
149
149
  ] });
150
- }, N = (t) => {
151
- var c;
152
- const e = t.possibleValue, a = typeof (e == null ? void 0 : e.rangeFrom) == "number" ? e.rangeFrom : 0, i = typeof (e == null ? void 0 : e.rangeTo) == "number" ? e.rangeTo : 1 / 0;
153
- switch (t.howToSetUp) {
154
- case f.LIST_OF_VALUES:
155
- return {
156
- schema: F(),
157
- value: (c = e.listSelected) == null ? void 0 : c[0]
158
- };
159
- case f.LIST_OF_VALUES_MULTI:
160
- return {
161
- schema: F(),
162
- value: ""
163
- };
164
- case f.RANGE:
165
- return {
166
- schema: B({
167
- rangeFrom: H().required("Range From is required").max(
168
- i,
169
- "'Range From' cannot be greater than 'Range To'"
170
- ).min(0, "'Range From' cannot be less than 0"),
171
- rangeTo: H().required("Range To is required").min(a, "'Range To' cannot be less than 'Range From'").min(0, "'Range To' cannot be less than 0")
172
- }),
173
- value: {
174
- rangeFrom: a,
175
- rangeTo: i
176
- }
177
- };
178
- case f.GREATER_THAN:
179
- case f.LESS_THAN:
180
- case f.EQUAL:
181
- return {
182
- schema: F().required("Required"),
183
- value: e.value
184
- };
185
- default:
186
- return {
187
- schema: F(),
188
- value: void 0
189
- };
150
+ }, _ = (t) => {
151
+ if ("value" in t && "valueUse" in t && t.value !== void 0) {
152
+ const e = t.value, a = typeof e == "object" && "from" in e && typeof e.from == "number" ? e.from : 0, i = typeof e == "object" && "to" in e && typeof e.to == "number" ? e.to : 1 / 0;
153
+ switch (t.valueUse) {
154
+ case f.LIST_OF_VALUES:
155
+ return {
156
+ schema: H().test(
157
+ "isArrayOrString",
158
+ "Must be an array of strings/numbers or a single string",
159
+ (l) => Array.isArray(l) ? l.every(
160
+ (s) => typeof s == "string" || typeof s == "number"
161
+ ) : typeof l == "string"
162
+ ),
163
+ value: e
164
+ };
165
+ case f.LIST_OF_VALUES_MULTI:
166
+ return {
167
+ schema: H().test(
168
+ "isArrayOrString",
169
+ "Must be an array of strings/numbers or a single string",
170
+ (l) => Array.isArray(l) ? l.every(
171
+ (s) => typeof s == "string" || typeof s == "number"
172
+ ) : typeof l == "string"
173
+ ),
174
+ value: e
175
+ };
176
+ case f.RANGE:
177
+ return {
178
+ schema: B({
179
+ from: j().required("Range From is required").max(i, "'Range From' cannot be greater than 'Range To'").min(0, "'Range From' cannot be less than 0"),
180
+ to: j().required("Range To is required").min(a, "'Range To' cannot be less than 'Range From'").min(0, "'Range To' cannot be less than 0")
181
+ }),
182
+ value: {
183
+ from: a,
184
+ to: i
185
+ }
186
+ };
187
+ case f.GREATER_THAN:
188
+ case f.LESS_THAN:
189
+ case f.EQUAL:
190
+ return t.dataType === R.PERCENTAGE ? {
191
+ schema: j().required("Percentage is required").min(0, "Percentage cannot be less than 0").max(100, "Percentage cannot be greater than 100"),
192
+ value: e
193
+ } : {
194
+ schema: I().required("Required"),
195
+ value: e
196
+ };
197
+ default:
198
+ return {
199
+ schema: I(),
200
+ value: void 0
201
+ };
202
+ }
190
203
  }
191
- }, ne = (t) => {
204
+ }, te = (t) => {
192
205
  const e = {}, a = {};
193
- if (t.decision) {
194
- const i = N(t.decision);
195
- i && (e[t.decision.name] = i.schema, a[t.decision.name] = i.value);
206
+ if (t) {
207
+ const i = _(t);
208
+ i && (e[t.name] = i.schema, a[t.name] = i.value);
196
209
  }
197
210
  return t.conditions && t.conditions.forEach((i) => {
198
- const c = N(i);
199
- c && (e[i.name] = c.schema, a[i.name] = c.value);
211
+ const l = _(i);
212
+ l && (e[i.name] = l.schema, a[i.name] = l.value);
200
213
  }), { validationSchema: B().shape(e), initialValues: a };
201
- }, R = (t) => {
214
+ }, U = (t) => {
202
215
  if (typeof t == "string")
203
216
  return t;
204
- if (typeof t == "object" && ("rangeFrom" in t || "rangeTo" in t))
217
+ if (typeof t == "object" && ("from" in t || "to" in t))
205
218
  return {
206
- rangeFrom: t.rangeFrom || "",
207
- rangeTo: t.rangeTo || ""
219
+ from: t.from || "",
220
+ to: t.to || ""
208
221
  };
209
222
  for (const e in t)
210
223
  if (Object.prototype.hasOwnProperty.call(t, e)) {
211
- const a = R(t[e]);
224
+ const a = U(t[e]);
212
225
  if (a) return a;
213
226
  }
214
227
  return "";
215
- }, te = (t) => {
216
- var s;
228
+ }, ae = (t) => {
229
+ var S;
217
230
  const {
218
231
  decision: e,
219
232
  formik: a,
220
233
  onChangeCondition: i,
221
- onChangeDecision: c,
222
- onStartChange: g,
223
- onEndChange: l,
224
- textValues: d,
234
+ onChangeDecision: l,
235
+ onStartChange: s,
236
+ onEndChange: m,
237
+ textValues: u,
225
238
  onCancel: b,
226
239
  onSubmit: C
227
- } = t, [p, v] = y(!1), [k, T] = y(!0);
228
- q(() => {
240
+ } = t, [g, v] = x(!1), [E, D] = x(!0), T = {
241
+ name: e.name,
242
+ dataType: e.dataType,
243
+ value: e.value,
244
+ valueUse: e.valueUse,
245
+ possibleValue: e.possibleValue
246
+ };
247
+ P(() => {
229
248
  console.log("Updated formik.errors in RulesFormUI:", a.errors);
230
249
  }, [a.errors]);
231
- const D = (r) => {
250
+ const w = (r) => {
232
251
  v(r.target.checked);
233
- }, w = (r) => {
234
- r.target.value ? T(!1) : T(!0);
235
- }, S = (r) => {
236
- const h = R(a.errors[r] || {});
237
- return typeof h == "string" ? h ? "invalid" : "pending" : h;
238
- }, u = (r) => {
239
- const h = R(a.errors[r] || {});
240
- return h;
252
+ }, k = (r) => {
253
+ r.target.value ? D(!1) : D(!0);
254
+ }, c = (r) => {
255
+ const p = U(a.errors[r] || {});
256
+ return typeof p == "string" ? p ? "invalid" : "pending" : p;
257
+ }, d = (r) => {
258
+ const p = U(a.errors[r] || {});
259
+ return p;
241
260
  };
242
- return /* @__PURE__ */ m(o, { direction: "column", gap: "24px", children: [
243
- /* @__PURE__ */ m(o, { direction: "column", gap: "16", children: [
244
- /* @__PURE__ */ n(x, { weight: "bold", size: "medium", children: d.criteria }),
245
- e.decision && /* @__PURE__ */ n(
261
+ return /* @__PURE__ */ h(o, { direction: "column", gap: "24px", children: [
262
+ /* @__PURE__ */ h(o, { direction: "column", gap: "16", children: [
263
+ /* @__PURE__ */ n(y, { weight: "bold", size: "medium", children: u.criteria }),
264
+ e && /* @__PURE__ */ n(
246
265
  L,
247
266
  {
248
- element: e.decision,
249
- onDecision: c,
250
- valueData: a.values[e.decision.name],
251
- message: a.errors[e.decision.name],
252
- status: S(e.decision.name),
267
+ element: T,
268
+ onDecision: l,
269
+ valueData: a.values[e.name],
270
+ message: a.errors[e.name],
271
+ status: c(e.name),
253
272
  textValues: {
254
273
  selectOptions: "Select an option",
255
274
  selectOption: "Option selected",
@@ -259,31 +278,31 @@ const X = (t) => {
259
278
  }
260
279
  )
261
280
  ] }),
262
- /* @__PURE__ */ n(E, { dashed: !0 }),
263
- /* @__PURE__ */ m(o, { direction: "column", children: [
264
- /* @__PURE__ */ m(o, { direction: "row", gap: "16px", justifyContent: "space-between", children: [
265
- /* @__PURE__ */ n(x, { children: d.factsThatConditionIt }),
281
+ /* @__PURE__ */ n(V, { dashed: !0 }),
282
+ /* @__PURE__ */ h(o, { direction: "column", children: [
283
+ /* @__PURE__ */ h(o, { direction: "row", gap: "16px", justifyContent: "space-between", children: [
284
+ /* @__PURE__ */ n(y, { children: u.factsThatConditionIt }),
266
285
  /* @__PURE__ */ n(
267
286
  $,
268
287
  {
269
288
  id: "toogleNone",
270
- onChange: D,
271
- checked: p,
289
+ onChange: w,
290
+ checked: g,
272
291
  size: "small",
273
- children: /* @__PURE__ */ n(x, { size: "medium", type: "label", weight: "bold", children: d.none })
292
+ children: /* @__PURE__ */ n(y, { size: "medium", type: "label", weight: "bold", children: u.none })
274
293
  }
275
294
  )
276
295
  ] }),
277
296
  e.conditions && e.conditions.map((r) => /* @__PURE__ */ n(o, { direction: "column", children: /* @__PURE__ */ n(
278
- Y,
297
+ ee,
279
298
  {
280
- checked: !p,
281
- handleToggleChange: (h) => {
282
- h.target.checked || i(
299
+ checked: !g,
300
+ handleToggleChange: (p) => {
301
+ p.target.checked || i(
283
302
  {
284
303
  value: "",
285
- rangeTo: 0,
286
- rangeFrom: 0,
304
+ to: 0,
305
+ from: 0,
287
306
  list: r.possibleValue.list
288
307
  },
289
308
  r.name
@@ -298,110 +317,114 @@ const X = (t) => {
298
317
  element: r,
299
318
  onDecision: i,
300
319
  valueData: a.values[r.name],
301
- message: u(r.name),
302
- status: S(r.name),
320
+ message: d(r.name),
321
+ status: c(r.name),
303
322
  textValues: {
304
323
  selectOptions: "Select an option",
305
324
  selectOption: "Option selected",
306
- rangeMin: (h) => `Minimum ${h}`,
307
- rangeMax: (h) => `Maximum ${h}`
325
+ rangeMin: (p) => `Minimum ${p}`,
326
+ rangeMax: (p) => `Maximum ${p}`
308
327
  }
309
328
  }
310
329
  )
311
330
  }
312
331
  ) }, r.name))
313
332
  ] }),
314
- /* @__PURE__ */ n(E, { dashed: !0 }),
333
+ /* @__PURE__ */ n(V, { dashed: !0 }),
315
334
  /* @__PURE__ */ n(o, { direction: "column", children: /* @__PURE__ */ n(
316
- X,
335
+ Y,
317
336
  {
318
- label: d.reasonForChange,
319
- labelText: d.change,
320
- onHandleChange: w,
321
- placeholder: d.changePlaceholder,
337
+ label: u.reasonForChange,
338
+ labelText: u.change,
339
+ onHandleChange: k,
340
+ placeholder: u.changePlaceholder,
322
341
  required: !0
323
342
  }
324
343
  ) }),
325
- /* @__PURE__ */ n(E, { dashed: !0 }),
326
- /* @__PURE__ */ n(o, { direction: "column", children: e.decision && /* @__PURE__ */ n(
327
- ee,
344
+ /* @__PURE__ */ n(V, { dashed: !0 }),
345
+ /* @__PURE__ */ n(o, { direction: "column", children: e && /* @__PURE__ */ n(
346
+ ne,
328
347
  {
329
- onHandleStartChange: (r) => g(r.target.value),
330
- onHandleEndChange: (r) => l(r.target.value),
331
- labelStart: d.termStart,
332
- labelEnd: d.termEnd,
333
- checkedClosed: !!e.decision.endDate,
334
- valueStart: e.decision.startDate.toLocaleDateString(
335
- "en-CA"
336
- ),
337
- valueEnd: ((s = e.decision.endDate) == null ? void 0 : s.toLocaleDateString("en-CA")) || ""
348
+ onHandleStartChange: (r) => s(r.target.value),
349
+ onHandleEndChange: (r) => m(r.target.value),
350
+ labelStart: u.termStart,
351
+ labelEnd: u.termEnd,
352
+ checkedClosed: !!e.endDate,
353
+ valueStart: e.startDate.toLocaleDateString("en-CA"),
354
+ valueEnd: ((S = e.endDate) == null ? void 0 : S.toLocaleDateString("en-CA")) || ""
338
355
  }
339
356
  ) }),
340
- /* @__PURE__ */ n(E, { dashed: !0 }),
341
- /* @__PURE__ */ m(o, { direction: "row", justifyContent: "end", gap: "16px", children: [
342
- /* @__PURE__ */ n(M, { appearance: "gray", onClick: b, children: d.cancel }),
357
+ /* @__PURE__ */ n(V, { dashed: !0 }),
358
+ /* @__PURE__ */ h(o, { direction: "row", justifyContent: "end", gap: "16px", children: [
359
+ /* @__PURE__ */ n(z, { appearance: "gray", onClick: b, children: u.cancel }),
343
360
  /* @__PURE__ */ n(
344
- M,
361
+ z,
345
362
  {
346
363
  onClick: C,
347
- disabled: k || !a.isValid,
364
+ disabled: E || !a.isValid,
348
365
  type: "submit",
349
- children: d.confirm
366
+ children: u.confirm
350
367
  }
351
368
  )
352
369
  ] })
353
370
  ] });
354
- }, Se = (t) => {
355
- const { id: e, decision: a, onCancel: i, onSubmitEvent: c, textValues: g } = t, [l, d] = y(a), b = (u, s) => {
356
- w.setFieldValue(u, s), w.validateField(u);
357
- }, C = (u, s) => {
358
- d((r) => {
359
- var A;
360
- const h = (A = r == null ? void 0 : r.conditions) == null ? void 0 : A.map((O) => O.name === s ? { ...O, value: u } : O);
361
- return b(s, u), { ...r, conditions: h };
362
- });
363
- }, p = (u) => {
364
- d(
365
- (s) => S(s, "value", u)
366
- );
367
- }, v = (u) => {
368
- d(
369
- (s) => S(s, "endDate", new Date(u))
371
+ }, Te = (t) => {
372
+ const { id: e, decision: a, onCancel: i, onSubmitEvent: l, textValues: s } = t, [m, u] = x(a), b = (c, d) => {
373
+ w.setFieldValue(c, d), w.validateField(c);
374
+ }, C = (c, d) => {
375
+ const S = c instanceof Date ? c.toISOString() : c;
376
+ u((r) => {
377
+ if (!r.conditions)
378
+ return r;
379
+ const p = r.conditions.map((O) => O.name === d ? { ...O, value: S } : O);
380
+ return {
381
+ ...r,
382
+ conditions: p
383
+ };
384
+ }), b(d, S);
385
+ }, g = (c) => {
386
+ typeof c == "object" && (c instanceof Date || "someProperty" in c) ? u(
387
+ (d) => k(d, "value", c)
388
+ ) : console.warn("Invalid type for value:", c);
389
+ }, v = (c) => {
390
+ u(
391
+ (d) => k(d, "endDate", new Date(c))
370
392
  );
371
- }, k = (u) => {
372
- d(
373
- (s) => S(s, "startDate", new Date(u))
393
+ }, E = (c) => {
394
+ u(
395
+ (d) => k(d, "startDate", new Date(c))
374
396
  );
375
- }, { validationSchema: T, initialValues: D } = ne(l);
376
- T.validate(D, { abortEarly: !1 }).then(() => console.log("Validation passed")).catch((u) => console.log("Validation failed:", u.errors));
397
+ }, { validationSchema: D, initialValues: T } = te(m);
398
+ D.validate(T, { abortEarly: !1 }).then(() => console.log("Validation passed")).catch((c) => console.log("Validation failed:", c.errors));
377
399
  const w = Q({
378
- initialValues: D,
379
- validationSchema: T,
400
+ initialValues: T,
401
+ validationSchema: D,
380
402
  validateOnChange: !0,
381
403
  validateOnBlur: !0,
382
404
  onSubmit: () => {
383
- c(l);
405
+ l(m);
384
406
  }
385
- }), S = (u, s, r) => ({
386
- ...u,
387
- decision: { ...u.decision, [s]: r }
407
+ }), k = (c, d, S) => ({
408
+ ...c,
409
+ ...c.decision,
410
+ [d]: S
388
411
  });
389
412
  return /* @__PURE__ */ n(
390
- te,
413
+ ae,
391
414
  {
392
415
  id: e,
393
416
  formik: w,
394
- decision: l,
417
+ decision: m,
395
418
  onCancel: i,
396
- onSubmit: () => c(l),
419
+ onSubmit: () => l(m),
397
420
  onChangeCondition: C,
398
- onChangeDecision: p,
399
- onStartChange: k,
421
+ onChangeDecision: g,
422
+ onStartChange: E,
400
423
  onEndChange: v,
401
- textValues: g
424
+ textValues: s
402
425
  }
403
426
  );
404
- }, _ = (t) => {
427
+ }, q = (t) => {
405
428
  if (!t)
406
429
  return;
407
430
  const e = t.value;
@@ -422,80 +445,84 @@ const X = (t) => {
422
445
  return e.value;
423
446
  }
424
447
  return e;
425
- }, De = (t) => {
426
- var c, g;
427
- const { decision: e, textValues: a } = t, i = (l) => l && Object.keys(l).length > 0;
428
- return /* @__PURE__ */ m(o, { direction: "column", gap: "24px", children: [
429
- /* @__PURE__ */ m(o, { direction: "column", gap: "16px", children: [
430
- /* @__PURE__ */ n(x, { type: "title", size: "medium", appearance: "gray", weight: "bold", children: a.criteria }),
431
- /* @__PURE__ */ n(o, { justifyContent: "space-between", children: e.decision && /* @__PURE__ */ n(o, { direction: "column", children: /* @__PURE__ */ n(
432
- V,
448
+ }, we = (t) => {
449
+ const { decision: e, textValues: a } = t, i = (s) => s && Object.keys(s).length > 0, l = {
450
+ name: e.name,
451
+ dataType: e.dataType,
452
+ value: e.value,
453
+ valueUse: e.valueUse
454
+ };
455
+ return /* @__PURE__ */ h(o, { direction: "column", gap: "24px", children: [
456
+ /* @__PURE__ */ h(o, { direction: "column", gap: "16px", children: [
457
+ /* @__PURE__ */ n(y, { type: "title", size: "medium", appearance: "gray", weight: "bold", children: a.criteria }),
458
+ /* @__PURE__ */ n(o, { justifyContent: "space-between", children: e && /* @__PURE__ */ n(o, { direction: "column", children: /* @__PURE__ */ n(
459
+ A,
433
460
  {
434
- element: e.decision,
435
- valueData: _(e.decision)
461
+ element: l,
462
+ valueData: q(l)
436
463
  }
437
- ) }, e.decision.name) })
464
+ ) }, e.name) })
438
465
  ] }),
439
- /* @__PURE__ */ m(o, { direction: "column", gap: "16px", justifyContent: "space-between", children: [
440
- /* @__PURE__ */ n(x, { type: "title", size: "medium", appearance: "gray", weight: "bold", children: a.factsThatConditionIt }),
441
- e.conditions && e.conditions.map(
442
- (l) => (console.log("condition: ", l), (typeof l.value == "object" && i(l.value) || l.value) && /* @__PURE__ */ n(o, { direction: "column", children: /* @__PURE__ */ n(
443
- V,
466
+ /* @__PURE__ */ h(o, { direction: "column", gap: "16px", justifyContent: "space-between", children: [
467
+ /* @__PURE__ */ n(y, { type: "title", size: "medium", appearance: "gray", weight: "bold", children: a.factsThatConditionIt }),
468
+ e.conditions && e.conditions.map((s) => {
469
+ const m = s.value;
470
+ return (typeof m == "object" && i(m) || m) && /* @__PURE__ */ n(o, { direction: "column", children: /* @__PURE__ */ n(
471
+ A,
444
472
  {
445
- element: l,
446
- valueData: _(l)
473
+ element: {
474
+ ...s,
475
+ value: m
476
+ },
477
+ valueData: q(s)
447
478
  }
448
- ) }, l.name))
449
- )
479
+ ) }, s.name);
480
+ })
450
481
  ] }),
451
- /* @__PURE__ */ m(o, { direction: "column", gap: "12px", children: [
452
- /* @__PURE__ */ n(x, { type: "title", size: "medium", appearance: "gray", weight: "bold", children: a.terms }),
453
- /* @__PURE__ */ m(o, { justifyContent: "space-between", children: [
454
- ((c = e == null ? void 0 : e.decision) == null ? void 0 : c.startDate) && /* @__PURE__ */ n(
455
- V,
482
+ /* @__PURE__ */ h(o, { direction: "column", gap: "12px", children: [
483
+ /* @__PURE__ */ n(y, { type: "title", size: "medium", appearance: "gray", weight: "bold", children: a.terms }),
484
+ /* @__PURE__ */ h(o, { justifyContent: "space-between", children: [
485
+ (e == null ? void 0 : e.startDate) && /* @__PURE__ */ n(
486
+ A,
456
487
  {
457
488
  element: {
458
489
  name: "Fecha de inicio",
459
- description: a.termStart,
460
490
  value: String(e.startDate),
461
491
  valueUse: f.EQUAL,
462
- dataType: U.DATE
492
+ dataType: R.DATE
463
493
  },
464
- valueData: new Date(
465
- e.decision.startDate
466
- ).toLocaleDateString("en-CA")
494
+ valueData: new Date(e.startDate).toLocaleDateString(
495
+ "en-CA"
496
+ )
467
497
  },
468
498
  "startDate"
469
499
  ),
470
- ((g = e == null ? void 0 : e.decision) == null ? void 0 : g.endDate) && /* @__PURE__ */ n(
471
- V,
500
+ (e == null ? void 0 : e.endDate) && /* @__PURE__ */ n(
501
+ A,
472
502
  {
473
503
  element: {
474
504
  name: "Fecha de final",
475
- description: a.termEnd,
476
505
  value: String(e.endDate),
477
506
  valueUse: f.EQUAL,
478
- dataType: U.DATE
507
+ dataType: R.DATE
479
508
  },
480
- valueData: new Date(e.decision.endDate).toLocaleDateString(
481
- "en-CA"
482
- )
509
+ valueData: new Date(e.endDate).toLocaleDateString("en-CA")
483
510
  },
484
511
  "endDate"
485
512
  )
486
513
  ] })
487
514
  ] })
488
515
  ] });
489
- }, ae = G.div`
516
+ }, re = G.div`
490
517
  border-radius: 8px;
491
- border: 1px solid ${W.palette.neutral.N30};
518
+ border: 1px solid ${X.palette.neutral.N30};
492
519
  box-sizing: border-box;
493
520
  display: flex;
494
521
  flex-direction: column;
495
522
  height: 340px;
496
523
  width: 332px;
497
524
  box-shadow: 0px 4px 8px 3px rgba(0, 0, 0, 0.1);
498
- `, re = G.div`
525
+ `, oe = G.div`
499
526
  width: 100%;
500
527
  height: 100%;
501
528
  overflow-y: auto;
@@ -513,34 +540,34 @@ const X = (t) => {
513
540
  background-color: #ebecf0;
514
541
  border-radius: 8px;
515
542
  }
516
- `, we = (t) => {
517
- const { children: e, handleDelete: a, handleView: i, id: c } = t;
518
- return /* @__PURE__ */ m(ae, { children: [
519
- /* @__PURE__ */ n(o, { height: "282px", gap: "24px", direction: "column", children: /* @__PURE__ */ n(re, { children: /* @__PURE__ */ n(o, { direction: "column", margin: "10px", children: e }) }) }),
520
- /* @__PURE__ */ m(o, { gap: "16px", direction: "column", margin: "2px 12px", children: [
521
- /* @__PURE__ */ n(E, {}),
522
- /* @__PURE__ */ m(o, { gap: "16px", justifyContent: "end", children: [
543
+ `, ke = (t) => {
544
+ const { children: e, handleDelete: a, handleView: i, id: l } = t;
545
+ return /* @__PURE__ */ h(re, { children: [
546
+ /* @__PURE__ */ n(o, { height: "282px", gap: "24px", direction: "column", children: /* @__PURE__ */ n(oe, { children: /* @__PURE__ */ n(o, { direction: "column", margin: "10px", children: e }) }) }),
547
+ /* @__PURE__ */ h(o, { gap: "16px", direction: "column", margin: "2px 12px", children: [
548
+ /* @__PURE__ */ n(V, {}),
549
+ /* @__PURE__ */ h(o, { gap: "16px", justifyContent: "end", children: [
523
550
  /* @__PURE__ */ n(
524
- I,
551
+ N,
525
552
  {
526
553
  appearance: "dark",
527
554
  size: "24px",
528
555
  cursorHover: !0,
529
- icon: /* @__PURE__ */ n(J, {}),
556
+ icon: /* @__PURE__ */ n(K, {}),
530
557
  onClick: () => {
531
- i(c);
558
+ i(l);
532
559
  }
533
560
  }
534
561
  ),
535
562
  /* @__PURE__ */ n(
536
- I,
563
+ N,
537
564
  {
538
565
  cursorHover: !0,
539
566
  appearance: "dark",
540
567
  size: "24px",
541
- icon: /* @__PURE__ */ n(K, {}),
568
+ icon: /* @__PURE__ */ n(W, {}),
542
569
  onClick: () => {
543
- a(c);
570
+ a(l);
544
571
  }
545
572
  }
546
573
  )
@@ -549,7 +576,7 @@ const X = (t) => {
549
576
  ] });
550
577
  };
551
578
  export {
552
- we as BusinessRuleCard,
553
- De as BusinessRuleView,
554
- Se as RulesForm
579
+ ke as BusinessRuleCard,
580
+ we as BusinessRuleView,
581
+ Te as RulesForm
555
582
  };
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "description": "",
12
12
  "private": false,
13
- "version": "0.1.12",
13
+ "version": "0.1.14",
14
14
  "type": "module",
15
15
  "exports": {
16
16
  ".": {
@@ -38,8 +38,8 @@
38
38
  "dependencies": {
39
39
  "@inubekit/button": "^4.44.1",
40
40
  "@inubekit/checkbox": "^0.2.2",
41
- "@inubekit/divider": "^0.16.1",
42
41
  "@inubekit/date": "^2.39.1",
42
+ "@inubekit/divider": "^0.16.1",
43
43
  "@inubekit/foundations": "^5.11.3",
44
44
  "@inubekit/grid": "^2.14.1",
45
45
  "@inubekit/icon": "^2.18.1",
@@ -48,15 +48,15 @@
48
48
  "@inubekit/text": "^2.17.0",
49
49
  "@inubekit/textarea": "^2.45.0",
50
50
  "@inubekit/toggle": "^3.8.2",
51
- "@isettingkit/input": "^0.1.21",
52
- "@isettingkit/view": "^0.1.12"
51
+ "@isettingkit/input": "^0.1.23",
52
+ "@isettingkit/view": "^0.1.13"
53
53
  },
54
54
  "peerDependencies": {
55
+ "formik": "^2.4.6",
55
56
  "react": "^18.2.0",
56
57
  "react-dom": "^18.2.0",
57
58
  "react-icons": "^5.0.1",
58
59
  "styled-components": "^6.1.8",
59
- "formik": "^2.4.6",
60
60
  "yup": "^1.4.0"
61
61
  },
62
62
  "publishConfig": {
@@ -87,7 +87,6 @@
87
87
  "husky": "^8.0.3",
88
88
  "lint-staged": "^15.2.0",
89
89
  "prettier": "^3.1.1",
90
- "storybook": "^8.0.2",
91
90
  "typescript": "^5.2.2",
92
91
  "vite": "^5.0.8",
93
92
  "vite-plugin-dts": "^3.7.2"