@zauru-sdk/components 1.0.53 → 1.0.60

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 (94) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/LICENCE.md +11 -11
  3. package/package.json +7 -7
  4. package/src/Alerts/ErrorBoundaryAlert/ErrorBoundaryAlert.tsx +66 -66
  5. package/src/Alerts/StaticAlert.tsx +121 -121
  6. package/src/Alerts/index.ts +2 -2
  7. package/src/BlockUI/BlockUI.tsx +50 -50
  8. package/src/BlockUI/index.tsx +1 -1
  9. package/src/Buttons/Button.tsx +90 -90
  10. package/src/Buttons/index.ts +1 -1
  11. package/src/Card/Card.tsx +24 -24
  12. package/src/Card/index.ts +1 -1
  13. package/src/Chat/ChatLayout.tsx +131 -131
  14. package/src/Chat/ChatMessageHistory.tsx +142 -142
  15. package/src/Chat/index.ts +2 -2
  16. package/src/ConnectionState/ConnectionState.tsx +27 -27
  17. package/src/ConnectionState/index.tsx +1 -1
  18. package/src/Containers/BodyContainer.tsx +14 -14
  19. package/src/Containers/ButtonSectionContainer.tsx +21 -21
  20. package/src/Containers/Container.tsx +39 -39
  21. package/src/Containers/DoubleContainer.tsx +48 -48
  22. package/src/Containers/MainContainer.tsx +17 -17
  23. package/src/Containers/OutletContainer.tsx +14 -14
  24. package/src/Containers/SubContainer.tsx +37 -37
  25. package/src/Containers/index.ts +7 -7
  26. package/src/DynamicTable/BasicPrintDynamicTable.tsx +73 -73
  27. package/src/DynamicTable/DynamicPrintTable.tsx +288 -288
  28. package/src/DynamicTable/DynamicTable.tsx +405 -405
  29. package/src/DynamicTable/GenericDynamicTable.tsx +456 -456
  30. package/src/DynamicTable/index.tsx +4 -4
  31. package/src/Footer/Footer.tsx +50 -50
  32. package/src/Footer/index.tsx +1 -1
  33. package/src/Form/Checkbox/index.tsx +96 -96
  34. package/src/Form/Checklist/index.tsx +35 -35
  35. package/src/Form/DatePicker/index.tsx +132 -132
  36. package/src/Form/DynamicBaculoForm/index.tsx +361 -361
  37. package/src/Form/FieldContainer/DoubleFieldContainer.tsx +35 -35
  38. package/src/Form/FieldContainer/QuadrupleFieldContainer.tsx +36 -36
  39. package/src/Form/FieldContainer/TripleFieldContainer.tsx +35 -35
  40. package/src/Form/FieldContainer/index.ts +3 -3
  41. package/src/Form/FileUpload/index.tsx +184 -184
  42. package/src/Form/FormButtons/index.tsx +78 -78
  43. package/src/Form/FormLayout/index.tsx +37 -37
  44. package/src/Form/SelectField/index.tsx +237 -237
  45. package/src/Form/TextArea/index.tsx +125 -125
  46. package/src/Form/TextField/index.tsx +194 -194
  47. package/src/Form/TimePicker/index.tsx +127 -127
  48. package/src/Form/YesNo/index.tsx +77 -77
  49. package/src/Form/index.ts +13 -13
  50. package/src/Labels/InfoLabel/index.tsx +21 -21
  51. package/src/Labels/index.tsx +1 -1
  52. package/src/Layouts/homeLayout/index.tsx +34 -34
  53. package/src/Layouts/index.ts +1 -1
  54. package/src/LineSeparator/LineSeparator.tsx +3 -3
  55. package/src/LineSeparator/index.tsx +1 -1
  56. package/src/Modal/Modal.tsx +104 -104
  57. package/src/Modal/index.tsx +1 -1
  58. package/src/NavBar/NavBar.tsx +223 -223
  59. package/src/NavBar/NavBar.types.ts +64 -64
  60. package/src/NavBar/NavBar.utils.ts +58 -58
  61. package/src/NavBar/index.tsx +5 -5
  62. package/src/ProgressBar/ProgressBar.tsx +25 -25
  63. package/src/ProgressBar/ProgressCircle.tsx +75 -75
  64. package/src/ProgressBar/index.tsx +2 -2
  65. package/src/Skeletons/LoadingInputSkeleton.tsx +12 -12
  66. package/src/Skeletons/index.ts +1 -1
  67. package/src/Tab/Tab.tsx +63 -63
  68. package/src/Tab/index.ts +1 -1
  69. package/src/Table/ZauruTable.tsx +265 -265
  70. package/src/Table/index.tsx +1 -1
  71. package/src/TaskList/TaskList.tsx +88 -88
  72. package/src/TaskList/index.ts +1 -1
  73. package/src/Titles/LabelArray.tsx +17 -17
  74. package/src/Titles/TableColumnTitle.tsx +9 -9
  75. package/src/Titles/TitleH1.tsx +10 -10
  76. package/src/Titles/TitleH2.tsx +10 -10
  77. package/src/Titles/TitleH3.tsx +10 -10
  78. package/src/Titles/index.ts +5 -5
  79. package/src/Tooltip/Tooltip.tsx +42 -42
  80. package/src/Tooltip/index.ts +1 -1
  81. package/src/WithTooltip/WithTooltip.tsx +21 -21
  82. package/src/WithTooltip/index.tsx +1 -1
  83. package/src/Wizards/StepWizard.tsx +88 -88
  84. package/src/Wizards/index.ts +1 -1
  85. package/src/Zendesk/Chat.tsx +83 -83
  86. package/src/Zendesk/index.ts +2 -2
  87. package/src/Zendesk/zendesk.config.ts +40 -40
  88. package/src/index.ts +24 -24
  89. package/src/postcss.config.mjs +5 -5
  90. package/src/tailwind.config.ts +10 -10
  91. package/src/tailwind.css +3 -3
  92. package/tsconfig.cjs.json +8 -8
  93. package/tsconfig.esm.json +11 -11
  94. package/tsconfig.json +17 -17
@@ -1,361 +1,361 @@
1
- import { TextField, TextFieldWithoutValidation } from "../TextField/index.js";
2
- import { TripleFieldContainer } from "../FieldContainer/index.js";
3
- import { DoubleFieldContainer } from "../FieldContainer/index.js";
4
- import { YesNo } from "../YesNo/index.js";
5
- import { TextArea } from "../TextArea/index.js";
6
- import { SelectField } from "../SelectField/index.js";
7
- import { FileUploadField } from "../FileUpload/index.js";
8
- import { FormDatePicker } from "../DatePicker/index.js";
9
- import { FormTimePicker } from "../TimePicker/index.js";
10
- import {
11
- FormFieldGraphQL,
12
- FormGraphQL,
13
- FormSubmissionValueGraphQL,
14
- GenericDynamicTableColumn,
15
- SelectFieldOption,
16
- } from "@zauru-sdk/types";
17
- import { GenericDynamicTable } from "../../DynamicTable/GenericDynamicTable.js";
18
- import { getDepSelectOptions, getMunSelectOptions } from "@zauru-sdk/common";
19
- import { StaticAlert } from "../../Alerts/index.js";
20
- import { SubContainer } from "../../Containers/index.js";
21
- import { LineSeparator } from "../../LineSeparator/index.js";
22
-
23
- type Props = {
24
- formName?: string;
25
- form?: FormGraphQL;
26
- options?: { showTitle: boolean; showDescription: boolean };
27
- defaultValues?: FormSubmissionValueGraphQL[];
28
- namesStr?: string;
29
- showingRules?: { name: string; show: boolean }[];
30
- readOnly?: boolean;
31
- };
32
-
33
- export function DynamicBaculoForm(props: Props) {
34
- const {
35
- form,
36
- options = { showDescription: false, showTitle: false },
37
- formName = "",
38
- namesStr = "",
39
- defaultValues = [],
40
- showingRules = [],
41
- readOnly = false,
42
- } = props;
43
-
44
- if (!form) {
45
- return (
46
- <StaticAlert
47
- title="No se encontró el formulario dinámico"
48
- description={`Ocurrió un error encontrando el formulario para ${formName}, contacte al administrador con este mensaje de error.`}
49
- type="info"
50
- />
51
- );
52
- }
53
-
54
- const renderFieldComponent = (field: Partial<FormFieldGraphQL>) => {
55
- const defaultValue = defaultValues?.find(
56
- (x) => x.settings_form_field.print_var_name === field.print_var_name
57
- );
58
- switch (field.field_type) {
59
- case "fixed_rows_table":
60
- case "fixed_columns_table": {
61
- const columns: GenericDynamicTableColumn[] =
62
- field.settings_form_field_table_headers?.map((x) => {
63
- return {
64
- label: x.name,
65
- name: `${namesStr}${x.id}_${field.id}`,
66
- type: x.cell_type === "yes_no" ? "checkbox" : "textField",
67
- } as GenericDynamicTableColumn;
68
- }) ?? [];
69
- return (
70
- <SubContainer key={field.id} title={field.name}>
71
- <GenericDynamicTable name="fixed_columns_table" columns={columns} />
72
- </SubContainer>
73
- );
74
- }
75
- case "zauru_data":
76
- return (
77
- <TextFieldWithoutValidation
78
- key={field.id}
79
- title={`${field.required ? "*" : ""}${field.name}`}
80
- hint={field.hint}
81
- defaultValue={defaultValue?.value ?? field.default_value}
82
- disabled={true}
83
- />
84
- );
85
- case "hour":
86
- return (
87
- <FormTimePicker
88
- key={field.id}
89
- title={`${field.required ? "*" : ""}${field.name}`}
90
- name={`${namesStr}${field.form_id}_${field.id}`}
91
- hint={field.hint}
92
- disabled={readOnly}
93
- defaultValue={defaultValue?.value}
94
- />
95
- );
96
- case "date":
97
- return (
98
- <FormDatePicker
99
- key={field.id}
100
- title={`${field.required ? "*" : ""}${field.name}`}
101
- name={`${namesStr}${field.form_id}_${field.id}`}
102
- hint={field.hint}
103
- disabled={readOnly}
104
- defaultValue={defaultValue?.value}
105
- />
106
- );
107
- case "file":
108
- return (
109
- <FileUploadField
110
- key={field.id}
111
- title={`${field.required ? "*" : ""}${field.name}`}
112
- name={`${namesStr}${field.form_id}_${field.id}`}
113
- hint={field.hint}
114
- disabled={readOnly}
115
- defaultValue={defaultValue?.value}
116
- download={true}
117
- />
118
- );
119
- case "image":
120
- return (
121
- <FileUploadField
122
- key={field.id}
123
- title={`${field.required ? "*" : ""}${field.name}`}
124
- name={`${namesStr}${field.form_id}_${field.id}`}
125
- hint={field.hint}
126
- showAvailableTypes
127
- fileTypes={["png", "jpg", "jpeg"]}
128
- disabled={readOnly}
129
- defaultValue={defaultValue?.value}
130
- />
131
- );
132
- case "pdf":
133
- return (
134
- <FileUploadField
135
- key={field.id}
136
- title={`${field.required ? "*" : ""}${field.name}`}
137
- name={`${namesStr}${field.form_id}_${field.id}`}
138
- hint={field.hint}
139
- showAvailableTypes
140
- fileTypes={["pdf"]}
141
- disabled={readOnly}
142
- defaultValue={defaultValue?.value}
143
- download={true}
144
- />
145
- );
146
- case "email":
147
- case "url":
148
- case "text":
149
- case "currency":
150
- case "country":
151
- return (
152
- <TextField
153
- key={field.id}
154
- title={`${field.required ? "*" : ""}${field.name}`}
155
- name={`${namesStr}${field.form_id}_${field.id}`}
156
- hint={field.hint}
157
- defaultValue={defaultValue?.value ?? field.default_value}
158
- disabled={readOnly}
159
- />
160
- );
161
- case "percentage":
162
- case "number":
163
- return (
164
- <TextField
165
- key={field.id}
166
- title={`${field.required ? "*" : ""}${field.name}`}
167
- name={`${namesStr}${field.form_id}_${field.id}`}
168
- hint={field.hint}
169
- defaultValue={defaultValue?.value ?? field.default_value}
170
- type="number"
171
- disabled={readOnly}
172
- />
173
- );
174
- case "yes_no":
175
- return (
176
- <YesNo
177
- key={field.id}
178
- title={`${field.required ? "*" : ""}${field.name}`}
179
- name={`${namesStr}${field.form_id}_${field.id}`}
180
- disabled={readOnly}
181
- defaultValue={
182
- field.default_value === "true" || defaultValue?.value === "true"
183
- }
184
- />
185
- );
186
- case "section":
187
- return (
188
- <div key={field.id}>
189
- <LineSeparator />
190
- <h3 className="mb-10 text-3xl font-bold leading-8 text-gray-900">
191
- {field.name}
192
- </h3>
193
- </div>
194
- );
195
- case "multi_line_text":
196
- return (
197
- <TextArea
198
- key={field.id}
199
- title={`${field.required ? "*" : ""}${field.name}`}
200
- name={`${namesStr}${field.form_id}_${field.id}`}
201
- defaultValue={defaultValue?.value ?? field.default_value}
202
- hint={field.hint}
203
- disabled={readOnly}
204
- />
205
- );
206
- case "gt_departamentos": {
207
- const optionsDep = getDepSelectOptions();
208
- return (
209
- <SelectField
210
- key={field.id}
211
- title={`${field.required ? "*" : ""}${field.name}`}
212
- name={`${namesStr}${field.form_id}_${field.id}`}
213
- hint={field.hint}
214
- isClearable={!field.required}
215
- options={optionsDep}
216
- disabled={readOnly}
217
- defaultValue={optionsDep.find(
218
- (x) => x.value === defaultValue?.value
219
- )}
220
- />
221
- );
222
- }
223
- case "gt_municipios": {
224
- const options = getMunSelectOptions();
225
-
226
- return (
227
- <SelectField
228
- key={field.id}
229
- title={`${field.required ? "*" : ""}${field.name}`}
230
- name={`${namesStr}${field.form_id}_${field.id}`}
231
- hint={field.hint}
232
- isClearable={!field.required}
233
- options={options}
234
- disabled={readOnly}
235
- defaultValue={options.find((x) => x.value === defaultValue?.value)}
236
- />
237
- );
238
- }
239
- case "single_select_options": {
240
- const formFieldOptions =
241
- field.settings_form_field_options?.map((x) => {
242
- return { label: x.label, value: x.value } as SelectFieldOption;
243
- }) ?? [];
244
-
245
- return (
246
- <SelectField
247
- key={field.id}
248
- title={`${field.required ? "*" : ""}${field.name}`}
249
- name={`${namesStr}${field.form_id}_${field.id}`}
250
- hint={field.hint}
251
- isClearable={!field.required}
252
- options={formFieldOptions}
253
- disabled={readOnly}
254
- defaultValue={formFieldOptions.find(
255
- (x) => x.value === defaultValue?.value
256
- )}
257
- />
258
- );
259
- }
260
- case "multi_select_options": {
261
- const formFieldOptions2 =
262
- field.settings_form_field_options?.map((x) => {
263
- return { label: x.label, value: x.value } as SelectFieldOption;
264
- }) ?? [];
265
-
266
- const defaultValuesMulti = (() => {
267
- const values =
268
- defaultValue?.value?.split(",").map((str) => str.trim()) ?? [];
269
- return formFieldOptions2.filter((x) => values.includes(x.value));
270
- })();
271
-
272
- return (
273
- <SelectField
274
- key={field.id}
275
- title={`${field.required ? "*" : ""}${field.name}`}
276
- name={`${namesStr}${field.form_id}_${field.id}`}
277
- hint={field.hint}
278
- isClearable={!field.required}
279
- isMulti
280
- options={formFieldOptions2}
281
- defaultValueMulti={defaultValuesMulti}
282
- disabled={readOnly}
283
- />
284
- );
285
- }
286
- default:
287
- return (
288
- <div key={field.id}>
289
- Componente no encontrado para: {field.field_type}
290
- </div>
291
- ); // o algún componente por defecto si lo prefieres
292
- }
293
- };
294
-
295
- const renderFields = () => {
296
- const fields = form.settings_form_fields;
297
- const fieldGroups: JSX.Element[] = [];
298
- let tempGroup: JSX.Element[] = [];
299
-
300
- fields.forEach((field, i) => {
301
- const rule = showingRules.find((x) => x.name === field.name);
302
- if (!(rule && !rule.show)) {
303
- const renderedField = renderFieldComponent(field);
304
- if (renderedField === null) {
305
- return;
306
- }
307
- tempGroup.push(renderedField);
308
-
309
- const isLastField = i === fields.length - 1;
310
- const isSectionField = field.field_type === "section";
311
-
312
- if (isSectionField) {
313
- tempGroup.pop();
314
- if (tempGroup.length === 1) {
315
- fieldGroups.push(tempGroup[0]);
316
- } else if (tempGroup.length === 2) {
317
- fieldGroups.push(
318
- <DoubleFieldContainer key={i}>{tempGroup}</DoubleFieldContainer>
319
- );
320
- } else if (tempGroup.length === 3) {
321
- fieldGroups.push(
322
- <TripleFieldContainer key={i}>{tempGroup}</TripleFieldContainer>
323
- );
324
- }
325
- fieldGroups.push(renderedField);
326
- tempGroup = [];
327
- } else if (isLastField) {
328
- if (tempGroup.length === 1) {
329
- fieldGroups.push(tempGroup[0]);
330
- } else if (tempGroup.length === 2) {
331
- fieldGroups.push(
332
- <DoubleFieldContainer key={i}>{tempGroup}</DoubleFieldContainer>
333
- );
334
- } else if (tempGroup.length === 3) {
335
- fieldGroups.push(
336
- <TripleFieldContainer key={i}>{tempGroup}</TripleFieldContainer>
337
- );
338
- }
339
- tempGroup = [];
340
- } else if (tempGroup.length === 3) {
341
- // Si hay 3 elementos en el grupo temporal y el siguiente campo no es 'section', se agrega a fieldGroups
342
- fieldGroups.push(
343
- <TripleFieldContainer key={i}>{tempGroup}</TripleFieldContainer>
344
- );
345
- tempGroup = [];
346
- }
347
- }
348
- });
349
-
350
- return fieldGroups;
351
- };
352
-
353
- return (
354
- <SubContainer
355
- title={options?.showTitle ? form.name : undefined}
356
- description={options?.showDescription ? form.description : undefined}
357
- >
358
- {renderFields()}
359
- </SubContainer>
360
- );
361
- }
1
+ import { TextField, TextFieldWithoutValidation } from "../TextField/index.js";
2
+ import { TripleFieldContainer } from "../FieldContainer/index.js";
3
+ import { DoubleFieldContainer } from "../FieldContainer/index.js";
4
+ import { YesNo } from "../YesNo/index.js";
5
+ import { TextArea } from "../TextArea/index.js";
6
+ import { SelectField } from "../SelectField/index.js";
7
+ import { FileUploadField } from "../FileUpload/index.js";
8
+ import { FormDatePicker } from "../DatePicker/index.js";
9
+ import { FormTimePicker } from "../TimePicker/index.js";
10
+ import {
11
+ FormFieldGraphQL,
12
+ FormGraphQL,
13
+ FormSubmissionValueGraphQL,
14
+ GenericDynamicTableColumn,
15
+ SelectFieldOption,
16
+ } from "@zauru-sdk/types";
17
+ import { GenericDynamicTable } from "../../DynamicTable/GenericDynamicTable.js";
18
+ import { getDepSelectOptions, getMunSelectOptions } from "@zauru-sdk/common";
19
+ import { StaticAlert } from "../../Alerts/index.js";
20
+ import { SubContainer } from "../../Containers/index.js";
21
+ import { LineSeparator } from "../../LineSeparator/index.js";
22
+
23
+ type Props = {
24
+ formName?: string;
25
+ form?: FormGraphQL;
26
+ options?: { showTitle: boolean; showDescription: boolean };
27
+ defaultValues?: FormSubmissionValueGraphQL[];
28
+ namesStr?: string;
29
+ showingRules?: { name: string; show: boolean }[];
30
+ readOnly?: boolean;
31
+ };
32
+
33
+ export function DynamicBaculoForm(props: Props) {
34
+ const {
35
+ form,
36
+ options = { showDescription: false, showTitle: false },
37
+ formName = "",
38
+ namesStr = "",
39
+ defaultValues = [],
40
+ showingRules = [],
41
+ readOnly = false,
42
+ } = props;
43
+
44
+ if (!form) {
45
+ return (
46
+ <StaticAlert
47
+ title="No se encontró el formulario dinámico"
48
+ description={`Ocurrió un error encontrando el formulario para ${formName}, contacte al administrador con este mensaje de error.`}
49
+ type="info"
50
+ />
51
+ );
52
+ }
53
+
54
+ const renderFieldComponent = (field: Partial<FormFieldGraphQL>) => {
55
+ const defaultValue = defaultValues?.find(
56
+ (x) => x.settings_form_field.print_var_name === field.print_var_name
57
+ );
58
+ switch (field.field_type) {
59
+ case "fixed_rows_table":
60
+ case "fixed_columns_table": {
61
+ const columns: GenericDynamicTableColumn[] =
62
+ field.settings_form_field_table_headers?.map((x) => {
63
+ return {
64
+ label: x.name,
65
+ name: `${namesStr}${x.id}_${field.id}`,
66
+ type: x.cell_type === "yes_no" ? "checkbox" : "textField",
67
+ } as GenericDynamicTableColumn;
68
+ }) ?? [];
69
+ return (
70
+ <SubContainer key={field.id} title={field.name}>
71
+ <GenericDynamicTable name="fixed_columns_table" columns={columns} />
72
+ </SubContainer>
73
+ );
74
+ }
75
+ case "zauru_data":
76
+ return (
77
+ <TextFieldWithoutValidation
78
+ key={field.id}
79
+ title={`${field.required ? "*" : ""}${field.name}`}
80
+ hint={field.hint}
81
+ defaultValue={defaultValue?.value ?? field.default_value}
82
+ disabled={true}
83
+ />
84
+ );
85
+ case "hour":
86
+ return (
87
+ <FormTimePicker
88
+ key={field.id}
89
+ title={`${field.required ? "*" : ""}${field.name}`}
90
+ name={`${namesStr}${field.form_id}_${field.id}`}
91
+ hint={field.hint}
92
+ disabled={readOnly}
93
+ defaultValue={defaultValue?.value}
94
+ />
95
+ );
96
+ case "date":
97
+ return (
98
+ <FormDatePicker
99
+ key={field.id}
100
+ title={`${field.required ? "*" : ""}${field.name}`}
101
+ name={`${namesStr}${field.form_id}_${field.id}`}
102
+ hint={field.hint}
103
+ disabled={readOnly}
104
+ defaultValue={defaultValue?.value}
105
+ />
106
+ );
107
+ case "file":
108
+ return (
109
+ <FileUploadField
110
+ key={field.id}
111
+ title={`${field.required ? "*" : ""}${field.name}`}
112
+ name={`${namesStr}${field.form_id}_${field.id}`}
113
+ hint={field.hint}
114
+ disabled={readOnly}
115
+ defaultValue={defaultValue?.value}
116
+ download={true}
117
+ />
118
+ );
119
+ case "image":
120
+ return (
121
+ <FileUploadField
122
+ key={field.id}
123
+ title={`${field.required ? "*" : ""}${field.name}`}
124
+ name={`${namesStr}${field.form_id}_${field.id}`}
125
+ hint={field.hint}
126
+ showAvailableTypes
127
+ fileTypes={["png", "jpg", "jpeg"]}
128
+ disabled={readOnly}
129
+ defaultValue={defaultValue?.value}
130
+ />
131
+ );
132
+ case "pdf":
133
+ return (
134
+ <FileUploadField
135
+ key={field.id}
136
+ title={`${field.required ? "*" : ""}${field.name}`}
137
+ name={`${namesStr}${field.form_id}_${field.id}`}
138
+ hint={field.hint}
139
+ showAvailableTypes
140
+ fileTypes={["pdf"]}
141
+ disabled={readOnly}
142
+ defaultValue={defaultValue?.value}
143
+ download={true}
144
+ />
145
+ );
146
+ case "email":
147
+ case "url":
148
+ case "text":
149
+ case "currency":
150
+ case "country":
151
+ return (
152
+ <TextField
153
+ key={field.id}
154
+ title={`${field.required ? "*" : ""}${field.name}`}
155
+ name={`${namesStr}${field.form_id}_${field.id}`}
156
+ hint={field.hint}
157
+ defaultValue={defaultValue?.value ?? field.default_value}
158
+ disabled={readOnly}
159
+ />
160
+ );
161
+ case "percentage":
162
+ case "number":
163
+ return (
164
+ <TextField
165
+ key={field.id}
166
+ title={`${field.required ? "*" : ""}${field.name}`}
167
+ name={`${namesStr}${field.form_id}_${field.id}`}
168
+ hint={field.hint}
169
+ defaultValue={defaultValue?.value ?? field.default_value}
170
+ type="number"
171
+ disabled={readOnly}
172
+ />
173
+ );
174
+ case "yes_no":
175
+ return (
176
+ <YesNo
177
+ key={field.id}
178
+ title={`${field.required ? "*" : ""}${field.name}`}
179
+ name={`${namesStr}${field.form_id}_${field.id}`}
180
+ disabled={readOnly}
181
+ defaultValue={
182
+ field.default_value === "true" || defaultValue?.value === "true"
183
+ }
184
+ />
185
+ );
186
+ case "section":
187
+ return (
188
+ <div key={field.id}>
189
+ <LineSeparator />
190
+ <h3 className="mb-10 text-3xl font-bold leading-8 text-gray-900">
191
+ {field.name}
192
+ </h3>
193
+ </div>
194
+ );
195
+ case "multi_line_text":
196
+ return (
197
+ <TextArea
198
+ key={field.id}
199
+ title={`${field.required ? "*" : ""}${field.name}`}
200
+ name={`${namesStr}${field.form_id}_${field.id}`}
201
+ defaultValue={defaultValue?.value ?? field.default_value}
202
+ hint={field.hint}
203
+ disabled={readOnly}
204
+ />
205
+ );
206
+ case "gt_departamentos": {
207
+ const optionsDep = getDepSelectOptions();
208
+ return (
209
+ <SelectField
210
+ key={field.id}
211
+ title={`${field.required ? "*" : ""}${field.name}`}
212
+ name={`${namesStr}${field.form_id}_${field.id}`}
213
+ hint={field.hint}
214
+ isClearable={!field.required}
215
+ options={optionsDep}
216
+ disabled={readOnly}
217
+ defaultValue={optionsDep.find(
218
+ (x) => x.value === defaultValue?.value
219
+ )}
220
+ />
221
+ );
222
+ }
223
+ case "gt_municipios": {
224
+ const options = getMunSelectOptions();
225
+
226
+ return (
227
+ <SelectField
228
+ key={field.id}
229
+ title={`${field.required ? "*" : ""}${field.name}`}
230
+ name={`${namesStr}${field.form_id}_${field.id}`}
231
+ hint={field.hint}
232
+ isClearable={!field.required}
233
+ options={options}
234
+ disabled={readOnly}
235
+ defaultValue={options.find((x) => x.value === defaultValue?.value)}
236
+ />
237
+ );
238
+ }
239
+ case "single_select_options": {
240
+ const formFieldOptions =
241
+ field.settings_form_field_options?.map((x) => {
242
+ return { label: x.label, value: x.value } as SelectFieldOption;
243
+ }) ?? [];
244
+
245
+ return (
246
+ <SelectField
247
+ key={field.id}
248
+ title={`${field.required ? "*" : ""}${field.name}`}
249
+ name={`${namesStr}${field.form_id}_${field.id}`}
250
+ hint={field.hint}
251
+ isClearable={!field.required}
252
+ options={formFieldOptions}
253
+ disabled={readOnly}
254
+ defaultValue={formFieldOptions.find(
255
+ (x) => x.value === defaultValue?.value
256
+ )}
257
+ />
258
+ );
259
+ }
260
+ case "multi_select_options": {
261
+ const formFieldOptions2 =
262
+ field.settings_form_field_options?.map((x) => {
263
+ return { label: x.label, value: x.value } as SelectFieldOption;
264
+ }) ?? [];
265
+
266
+ const defaultValuesMulti = (() => {
267
+ const values =
268
+ defaultValue?.value?.split(",").map((str) => str.trim()) ?? [];
269
+ return formFieldOptions2.filter((x) => values.includes(x.value));
270
+ })();
271
+
272
+ return (
273
+ <SelectField
274
+ key={field.id}
275
+ title={`${field.required ? "*" : ""}${field.name}`}
276
+ name={`${namesStr}${field.form_id}_${field.id}`}
277
+ hint={field.hint}
278
+ isClearable={!field.required}
279
+ isMulti
280
+ options={formFieldOptions2}
281
+ defaultValueMulti={defaultValuesMulti}
282
+ disabled={readOnly}
283
+ />
284
+ );
285
+ }
286
+ default:
287
+ return (
288
+ <div key={field.id}>
289
+ Componente no encontrado para: {field.field_type}
290
+ </div>
291
+ ); // o algún componente por defecto si lo prefieres
292
+ }
293
+ };
294
+
295
+ const renderFields = () => {
296
+ const fields = form.settings_form_fields;
297
+ const fieldGroups: JSX.Element[] = [];
298
+ let tempGroup: JSX.Element[] = [];
299
+
300
+ fields.forEach((field, i) => {
301
+ const rule = showingRules.find((x) => x.name === field.name);
302
+ if (!(rule && !rule.show)) {
303
+ const renderedField = renderFieldComponent(field);
304
+ if (renderedField === null) {
305
+ return;
306
+ }
307
+ tempGroup.push(renderedField);
308
+
309
+ const isLastField = i === fields.length - 1;
310
+ const isSectionField = field.field_type === "section";
311
+
312
+ if (isSectionField) {
313
+ tempGroup.pop();
314
+ if (tempGroup.length === 1) {
315
+ fieldGroups.push(tempGroup[0]);
316
+ } else if (tempGroup.length === 2) {
317
+ fieldGroups.push(
318
+ <DoubleFieldContainer key={i}>{tempGroup}</DoubleFieldContainer>
319
+ );
320
+ } else if (tempGroup.length === 3) {
321
+ fieldGroups.push(
322
+ <TripleFieldContainer key={i}>{tempGroup}</TripleFieldContainer>
323
+ );
324
+ }
325
+ fieldGroups.push(renderedField);
326
+ tempGroup = [];
327
+ } else if (isLastField) {
328
+ if (tempGroup.length === 1) {
329
+ fieldGroups.push(tempGroup[0]);
330
+ } else if (tempGroup.length === 2) {
331
+ fieldGroups.push(
332
+ <DoubleFieldContainer key={i}>{tempGroup}</DoubleFieldContainer>
333
+ );
334
+ } else if (tempGroup.length === 3) {
335
+ fieldGroups.push(
336
+ <TripleFieldContainer key={i}>{tempGroup}</TripleFieldContainer>
337
+ );
338
+ }
339
+ tempGroup = [];
340
+ } else if (tempGroup.length === 3) {
341
+ // Si hay 3 elementos en el grupo temporal y el siguiente campo no es 'section', se agrega a fieldGroups
342
+ fieldGroups.push(
343
+ <TripleFieldContainer key={i}>{tempGroup}</TripleFieldContainer>
344
+ );
345
+ tempGroup = [];
346
+ }
347
+ }
348
+ });
349
+
350
+ return fieldGroups;
351
+ };
352
+
353
+ return (
354
+ <SubContainer
355
+ title={options?.showTitle ? form.name : undefined}
356
+ description={options?.showDescription ? form.description : undefined}
357
+ >
358
+ {renderFields()}
359
+ </SubContainer>
360
+ );
361
+ }