goobs-frontend 0.7.64 → 0.7.65
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/hook/useHelperFooter.tsx +174 -201
- package/src/components/Button/index.tsx +208 -162
- package/src/components/ConfirmationCodeInput/index.tsx +7 -9
- package/src/components/Nav/HorizontalVariant/index.tsx +13 -39
- package/src/components/StyledComponent/hooks/useInputHelperFooter.tsx +567 -0
- package/src/components/StyledComponent/hooks/useRequiredFieldsValidator.tsx +137 -0
- package/src/components/StyledComponent/index.tsx +26 -31
- package/src/components/TransferList/index.tsx +12 -4
- package/src/components/StyledComponent/helperfooter/useHelperFooter.tsx +0 -638
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { useState, useRef, useEffect } from 'react'
|
|
4
4
|
import { Box, InputLabel, OutlinedInput, styled } from '@mui/material'
|
|
5
|
+
import { session } from 'goobs-cache'
|
|
5
6
|
import { useDropdown } from './hooks/useDropdown'
|
|
6
7
|
import { usePhoneNumber } from './hooks/usePhoneNumber'
|
|
7
8
|
import { useSplitButton } from './hooks/useSplitButton'
|
|
@@ -9,9 +10,10 @@ import { Typography } from './../Typography'
|
|
|
9
10
|
import { red, green } from '../../styles/palette'
|
|
10
11
|
import { StartAdornment, EndAdornment } from './adornment'
|
|
11
12
|
import {
|
|
12
|
-
|
|
13
|
+
useInputHelperFooter,
|
|
13
14
|
HelperFooterMessage,
|
|
14
|
-
} from './
|
|
15
|
+
} from './hooks/useInputHelperFooter'
|
|
16
|
+
import { useRequiredFieldsValidator } from './hooks/useRequiredFieldsValidator'
|
|
15
17
|
import labelStyles from '../../styles/StyledComponent/Label'
|
|
16
18
|
import { useHasInputEffect, usePreventAutocompleteEffect } from './useEffects'
|
|
17
19
|
|
|
@@ -94,6 +96,8 @@ export interface StyledComponentProps {
|
|
|
94
96
|
onOptionSelect?: (option: string) => void
|
|
95
97
|
/** Callback function when the input value changes */
|
|
96
98
|
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void
|
|
99
|
+
/** Priority of the spread message */
|
|
100
|
+
spreadMessagePriority?: number
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
/**
|
|
@@ -135,7 +139,6 @@ const StyledComponent: React.FC<StyledComponentProps> = props => {
|
|
|
135
139
|
value,
|
|
136
140
|
valuestatus,
|
|
137
141
|
placeholder,
|
|
138
|
-
required = false,
|
|
139
142
|
formname,
|
|
140
143
|
formSubmitted = false,
|
|
141
144
|
'aria-label': ariaLabel,
|
|
@@ -144,17 +147,22 @@ const StyledComponent: React.FC<StyledComponentProps> = props => {
|
|
|
144
147
|
'aria-describedby': ariaDescribedBy,
|
|
145
148
|
onOptionSelect,
|
|
146
149
|
onChange,
|
|
150
|
+
spreadMessagePriority,
|
|
147
151
|
} = props
|
|
148
152
|
|
|
149
|
-
const {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const { validateField } = useInputHelperFooter()
|
|
154
|
+
const helperFooterAtom = session.atom<Record<string, HelperFooterMessage>>({})
|
|
155
|
+
const [helperFooterValue] = session.useAtom(helperFooterAtom)
|
|
156
|
+
|
|
157
|
+
const showErrorAtom = session.atom<boolean>(false)
|
|
158
|
+
const [showError, setShowError] = session.useAtom(showErrorAtom)
|
|
159
|
+
|
|
160
|
+
const hasInputRef = useRef(false)
|
|
161
|
+
|
|
162
|
+
useRequiredFieldsValidator(formname || '', [props], hasInputRef)
|
|
163
|
+
|
|
155
164
|
const [isFocused, setIsFocused] = useState(false)
|
|
156
165
|
const [hasInput, setHasInput] = useState(false)
|
|
157
|
-
const [showError, setShowError] = useState(false)
|
|
158
166
|
const [passwordVisible, setPasswordVisible] = useState(false)
|
|
159
167
|
const inputRefInternal = useRef<HTMLInputElement>(null)
|
|
160
168
|
const inputBoxRef = useRef<HTMLDivElement>(null)
|
|
@@ -177,24 +185,6 @@ const StyledComponent: React.FC<StyledComponentProps> = props => {
|
|
|
177
185
|
useHasInputEffect(value, valuestatus, setHasInput)
|
|
178
186
|
usePreventAutocompleteEffect(inputRefInternal)
|
|
179
187
|
|
|
180
|
-
/**
|
|
181
|
-
* Initialize required fields when the form name changes
|
|
182
|
-
*/
|
|
183
|
-
useEffect(() => {
|
|
184
|
-
if (formname) {
|
|
185
|
-
initializeRequiredFields(formname)
|
|
186
|
-
}
|
|
187
|
-
}, [formname, initializeRequiredFields])
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Validate required field when relevant props change
|
|
191
|
-
*/
|
|
192
|
-
useEffect(() => {
|
|
193
|
-
if (required && formname && name && label) {
|
|
194
|
-
validateRequiredField(required, formname, name, label)
|
|
195
|
-
}
|
|
196
|
-
}, [required, formname, name, label, validateRequiredField])
|
|
197
|
-
|
|
198
188
|
/**
|
|
199
189
|
* Show error after a delay when form is submitted or input has value
|
|
200
190
|
*/
|
|
@@ -204,7 +194,11 @@ const StyledComponent: React.FC<StyledComponentProps> = props => {
|
|
|
204
194
|
}, 1000)
|
|
205
195
|
|
|
206
196
|
return () => clearTimeout(timer)
|
|
207
|
-
}, [formSubmitted, hasInput])
|
|
197
|
+
}, [formSubmitted, hasInput, setShowError])
|
|
198
|
+
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
hasInputRef.current = !!value
|
|
201
|
+
}, [value])
|
|
208
202
|
|
|
209
203
|
const currentHelperFooter = name ? helperFooterValue[name] : undefined
|
|
210
204
|
|
|
@@ -231,11 +225,12 @@ const StyledComponent: React.FC<StyledComponentProps> = props => {
|
|
|
231
225
|
}
|
|
232
226
|
|
|
233
227
|
setHasInput(!!e.target.value)
|
|
228
|
+
hasInputRef.current = !!e.target.value
|
|
234
229
|
|
|
235
230
|
const formData = new FormData()
|
|
236
231
|
formData.append(e.target.name, e.target.value)
|
|
237
232
|
if (name && label && formname) {
|
|
238
|
-
validateField(name, formData, label,
|
|
233
|
+
validateField(name, formData, label, formname, spreadMessagePriority)
|
|
239
234
|
}
|
|
240
235
|
}
|
|
241
236
|
|
|
@@ -254,7 +249,7 @@ const StyledComponent: React.FC<StyledComponentProps> = props => {
|
|
|
254
249
|
if (name && label && !hasInput && formname) {
|
|
255
250
|
const formData = new FormData()
|
|
256
251
|
formData.append(name, '')
|
|
257
|
-
validateField(name, formData, label,
|
|
252
|
+
validateField(name, formData, label, formname, spreadMessagePriority)
|
|
258
253
|
}
|
|
259
254
|
}
|
|
260
255
|
|
|
@@ -80,7 +80,9 @@ const TransferList: React.FC<TransferListProps> = ({
|
|
|
80
80
|
const newRight = right.concat(left)
|
|
81
81
|
setRight(newRight)
|
|
82
82
|
setLeft([])
|
|
83
|
-
|
|
83
|
+
if (onChange) {
|
|
84
|
+
onChange(newRight)
|
|
85
|
+
}
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
/**
|
|
@@ -92,7 +94,9 @@ const TransferList: React.FC<TransferListProps> = ({
|
|
|
92
94
|
setRight(newRight)
|
|
93
95
|
setLeft(newLeft)
|
|
94
96
|
setChecked(not(checked, leftChecked))
|
|
95
|
-
|
|
97
|
+
if (onChange) {
|
|
98
|
+
onChange(newRight)
|
|
99
|
+
}
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
/**
|
|
@@ -104,7 +108,9 @@ const TransferList: React.FC<TransferListProps> = ({
|
|
|
104
108
|
setLeft(newLeft)
|
|
105
109
|
setRight(newRight)
|
|
106
110
|
setChecked(not(checked, rightChecked))
|
|
107
|
-
|
|
111
|
+
if (onChange) {
|
|
112
|
+
onChange(newRight)
|
|
113
|
+
}
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
/**
|
|
@@ -114,7 +120,9 @@ const TransferList: React.FC<TransferListProps> = ({
|
|
|
114
120
|
const newLeft = left.concat(right)
|
|
115
121
|
setLeft(newLeft)
|
|
116
122
|
setRight([])
|
|
117
|
-
|
|
123
|
+
if (onChange) {
|
|
124
|
+
onChange([])
|
|
125
|
+
}
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
/**
|