@m4l/components 9.3.16-JT19092025.beta.1 → 9.3.17
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.
- package/components/Stepper/Stepper.styles.js +1 -6
- package/components/Stepper/hooks/useStepperActions/index.js +3 -21
- package/components/Stepper/subcomponents/StepArea/index.js +0 -4
- package/components/Stepper/subcomponents/StepperButtons/StepperCancelButton/index.d.ts +1 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperCancelButton/index.js +6 -39
- package/components/Stepper/subcomponents/StepperButtons/StepperNextButton/index.d.ts +1 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperNextButton/index.js +3 -5
- package/components/Stepper/subcomponents/StepperButtons/StepperPrevButton/index.d.ts +1 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperPrevButton/index.js +3 -5
- package/components/Stepper/subcomponents/StepperButtons/StepperSubmitButton/index.d.ts +1 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperSubmitButton/index.js +3 -5
- package/components/Stepper/subcomponents/StepperFooter/subcomponents/StepperFooterRightActions/index.js +9 -17
- package/components/Stepper/types.d.ts +0 -7
- package/components/areas/icons.js +1 -1
- package/components/hook-form/RHFAutocomplete/RHFAutocomplete.js +3 -35
- package/components/hook-form/RHFAutocomplete/types.d.ts +1 -6
- package/components/hook-form/RHFormContext/index.d.ts +1 -1
- package/components/hook-form/RHFormContext/index.js +4 -29
- package/components/index.d.ts +1 -0
- package/components/mui_extended/Autocomplete/Autocomplete.js +12 -6
- package/components/mui_extended/Autocomplete/Autocomplete.styles.js +48 -5
- package/components/mui_extended/Autocomplete/hooks/useEndAdornments.d.ts +1 -0
- package/components/mui_extended/Autocomplete/hooks/useEndAdornments.js +4 -3
- package/components/mui_extended/Autocomplete/hooks/useStartAdornments.js +4 -4
- package/components/mui_extended/Autocomplete/hooks/useValuesAndHandlers.js +39 -4
- package/components/mui_extended/Autocomplete/slots/AutocompleteEnum.d.ts +3 -1
- package/components/mui_extended/Autocomplete/slots/AutocompleteEnum.js +2 -0
- package/components/mui_extended/Autocomplete/slots/AutocompleteSlots.d.ts +6 -0
- package/components/mui_extended/Autocomplete/slots/AutocompleteSlots.js +11 -1
- package/components/mui_extended/Autocomplete/types.d.ts +1 -1
- package/components/mui_extended/Button/ButtonStyles.js +3 -6
- package/components/mui_extended/Popper/Popper.js +9 -2
- package/components/mui_extended/Popper/types.d.ts +1 -0
- package/components/mui_extended/Select/Select.js +17 -10
- package/components/mui_extended/Select/Select.styles.js +17 -10
- package/components/mui_extended/Select/types.d.ts +1 -1
- package/components/mui_extended/TextField/TextField.d.ts +2 -1
- package/components/mui_extended/TextField/TextField.js +25 -4
- package/components/mui_extended/TextField/TextField.styles.js +132 -125
- package/components/mui_extended/TextField/slots/TextFieldSlots.d.ts +3 -9
- package/components/mui_extended/TextField/slots/TextFieldSlots.js +2 -1
- package/components/mui_extended/Typography/Typography.js +1 -1
- package/package.json +1 -1
- package/test/mocks/dictionary-mock.d.ts +433 -0
- package/components/Stepper/hooks/useDynamicValidation/index.d.ts +0 -9
- package/components/Stepper/hooks/useDynamicValidation/index.js +0 -57
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock compartido para el endpoint domain/dictionaries
|
|
3
|
+
* Puede ser reutilizado en diferentes contextos: Storybook, Cypress, Jest, etc.
|
|
4
|
+
*/
|
|
5
|
+
export interface DictionaryMockData {
|
|
6
|
+
data: {
|
|
7
|
+
accordion_basic_information: string;
|
|
8
|
+
accordion_contact_data: string;
|
|
9
|
+
grid_action_add: string;
|
|
10
|
+
label_active: string;
|
|
11
|
+
label_created_at: string;
|
|
12
|
+
label_email: string;
|
|
13
|
+
label_first_name: string;
|
|
14
|
+
label_first_phone: string;
|
|
15
|
+
label_id: string;
|
|
16
|
+
label_last_name: string;
|
|
17
|
+
label_last_sign_in: string;
|
|
18
|
+
label_privilege_active: string;
|
|
19
|
+
label_privilege_name: string;
|
|
20
|
+
label_role_name: string;
|
|
21
|
+
label_second_phone: string;
|
|
22
|
+
label_updated_at: string;
|
|
23
|
+
label_user_type_name: string;
|
|
24
|
+
modal_delete_message: string;
|
|
25
|
+
modal_delete_title: string;
|
|
26
|
+
modal_disable_message: string;
|
|
27
|
+
modal_disable_title: string;
|
|
28
|
+
module_action_add: string;
|
|
29
|
+
module_action_refresh: string;
|
|
30
|
+
module_list: string;
|
|
31
|
+
module_name: string;
|
|
32
|
+
module_name_add: string;
|
|
33
|
+
module_name_edit: string;
|
|
34
|
+
row_action_delete: string;
|
|
35
|
+
row_action_disable: string;
|
|
36
|
+
row_action_edit: string;
|
|
37
|
+
row_action_enable: string;
|
|
38
|
+
row_action_view_detail: string;
|
|
39
|
+
tab_general: string;
|
|
40
|
+
tab_logs: string;
|
|
41
|
+
tab_privileges: string;
|
|
42
|
+
test_get_label: string;
|
|
43
|
+
};
|
|
44
|
+
account_popover: {
|
|
45
|
+
label_logout: string;
|
|
46
|
+
label_settings: string;
|
|
47
|
+
label_version: string;
|
|
48
|
+
};
|
|
49
|
+
areas: {
|
|
50
|
+
area_add_new: string;
|
|
51
|
+
area_error_description: string;
|
|
52
|
+
area_error_intro: string;
|
|
53
|
+
area_error_recommendation: string;
|
|
54
|
+
area_error_title: string;
|
|
55
|
+
label_close_window: string;
|
|
56
|
+
label_collapse_window: string;
|
|
57
|
+
label_delete_area: string;
|
|
58
|
+
label_edit_area: string;
|
|
59
|
+
label_maximize_window: string;
|
|
60
|
+
label_minimize_window: string;
|
|
61
|
+
label_module_actions: string;
|
|
62
|
+
label_new_area: string;
|
|
63
|
+
label_persist_module_cookies: string;
|
|
64
|
+
label_uncollapse_window: string;
|
|
65
|
+
label_window: string;
|
|
66
|
+
validation_edit_area: string;
|
|
67
|
+
'': string;
|
|
68
|
+
};
|
|
69
|
+
autocomplete: {
|
|
70
|
+
loading_options: string;
|
|
71
|
+
no_options: string;
|
|
72
|
+
};
|
|
73
|
+
boolean_formatter: {
|
|
74
|
+
boolean_active: string;
|
|
75
|
+
boolean_false: string;
|
|
76
|
+
boolean_inactive: string;
|
|
77
|
+
boolean_no: string;
|
|
78
|
+
boolean_true: string;
|
|
79
|
+
boolean_yes: string;
|
|
80
|
+
};
|
|
81
|
+
common_actions: {
|
|
82
|
+
cancel: string;
|
|
83
|
+
confirm_quit_msg: string;
|
|
84
|
+
confirm_quit_title: string;
|
|
85
|
+
intro: string;
|
|
86
|
+
};
|
|
87
|
+
course_formatter: {
|
|
88
|
+
label_east: string;
|
|
89
|
+
label_north: string;
|
|
90
|
+
label_north_east: string;
|
|
91
|
+
label_north_west: string;
|
|
92
|
+
label_south: string;
|
|
93
|
+
label_south_east: string;
|
|
94
|
+
label_south_west: string;
|
|
95
|
+
label_west: string;
|
|
96
|
+
};
|
|
97
|
+
data_grid: {
|
|
98
|
+
actions: string;
|
|
99
|
+
add_filter: string;
|
|
100
|
+
density_compact: string;
|
|
101
|
+
density_confortable: string;
|
|
102
|
+
density_standard: string;
|
|
103
|
+
filter_holder: string;
|
|
104
|
+
freeze_column: string;
|
|
105
|
+
hide_column: string;
|
|
106
|
+
no_actions_label: string;
|
|
107
|
+
order_asc_column: string;
|
|
108
|
+
order_desc_column: string;
|
|
109
|
+
remove_order_column: string;
|
|
110
|
+
rows: string;
|
|
111
|
+
settings_column_frozen: string;
|
|
112
|
+
settings_column_name: string;
|
|
113
|
+
settings_column_position: string;
|
|
114
|
+
settings_column_visible: string;
|
|
115
|
+
settings_move_down: string;
|
|
116
|
+
settings_move_first: string;
|
|
117
|
+
settings_move_last: string;
|
|
118
|
+
settings_move_up: string;
|
|
119
|
+
settings_no_visible_all: string;
|
|
120
|
+
settings_restore: string;
|
|
121
|
+
settings_sel_columns: string;
|
|
122
|
+
settings_title: string;
|
|
123
|
+
settings_visible_all: string;
|
|
124
|
+
tooltip_density: string;
|
|
125
|
+
tooltip_filter_hide: string;
|
|
126
|
+
tooltip_filter_show: string;
|
|
127
|
+
tooltip_settings: string;
|
|
128
|
+
unfreeze_column: string;
|
|
129
|
+
};
|
|
130
|
+
distance_to_now_formmater: {
|
|
131
|
+
label_sentence_future_others: string;
|
|
132
|
+
label_sentence_future_seconds: string;
|
|
133
|
+
label_sentence_past_others: string;
|
|
134
|
+
label_sentence_past_seconds: string;
|
|
135
|
+
label_sentence_present_others: string;
|
|
136
|
+
label_sentence_present_seconds: string;
|
|
137
|
+
label_unit_time_day: string;
|
|
138
|
+
label_unit_time_days: string;
|
|
139
|
+
label_unit_time_hour: string;
|
|
140
|
+
label_unit_time_hours: string;
|
|
141
|
+
label_unit_time_minute: string;
|
|
142
|
+
label_unit_time_minutes: string;
|
|
143
|
+
label_unit_time_month: string;
|
|
144
|
+
label_unit_time_months: string;
|
|
145
|
+
label_unit_time_second: string;
|
|
146
|
+
label_unit_time_seconds: string;
|
|
147
|
+
label_unit_time_year: string;
|
|
148
|
+
label_unit_time_years: string;
|
|
149
|
+
};
|
|
150
|
+
dynamic_filter: {
|
|
151
|
+
all_fields: string;
|
|
152
|
+
error_invalid_date: string;
|
|
153
|
+
error_invalid_filters_before: string;
|
|
154
|
+
error_operand_mustbe_number: string;
|
|
155
|
+
error_operand_required: string;
|
|
156
|
+
error_operator_required: string;
|
|
157
|
+
filter_tooltip_dirty: string;
|
|
158
|
+
filter_tooltip_invalid: string;
|
|
159
|
+
filter_tooltip_refresh: string;
|
|
160
|
+
input_placeholder: string;
|
|
161
|
+
label_boolean_operand1: string;
|
|
162
|
+
label_boolean_operator: string;
|
|
163
|
+
label_no_fields_available: string;
|
|
164
|
+
label_operand1_date_time: string;
|
|
165
|
+
label_operand1_number: string;
|
|
166
|
+
label_operand1_string: string;
|
|
167
|
+
label_operand2_date_time: string;
|
|
168
|
+
label_operand2_number: string;
|
|
169
|
+
label_operator_date_time: string;
|
|
170
|
+
label_operator_number: string;
|
|
171
|
+
label_operator_string: string;
|
|
172
|
+
label_select_async_operand1: string;
|
|
173
|
+
label_select_operands_array: string;
|
|
174
|
+
label_select_operator: string;
|
|
175
|
+
operand_false: string;
|
|
176
|
+
operand_true: string;
|
|
177
|
+
operator_b: string;
|
|
178
|
+
operator_c: string;
|
|
179
|
+
operator_e: string;
|
|
180
|
+
operator_gt: string;
|
|
181
|
+
operator_gte: string;
|
|
182
|
+
operator_in: string;
|
|
183
|
+
operator_lt: string;
|
|
184
|
+
operator_lte: string;
|
|
185
|
+
operator_nc: string;
|
|
186
|
+
operator_ne: string;
|
|
187
|
+
operator_nin: string;
|
|
188
|
+
operator_required: string;
|
|
189
|
+
tooltip_clear_filter: string;
|
|
190
|
+
tooltip_clear_filters: string;
|
|
191
|
+
};
|
|
192
|
+
dynamic_sort: {
|
|
193
|
+
input_placeholder: string;
|
|
194
|
+
label_ascending: string;
|
|
195
|
+
label_boolean_operand1: string;
|
|
196
|
+
label_descending: string;
|
|
197
|
+
label_no_fields_available: string;
|
|
198
|
+
operator_asc: string;
|
|
199
|
+
operator_desc: string;
|
|
200
|
+
sort_tooltip_dirty: string;
|
|
201
|
+
sort_tooltip_refresh: string;
|
|
202
|
+
tooltip_clear_sort: string;
|
|
203
|
+
tooltip_clear_sorts: string;
|
|
204
|
+
};
|
|
205
|
+
fallback: {
|
|
206
|
+
label_description: string;
|
|
207
|
+
label_intro: string;
|
|
208
|
+
label_title: string;
|
|
209
|
+
};
|
|
210
|
+
form_add_edit: {
|
|
211
|
+
error_authorization_message: string;
|
|
212
|
+
label_error_title: string;
|
|
213
|
+
};
|
|
214
|
+
indicator_csq: {
|
|
215
|
+
label_csq_title: string;
|
|
216
|
+
label_quality_acceptable: string;
|
|
217
|
+
label_quality_excellent: string;
|
|
218
|
+
label_quality_good: string;
|
|
219
|
+
label_quality_not_detectable: string;
|
|
220
|
+
label_quality_weak: string;
|
|
221
|
+
};
|
|
222
|
+
indicator_battery: {
|
|
223
|
+
label_status: string;
|
|
224
|
+
label_status_acceptable: string;
|
|
225
|
+
label_status_excellent: string;
|
|
226
|
+
label_status_good: string;
|
|
227
|
+
label_status_not_detectable: string;
|
|
228
|
+
label_status_weak: string;
|
|
229
|
+
label_voltage: string;
|
|
230
|
+
title_backup: string;
|
|
231
|
+
title_main: string;
|
|
232
|
+
};
|
|
233
|
+
loading_error: {
|
|
234
|
+
label_error_description: string;
|
|
235
|
+
label_error_intro: string;
|
|
236
|
+
label_error_recommendation: string;
|
|
237
|
+
label_error_title: string;
|
|
238
|
+
};
|
|
239
|
+
map: {
|
|
240
|
+
label_gpstools_name: string;
|
|
241
|
+
label_layer_autofocus: string;
|
|
242
|
+
label_layer_cluster: string;
|
|
243
|
+
label_layer_name: string;
|
|
244
|
+
label_layer_visible: string;
|
|
245
|
+
label_map_sources: string;
|
|
246
|
+
label_tile_bing: string;
|
|
247
|
+
label_tile_google_hybrid: string;
|
|
248
|
+
label_tile_google_roads: string;
|
|
249
|
+
label_tile_google_satellite: string;
|
|
250
|
+
label_tile_osm: string;
|
|
251
|
+
row_action_layer_delete: string;
|
|
252
|
+
};
|
|
253
|
+
map_gps_tools: {
|
|
254
|
+
label_alias: string;
|
|
255
|
+
label_color: string;
|
|
256
|
+
label_customer_id: string;
|
|
257
|
+
label_dash_array: string;
|
|
258
|
+
label_draw: string;
|
|
259
|
+
label_finish: string;
|
|
260
|
+
label_geometry_circle: string;
|
|
261
|
+
label_geometry_polygon: string;
|
|
262
|
+
label_geometry_rectangle: string;
|
|
263
|
+
label_geometry_type: string;
|
|
264
|
+
label_id: string;
|
|
265
|
+
label_lat: string;
|
|
266
|
+
label_lon: string;
|
|
267
|
+
label_name: string;
|
|
268
|
+
label_opacity: string;
|
|
269
|
+
label_place_marker: string;
|
|
270
|
+
label_radius: string;
|
|
271
|
+
label_tab_geo: string;
|
|
272
|
+
label_time_min_in_seconds: string;
|
|
273
|
+
label_time_min_out_seconds: string;
|
|
274
|
+
label_weight: string;
|
|
275
|
+
module_name_geofence_add: string;
|
|
276
|
+
module_name_geofence_edit: string;
|
|
277
|
+
paper_config: string;
|
|
278
|
+
paper_fill: string;
|
|
279
|
+
paper_general: string;
|
|
280
|
+
paper_stroke: string;
|
|
281
|
+
row_action_geo_delete: string;
|
|
282
|
+
row_action_geo_edit: string;
|
|
283
|
+
tab_general_config_tooltip: string;
|
|
284
|
+
tab_style_tooltip: string;
|
|
285
|
+
};
|
|
286
|
+
map_popup_my_gps: {
|
|
287
|
+
label_address: string;
|
|
288
|
+
label_course: string;
|
|
289
|
+
label_driver: string;
|
|
290
|
+
label_last_report: string;
|
|
291
|
+
label_location: string;
|
|
292
|
+
label_speed: string;
|
|
293
|
+
label_status: string;
|
|
294
|
+
label_time_in_status: string;
|
|
295
|
+
label_view_more: string;
|
|
296
|
+
};
|
|
297
|
+
master_detail_layout: {
|
|
298
|
+
no_split: string;
|
|
299
|
+
split_horizontal: string;
|
|
300
|
+
split_vertical: string;
|
|
301
|
+
view_detail: string;
|
|
302
|
+
};
|
|
303
|
+
menu_actions: {
|
|
304
|
+
no_actions_label: string;
|
|
305
|
+
};
|
|
306
|
+
modal_dialog: {
|
|
307
|
+
action_accept: string;
|
|
308
|
+
action_cancel: string;
|
|
309
|
+
label_window_confirm: string;
|
|
310
|
+
};
|
|
311
|
+
my_device_status: {
|
|
312
|
+
label_max_speed: string;
|
|
313
|
+
label_moving: string;
|
|
314
|
+
label_no_gps_signal: string;
|
|
315
|
+
label_off: string;
|
|
316
|
+
label_power_saving: string;
|
|
317
|
+
label_stopped: string;
|
|
318
|
+
label_stopped_e_ralenti: string;
|
|
319
|
+
label_stopped_ralenti: string;
|
|
320
|
+
label_towing: string;
|
|
321
|
+
};
|
|
322
|
+
no_item_privileges: {
|
|
323
|
+
label_message: string;
|
|
324
|
+
label_title: string;
|
|
325
|
+
};
|
|
326
|
+
no_item_selected: {
|
|
327
|
+
detail: string;
|
|
328
|
+
message: string;
|
|
329
|
+
title: string;
|
|
330
|
+
};
|
|
331
|
+
object_logs: {
|
|
332
|
+
created_at: string;
|
|
333
|
+
email: string;
|
|
334
|
+
ip: string;
|
|
335
|
+
log_detail: string;
|
|
336
|
+
log_preview: string;
|
|
337
|
+
modal_detail_title: string;
|
|
338
|
+
privilege_name: string;
|
|
339
|
+
resource_name: string;
|
|
340
|
+
service_id: string;
|
|
341
|
+
view_log_detail: string;
|
|
342
|
+
};
|
|
343
|
+
pager: {
|
|
344
|
+
first: string;
|
|
345
|
+
last: string;
|
|
346
|
+
next: string;
|
|
347
|
+
no_records: string;
|
|
348
|
+
of: string;
|
|
349
|
+
page: string;
|
|
350
|
+
previous: string;
|
|
351
|
+
rows: string;
|
|
352
|
+
rows_per_page: string;
|
|
353
|
+
total_rows: string;
|
|
354
|
+
};
|
|
355
|
+
pdf_viewer: {
|
|
356
|
+
label_download_pdf: string;
|
|
357
|
+
};
|
|
358
|
+
period: {
|
|
359
|
+
label_days: string;
|
|
360
|
+
label_months: string;
|
|
361
|
+
label_years: string;
|
|
362
|
+
};
|
|
363
|
+
period_formatter: {
|
|
364
|
+
label_day: string;
|
|
365
|
+
label_days: string;
|
|
366
|
+
label_month: string;
|
|
367
|
+
label_months: string;
|
|
368
|
+
label_year: string;
|
|
369
|
+
label_years: string;
|
|
370
|
+
};
|
|
371
|
+
rhf_autocomplete: {
|
|
372
|
+
loading_options: string;
|
|
373
|
+
no_options: string;
|
|
374
|
+
};
|
|
375
|
+
rhf_uploadimage: {
|
|
376
|
+
click_button: string;
|
|
377
|
+
description: string;
|
|
378
|
+
divider_text: string;
|
|
379
|
+
title_upload: string;
|
|
380
|
+
};
|
|
381
|
+
rhfcolorpicker: {
|
|
382
|
+
accept: string;
|
|
383
|
+
};
|
|
384
|
+
rhfuploadsinglefile: {
|
|
385
|
+
accept_file: string;
|
|
386
|
+
accept_size: string;
|
|
387
|
+
button_text: string;
|
|
388
|
+
description: string;
|
|
389
|
+
divider_text: string;
|
|
390
|
+
error_file_rejected: string;
|
|
391
|
+
error_max_size: string;
|
|
392
|
+
title: string;
|
|
393
|
+
};
|
|
394
|
+
select: {
|
|
395
|
+
no_options: string;
|
|
396
|
+
};
|
|
397
|
+
sidebar: {
|
|
398
|
+
label_no_items: string;
|
|
399
|
+
};
|
|
400
|
+
stepper: {
|
|
401
|
+
label_cancel_button: string;
|
|
402
|
+
label_next_button: string;
|
|
403
|
+
label_prev_button: string;
|
|
404
|
+
label_submit_button: string;
|
|
405
|
+
};
|
|
406
|
+
upload_image: {
|
|
407
|
+
click_button: string;
|
|
408
|
+
description: string;
|
|
409
|
+
title_upload: string;
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Datos mock completos para el endpoint domain/dictionaries
|
|
414
|
+
*/
|
|
415
|
+
export declare const dictionaryMockData: DictionaryMockData;
|
|
416
|
+
/**
|
|
417
|
+
* Función helper para crear datos mock personalizados
|
|
418
|
+
* @param overrides - Datos para sobrescribir en el mock por defecto
|
|
419
|
+
* @returns Datos mock personalizados
|
|
420
|
+
*/
|
|
421
|
+
export declare const createCustomDictionaryMock: (overrides?: Partial<DictionaryMockData>) => DictionaryMockData;
|
|
422
|
+
/**
|
|
423
|
+
* Función helper para crear datos mock para diferentes idiomas
|
|
424
|
+
* @param language - Código del idioma ('es', 'en', etc.)
|
|
425
|
+
* @returns Datos mock traducidos
|
|
426
|
+
*/
|
|
427
|
+
export declare const createLocalizedDictionaryMock: (language?: "es" | "en") => DictionaryMockData;
|
|
428
|
+
/**
|
|
429
|
+
* Función helper para crear datos mock para diferentes módulos
|
|
430
|
+
* @param moduleName - Nombre del módulo
|
|
431
|
+
* @returns Datos mock personalizados para el módulo
|
|
432
|
+
*/
|
|
433
|
+
export declare const createModuleDictionaryMock: (moduleName: string) => DictionaryMockData;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook que simula validación onChange de campos específicos del Stepper, manteniendo el formulario en modo onSubmit para preservar el rendimiento.
|
|
3
|
-
* @returns Objeto con funciones para manejar la validación dinámica
|
|
4
|
-
*/
|
|
5
|
-
export declare function useDynamicValidation(): {
|
|
6
|
-
activateFieldsValidation: (fields: string[]) => void;
|
|
7
|
-
clearAllValidation: () => void;
|
|
8
|
-
activeFields: string[];
|
|
9
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { useState, useRef, useEffect, useCallback } from "react";
|
|
2
|
-
import { useFormContext, useWatch } from "react-hook-form";
|
|
3
|
-
function useDynamicValidation() {
|
|
4
|
-
const { trigger } = useFormContext();
|
|
5
|
-
const [activeFields, setActiveFields] = useState([]);
|
|
6
|
-
const watchValues = useWatch({
|
|
7
|
-
name: activeFields.length > 0 ? activeFields : ["__dummy__"]
|
|
8
|
-
});
|
|
9
|
-
const lastValuesRef = useRef({});
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (activeFields.length === 0) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const currentValues = activeFields.length === 1 ? { [activeFields[0]]: watchValues } : activeFields.reduce((acc, field, index) => {
|
|
15
|
-
acc[field] = Array.isArray(watchValues) ? watchValues[index] : watchValues;
|
|
16
|
-
return acc;
|
|
17
|
-
}, {});
|
|
18
|
-
const changedFields = activeFields.filter((field) => {
|
|
19
|
-
const currentValue = currentValues[field];
|
|
20
|
-
const lastValue = lastValuesRef.current[field];
|
|
21
|
-
const hasChanged = JSON.stringify(currentValue) !== JSON.stringify(lastValue);
|
|
22
|
-
if (hasChanged) {
|
|
23
|
-
lastValuesRef.current[field] = currentValue;
|
|
24
|
-
}
|
|
25
|
-
return hasChanged;
|
|
26
|
-
});
|
|
27
|
-
if (changedFields.length > 0) {
|
|
28
|
-
const timeoutId = setTimeout(() => {
|
|
29
|
-
trigger(changedFields);
|
|
30
|
-
}, 100);
|
|
31
|
-
return () => clearTimeout(timeoutId);
|
|
32
|
-
}
|
|
33
|
-
}, [activeFields, trigger, watchValues]);
|
|
34
|
-
const activateFieldsValidation = useCallback((fields) => {
|
|
35
|
-
setActiveFields((prev) => {
|
|
36
|
-
const newFields = fields.filter((field) => !prev.includes(field));
|
|
37
|
-
return [...prev, ...newFields];
|
|
38
|
-
});
|
|
39
|
-
fields.forEach((field) => {
|
|
40
|
-
if (!lastValuesRef.current.hasOwnProperty(field)) {
|
|
41
|
-
lastValuesRef.current[field] = void 0;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}, []);
|
|
45
|
-
const clearAllValidation = useCallback(() => {
|
|
46
|
-
setActiveFields([]);
|
|
47
|
-
lastValuesRef.current = {};
|
|
48
|
-
}, []);
|
|
49
|
-
return {
|
|
50
|
-
activateFieldsValidation,
|
|
51
|
-
clearAllValidation,
|
|
52
|
-
activeFields
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export {
|
|
56
|
-
useDynamicValidation as u
|
|
57
|
-
};
|