goobs-frontend 0.7.67 → 0.7.69
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 -16
- package/src/app/_app.tsx +8 -8
- package/src/components/Button/index.tsx +95 -203
- package/src/components/ConfirmationCodeInput/index.tsx +4 -6
- package/src/components/Content/Structure/button/useButton.tsx +1 -35
- package/src/components/Content/Structure/datefield/useDateField.tsx +55 -0
- package/src/components/Content/Structure/dropdown/useDropdown.tsx +55 -0
- package/src/components/Content/Structure/incremementNumberField/useIncremementNumberField.tsx +65 -0
- package/src/components/Content/Structure/numberField/useNumberField.tsx +55 -0
- package/src/components/Content/Structure/passwordField/usePasswordField.tsx +57 -0
- package/src/components/Content/Structure/phoneNumber/usePhoneNumber.tsx +0 -0
- package/src/components/Content/Structure/qrcode/useQRCode.tsx +69 -0
- package/src/components/Content/Structure/searchbar/useSearchbar.tsx +55 -0
- package/src/components/Content/Structure/textfield/useTextField.tsx +84 -0
- package/src/components/Content/index.tsx +44 -7
- package/src/components/DateField/index.tsx +112 -0
- package/src/components/Dropdown/index.tsx +91 -0
- package/src/components/Form/Popup/index.tsx +1 -1
- package/src/components/IncrementNumberField/index.tsx +123 -0
- package/src/components/Nav/HorizontalVariant/index.tsx +18 -12
- package/src/components/Nav/VerticalVariant/index.tsx +14 -10
- package/src/components/NumberField/index.tsx +95 -0
- package/src/components/PasswordField/index.tsx +105 -0
- package/src/components/PhoneNumberField/index.tsx +102 -0
- package/src/components/PricingTable/index.tsx +10 -8
- package/src/components/QRCode/index.tsx +105 -0
- package/src/components/Searchbar/index.tsx +77 -0
- package/src/components/TextField/index.tsx +130 -0
- package/src/components/Toolbar/index.tsx +11 -10
- package/src/index.ts +54 -9
- package/src/components/Button/hook/useHelperFooter.tsx +0 -214
- package/src/components/Content/Structure/styledcomponent/useStyledComponent.tsx +0 -104
- package/src/components/StyledComponent/adornment/index.tsx +0 -125
- package/src/components/StyledComponent/hooks/useDropdown.tsx +0 -150
- package/src/components/StyledComponent/hooks/useInputHelperFooter.tsx +0 -524
- package/src/components/StyledComponent/hooks/usePhoneNumber.tsx +0 -99
- package/src/components/StyledComponent/hooks/useRequiredFieldsValidator.tsx +0 -190
- package/src/components/StyledComponent/hooks/useSearchbar.tsx +0 -46
- package/src/components/StyledComponent/hooks/useSplitButton.tsx +0 -70
- package/src/components/StyledComponent/index.tsx +0 -473
- package/src/components/StyledComponent/useCallbacks/index.tsx +0 -46
- package/src/styles/StyledComponent/Label/index.ts +0 -76
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { TextField, InputAdornment, styled } from '@mui/material'
|
|
3
|
+
import SearchIcon from '@mui/icons-material/Search'
|
|
4
|
+
|
|
5
|
+
export interface SearchbarProps {
|
|
6
|
+
label?: string
|
|
7
|
+
backgroundcolor?: string
|
|
8
|
+
iconcolor?: string
|
|
9
|
+
outlinecolor?: string
|
|
10
|
+
fontcolor?: string
|
|
11
|
+
placeholder?: string
|
|
12
|
+
onChange?: () => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const StyledTextField = styled(TextField)<{
|
|
16
|
+
backgroundcolor?: string
|
|
17
|
+
outlinecolor?: string
|
|
18
|
+
$fontcolor?: string // Use $ prefix to avoid passing it as DOM attribute
|
|
19
|
+
}>(({ theme, backgroundcolor, outlinecolor, $fontcolor }) => ({
|
|
20
|
+
'& .MuiOutlinedInput-root': {
|
|
21
|
+
backgroundColor: backgroundcolor || theme.palette.background.paper,
|
|
22
|
+
'& fieldset': {
|
|
23
|
+
borderColor: outlinecolor || theme.palette.primary.main,
|
|
24
|
+
},
|
|
25
|
+
'&:hover fieldset': {
|
|
26
|
+
borderColor: outlinecolor || theme.palette.primary.main,
|
|
27
|
+
},
|
|
28
|
+
'&.Mui-focused fieldset': {
|
|
29
|
+
borderColor: outlinecolor || theme.palette.primary.main,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
'& .MuiInputLabel-root': {
|
|
33
|
+
color: $fontcolor || theme.palette.text.primary,
|
|
34
|
+
'&.Mui-focused': {
|
|
35
|
+
color: $fontcolor || theme.palette.primary.main,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
'& .MuiInputBase-input': {
|
|
39
|
+
color: $fontcolor || theme.palette.text.primary,
|
|
40
|
+
},
|
|
41
|
+
}))
|
|
42
|
+
|
|
43
|
+
const Searchbar: React.FC<SearchbarProps> = ({
|
|
44
|
+
label,
|
|
45
|
+
backgroundcolor,
|
|
46
|
+
iconcolor,
|
|
47
|
+
outlinecolor,
|
|
48
|
+
fontcolor,
|
|
49
|
+
placeholder,
|
|
50
|
+
onChange,
|
|
51
|
+
}) => {
|
|
52
|
+
const handleChange = () => {
|
|
53
|
+
onChange?.()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<StyledTextField
|
|
58
|
+
label={label}
|
|
59
|
+
variant="outlined"
|
|
60
|
+
fullWidth
|
|
61
|
+
placeholder={placeholder}
|
|
62
|
+
backgroundcolor={backgroundcolor}
|
|
63
|
+
outlinecolor={outlinecolor}
|
|
64
|
+
$fontcolor={fontcolor}
|
|
65
|
+
InputProps={{
|
|
66
|
+
startAdornment: (
|
|
67
|
+
<InputAdornment position="start">
|
|
68
|
+
<SearchIcon style={{ color: iconcolor }} />
|
|
69
|
+
</InputAdornment>
|
|
70
|
+
),
|
|
71
|
+
}}
|
|
72
|
+
onChange={handleChange}
|
|
73
|
+
/>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default Searchbar
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React, { useCallback, useMemo } from 'react'
|
|
2
|
+
import { Box, TextField as MuiTextField, TextFieldProps } from '@mui/material'
|
|
3
|
+
|
|
4
|
+
export interface CustomTextFieldProps extends Omit<TextFieldProps, 'name'> {
|
|
5
|
+
name: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const TextField: React.FC<CustomTextFieldProps> = React.memo(props => {
|
|
9
|
+
const {
|
|
10
|
+
name,
|
|
11
|
+
label,
|
|
12
|
+
placeholder,
|
|
13
|
+
onChange,
|
|
14
|
+
onFocus,
|
|
15
|
+
onBlur,
|
|
16
|
+
value,
|
|
17
|
+
error,
|
|
18
|
+
sx,
|
|
19
|
+
InputProps,
|
|
20
|
+
...restProps
|
|
21
|
+
} = props
|
|
22
|
+
|
|
23
|
+
const handleChange = useCallback(
|
|
24
|
+
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
25
|
+
if (onChange) {
|
|
26
|
+
onChange(e)
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
[onChange]
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
const handleFocus = useCallback(
|
|
33
|
+
(e: React.FocusEvent<HTMLInputElement>) => {
|
|
34
|
+
if (onFocus) {
|
|
35
|
+
onFocus(e)
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
[onFocus]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const handleBlur = useCallback(
|
|
42
|
+
(e: React.FocusEvent<HTMLInputElement>) => {
|
|
43
|
+
if (onBlur) {
|
|
44
|
+
onBlur(e)
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[onBlur]
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const handleClick = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
|
|
51
|
+
e.preventDefault()
|
|
52
|
+
}, [])
|
|
53
|
+
|
|
54
|
+
const inputStyle = useMemo<React.CSSProperties>(
|
|
55
|
+
() => ({
|
|
56
|
+
backgroundColor: 'inherit',
|
|
57
|
+
width: '100%',
|
|
58
|
+
height: 40,
|
|
59
|
+
cursor: 'text',
|
|
60
|
+
boxSizing: 'border-box',
|
|
61
|
+
borderRadius: 5,
|
|
62
|
+
paddingRight: 6,
|
|
63
|
+
}),
|
|
64
|
+
[]
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
const mergedInputProps = useMemo(
|
|
68
|
+
() => ({
|
|
69
|
+
...InputProps,
|
|
70
|
+
style: {
|
|
71
|
+
...inputStyle,
|
|
72
|
+
...InputProps?.style,
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
[InputProps, inputStyle]
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const labelStyle = useMemo(
|
|
79
|
+
() => ({
|
|
80
|
+
'&.MuiInputLabel-shrink': {
|
|
81
|
+
top: '0px',
|
|
82
|
+
left: '0px',
|
|
83
|
+
},
|
|
84
|
+
'&:not(.MuiInputLabel-shrink)': {
|
|
85
|
+
transform: 'scale(1)',
|
|
86
|
+
transformOrigin: 'top left',
|
|
87
|
+
top: '9px',
|
|
88
|
+
left: '12px',
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
[]
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Box
|
|
96
|
+
sx={{
|
|
97
|
+
display: 'flex',
|
|
98
|
+
flexDirection: 'column',
|
|
99
|
+
justifyContent: 'center',
|
|
100
|
+
width: '100%',
|
|
101
|
+
marginTop: '5px',
|
|
102
|
+
height: '62px',
|
|
103
|
+
...sx,
|
|
104
|
+
}}
|
|
105
|
+
onClick={handleClick}
|
|
106
|
+
>
|
|
107
|
+
<MuiTextField
|
|
108
|
+
name={name}
|
|
109
|
+
label={label}
|
|
110
|
+
placeholder={placeholder}
|
|
111
|
+
onChange={handleChange}
|
|
112
|
+
onFocus={handleFocus}
|
|
113
|
+
onBlur={handleBlur}
|
|
114
|
+
value={value}
|
|
115
|
+
error={error}
|
|
116
|
+
InputProps={mergedInputProps}
|
|
117
|
+
InputLabelProps={{
|
|
118
|
+
sx: labelStyle,
|
|
119
|
+
}}
|
|
120
|
+
fullWidth
|
|
121
|
+
variant="outlined"
|
|
122
|
+
{...restProps}
|
|
123
|
+
/>
|
|
124
|
+
</Box>
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
TextField.displayName = 'TextField'
|
|
129
|
+
|
|
130
|
+
export default TextField
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import React, { useState } from 'react'
|
|
3
3
|
import { Box, styled } from '@mui/material'
|
|
4
|
-
import StyledComponent, { StyledComponentProps } from '../StyledComponent'
|
|
5
4
|
import CustomButton, { CustomButtonProps } from '../Button'
|
|
5
|
+
import Searchbar, { SearchbarProps } from '../Searchbar'
|
|
6
|
+
import Dropdown, { DropdownProps } from '../Dropdown'
|
|
6
7
|
import { white, black, semiTransparentWhite } from '../../styles/palette'
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -18,8 +19,8 @@ const VerticalDivider = styled(Box)({
|
|
|
18
19
|
*/
|
|
19
20
|
export interface ToolbarProps {
|
|
20
21
|
buttons?: CustomButtonProps[]
|
|
21
|
-
dropdowns?:
|
|
22
|
-
searchbarProps?:
|
|
22
|
+
dropdowns?: DropdownProps[]
|
|
23
|
+
searchbarProps?: SearchbarProps
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -30,7 +31,6 @@ export interface ToolbarProps {
|
|
|
30
31
|
function CustomToolbar({ buttons, dropdowns, searchbarProps }: ToolbarProps) {
|
|
31
32
|
// State for checkbox width (set to 45px as default)
|
|
32
33
|
const [checkboxWidth] = useState(45)
|
|
33
|
-
|
|
34
34
|
// Explicitly set toolbar height to 56px
|
|
35
35
|
const toolbarHeight = 56
|
|
36
36
|
|
|
@@ -101,12 +101,12 @@ function CustomToolbar({ buttons, dropdowns, searchbarProps }: ToolbarProps) {
|
|
|
101
101
|
height: '100%',
|
|
102
102
|
}}
|
|
103
103
|
>
|
|
104
|
-
<
|
|
105
|
-
componentvariant="searchbar"
|
|
104
|
+
<Searchbar
|
|
106
105
|
backgroundcolor={semiTransparentWhite.main}
|
|
107
106
|
label="Search the DataGrid"
|
|
108
|
-
|
|
107
|
+
fontcolor={black.main}
|
|
109
108
|
iconcolor={black.main}
|
|
109
|
+
onChange={() => console.log('Search changed')}
|
|
110
110
|
{...searchbarProps}
|
|
111
111
|
/>
|
|
112
112
|
</Box>
|
|
@@ -122,11 +122,12 @@ function CustomToolbar({ buttons, dropdowns, searchbarProps }: ToolbarProps) {
|
|
|
122
122
|
}}
|
|
123
123
|
>
|
|
124
124
|
{dropdowns.map((dropdown, index) => (
|
|
125
|
-
<
|
|
125
|
+
<Dropdown
|
|
126
126
|
key={index}
|
|
127
|
-
componentvariant="dropdown"
|
|
128
127
|
outlinecolor={black.main}
|
|
129
|
-
|
|
128
|
+
fontcolor={black.main}
|
|
129
|
+
shrunkfontcolor={black.main}
|
|
130
|
+
onChange={() => console.log('Dropdown changed')}
|
|
130
131
|
{...dropdown}
|
|
131
132
|
/>
|
|
132
133
|
))}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
1
3
|
// Components
|
|
2
|
-
import CustomButton
|
|
4
|
+
import CustomButton from './components/Button'
|
|
3
5
|
import CustomGrid, {
|
|
4
6
|
Alignment,
|
|
5
7
|
BorderProp,
|
|
@@ -7,9 +9,6 @@ import CustomGrid, {
|
|
|
7
9
|
gridconfig,
|
|
8
10
|
cellconfig,
|
|
9
11
|
} from './components/Grid'
|
|
10
|
-
import StyledComponent, {
|
|
11
|
-
StyledComponentProps,
|
|
12
|
-
} from './components/StyledComponent'
|
|
13
12
|
import Typography, {
|
|
14
13
|
FontFamily,
|
|
15
14
|
TypographyVariant,
|
|
@@ -37,13 +36,25 @@ import { CustomStepper, CustomStepperProps } from './components/Stepper'
|
|
|
37
36
|
import CustomToolbar, { ToolbarProps } from './components/Toolbar'
|
|
38
37
|
import TransferList, { TransferListProps } from './components/TransferList'
|
|
39
38
|
import StyledTooltip, { CustomTooltipProps } from './components/Tooltip'
|
|
40
|
-
import
|
|
39
|
+
import QRCodeComponent, { QRCodeProps } from './components/QRCode'
|
|
40
|
+
|
|
41
|
+
// New imports
|
|
42
|
+
import DateField from './components/DateField'
|
|
43
|
+
import Dropdown from './components/Dropdown'
|
|
44
|
+
import IncrementNumberField from './components/IncrementNumberField'
|
|
45
|
+
import NumberField from './components/NumberField'
|
|
46
|
+
import PasswordField from './components/PasswordField'
|
|
47
|
+
import PhoneNumberField from './components/PhoneNumberField'
|
|
48
|
+
import Searchbar from './components/Searchbar'
|
|
49
|
+
import TextField from './components/TextField'
|
|
41
50
|
|
|
42
51
|
// Animations
|
|
43
52
|
import { Animation } from './components/Content/Structure/animations'
|
|
44
53
|
|
|
45
54
|
// Importing ExtendedButtonProps from useButton
|
|
46
55
|
import { ExtendedButtonProps } from './components/Content/Structure/button/useButton'
|
|
56
|
+
import { ExtendedTypographyProps } from './components/Content/Structure/typography/useGridTypography'
|
|
57
|
+
import { ExtendedTextFieldProps } from './components/Content/Structure/textfield/useTextField'
|
|
47
58
|
|
|
48
59
|
// Colors
|
|
49
60
|
import {
|
|
@@ -142,10 +153,23 @@ declare type StyledTooltipComponentProps = React.ComponentProps<
|
|
|
142
153
|
typeof StyledTooltip
|
|
143
154
|
>
|
|
144
155
|
|
|
156
|
+
// New type declarations
|
|
157
|
+
declare type DateFieldProps = React.ComponentProps<typeof DateField>
|
|
158
|
+
declare type DropdownProps = React.ComponentProps<typeof Dropdown>
|
|
159
|
+
declare type IncrementNumberFieldProps = React.ComponentProps<
|
|
160
|
+
typeof IncrementNumberField
|
|
161
|
+
>
|
|
162
|
+
declare type NumberFieldProps = React.ComponentProps<typeof NumberField>
|
|
163
|
+
declare type PasswordFieldProps = React.ComponentProps<typeof PasswordField>
|
|
164
|
+
declare type PhoneNumberFieldProps = React.ComponentProps<
|
|
165
|
+
typeof PhoneNumberField
|
|
166
|
+
>
|
|
167
|
+
declare type SearchbarProps = React.ComponentProps<typeof Searchbar>
|
|
168
|
+
declare type TextFieldProps = React.ComponentProps<typeof TextField>
|
|
169
|
+
|
|
145
170
|
// Named exports
|
|
146
171
|
export { CustomButton }
|
|
147
172
|
export { CustomGrid }
|
|
148
|
-
export { StyledComponent }
|
|
149
173
|
export { Typography }
|
|
150
174
|
export { ConfirmationCodeInput }
|
|
151
175
|
export { RadioGroup }
|
|
@@ -161,16 +185,26 @@ export { CustomToolbar }
|
|
|
161
185
|
export { TransferList }
|
|
162
186
|
export { StyledTooltip }
|
|
163
187
|
export { formContainerStyle }
|
|
188
|
+
export { QRCodeComponent }
|
|
189
|
+
|
|
190
|
+
// New named exports
|
|
191
|
+
export { DateField }
|
|
192
|
+
export { Dropdown }
|
|
193
|
+
export { IncrementNumberField }
|
|
194
|
+
export { NumberField }
|
|
195
|
+
export { PasswordField }
|
|
196
|
+
export { PhoneNumberField }
|
|
197
|
+
export { Searchbar }
|
|
198
|
+
export { TextField }
|
|
164
199
|
|
|
165
200
|
// Exporting ExtendedButtonProps
|
|
166
201
|
export type { ExtendedButtonProps }
|
|
167
|
-
|
|
202
|
+
export type { ExtendedTypographyProps }
|
|
203
|
+
export type { ExtendedTextFieldProps }
|
|
168
204
|
// Type exports
|
|
169
205
|
export type { CustomButtonProps }
|
|
170
|
-
export type { ButtonAlignment }
|
|
171
206
|
export type { CustomGridProps }
|
|
172
207
|
export type { Alignment, BorderProp, columnconfig, gridconfig, cellconfig }
|
|
173
|
-
export type { StyledComponentProps }
|
|
174
208
|
export type { FontFamily, TypographyVariant, TypographyProps }
|
|
175
209
|
export type { ConfirmationCodeInputsProps }
|
|
176
210
|
export type { RadioOption, RadioGroupProps }
|
|
@@ -184,6 +218,7 @@ export type { CustomStepperProps }
|
|
|
184
218
|
export type { ToolbarProps }
|
|
185
219
|
export type { TransferListProps }
|
|
186
220
|
export type { CustomTooltipProps }
|
|
221
|
+
export type { QRCodeProps }
|
|
187
222
|
|
|
188
223
|
// Additional type exports for the newly declared types
|
|
189
224
|
export type { TypographyComponentProps }
|
|
@@ -201,6 +236,16 @@ export type { CustomToolbarComponentProps }
|
|
|
201
236
|
export type { TransferListComponentProps }
|
|
202
237
|
export type { StyledTooltipComponentProps }
|
|
203
238
|
|
|
239
|
+
// New type exports
|
|
240
|
+
export type { DateFieldProps }
|
|
241
|
+
export type { DropdownProps }
|
|
242
|
+
export type { IncrementNumberFieldProps }
|
|
243
|
+
export type { NumberFieldProps }
|
|
244
|
+
export type { PasswordFieldProps }
|
|
245
|
+
export type { PhoneNumberFieldProps }
|
|
246
|
+
export type { SearchbarProps }
|
|
247
|
+
export type { TextFieldProps }
|
|
248
|
+
|
|
204
249
|
// Animation type export
|
|
205
250
|
export type { Animation }
|
|
206
251
|
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react'
|
|
2
|
-
import { session } from 'goobs-cache'
|
|
3
|
-
|
|
4
|
-
export interface HelperFooterMessage {
|
|
5
|
-
status: 'error' | 'success' | 'emptyAndRequired'
|
|
6
|
-
statusMessage: string
|
|
7
|
-
spreadMessage: string
|
|
8
|
-
spreadMessagePriority: number
|
|
9
|
-
required: boolean
|
|
10
|
-
hasInput?: boolean
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const useHelperFooter = (initialFormname?: string) => {
|
|
14
|
-
console.log(
|
|
15
|
-
'useHelperFooter: Hook called with initialFormname:',
|
|
16
|
-
initialFormname
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
const helperFooterAtom = useMemo(
|
|
20
|
-
() => session.atom<Record<string, HelperFooterMessage> | null>(null),
|
|
21
|
-
[]
|
|
22
|
-
)
|
|
23
|
-
const currentErrorIndexAtom = useMemo(() => session.atom<number>(0), [])
|
|
24
|
-
|
|
25
|
-
const [helperFooters, setHelperFooters] = session.useAtom(helperFooterAtom)
|
|
26
|
-
const [currentErrorIndex, setCurrentErrorIndex] = session.useAtom(
|
|
27
|
-
currentErrorIndexAtom
|
|
28
|
-
)
|
|
29
|
-
const [helperFooterResult] = session.useAtom(
|
|
30
|
-
useMemo(
|
|
31
|
-
() => session.atom(`helperfooter:${initialFormname}`),
|
|
32
|
-
[initialFormname]
|
|
33
|
-
)
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
const fetchHelperFooters = useCallback((): Record<
|
|
37
|
-
string,
|
|
38
|
-
HelperFooterMessage
|
|
39
|
-
> | null => {
|
|
40
|
-
console.log('useHelperFooter: fetchHelperFooters called')
|
|
41
|
-
if (!initialFormname) {
|
|
42
|
-
console.log('useHelperFooter: No formname provided, returning null')
|
|
43
|
-
return null
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
helperFooters === null &&
|
|
48
|
-
helperFooterResult &&
|
|
49
|
-
typeof helperFooterResult === 'object' &&
|
|
50
|
-
helperFooterResult !== null
|
|
51
|
-
) {
|
|
52
|
-
const fetchedHelperFooters: Record<string, HelperFooterMessage> = {}
|
|
53
|
-
|
|
54
|
-
for (const [key, value] of Object.entries(helperFooterResult)) {
|
|
55
|
-
if (
|
|
56
|
-
typeof value === 'object' &&
|
|
57
|
-
value !== null &&
|
|
58
|
-
'status' in value &&
|
|
59
|
-
'statusMessage' in value &&
|
|
60
|
-
'spreadMessage' in value &&
|
|
61
|
-
'spreadMessagePriority' in value &&
|
|
62
|
-
'required' in value &&
|
|
63
|
-
'hasInput' in value
|
|
64
|
-
) {
|
|
65
|
-
fetchedHelperFooters[key] = {
|
|
66
|
-
status: value.status as 'error' | 'success' | 'emptyAndRequired',
|
|
67
|
-
statusMessage: String(value.statusMessage),
|
|
68
|
-
spreadMessage: String(value.spreadMessage),
|
|
69
|
-
spreadMessagePriority: Number(value.spreadMessagePriority),
|
|
70
|
-
required: Boolean(value.required),
|
|
71
|
-
hasInput: Boolean(value.hasInput),
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
console.log(
|
|
77
|
-
'useHelperFooter: Fetched helper footers:',
|
|
78
|
-
fetchedHelperFooters
|
|
79
|
-
)
|
|
80
|
-
setHelperFooters(fetchedHelperFooters)
|
|
81
|
-
return fetchedHelperFooters
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return helperFooters
|
|
85
|
-
}, [helperFooters, helperFooterResult, initialFormname, setHelperFooters])
|
|
86
|
-
|
|
87
|
-
const updateFormValidation = useCallback((): boolean => {
|
|
88
|
-
console.log('useHelperFooter: updateFormValidation called')
|
|
89
|
-
const fetchedHelperFooters = fetchHelperFooters()
|
|
90
|
-
|
|
91
|
-
if (fetchedHelperFooters) {
|
|
92
|
-
const errorFooters = Object.values(fetchedHelperFooters).filter(
|
|
93
|
-
footer =>
|
|
94
|
-
(footer.status === 'error' || footer.status === 'emptyAndRequired') &&
|
|
95
|
-
footer.required
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
console.log('useHelperFooter: Error footers:', errorFooters)
|
|
99
|
-
|
|
100
|
-
if (errorFooters.length === 0) {
|
|
101
|
-
setCurrentErrorIndex(0)
|
|
102
|
-
console.log('useHelperFooter: No errors found, returning true')
|
|
103
|
-
return true
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
errorFooters.sort(
|
|
107
|
-
(a, b) => a.spreadMessagePriority - b.spreadMessagePriority
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
if (currentErrorIndex >= errorFooters.length) {
|
|
111
|
-
setCurrentErrorIndex(0)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
console.log('useHelperFooter: Errors found, returning false')
|
|
115
|
-
return false
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
console.log('useHelperFooter: No helper footers, returning true')
|
|
119
|
-
return true
|
|
120
|
-
}, [fetchHelperFooters, currentErrorIndex, setCurrentErrorIndex])
|
|
121
|
-
|
|
122
|
-
const checkFormStatus = useCallback(() => {
|
|
123
|
-
console.log('useHelperFooter: checkFormStatus called')
|
|
124
|
-
const fetchedHelperFooters = fetchHelperFooters()
|
|
125
|
-
const status = fetchedHelperFooters
|
|
126
|
-
? Object.values(fetchedHelperFooters).every(
|
|
127
|
-
value => !value.required || (value.required && value.hasInput)
|
|
128
|
-
)
|
|
129
|
-
: true
|
|
130
|
-
console.log('useHelperFooter: Form status:', status)
|
|
131
|
-
return status
|
|
132
|
-
}, [fetchHelperFooters])
|
|
133
|
-
|
|
134
|
-
const getEmptyRequiredFields = useCallback(() => {
|
|
135
|
-
console.log('useHelperFooter: getEmptyRequiredFields called')
|
|
136
|
-
const fetchedHelperFooters = fetchHelperFooters()
|
|
137
|
-
if (!fetchedHelperFooters) return []
|
|
138
|
-
const emptyFields = Object.entries(fetchedHelperFooters)
|
|
139
|
-
.filter(([, value]) => value.required && !value.hasInput)
|
|
140
|
-
.map(([key]) => key)
|
|
141
|
-
console.log('useHelperFooter: Empty required fields:', emptyFields)
|
|
142
|
-
return emptyFields
|
|
143
|
-
}, [fetchHelperFooters])
|
|
144
|
-
|
|
145
|
-
const getCurrentErrorMessage = useCallback(() => {
|
|
146
|
-
console.log('useHelperFooter: getCurrentErrorMessage called')
|
|
147
|
-
const fetchedHelperFooters = fetchHelperFooters()
|
|
148
|
-
if (!fetchedHelperFooters) return undefined
|
|
149
|
-
const errorFooters = Object.values(fetchedHelperFooters).filter(
|
|
150
|
-
footer =>
|
|
151
|
-
(footer.status === 'error' || footer.status === 'emptyAndRequired') &&
|
|
152
|
-
footer.required
|
|
153
|
-
)
|
|
154
|
-
if (errorFooters.length === 0) return undefined
|
|
155
|
-
const message = errorFooters[currentErrorIndex]?.spreadMessage
|
|
156
|
-
console.log('useHelperFooter: Current error message:', message)
|
|
157
|
-
return message
|
|
158
|
-
}, [fetchHelperFooters, currentErrorIndex])
|
|
159
|
-
|
|
160
|
-
const isFormValid = useCallback(() => {
|
|
161
|
-
const fetchedHelperFooters = fetchHelperFooters()
|
|
162
|
-
if (!fetchedHelperFooters) return true
|
|
163
|
-
const valid = Object.values(fetchedHelperFooters).every(
|
|
164
|
-
footer =>
|
|
165
|
-
footer.status !== 'error' && footer.status !== 'emptyAndRequired'
|
|
166
|
-
)
|
|
167
|
-
console.log('useHelperFooter: isFormValid:', valid)
|
|
168
|
-
return valid
|
|
169
|
-
}, [fetchHelperFooters])
|
|
170
|
-
|
|
171
|
-
const nextError = useCallback(() => {
|
|
172
|
-
console.log('useHelperFooter: nextError called')
|
|
173
|
-
const fetchedHelperFooters = fetchHelperFooters()
|
|
174
|
-
if (!fetchedHelperFooters) return
|
|
175
|
-
const errorFooters = Object.values(fetchedHelperFooters).filter(
|
|
176
|
-
footer =>
|
|
177
|
-
(footer.status === 'error' || footer.status === 'emptyAndRequired') &&
|
|
178
|
-
footer.required
|
|
179
|
-
)
|
|
180
|
-
if (errorFooters.length > 0) {
|
|
181
|
-
setCurrentErrorIndex(prevIndex => (prevIndex + 1) % errorFooters.length)
|
|
182
|
-
console.log(
|
|
183
|
-
'useHelperFooter: New error index:',
|
|
184
|
-
(currentErrorIndex + 1) % errorFooters.length
|
|
185
|
-
)
|
|
186
|
-
}
|
|
187
|
-
}, [fetchHelperFooters, currentErrorIndex, setCurrentErrorIndex])
|
|
188
|
-
|
|
189
|
-
const result = useMemo(
|
|
190
|
-
() => ({
|
|
191
|
-
errorMessage: getCurrentErrorMessage,
|
|
192
|
-
isFormValid,
|
|
193
|
-
updateFormValidation,
|
|
194
|
-
fetchHelperFooters,
|
|
195
|
-
nextError,
|
|
196
|
-
checkFormStatus,
|
|
197
|
-
getEmptyRequiredFields,
|
|
198
|
-
}),
|
|
199
|
-
[
|
|
200
|
-
getCurrentErrorMessage,
|
|
201
|
-
isFormValid,
|
|
202
|
-
updateFormValidation,
|
|
203
|
-
fetchHelperFooters,
|
|
204
|
-
nextError,
|
|
205
|
-
checkFormStatus,
|
|
206
|
-
getEmptyRequiredFields,
|
|
207
|
-
]
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
console.log('useHelperFooter: Returning result:', result)
|
|
211
|
-
return result
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export default useHelperFooter
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import StyledComponent, {
|
|
3
|
-
StyledComponentProps,
|
|
4
|
-
} from '../../../../components/StyledComponent'
|
|
5
|
-
import { columnconfig, cellconfig } from '../../../Grid'
|
|
6
|
-
|
|
7
|
-
type ExtendedColumnConfig = Omit<columnconfig, 'component'> & {
|
|
8
|
-
component?: columnconfig['component']
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ExtendedStyledComponentProps
|
|
12
|
-
extends Omit<StyledComponentProps, 'columnconfig'> {
|
|
13
|
-
columnconfig?: ExtendedColumnConfig
|
|
14
|
-
cellconfig?: cellconfig
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const useStyledComponent = (grid: {
|
|
18
|
-
styledcomponent?:
|
|
19
|
-
| ExtendedStyledComponentProps
|
|
20
|
-
| ExtendedStyledComponentProps[]
|
|
21
|
-
}): columnconfig | columnconfig[] | null => {
|
|
22
|
-
if (!grid.styledcomponent) return null
|
|
23
|
-
|
|
24
|
-
const renderStyledComponent = (
|
|
25
|
-
component: ExtendedStyledComponentProps,
|
|
26
|
-
index: number
|
|
27
|
-
): columnconfig => {
|
|
28
|
-
const {
|
|
29
|
-
name,
|
|
30
|
-
outlinecolor,
|
|
31
|
-
iconcolor,
|
|
32
|
-
backgroundcolor,
|
|
33
|
-
combinedfontcolor,
|
|
34
|
-
unshrunkfontcolor,
|
|
35
|
-
shrunkfontcolor,
|
|
36
|
-
autoComplete,
|
|
37
|
-
componentvariant,
|
|
38
|
-
options,
|
|
39
|
-
helperfooter,
|
|
40
|
-
placeholder,
|
|
41
|
-
minRows,
|
|
42
|
-
label,
|
|
43
|
-
shrunklabellocation,
|
|
44
|
-
value,
|
|
45
|
-
columnconfig: itemColumnConfig,
|
|
46
|
-
valuestatus,
|
|
47
|
-
cellconfig,
|
|
48
|
-
required,
|
|
49
|
-
...restProps
|
|
50
|
-
} = component
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
!itemColumnConfig ||
|
|
54
|
-
typeof itemColumnConfig !== 'object' ||
|
|
55
|
-
typeof itemColumnConfig.row !== 'number' ||
|
|
56
|
-
typeof itemColumnConfig.column !== 'number'
|
|
57
|
-
) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
'columnconfig must be an object with row and column as numbers'
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Merge the cellconfig with the columnconfig
|
|
64
|
-
const mergedConfig: columnconfig = {
|
|
65
|
-
...itemColumnConfig,
|
|
66
|
-
cellconfig: {
|
|
67
|
-
...cellconfig,
|
|
68
|
-
},
|
|
69
|
-
component: (
|
|
70
|
-
<StyledComponent
|
|
71
|
-
key={`styledcomponent-${index}`}
|
|
72
|
-
name={name}
|
|
73
|
-
outlinecolor={outlinecolor}
|
|
74
|
-
iconcolor={iconcolor}
|
|
75
|
-
backgroundcolor={backgroundcolor}
|
|
76
|
-
combinedfontcolor={combinedfontcolor}
|
|
77
|
-
unshrunkfontcolor={unshrunkfontcolor}
|
|
78
|
-
shrunkfontcolor={shrunkfontcolor}
|
|
79
|
-
autoComplete={autoComplete}
|
|
80
|
-
componentvariant={componentvariant}
|
|
81
|
-
options={options}
|
|
82
|
-
helperfooter={helperfooter}
|
|
83
|
-
placeholder={placeholder}
|
|
84
|
-
minRows={minRows}
|
|
85
|
-
label={label}
|
|
86
|
-
shrunklabellocation={shrunklabellocation}
|
|
87
|
-
value={value}
|
|
88
|
-
valuestatus={valuestatus}
|
|
89
|
-
required={required}
|
|
90
|
-
{...restProps}
|
|
91
|
-
/>
|
|
92
|
-
),
|
|
93
|
-
}
|
|
94
|
-
return mergedConfig
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (Array.isArray(grid.styledcomponent)) {
|
|
98
|
-
return grid.styledcomponent.map(renderStyledComponent)
|
|
99
|
-
} else {
|
|
100
|
-
return renderStyledComponent(grid.styledcomponent, 0)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export default useStyledComponent
|