@verifiedinc-public/shared-ui-elements 1.3.2 → 2.0.0
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/README.md +4 -24
- package/dist/components/index.mjs +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.mjs +1 -0
- package/dist/hooks/useSearchParams.d.ts +5 -0
- package/dist/index.mjs +1 -0
- package/dist/shared/index-CTvz4BbG.mjs +105 -0
- package/dist/shared/phone.schema-XBbyizhq.mjs +1 -0
- package/dist/shared/shadows-fgmuXym6.mjs +1 -0
- package/dist/shared/unix.schema-CMYTtXco.mjs +1 -0
- package/dist/shared/useQRCode-DXiPIj-D.mjs +1 -0
- package/dist/shared/useSearchParams-CW9y02Ym.mjs +1 -0
- package/dist/styles/index.mjs +1 -0
- package/dist/utils/masks/index.mjs +1 -0
- package/dist/utils/string/index.mjs +1 -0
- package/dist/validations/index.mjs +1 -0
- package/package.json +29 -8
- package/dist/shared-ui-elements.mjs +0 -105
- package/src/components/Alert/Alert.tsx +0 -8
- package/src/components/Alert/FullWidthAlert.tsx +0 -27
- package/src/components/Alert/index.ts +0 -2
- package/src/components/Backdrop/index.tsx +0 -34
- package/src/components/Banners/Banner.tsx +0 -42
- package/src/components/Banners/ExactBirthdayBanner.tsx +0 -18
- package/src/components/Banners/ResendPhoneBanner.tsx +0 -55
- package/src/components/Banners/TestPhoneNumbersBanner.tsx +0 -25
- package/src/components/Banners/index.tsx +0 -4
- package/src/components/Button/index.tsx +0 -8
- package/src/components/CredentialRequestsEditor/CredentialRequestsEditor.context.tsx +0 -98
- package/src/components/CredentialRequestsEditor/components/CredentialRequestsField.tsx +0 -103
- package/src/components/CredentialRequestsEditor/components/DataFieldAccordion.tsx +0 -337
- package/src/components/CredentialRequestsEditor/components/DataFieldDeleteModal.tsx +0 -64
- package/src/components/CredentialRequestsEditor/components/DataFieldDescription.tsx +0 -68
- package/src/components/CredentialRequestsEditor/components/DataFieldMandatory.tsx +0 -84
- package/src/components/CredentialRequestsEditor/components/DataFieldMulti.tsx +0 -74
- package/src/components/CredentialRequestsEditor/components/DataFieldOptionType.tsx +0 -84
- package/src/components/CredentialRequestsEditor/components/DataFieldSection.tsx +0 -48
- package/src/components/CredentialRequestsEditor/components/DataFieldUserInput.tsx +0 -71
- package/src/components/CredentialRequestsEditor/components/RadioOption.tsx +0 -89
- package/src/components/CredentialRequestsEditor/contexts/CredentialRequestFieldContext.tsx +0 -36
- package/src/components/CredentialRequestsEditor/index.tsx +0 -15
- package/src/components/CredentialRequestsEditor/types/compositeCredentialSchema.ts +0 -1
- package/src/components/CredentialRequestsEditor/types/credentialSchemasDto.ts +0 -3
- package/src/components/CredentialRequestsEditor/types/form.ts +0 -28
- package/src/components/CredentialRequestsEditor/types/mandatoryEnum.ts +0 -5
- package/src/components/CredentialRequestsEditor/utils/buildDataFieldValue.ts +0 -65
- package/src/components/CredentialRequestsEditor/utils/prettyField.ts +0 -16
- package/src/components/Image.tsx +0 -10
- package/src/components/QRCodeDisplay/index.tsx +0 -50
- package/src/components/RequiredLabel/index.tsx +0 -15
- package/src/components/Snackbar/index.tsx +0 -156
- package/src/components/TextField/index.tsx +0 -8
- package/src/components/Tip/index.tsx +0 -18
- package/src/components/Typography/index.tsx +0 -8
- package/src/components/When.tsx +0 -28
- package/src/components/form/CountrySelector.tsx +0 -96
- package/src/components/form/DataFieldClearAdornment.tsx +0 -28
- package/src/components/form/DateInput.tsx +0 -78
- package/src/components/form/DefaultInput.tsx +0 -26
- package/src/components/form/InputMask.tsx +0 -41
- package/src/components/form/OTPInput.tsx +0 -254
- package/src/components/form/PhoneInput.tsx +0 -152
- package/src/components/form/SSNInput.tsx +0 -99
- package/src/components/form/SelectInput.tsx +0 -101
- package/src/components/form/TextMaskCustom.tsx +0 -48
- package/src/components/form/index.ts +0 -5
- package/src/components/index.ts +0 -13
- package/src/components/terms/AcceptTermsNotice.tsx +0 -27
- package/src/components/terms/LegalLink.tsx +0 -22
- package/src/components/verified/VerifiedImage.tsx +0 -272
- package/src/components/verified/VerifiedIncLogo.tsx +0 -11
- package/src/components/verified/index.ts +0 -2
- package/src/hooks/index.ts +0 -5
- package/src/hooks/useCallbackRef.ts +0 -22
- package/src/hooks/useCopyToClipboard.ts +0 -76
- package/src/hooks/useDisclosure.ts +0 -96
- package/src/hooks/useLocalStorage.ts +0 -24
- package/src/hooks/usePrevious.ts +0 -17
- package/src/hooks/useQRCode.ts +0 -62
- package/src/index.ts +0 -13
- package/src/stories/components/Alert.stories.tsx +0 -41
- package/src/stories/components/Button.stories.ts +0 -49
- package/src/stories/components/CredentialRequestsEditor.stories.tsx +0 -98
- package/src/stories/components/QRCodeDisplay.stories.tsx +0 -60
- package/src/stories/components/TextField.stories.ts +0 -59
- package/src/stories/components/Typography.stories.ts +0 -140
- package/src/stories/components/VerifiedImage.stories.tsx +0 -32
- package/src/stories/components/form/DateInput.stories.ts +0 -36
- package/src/stories/components/form/OTPInput.stories.tsx +0 -90
- package/src/stories/components/form/PhoneInput.stories.tsx +0 -34
- package/src/stories/components/form/SSNInput.stories.ts +0 -30
- package/src/stories/components/form/SelectInput.stories.ts +0 -39
- package/src/stories/hooks/useCopyToClipboard.stories.tsx +0 -45
- package/src/styles/colors.ts +0 -60
- package/src/styles/index.ts +0 -3
- package/src/styles/shadows.ts +0 -6
- package/src/styles/theme.ts +0 -257
- package/src/styles/typography.ts +0 -86
- package/src/utils/date.ts +0 -32
- package/src/utils/index.ts +0 -6
- package/src/utils/masks/index.ts +0 -6
- package/src/utils/omitProperty.ts +0 -19
- package/src/utils/phone.ts +0 -76
- package/src/utils/ssn.ts +0 -8
- package/src/utils/string/index.ts +0 -2
- package/src/utils/string/toCapitalize.ts +0 -13
- package/src/utils/string/toSentenceCase.ts +0 -7
- package/src/utils/wrapPromise.ts +0 -19
- package/src/validations/date.schema.ts +0 -18
- package/src/validations/description.schema.ts +0 -5
- package/src/validations/email.schema.ts +0 -3
- package/src/validations/field.schema.ts +0 -3
- package/src/validations/index.ts +0 -8
- package/src/validations/phone.schema.ts +0 -6
- package/src/validations/ssn.schema.ts +0 -24
- package/src/validations/state.schema.ts +0 -3
- package/src/validations/unix.schema.ts +0 -11
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Accordion,
|
|
4
|
-
AccordionDetails,
|
|
5
|
-
AccordionSummary,
|
|
6
|
-
Box,
|
|
7
|
-
IconButton,
|
|
8
|
-
Paper,
|
|
9
|
-
Stack,
|
|
10
|
-
Typography,
|
|
11
|
-
useTheme,
|
|
12
|
-
} from '@mui/material';
|
|
13
|
-
import {
|
|
14
|
-
CheckCircle,
|
|
15
|
-
ChevronLeft,
|
|
16
|
-
Close,
|
|
17
|
-
Delete,
|
|
18
|
-
Menu,
|
|
19
|
-
} from '@mui/icons-material';
|
|
20
|
-
import { useDrag, useDrop } from 'react-dnd';
|
|
21
|
-
import { useController, useFormContext } from 'react-hook-form';
|
|
22
|
-
|
|
23
|
-
import { RequiredLabel } from '../../RequiredLabel';
|
|
24
|
-
|
|
25
|
-
import { prettyField } from '../utils/prettyField';
|
|
26
|
-
import {
|
|
27
|
-
type CredentialRequestsEditorForm,
|
|
28
|
-
type CredentialRequestsWithNew,
|
|
29
|
-
} from '../types/form';
|
|
30
|
-
import { MandatoryEnum } from '../types/mandatoryEnum';
|
|
31
|
-
import { useCredentialRequestField } from '../contexts/CredentialRequestFieldContext';
|
|
32
|
-
import { DataFieldOptionType } from './DataFieldOptionType';
|
|
33
|
-
import { DataFieldDescription } from './DataFieldDescription';
|
|
34
|
-
import { DataFieldMandatory } from './DataFieldMandatory';
|
|
35
|
-
import { DataFieldUserInput } from './DataFieldUserInput';
|
|
36
|
-
import { DataFieldDeleteModal } from './DataFieldDeleteModal';
|
|
37
|
-
import { DataFieldMulti } from './DataFieldMulti';
|
|
38
|
-
|
|
39
|
-
interface DataFieldAccordionProps {
|
|
40
|
-
defaultExpanded?: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function DataFieldAccordion(
|
|
44
|
-
props: DataFieldAccordionProps,
|
|
45
|
-
): React.JSX.Element {
|
|
46
|
-
const { defaultExpanded } = props;
|
|
47
|
-
const credentialRequestField = useCredentialRequestField();
|
|
48
|
-
const formContext = useFormContext<CredentialRequestsEditorForm>();
|
|
49
|
-
const field = useController<CredentialRequestsEditorForm>({
|
|
50
|
-
name: `${credentialRequestField?.path as any}` as any,
|
|
51
|
-
});
|
|
52
|
-
const credentialRequest = field.field.value as CredentialRequestsWithNew;
|
|
53
|
-
const credentialRequests = formContext.watch('credentialRequests');
|
|
54
|
-
const isNew: boolean = (credentialRequestField?.field as any).isNew;
|
|
55
|
-
const [expanded, setOpen] = useState((defaultExpanded ?? isNew) || false);
|
|
56
|
-
const [modalOpen, setModalOpen] = useState(false);
|
|
57
|
-
|
|
58
|
-
const accordionRef = useRef<HTMLDivElement | null>(null);
|
|
59
|
-
|
|
60
|
-
const fieldType = String(credentialRequestField?.field.type);
|
|
61
|
-
const type = prettyField(fieldType || 'Choose a type...');
|
|
62
|
-
|
|
63
|
-
const theme = useTheme();
|
|
64
|
-
const chevronClassName = 'chevron';
|
|
65
|
-
|
|
66
|
-
const canDrop = useCallback(
|
|
67
|
-
(item: typeof credentialRequestField) => {
|
|
68
|
-
const source = item;
|
|
69
|
-
const target = credentialRequestField;
|
|
70
|
-
|
|
71
|
-
if (!source || !target) return false;
|
|
72
|
-
|
|
73
|
-
const getParentPath = (path: string): string =>
|
|
74
|
-
path.split('.').slice(0, -2).join('.');
|
|
75
|
-
|
|
76
|
-
const sourcePath = getParentPath(source?.path ?? '');
|
|
77
|
-
const targetPath = getParentPath(target?.path ?? '');
|
|
78
|
-
const isSameGroup = sourcePath === targetPath;
|
|
79
|
-
|
|
80
|
-
const fromLevel = source.level;
|
|
81
|
-
const fromIndex = source.index;
|
|
82
|
-
const toLevel = target.level;
|
|
83
|
-
const toIndex = target.index;
|
|
84
|
-
|
|
85
|
-
// Allow to drop only on the same level and different index
|
|
86
|
-
if (fromLevel !== toLevel || fromIndex === toIndex || !isSameGroup) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return true;
|
|
91
|
-
},
|
|
92
|
-
[credentialRequestField],
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const [{ opacity }, drag, preview] = useDrag(
|
|
96
|
-
() => ({
|
|
97
|
-
type: 'data-field-drag',
|
|
98
|
-
item: () => credentialRequestField,
|
|
99
|
-
collect: (monitor) => ({
|
|
100
|
-
opacity: monitor.isDragging() ? 0 : 1,
|
|
101
|
-
}),
|
|
102
|
-
}),
|
|
103
|
-
[credentialRequestField, credentialRequests],
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const [{ opacity: dropOpacity }, drop] = useDrop(
|
|
107
|
-
() => ({
|
|
108
|
-
accept: 'data-field-drag',
|
|
109
|
-
canDrop(item) {
|
|
110
|
-
return canDrop(item as typeof credentialRequestField);
|
|
111
|
-
},
|
|
112
|
-
drop(item) {
|
|
113
|
-
const source = item as typeof credentialRequestField;
|
|
114
|
-
const target = credentialRequestField;
|
|
115
|
-
|
|
116
|
-
if (!source || !target) return;
|
|
117
|
-
if (!canDrop(source)) return;
|
|
118
|
-
|
|
119
|
-
const fromIndex = source.index;
|
|
120
|
-
const toIndex = target.index;
|
|
121
|
-
|
|
122
|
-
credentialRequestField.fieldArray.move(fromIndex, toIndex);
|
|
123
|
-
},
|
|
124
|
-
collect: (monitor) => {
|
|
125
|
-
if (monitor.isOver()) {
|
|
126
|
-
return {
|
|
127
|
-
opacity: monitor.canDrop() ? 0.4 : 1,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
opacity: 1,
|
|
132
|
-
};
|
|
133
|
-
},
|
|
134
|
-
}),
|
|
135
|
-
[credentialRequestField, credentialRequests],
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const handleRemove = (): void => {
|
|
139
|
-
if (!credentialRequestField) return;
|
|
140
|
-
setModalOpen(false);
|
|
141
|
-
|
|
142
|
-
// Delete parent when the last field was removed from the stack of form fields.
|
|
143
|
-
// The validation should be against less or equal than 1 because is against a previous state check.
|
|
144
|
-
if (credentialRequestField.fieldArray.fields.length <= 1) {
|
|
145
|
-
credentialRequestField.onAllFieldsDelete();
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
credentialRequestField.fieldArray.remove(credentialRequestField.index);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const renderTitle = (): React.JSX.Element => {
|
|
153
|
-
const typographyStyle = {
|
|
154
|
-
fontStyle: fieldType ? 'normal' : 'italic',
|
|
155
|
-
fontSize: '16px',
|
|
156
|
-
fontWeight: '800',
|
|
157
|
-
textAlign: 'left !important',
|
|
158
|
-
alignSelf: 'flex-start',
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
return (
|
|
162
|
-
<Typography variant='body1' sx={typographyStyle}>
|
|
163
|
-
{credentialRequest.mandatory !== MandatoryEnum.NO ? (
|
|
164
|
-
<RequiredLabel>{type}</RequiredLabel>
|
|
165
|
-
) : (
|
|
166
|
-
type
|
|
167
|
-
)}
|
|
168
|
-
</Typography>
|
|
169
|
-
);
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const renderUserInput = (): React.JSX.Element => {
|
|
173
|
-
const allowUserInput = credentialRequest.allowUserInput;
|
|
174
|
-
|
|
175
|
-
return (
|
|
176
|
-
<Stack direction='row' alignItems='center' spacing={0.5} pl={5.25}>
|
|
177
|
-
{allowUserInput ? (
|
|
178
|
-
<CheckCircle
|
|
179
|
-
sx={{ fontSize: '12px', color: theme.palette.text.disabled }}
|
|
180
|
-
/>
|
|
181
|
-
) : (
|
|
182
|
-
<Close
|
|
183
|
-
sx={{ fontSize: '12px', color: theme.palette.text.disabled }}
|
|
184
|
-
/>
|
|
185
|
-
)}
|
|
186
|
-
<Typography
|
|
187
|
-
variant='body1'
|
|
188
|
-
color='text.disabled'
|
|
189
|
-
sx={{
|
|
190
|
-
fontSize: '12px',
|
|
191
|
-
fontWeight: '400',
|
|
192
|
-
alignSelf: 'flex-start',
|
|
193
|
-
textAlign: 'left!important',
|
|
194
|
-
}}
|
|
195
|
-
>
|
|
196
|
-
Allow User Input
|
|
197
|
-
</Typography>
|
|
198
|
-
</Stack>
|
|
199
|
-
);
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
if (!isNew) return;
|
|
204
|
-
accordionRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
205
|
-
}, [isNew]);
|
|
206
|
-
|
|
207
|
-
return (
|
|
208
|
-
<Stack
|
|
209
|
-
ref={drop}
|
|
210
|
-
sx={{ position: 'relative', width: '100%', opacity: dropOpacity }}
|
|
211
|
-
>
|
|
212
|
-
<Paper
|
|
213
|
-
ref={(element) => preview(element)}
|
|
214
|
-
sx={{
|
|
215
|
-
p: '0!important',
|
|
216
|
-
width: `calc(100% - ${
|
|
217
|
-
(credentialRequestField?.level ?? 0) * 30
|
|
218
|
-
}px)!important`,
|
|
219
|
-
alignSelf: 'flex-end',
|
|
220
|
-
opacity,
|
|
221
|
-
}}
|
|
222
|
-
>
|
|
223
|
-
<Box>
|
|
224
|
-
<Accordion
|
|
225
|
-
defaultExpanded={isNew}
|
|
226
|
-
expanded={expanded}
|
|
227
|
-
sx={{
|
|
228
|
-
boxShadow: 'none',
|
|
229
|
-
'&::before': {
|
|
230
|
-
display: 'none',
|
|
231
|
-
},
|
|
232
|
-
my: '0px !important',
|
|
233
|
-
mt: 0,
|
|
234
|
-
p: '8px !important',
|
|
235
|
-
}}
|
|
236
|
-
data-testid='custom-demo-dialog-data-field-accordion'
|
|
237
|
-
>
|
|
238
|
-
<AccordionSummary
|
|
239
|
-
onClick={() => {
|
|
240
|
-
setOpen((prev) => !prev);
|
|
241
|
-
}}
|
|
242
|
-
expandIcon={
|
|
243
|
-
<>
|
|
244
|
-
<IconButton
|
|
245
|
-
size='small'
|
|
246
|
-
onClick={(e) => {
|
|
247
|
-
e.stopPropagation();
|
|
248
|
-
setModalOpen(true);
|
|
249
|
-
}}
|
|
250
|
-
data-testid='custom-demo-dialog-data-field-delete-button'
|
|
251
|
-
>
|
|
252
|
-
<Delete
|
|
253
|
-
fontSize='small'
|
|
254
|
-
sx={{
|
|
255
|
-
transform: 'rotate(0deg)',
|
|
256
|
-
}}
|
|
257
|
-
/>
|
|
258
|
-
</IconButton>
|
|
259
|
-
<Stack
|
|
260
|
-
className={chevronClassName}
|
|
261
|
-
sx={{ ml: 1, alignSelf: 'center' }}
|
|
262
|
-
>
|
|
263
|
-
<ChevronLeft
|
|
264
|
-
fontSize='small'
|
|
265
|
-
sx={{
|
|
266
|
-
color: '#0dbc3d',
|
|
267
|
-
transform: 'rotate(0deg)',
|
|
268
|
-
}}
|
|
269
|
-
/>
|
|
270
|
-
</Stack>
|
|
271
|
-
</>
|
|
272
|
-
}
|
|
273
|
-
sx={{
|
|
274
|
-
px: 0,
|
|
275
|
-
minHeight: 'auto!important',
|
|
276
|
-
'& .MuiAccordionSummary-content': {
|
|
277
|
-
my: '0px !important',
|
|
278
|
-
},
|
|
279
|
-
'& .MuiAccordionSummary-expandIconWrapper': {
|
|
280
|
-
alignSelf: 'flex-start',
|
|
281
|
-
transform: 'rotate(0deg) !important',
|
|
282
|
-
[`& .${chevronClassName}`]: {
|
|
283
|
-
transition: 'transform .3s',
|
|
284
|
-
},
|
|
285
|
-
'&.Mui-expanded': {
|
|
286
|
-
[`& .${chevronClassName}`]: {
|
|
287
|
-
transform: 'rotate(-90deg)',
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
}}
|
|
292
|
-
>
|
|
293
|
-
<Stack sx={{ alignItems: 'flex-start', mr: 0.5 }}>
|
|
294
|
-
<Stack direction='column' alignItems='flex-start' spacing={0}>
|
|
295
|
-
<Stack direction='row' alignItems='center' spacing={1}>
|
|
296
|
-
<IconButton
|
|
297
|
-
ref={drag}
|
|
298
|
-
size='small'
|
|
299
|
-
color='success'
|
|
300
|
-
onClick={(e) => {
|
|
301
|
-
e.preventDefault();
|
|
302
|
-
e.stopPropagation();
|
|
303
|
-
}}
|
|
304
|
-
sx={{ cursor: 'grab' }}
|
|
305
|
-
>
|
|
306
|
-
<Menu />
|
|
307
|
-
</IconButton>
|
|
308
|
-
{renderTitle()}
|
|
309
|
-
</Stack>
|
|
310
|
-
{renderUserInput()}
|
|
311
|
-
</Stack>
|
|
312
|
-
</Stack>
|
|
313
|
-
</AccordionSummary>
|
|
314
|
-
<AccordionDetails sx={{ pt: 3 }}>
|
|
315
|
-
{expanded && (
|
|
316
|
-
<Stack spacing={2}>
|
|
317
|
-
<DataFieldOptionType />
|
|
318
|
-
<DataFieldDescription />
|
|
319
|
-
<DataFieldMandatory />
|
|
320
|
-
<DataFieldUserInput />
|
|
321
|
-
<DataFieldMulti />
|
|
322
|
-
</Stack>
|
|
323
|
-
)}
|
|
324
|
-
</AccordionDetails>
|
|
325
|
-
</Accordion>
|
|
326
|
-
</Box>
|
|
327
|
-
</Paper>
|
|
328
|
-
<DataFieldDeleteModal
|
|
329
|
-
open={modalOpen}
|
|
330
|
-
onClose={() => {
|
|
331
|
-
setModalOpen(false);
|
|
332
|
-
}}
|
|
333
|
-
onConfirm={handleRemove}
|
|
334
|
-
/>
|
|
335
|
-
</Stack>
|
|
336
|
-
);
|
|
337
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Dialog,
|
|
3
|
-
DialogActions,
|
|
4
|
-
DialogContent,
|
|
5
|
-
DialogTitle,
|
|
6
|
-
type SxProps,
|
|
7
|
-
Typography,
|
|
8
|
-
} from '@mui/material';
|
|
9
|
-
|
|
10
|
-
import { Button } from '../../Button';
|
|
11
|
-
|
|
12
|
-
const buttonStyle: SxProps = {
|
|
13
|
-
minHeight: 20,
|
|
14
|
-
mt: 2,
|
|
15
|
-
py: 1,
|
|
16
|
-
px: 1.25,
|
|
17
|
-
fontWeight: '800',
|
|
18
|
-
fontSize: '13px',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
interface DataFieldDeleteModalProps {
|
|
22
|
-
open: boolean;
|
|
23
|
-
onClose: () => void;
|
|
24
|
-
onConfirm: () => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function DataFieldDeleteModal({
|
|
28
|
-
open,
|
|
29
|
-
onClose,
|
|
30
|
-
onConfirm,
|
|
31
|
-
}: DataFieldDeleteModalProps): React.JSX.Element {
|
|
32
|
-
return (
|
|
33
|
-
<Dialog open={open} onClose={onClose}>
|
|
34
|
-
<DialogTitle>Delete Data Field?</DialogTitle>
|
|
35
|
-
<DialogContent>
|
|
36
|
-
<Typography>
|
|
37
|
-
Are you sure you want to delete this data field?
|
|
38
|
-
</Typography>
|
|
39
|
-
</DialogContent>
|
|
40
|
-
<DialogActions sx={{ justifyContent: 'space-between' }}>
|
|
41
|
-
<Button
|
|
42
|
-
variant='text'
|
|
43
|
-
color='neutral'
|
|
44
|
-
size='small'
|
|
45
|
-
onClick={onClose}
|
|
46
|
-
sx={buttonStyle}
|
|
47
|
-
data-testid='custom-demo-dialog-data-field-delete-cancel-button'
|
|
48
|
-
>
|
|
49
|
-
Don't Delete
|
|
50
|
-
</Button>
|
|
51
|
-
<Button
|
|
52
|
-
variant='contained'
|
|
53
|
-
color='error'
|
|
54
|
-
size='small'
|
|
55
|
-
onClick={onConfirm}
|
|
56
|
-
sx={buttonStyle}
|
|
57
|
-
data-testid='custom-demo-dialog-data-field-delete-confirm-button'
|
|
58
|
-
>
|
|
59
|
-
Delete
|
|
60
|
-
</Button>
|
|
61
|
-
</DialogActions>
|
|
62
|
-
</Dialog>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { useRef, useState } from 'react';
|
|
2
|
-
import { useController } from 'react-hook-form';
|
|
3
|
-
import debounce from 'lodash/debounce';
|
|
4
|
-
import { TextField } from '@mui/material';
|
|
5
|
-
|
|
6
|
-
import { type CredentialRequestsEditorForm } from '../types/form';
|
|
7
|
-
import { useCredentialRequestsEditor } from '../CredentialRequestsEditor.context';
|
|
8
|
-
import { useCredentialRequestField } from '../contexts/CredentialRequestFieldContext';
|
|
9
|
-
import { DataFieldSection } from './DataFieldSection';
|
|
10
|
-
|
|
11
|
-
export function DataFieldDescription(): React.JSX.Element {
|
|
12
|
-
const { features } = useCredentialRequestsEditor();
|
|
13
|
-
const isFeatureDisabled = features?.description?.disabled === true;
|
|
14
|
-
|
|
15
|
-
const credentialRequestField = useCredentialRequestField();
|
|
16
|
-
const description = useController<CredentialRequestsEditorForm>({
|
|
17
|
-
name: `${credentialRequestField?.path as any}.description` as any,
|
|
18
|
-
});
|
|
19
|
-
const [value, setValue] = useState(description.field.value ?? '');
|
|
20
|
-
|
|
21
|
-
const debounceChange = useRef(
|
|
22
|
-
debounce((value: string) => {
|
|
23
|
-
// Update form state
|
|
24
|
-
description.field.onChange({ target: { value } });
|
|
25
|
-
}, 500),
|
|
26
|
-
).current;
|
|
27
|
-
|
|
28
|
-
const handleChange = (e: any): void => {
|
|
29
|
-
if (isFeatureDisabled) return;
|
|
30
|
-
setValue(e.target.value);
|
|
31
|
-
debounceChange(e.target.value);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<DataFieldSection
|
|
36
|
-
title='Field Description'
|
|
37
|
-
description='What text appears under the field'
|
|
38
|
-
tip={
|
|
39
|
-
<>
|
|
40
|
-
<pre>POST /1-click</pre>
|
|
41
|
-
<pre>{`{\n description?: string\n}`}</pre>
|
|
42
|
-
</>
|
|
43
|
-
}
|
|
44
|
-
sx={{
|
|
45
|
-
opacity: isFeatureDisabled ? 0.5 : 1,
|
|
46
|
-
}}
|
|
47
|
-
>
|
|
48
|
-
<TextField
|
|
49
|
-
{...description.field}
|
|
50
|
-
value={value}
|
|
51
|
-
onChange={handleChange}
|
|
52
|
-
error={!!description.fieldState.error}
|
|
53
|
-
helperText={
|
|
54
|
-
description.fieldState.error?.message ??
|
|
55
|
-
'Optional — defaults to empty'
|
|
56
|
-
}
|
|
57
|
-
label='Description'
|
|
58
|
-
color='success'
|
|
59
|
-
size='small'
|
|
60
|
-
className='original'
|
|
61
|
-
inputProps={{
|
|
62
|
-
'data-testid': 'custom-demo-dialog-data-field-description-input',
|
|
63
|
-
}}
|
|
64
|
-
disabled={isFeatureDisabled}
|
|
65
|
-
/>
|
|
66
|
-
</DataFieldSection>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { useController } from 'react-hook-form';
|
|
2
|
-
import { RadioGroup } from '@mui/material';
|
|
3
|
-
|
|
4
|
-
import { type CredentialRequestsEditorForm } from '../types/form';
|
|
5
|
-
import { MandatoryEnum } from '../types/mandatoryEnum';
|
|
6
|
-
import { useCredentialRequestsEditor } from '../CredentialRequestsEditor.context';
|
|
7
|
-
import { useCredentialRequestField } from '../contexts/CredentialRequestFieldContext';
|
|
8
|
-
import { RadioOption } from './RadioOption';
|
|
9
|
-
import { DataFieldSection } from './DataFieldSection';
|
|
10
|
-
|
|
11
|
-
export function DataFieldMandatory(): React.JSX.Element {
|
|
12
|
-
const { features } = useCredentialRequestsEditor();
|
|
13
|
-
const isFeatureDisabled = features?.mandatory?.disabled === true;
|
|
14
|
-
|
|
15
|
-
const credentialRequestField = useCredentialRequestField();
|
|
16
|
-
const mandatory = useController<CredentialRequestsEditorForm>({
|
|
17
|
-
name: `${credentialRequestField?.path as any}.mandatory` as any,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<DataFieldSection
|
|
22
|
-
title='Optional or Required'
|
|
23
|
-
description="Whether it's optional or required for the user to share this data"
|
|
24
|
-
tip={
|
|
25
|
-
<>
|
|
26
|
-
<pre>POST /1-click</pre>
|
|
27
|
-
<pre>{`{\n mandatory?: enum\n}`}</pre>
|
|
28
|
-
</>
|
|
29
|
-
}
|
|
30
|
-
sx={{
|
|
31
|
-
opacity: isFeatureDisabled ? 0.5 : 1,
|
|
32
|
-
}}
|
|
33
|
-
>
|
|
34
|
-
<RadioGroup
|
|
35
|
-
value={mandatory.field.value}
|
|
36
|
-
onChange={(e) => {
|
|
37
|
-
if (isFeatureDisabled) return;
|
|
38
|
-
const value = e.target.value as MandatoryEnum;
|
|
39
|
-
|
|
40
|
-
// Update form state
|
|
41
|
-
mandatory.field.onChange({ target: { value } });
|
|
42
|
-
}}
|
|
43
|
-
>
|
|
44
|
-
<RadioOption
|
|
45
|
-
isDefault
|
|
46
|
-
value={MandatoryEnum.NO}
|
|
47
|
-
title='Optional'
|
|
48
|
-
description='Optional for the user to share'
|
|
49
|
-
tip={MandatoryEnum.NO}
|
|
50
|
-
inputProps={
|
|
51
|
-
{
|
|
52
|
-
'data-testid': 'custom-demo-dialog-mandatory-no-radio',
|
|
53
|
-
} as any
|
|
54
|
-
}
|
|
55
|
-
disabled={isFeatureDisabled}
|
|
56
|
-
/>
|
|
57
|
-
<RadioOption
|
|
58
|
-
value={MandatoryEnum.IF_AVAILABLE}
|
|
59
|
-
title='Required if available'
|
|
60
|
-
description='Required to share, if the user has it'
|
|
61
|
-
tip={MandatoryEnum.IF_AVAILABLE}
|
|
62
|
-
inputProps={
|
|
63
|
-
{
|
|
64
|
-
'data-testid': 'custom-demo-dialog-mandatory-if_available-radio',
|
|
65
|
-
} as any
|
|
66
|
-
}
|
|
67
|
-
disabled={isFeatureDisabled}
|
|
68
|
-
/>
|
|
69
|
-
<RadioOption
|
|
70
|
-
value={MandatoryEnum.YES}
|
|
71
|
-
title='Required'
|
|
72
|
-
description="Required — flow fails if user doesn't have it"
|
|
73
|
-
tip={MandatoryEnum.YES}
|
|
74
|
-
inputProps={
|
|
75
|
-
{
|
|
76
|
-
'data-testid': 'custom-demo-dialog-mandatory-yes-radio',
|
|
77
|
-
} as any
|
|
78
|
-
}
|
|
79
|
-
disabled={isFeatureDisabled}
|
|
80
|
-
/>
|
|
81
|
-
</RadioGroup>
|
|
82
|
-
</DataFieldSection>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { RadioGroup } from '@mui/material';
|
|
2
|
-
import { useController } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { type CredentialRequestsEditorForm } from '../types/form';
|
|
5
|
-
import { useCredentialRequestsEditor } from '../CredentialRequestsEditor.context';
|
|
6
|
-
import { useCredentialRequestField } from '../contexts/CredentialRequestFieldContext';
|
|
7
|
-
import { RadioOption } from './RadioOption';
|
|
8
|
-
import { DataFieldSection } from './DataFieldSection';
|
|
9
|
-
|
|
10
|
-
export function DataFieldMulti(): React.JSX.Element | null {
|
|
11
|
-
const { features } = useCredentialRequestsEditor();
|
|
12
|
-
const isFeatureDisabled = features?.multi?.disabled === true;
|
|
13
|
-
|
|
14
|
-
const credentialRequestField = useCredentialRequestField();
|
|
15
|
-
const multi = useController<CredentialRequestsEditorForm>({
|
|
16
|
-
name: `${credentialRequestField?.path as any}.multi` as any,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
if ((credentialRequestField?.level ?? 0) > 0) return null;
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<DataFieldSection
|
|
23
|
-
title='Multiple Values'
|
|
24
|
-
description='Whether multiple data values should be included if available'
|
|
25
|
-
tip={
|
|
26
|
-
<>
|
|
27
|
-
<pre>POST /1-click</pre>
|
|
28
|
-
<pre>{`{\n multi?: boolean\n}`}</pre>
|
|
29
|
-
</>
|
|
30
|
-
}
|
|
31
|
-
sx={{
|
|
32
|
-
opacity: isFeatureDisabled ? 0.5 : 1,
|
|
33
|
-
}}
|
|
34
|
-
>
|
|
35
|
-
<RadioGroup
|
|
36
|
-
value={multi.field.value ?? false}
|
|
37
|
-
onChange={(_, value) => {
|
|
38
|
-
if (isFeatureDisabled) return;
|
|
39
|
-
|
|
40
|
-
// Update form state
|
|
41
|
-
multi.field.onChange({
|
|
42
|
-
target: { value: value === 'true' },
|
|
43
|
-
});
|
|
44
|
-
}}
|
|
45
|
-
>
|
|
46
|
-
<RadioOption
|
|
47
|
-
value={true}
|
|
48
|
-
title='Yes'
|
|
49
|
-
description='Multiple values will be included if available'
|
|
50
|
-
tip='true'
|
|
51
|
-
inputProps={
|
|
52
|
-
{
|
|
53
|
-
'data-testid': 'custom-demo-dialog-multi-yes-radio',
|
|
54
|
-
} as any
|
|
55
|
-
}
|
|
56
|
-
disabled={isFeatureDisabled}
|
|
57
|
-
/>
|
|
58
|
-
<RadioOption
|
|
59
|
-
isDefault
|
|
60
|
-
value={false}
|
|
61
|
-
title='No'
|
|
62
|
-
description="Multiple values won't be included"
|
|
63
|
-
tip='false'
|
|
64
|
-
inputProps={
|
|
65
|
-
{
|
|
66
|
-
'data-testid': 'custom-demo-dialog-multi-no-radio',
|
|
67
|
-
} as any
|
|
68
|
-
}
|
|
69
|
-
disabled={isFeatureDisabled}
|
|
70
|
-
/>
|
|
71
|
-
</RadioGroup>
|
|
72
|
-
</DataFieldSection>
|
|
73
|
-
);
|
|
74
|
-
}
|