goobs-frontend 0.7.57 → 0.7.59
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/package.json +14 -14
- package/src/components/Button/index.tsx +6 -65
- package/src/components/ConfirmationCodeInput/index.tsx +40 -5
- package/src/components/Content/Structure/styledcomponent/useStyledComponent.tsx +0 -6
- package/src/components/Form/Popup/index.tsx +143 -106
- package/src/components/StyledComponent/{adornments.tsx → adornment/index.tsx} +17 -12
- package/src/components/StyledComponent/helperfooter/useHelperFooter.tsx +225 -89
- package/src/components/StyledComponent/index.tsx +99 -182
- package/src/components/StyledComponent/useEffects/index.tsx +54 -0
- package/src/index.ts +1 -2
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useCallback } from 'react'
|
|
3
|
+
import { useCallback, useState, useMemo, useRef, useEffect } from 'react'
|
|
4
4
|
import { debounce } from 'lodash'
|
|
5
|
-
import
|
|
5
|
+
import React from 'react'
|
|
6
|
+
import { get, set, StringValue } from 'goobs-cache'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
|
-
* Validates if the given string is
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
9
|
+
* Validates if the given string is a valid email format.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} email - The email string to validate.
|
|
12
|
+
* @returns {boolean} True if the email is valid, false otherwise.
|
|
11
13
|
*/
|
|
12
14
|
const isValidEmailFormat = (email: string): boolean => {
|
|
13
15
|
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
|
|
14
|
-
|
|
15
|
-
return result
|
|
16
|
+
return emailRegex.test(email)
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Represents a message for the helper footer.
|
|
21
|
+
*
|
|
22
|
+
* @interface HelperFooterMessage
|
|
23
|
+
* @property {('error' | 'success')} status - The status of the message.
|
|
24
|
+
* @property {string} statusMessage - The detailed status message.
|
|
25
|
+
* @property {string} spreadMessage - A condensed version of the message for spreading.
|
|
26
|
+
* @property {number} spreadMessagePriority - The priority of the spread message.
|
|
27
|
+
* @property {string} formname - The name of the form this message is associated with.
|
|
28
|
+
* @property {boolean} required - Indicates if the field associated with this message is required.
|
|
20
29
|
*/
|
|
21
30
|
export interface HelperFooterMessage {
|
|
22
31
|
status: 'error' | 'success'
|
|
@@ -28,12 +37,25 @@ export interface HelperFooterMessage {
|
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
40
|
+
* A custom hook for managing form validation and helper messages.
|
|
41
|
+
*
|
|
42
|
+
* @returns {Object} An object containing validation functions and helper footer state.
|
|
33
43
|
*/
|
|
34
44
|
export const useHelperFooter = () => {
|
|
45
|
+
const [helperFooterValue, setHelperFooterValue] = useState<
|
|
46
|
+
Record<string, HelperFooterMessage>
|
|
47
|
+
>({})
|
|
48
|
+
const helperFooterRef = useRef<Record<string, HelperFooterMessage>>({})
|
|
49
|
+
|
|
35
50
|
/**
|
|
36
|
-
* Handles generic error
|
|
51
|
+
* Handles creation of generic error messages for form fields.
|
|
52
|
+
*
|
|
53
|
+
* @param {FormData} formData - The form data to validate.
|
|
54
|
+
* @param {string} name - The name of the form field.
|
|
55
|
+
* @param {string} label - The label of the form field.
|
|
56
|
+
* @param {boolean} required - Whether the field is required.
|
|
57
|
+
* @param {string} formname - The name of the form.
|
|
58
|
+
* @returns {HelperFooterMessage | undefined} An error message object if there's an error, undefined otherwise.
|
|
37
59
|
*/
|
|
38
60
|
const handleGenericErrorCreation = useCallback(
|
|
39
61
|
(
|
|
@@ -43,9 +65,10 @@ export const useHelperFooter = () => {
|
|
|
43
65
|
required: boolean,
|
|
44
66
|
formname: string
|
|
45
67
|
): HelperFooterMessage | undefined => {
|
|
68
|
+
console.log(`Handling generic error creation for ${name}`)
|
|
46
69
|
const value = formData.get(name) as string
|
|
47
|
-
|
|
48
70
|
if (required && (!value || !value.trim())) {
|
|
71
|
+
console.log(`Error: ${label} is required`)
|
|
49
72
|
return {
|
|
50
73
|
status: 'error',
|
|
51
74
|
statusMessage: `${label} is required. Please enter a ${label.toLowerCase()}.`,
|
|
@@ -55,14 +78,19 @@ export const useHelperFooter = () => {
|
|
|
55
78
|
required,
|
|
56
79
|
}
|
|
57
80
|
}
|
|
58
|
-
|
|
81
|
+
console.log(`No error for ${name}`)
|
|
59
82
|
return undefined
|
|
60
83
|
},
|
|
61
84
|
[]
|
|
62
85
|
)
|
|
63
86
|
|
|
64
87
|
/**
|
|
65
|
-
* Handles
|
|
88
|
+
* Handles creation of email-specific error messages.
|
|
89
|
+
*
|
|
90
|
+
* @param {FormData} formData - The form data to validate.
|
|
91
|
+
* @param {boolean} required - Whether the email field is required.
|
|
92
|
+
* @param {string} formname - The name of the form.
|
|
93
|
+
* @returns {HelperFooterMessage | undefined} An error or success message object, or undefined if no message is needed.
|
|
66
94
|
*/
|
|
67
95
|
const handleEmailErrorCreation = useCallback(
|
|
68
96
|
(
|
|
@@ -70,9 +98,10 @@ export const useHelperFooter = () => {
|
|
|
70
98
|
required: boolean,
|
|
71
99
|
formname: string
|
|
72
100
|
): HelperFooterMessage | undefined => {
|
|
101
|
+
console.log('Handling email error creation')
|
|
73
102
|
const email = formData.get('email') as string
|
|
74
|
-
|
|
75
103
|
if (required && (!email || !email.trim())) {
|
|
104
|
+
console.log('Error: Email is required')
|
|
76
105
|
return {
|
|
77
106
|
status: 'error',
|
|
78
107
|
statusMessage: 'Please enter an email address.',
|
|
@@ -82,12 +111,9 @@ export const useHelperFooter = () => {
|
|
|
82
111
|
required,
|
|
83
112
|
}
|
|
84
113
|
}
|
|
85
|
-
|
|
86
|
-
if (!email) {
|
|
87
|
-
return undefined
|
|
88
|
-
}
|
|
89
|
-
|
|
114
|
+
if (!email) return undefined
|
|
90
115
|
if (email && !isValidEmailFormat(email)) {
|
|
116
|
+
console.log('Error: Invalid email format')
|
|
91
117
|
return {
|
|
92
118
|
status: 'error',
|
|
93
119
|
statusMessage: 'Please enter a valid email address.',
|
|
@@ -97,7 +123,7 @@ export const useHelperFooter = () => {
|
|
|
97
123
|
required,
|
|
98
124
|
}
|
|
99
125
|
}
|
|
100
|
-
|
|
126
|
+
console.log('Email is valid')
|
|
101
127
|
return {
|
|
102
128
|
status: 'success',
|
|
103
129
|
statusMessage: 'Email is valid.',
|
|
@@ -111,25 +137,61 @@ export const useHelperFooter = () => {
|
|
|
111
137
|
)
|
|
112
138
|
|
|
113
139
|
/**
|
|
114
|
-
* Handles password
|
|
140
|
+
* Handles creation of password-specific error messages and stores the password in the client cache.
|
|
141
|
+
*
|
|
142
|
+
* @param {FormData} formData - The form data to validate.
|
|
143
|
+
* @param {boolean} required - Whether the password field is required.
|
|
144
|
+
* @param {string} formname - The name of the form.
|
|
145
|
+
* @returns {HelperFooterMessage | undefined} An error or success message object, or undefined if no message is needed.
|
|
115
146
|
*/
|
|
116
147
|
const handlePasswordErrorCreation = useCallback(
|
|
117
|
-
|
|
148
|
+
(
|
|
118
149
|
formData: FormData,
|
|
119
150
|
required: boolean,
|
|
120
151
|
formname: string
|
|
121
|
-
):
|
|
152
|
+
): HelperFooterMessage | undefined => {
|
|
153
|
+
console.log('Handling password error creation')
|
|
122
154
|
const password = formData.get('verifyPassword') as string
|
|
155
|
+
console.log('Password received:', password)
|
|
156
|
+
|
|
157
|
+
const debouncedPasswordStorage = debounce(async () => {
|
|
158
|
+
console.log('Attempting to store password in goobs-cache client store')
|
|
159
|
+
try {
|
|
160
|
+
if (password) {
|
|
161
|
+
console.log('Setting password in goobs-cache:', password)
|
|
162
|
+
await set(
|
|
163
|
+
'verifyPassword',
|
|
164
|
+
{ type: 'string', value: password } as StringValue,
|
|
165
|
+
new Date(Date.now() + 30 * 60 * 1000),
|
|
166
|
+
'client'
|
|
167
|
+
)
|
|
168
|
+
console.log('Password set operation completed')
|
|
169
|
+
|
|
170
|
+
// Immediately retrieve the password to verify it was stored
|
|
171
|
+
console.log('Attempting to retrieve password from client store')
|
|
172
|
+
const storedPassword = await get('verifyPassword', 'client')
|
|
173
|
+
console.log('Raw stored password result:', storedPassword)
|
|
174
|
+
|
|
175
|
+
if (storedPassword && storedPassword.value) {
|
|
176
|
+
console.log(
|
|
177
|
+
'Immediately retrieved password from client store:',
|
|
178
|
+
storedPassword.value
|
|
179
|
+
)
|
|
180
|
+
} else {
|
|
181
|
+
console.log('Retrieved password is null or undefined')
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
console.log('Password is null or empty, not storing in goobs-cache')
|
|
185
|
+
}
|
|
186
|
+
} catch (error) {
|
|
187
|
+
console.error('Error interacting with goobs-cache:', error)
|
|
188
|
+
}
|
|
189
|
+
}, 2000)
|
|
123
190
|
|
|
124
|
-
|
|
125
|
-
await set(
|
|
126
|
-
'verifyPassword',
|
|
127
|
-
{ type: 'string', value: password } as StringValue,
|
|
128
|
-
new Date(Date.now() + 30 * 60 * 1000),
|
|
129
|
-
'client'
|
|
130
|
-
)
|
|
191
|
+
debouncedPasswordStorage()
|
|
131
192
|
|
|
132
193
|
if (required && (!password || !password.trim())) {
|
|
194
|
+
console.log('Error: Password is required')
|
|
133
195
|
return {
|
|
134
196
|
status: 'error',
|
|
135
197
|
statusMessage: 'Password is required.',
|
|
@@ -139,11 +201,7 @@ export const useHelperFooter = () => {
|
|
|
139
201
|
required,
|
|
140
202
|
}
|
|
141
203
|
}
|
|
142
|
-
|
|
143
|
-
if (!password) {
|
|
144
|
-
return undefined
|
|
145
|
-
}
|
|
146
|
-
|
|
204
|
+
if (!password) return undefined
|
|
147
205
|
const passwordRegex =
|
|
148
206
|
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
|
|
149
207
|
const passwordComplexityStatus: 'error' | 'success' = passwordRegex.test(
|
|
@@ -151,8 +209,8 @@ export const useHelperFooter = () => {
|
|
|
151
209
|
)
|
|
152
210
|
? 'success'
|
|
153
211
|
: 'error'
|
|
154
|
-
|
|
155
212
|
if (passwordComplexityStatus === 'error') {
|
|
213
|
+
console.log('Error: Invalid password complexity')
|
|
156
214
|
return {
|
|
157
215
|
status: 'error',
|
|
158
216
|
statusMessage:
|
|
@@ -163,7 +221,7 @@ export const useHelperFooter = () => {
|
|
|
163
221
|
required,
|
|
164
222
|
}
|
|
165
223
|
}
|
|
166
|
-
|
|
224
|
+
console.log('Password meets all requirements')
|
|
167
225
|
return {
|
|
168
226
|
status: 'success',
|
|
169
227
|
statusMessage: 'Password meets all requirements.',
|
|
@@ -177,7 +235,12 @@ export const useHelperFooter = () => {
|
|
|
177
235
|
)
|
|
178
236
|
|
|
179
237
|
/**
|
|
180
|
-
* Handles
|
|
238
|
+
* Handles creation of confirm password error messages by comparing with the stored password.
|
|
239
|
+
*
|
|
240
|
+
* @param {FormData} formData - The form data to validate.
|
|
241
|
+
* @param {boolean} required - Whether the confirm password field is required.
|
|
242
|
+
* @param {string} formname - The name of the form.
|
|
243
|
+
* @returns {Promise<HelperFooterMessage | undefined>} A promise that resolves to an error or success message object, or undefined if no message is needed.
|
|
181
244
|
*/
|
|
182
245
|
const handleConfirmPasswordErrorCreation = useCallback(
|
|
183
246
|
async (
|
|
@@ -185,9 +248,12 @@ export const useHelperFooter = () => {
|
|
|
185
248
|
required: boolean,
|
|
186
249
|
formname: string
|
|
187
250
|
): Promise<HelperFooterMessage | undefined> => {
|
|
251
|
+
console.log('Handling confirm password error creation')
|
|
188
252
|
const confirmPassword = formData.get('confirmPassword') as string
|
|
253
|
+
console.log('Confirm password received:', confirmPassword)
|
|
189
254
|
|
|
190
255
|
if (required && (!confirmPassword || !confirmPassword.trim())) {
|
|
256
|
+
console.log('Error: Password confirmation is required')
|
|
191
257
|
return {
|
|
192
258
|
status: 'error',
|
|
193
259
|
statusMessage: 'Please confirm your password.',
|
|
@@ -197,23 +263,38 @@ export const useHelperFooter = () => {
|
|
|
197
263
|
required,
|
|
198
264
|
}
|
|
199
265
|
}
|
|
266
|
+
if (!confirmPassword) return undefined
|
|
200
267
|
|
|
201
|
-
|
|
202
|
-
|
|
268
|
+
console.log(
|
|
269
|
+
'Attempting to retrieve verify password from goobs-cache client store'
|
|
270
|
+
)
|
|
271
|
+
let verifyPasswordResult
|
|
272
|
+
try {
|
|
273
|
+
verifyPasswordResult = await get('verifyPassword', 'client')
|
|
274
|
+
console.log('Retrieved verify password result:', verifyPasswordResult)
|
|
275
|
+
} catch (error) {
|
|
276
|
+
console.error('Error retrieving password from goobs-cache:', error)
|
|
203
277
|
}
|
|
204
278
|
|
|
205
|
-
const verifyPasswordResult = await get('verifyPassword', 'client')
|
|
206
279
|
let verifyPassword: string | undefined
|
|
207
|
-
|
|
208
280
|
if (
|
|
209
281
|
verifyPasswordResult &&
|
|
210
282
|
typeof verifyPasswordResult === 'object' &&
|
|
211
|
-
'value' in verifyPasswordResult
|
|
283
|
+
'value' in verifyPasswordResult &&
|
|
284
|
+
verifyPasswordResult.value &&
|
|
285
|
+
typeof verifyPasswordResult.value === 'object' &&
|
|
286
|
+
'value' in verifyPasswordResult.value
|
|
212
287
|
) {
|
|
213
|
-
verifyPassword =
|
|
288
|
+
verifyPassword = verifyPasswordResult.value.value
|
|
289
|
+
console.log('Verify password from client store:', verifyPassword)
|
|
290
|
+
} else {
|
|
291
|
+
console.log(
|
|
292
|
+
'Verify password not found in client store or in unexpected format'
|
|
293
|
+
)
|
|
214
294
|
}
|
|
215
295
|
|
|
216
296
|
if (!verifyPassword) {
|
|
297
|
+
console.log('Error: Password not set')
|
|
217
298
|
return {
|
|
218
299
|
status: 'error',
|
|
219
300
|
statusMessage: 'Please enter your password first.',
|
|
@@ -225,6 +306,7 @@ export const useHelperFooter = () => {
|
|
|
225
306
|
}
|
|
226
307
|
|
|
227
308
|
if (confirmPassword !== verifyPassword) {
|
|
309
|
+
console.log('Error: Passwords do not match')
|
|
228
310
|
return {
|
|
229
311
|
status: 'error',
|
|
230
312
|
statusMessage: 'Passwords do not match.',
|
|
@@ -235,6 +317,7 @@ export const useHelperFooter = () => {
|
|
|
235
317
|
}
|
|
236
318
|
}
|
|
237
319
|
|
|
320
|
+
console.log('Passwords match')
|
|
238
321
|
return {
|
|
239
322
|
status: 'success',
|
|
240
323
|
statusMessage: 'Passwords match.',
|
|
@@ -248,7 +331,12 @@ export const useHelperFooter = () => {
|
|
|
248
331
|
)
|
|
249
332
|
|
|
250
333
|
/**
|
|
251
|
-
* Handles phone number
|
|
334
|
+
* Handles creation of phone number error messages.
|
|
335
|
+
*
|
|
336
|
+
* @param {FormData} formData - The form data to validate.
|
|
337
|
+
* @param {boolean} required - Whether the phone number field is required.
|
|
338
|
+
* @param {string} formname - The name of the form.
|
|
339
|
+
* @returns {HelperFooterMessage | undefined} An error or success message object, or undefined if no message is needed.
|
|
252
340
|
*/
|
|
253
341
|
const handlePhoneNumberErrorCreation = useCallback(
|
|
254
342
|
(
|
|
@@ -256,9 +344,10 @@ export const useHelperFooter = () => {
|
|
|
256
344
|
required: boolean,
|
|
257
345
|
formname: string
|
|
258
346
|
): HelperFooterMessage | undefined => {
|
|
347
|
+
console.log('Handling phone number error creation')
|
|
259
348
|
const phoneNumber = formData.get('phoneNumber') as string
|
|
260
|
-
|
|
261
349
|
if (required && (!phoneNumber || !phoneNumber.trim())) {
|
|
350
|
+
console.log('Error: Phone number is required')
|
|
262
351
|
return {
|
|
263
352
|
status: 'error',
|
|
264
353
|
statusMessage:
|
|
@@ -269,18 +358,14 @@ export const useHelperFooter = () => {
|
|
|
269
358
|
required,
|
|
270
359
|
}
|
|
271
360
|
}
|
|
272
|
-
|
|
273
|
-
if (!phoneNumber) {
|
|
274
|
-
return undefined
|
|
275
|
-
}
|
|
276
|
-
|
|
361
|
+
if (!phoneNumber) return undefined
|
|
277
362
|
const digitsOnly = phoneNumber.replace(/[^\d]/g, '')
|
|
278
363
|
const length = digitsOnly.length
|
|
279
|
-
|
|
280
364
|
if (
|
|
281
365
|
(length === 10 && !digitsOnly.startsWith('1')) ||
|
|
282
366
|
(length === 11 && digitsOnly.startsWith('1'))
|
|
283
367
|
) {
|
|
368
|
+
console.log('Phone number is valid')
|
|
284
369
|
return {
|
|
285
370
|
status: 'success',
|
|
286
371
|
statusMessage: 'Phone number is valid.',
|
|
@@ -290,6 +375,7 @@ export const useHelperFooter = () => {
|
|
|
290
375
|
required,
|
|
291
376
|
}
|
|
292
377
|
} else {
|
|
378
|
+
console.log('Error: Invalid phone number format')
|
|
293
379
|
return {
|
|
294
380
|
status: 'error',
|
|
295
381
|
statusMessage:
|
|
@@ -305,7 +391,13 @@ export const useHelperFooter = () => {
|
|
|
305
391
|
)
|
|
306
392
|
|
|
307
393
|
/**
|
|
308
|
-
* Validates a
|
|
394
|
+
* Validates a specific field in the form.
|
|
395
|
+
*
|
|
396
|
+
* @param {string} name - The name of the field to validate.
|
|
397
|
+
* @param {FormData} formData - The form data to validate.
|
|
398
|
+
* @param {string} label - The label of the field.
|
|
399
|
+
* @param {boolean} required - Whether the field is required.
|
|
400
|
+
* @param {string} formname - The name of the form.
|
|
309
401
|
*/
|
|
310
402
|
const validateField = useCallback(
|
|
311
403
|
(
|
|
@@ -315,10 +407,9 @@ export const useHelperFooter = () => {
|
|
|
315
407
|
required: boolean,
|
|
316
408
|
formname: string
|
|
317
409
|
) => {
|
|
318
|
-
|
|
410
|
+
console.log(`Validating field: ${name}`)
|
|
411
|
+
const validation = () => {
|
|
319
412
|
let validationResult: HelperFooterMessage | undefined
|
|
320
|
-
|
|
321
|
-
// Determine which validation function to use based on the field name
|
|
322
413
|
switch (name) {
|
|
323
414
|
case 'email':
|
|
324
415
|
validationResult = handleEmailErrorCreation(
|
|
@@ -328,19 +419,22 @@ export const useHelperFooter = () => {
|
|
|
328
419
|
)
|
|
329
420
|
break
|
|
330
421
|
case 'verifyPassword':
|
|
331
|
-
validationResult =
|
|
422
|
+
validationResult = handlePasswordErrorCreation(
|
|
332
423
|
formData,
|
|
333
424
|
required,
|
|
334
425
|
formname
|
|
335
426
|
)
|
|
336
427
|
break
|
|
337
428
|
case 'confirmPassword':
|
|
338
|
-
|
|
429
|
+
handleConfirmPasswordErrorCreation(
|
|
339
430
|
formData,
|
|
340
431
|
required,
|
|
341
432
|
formname
|
|
342
|
-
)
|
|
343
|
-
|
|
433
|
+
).then(result => {
|
|
434
|
+
validationResult = result
|
|
435
|
+
updateHelperFooter(name, validationResult)
|
|
436
|
+
})
|
|
437
|
+
return
|
|
344
438
|
case 'phoneNumber':
|
|
345
439
|
validationResult = handlePhoneNumberErrorCreation(
|
|
346
440
|
formData,
|
|
@@ -358,33 +452,10 @@ export const useHelperFooter = () => {
|
|
|
358
452
|
)
|
|
359
453
|
}
|
|
360
454
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
let currentHelperFooter: Record<string, HelperFooterMessage> = {}
|
|
364
|
-
if (
|
|
365
|
-
helperFooterResult &&
|
|
366
|
-
typeof helperFooterResult === 'object' &&
|
|
367
|
-
'value' in helperFooterResult
|
|
368
|
-
) {
|
|
369
|
-
currentHelperFooter = (helperFooterResult as JSONValue)
|
|
370
|
-
.value as Record<string, HelperFooterMessage>
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (validationResult) {
|
|
374
|
-
currentHelperFooter[name] = validationResult
|
|
375
|
-
} else {
|
|
376
|
-
delete currentHelperFooter[name]
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
await set(
|
|
380
|
-
'helperFooter',
|
|
381
|
-
{ type: 'json', value: currentHelperFooter } as JSONValue,
|
|
382
|
-
new Date(Date.now() + 30 * 60 * 1000), // 30 minutes expiration
|
|
383
|
-
'client'
|
|
384
|
-
)
|
|
385
|
-
}, 300)
|
|
455
|
+
updateHelperFooter(name, validationResult)
|
|
456
|
+
}
|
|
386
457
|
|
|
387
|
-
|
|
458
|
+
validation()
|
|
388
459
|
},
|
|
389
460
|
[
|
|
390
461
|
handleEmailErrorCreation,
|
|
@@ -395,7 +466,72 @@ export const useHelperFooter = () => {
|
|
|
395
466
|
]
|
|
396
467
|
)
|
|
397
468
|
|
|
398
|
-
|
|
399
|
-
|
|
469
|
+
const updateHelperFooter = (
|
|
470
|
+
name: string,
|
|
471
|
+
validationResult: HelperFooterMessage | undefined
|
|
472
|
+
) => {
|
|
473
|
+
if (validationResult) {
|
|
474
|
+
helperFooterRef.current = {
|
|
475
|
+
...helperFooterRef.current,
|
|
476
|
+
[name]: validationResult,
|
|
477
|
+
}
|
|
478
|
+
} else {
|
|
479
|
+
helperFooterRef.current = Object.fromEntries(
|
|
480
|
+
Object.entries(helperFooterRef.current).filter(([key]) => key !== name)
|
|
481
|
+
)
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
console.log('Updated helperFooterRef:', helperFooterRef.current)
|
|
485
|
+
setHelperFooterValue({ ...helperFooterRef.current })
|
|
486
|
+
console.log('Helper footer updated in state')
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const validateRequiredField = useCallback(
|
|
490
|
+
(required: boolean, formname: string, name: string, label: string) => {
|
|
491
|
+
console.log('validateRequiredField: Starting', {
|
|
492
|
+
required,
|
|
493
|
+
formname,
|
|
494
|
+
name,
|
|
495
|
+
label,
|
|
496
|
+
})
|
|
497
|
+
if (required && formname && name && label) {
|
|
498
|
+
console.log('validateRequiredField: Validating required field')
|
|
499
|
+
const emptyFormData = new FormData()
|
|
500
|
+
emptyFormData.append(name, '')
|
|
501
|
+
validateField(name, emptyFormData, label, required, formname)
|
|
502
|
+
} else {
|
|
503
|
+
console.log(
|
|
504
|
+
'validateRequiredField: Not validating (missing required props)'
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
[validateField]
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
const useShowErrorEffect = (
|
|
512
|
+
formSubmitted: boolean,
|
|
513
|
+
hasInput: boolean,
|
|
514
|
+
isFocused: boolean,
|
|
515
|
+
setShowError: React.Dispatch<React.SetStateAction<boolean>>
|
|
516
|
+
) => {
|
|
517
|
+
useEffect(() => {
|
|
518
|
+
const showError = formSubmitted || (hasInput && !isFocused)
|
|
519
|
+
console.log('useShowErrorEffect: Setting showError to', showError, {
|
|
520
|
+
formSubmitted,
|
|
521
|
+
hasInput,
|
|
522
|
+
isFocused,
|
|
523
|
+
})
|
|
524
|
+
setShowError(showError)
|
|
525
|
+
}, [formSubmitted, hasInput, isFocused, setShowError])
|
|
400
526
|
}
|
|
527
|
+
|
|
528
|
+
return useMemo(
|
|
529
|
+
() => ({
|
|
530
|
+
validateField,
|
|
531
|
+
validateRequiredField,
|
|
532
|
+
helperFooterValue,
|
|
533
|
+
useShowErrorEffect,
|
|
534
|
+
}),
|
|
535
|
+
[validateField, validateRequiredField, helperFooterValue]
|
|
536
|
+
)
|
|
401
537
|
}
|