@infosoftas/s4-orders-js-sdk 0.1.21-3 → 0.2.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/.editorconfig +8 -8
- package/.release-it.json +10 -10
- package/README.md +565 -471
- package/package.json +62 -58
- package/src/App.completion.test.tsx +738 -0
- package/src/App.tsx +753 -639
- package/src/ErrorBoundary.tsx +41 -41
- package/src/api/InvoiceApi.ts +23 -23
- package/src/api/OrdersApi.ts +74 -59
- package/src/api/SubscribeApi.ts +18 -18
- package/src/bundle.ts +4 -4
- package/src/components/Alert/Alert.tsx +23 -23
- package/src/components/Button/Button.tsx +39 -39
- package/src/components/EHFForm/EHFForm.tsx +253 -253
- package/src/components/FormFields/AddressField.tsx +55 -55
- package/src/components/FormFields/EmailField.tsx +53 -53
- package/src/components/FormFields/FormFields.helper.ts +34 -34
- package/src/components/FormFields/FormFieldsMapper.ts +34 -34
- package/src/components/FormFields/InputField.tsx +52 -52
- package/src/components/FormFields/NameField.tsx +52 -52
- package/src/components/FormFields/PhoneField.tsx +53 -53
- package/src/components/FormFields/TermsCheckbox.tsx +70 -70
- package/src/components/FormFields/ToggleFiled.tsx +52 -52
- package/src/components/FormFields/fieldValidators.ts +71 -71
- package/src/components/MainIframe/MainIframe.tsx +42 -42
- package/src/components/OIOForm/OIOForm.tsx +307 -307
- package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
- package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
- package/src/components/OrderForm/OrderForm.tsx +420 -420
- package/src/components/OrderForm/PaymentMethodContent.tsx +62 -62
- package/src/components/OrderForm/PaymentMethodSection.tsx +79 -79
- package/src/components/OrderForm/SubmitConfirmationDialog.tsx +55 -55
- package/src/components/OrderForm/orderFormState.ts +171 -171
- package/src/components/OrderForm/useSlotElement.tsx +89 -89
- package/src/constants/index.ts +13 -13
- package/src/enums/api.ts +5 -5
- package/src/enums/general.ts +40 -40
- package/src/hooks/useIframe.tsx +59 -59
- package/src/hooks/useMessageEvent.tsx +194 -194
- package/src/hooks/useOrderForm.tsx +403 -403
- package/src/hooks/useQueryParams.ts +5 -5
- package/src/index.tsx +30 -30
- package/src/lib/utils.ts +1 -1
- package/src/types/api.ts +28 -28
- package/src/types/general.ts +154 -136
- package/src/types/order.ts +91 -70
- package/src/utils/fetcher.ts +131 -113
- package/src/utils/helper.ts +78 -78
- package/src/utils/order.helper.ts +272 -272
- package/src/utils/waitForOrderCompletion.ts +125 -0
- package/tsconfig.json +38 -38
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { type FC, useId } from 'react';
|
|
2
|
-
import { useFormContext } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
-
import { Input } from '../ui/input';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
name: string;
|
|
9
|
-
required: boolean;
|
|
10
|
-
readOnly: boolean;
|
|
11
|
-
label?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const EmailField: FC<Props> = ({
|
|
15
|
-
name = 'email',
|
|
16
|
-
required = false,
|
|
17
|
-
readOnly = false,
|
|
18
|
-
label = 'Email',
|
|
19
|
-
}) => {
|
|
20
|
-
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
-
const { error } = getFieldState(name, formState);
|
|
22
|
-
const id = useId();
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
-
<FieldLabel htmlFor={id}>
|
|
27
|
-
<span>
|
|
28
|
-
{label}
|
|
29
|
-
{required && (
|
|
30
|
-
<span aria-hidden="true" className="text-destructive">
|
|
31
|
-
{' '}
|
|
32
|
-
*
|
|
33
|
-
</span>
|
|
34
|
-
)}
|
|
35
|
-
</span>
|
|
36
|
-
</FieldLabel>
|
|
37
|
-
<Input
|
|
38
|
-
id={id}
|
|
39
|
-
type="email"
|
|
40
|
-
autoComplete="email"
|
|
41
|
-
readOnly={readOnly}
|
|
42
|
-
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
43
|
-
aria-invalid={!!error}
|
|
44
|
-
aria-required={required}
|
|
45
|
-
required={required}
|
|
46
|
-
{...register(name)}
|
|
47
|
-
/>
|
|
48
|
-
<FieldError errors={[error]} />
|
|
49
|
-
</Field>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export default EmailField;
|
|
1
|
+
import { type FC, useId } from 'react';
|
|
2
|
+
import { useFormContext } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
+
import { Input } from '../ui/input';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
label?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const EmailField: FC<Props> = ({
|
|
15
|
+
name = 'email',
|
|
16
|
+
required = false,
|
|
17
|
+
readOnly = false,
|
|
18
|
+
label = 'Email',
|
|
19
|
+
}) => {
|
|
20
|
+
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
+
const { error } = getFieldState(name, formState);
|
|
22
|
+
const id = useId();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
+
<FieldLabel htmlFor={id}>
|
|
27
|
+
<span>
|
|
28
|
+
{label}
|
|
29
|
+
{required && (
|
|
30
|
+
<span aria-hidden="true" className="text-destructive">
|
|
31
|
+
{' '}
|
|
32
|
+
*
|
|
33
|
+
</span>
|
|
34
|
+
)}
|
|
35
|
+
</span>
|
|
36
|
+
</FieldLabel>
|
|
37
|
+
<Input
|
|
38
|
+
id={id}
|
|
39
|
+
type="email"
|
|
40
|
+
autoComplete="email"
|
|
41
|
+
readOnly={readOnly}
|
|
42
|
+
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
43
|
+
aria-invalid={!!error}
|
|
44
|
+
aria-required={required}
|
|
45
|
+
required={required}
|
|
46
|
+
{...register(name)}
|
|
47
|
+
/>
|
|
48
|
+
<FieldError errors={[error]} />
|
|
49
|
+
</Field>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default EmailField;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import type { OrderFormFieldType } from '../../types/general';
|
|
2
|
-
|
|
3
|
-
export const FIELD_TYPES = {
|
|
4
|
-
PHONE: 'phoneNumber',
|
|
5
|
-
EMAIL: 'email',
|
|
6
|
-
NAME: 'name',
|
|
7
|
-
COUNTRY: 'country',
|
|
8
|
-
CITY: 'city',
|
|
9
|
-
ADDRESS: 'address',
|
|
10
|
-
ZIP: 'zip',
|
|
11
|
-
CARE_OF: 'careOf',
|
|
12
|
-
ORGANIZATION_NUMBER: 'organizationNumber',
|
|
13
|
-
BUYER_REFERENCE: 'buyerReference',
|
|
14
|
-
ORDER_REFERENCE: 'orderReference',
|
|
15
|
-
INVOICE_NAME: 'invoiceName',
|
|
16
|
-
INVOICE_ADDRESS: 'invoiceAddress',
|
|
17
|
-
INVOICE_CITY: 'invoiceCity',
|
|
18
|
-
INVOICE_ZIP: 'invoiceZip',
|
|
19
|
-
INVOICE_COUNTRY: 'invoiceCountry',
|
|
20
|
-
INVOICE_PHONE: 'invoicePhoneNumber',
|
|
21
|
-
INVOICE_EMAIL: 'invoiceEmail',
|
|
22
|
-
INVOICE_CARE_OF: 'invoiceCareOf',
|
|
23
|
-
INVOICE_BUYER_REFERENCE: 'invoiceBuyerReference',
|
|
24
|
-
TERMS_CHECKBOX: 'termsCheckbox',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const DEFAULT_ORDER_FORM_FIELDS: OrderFormFieldType[] = [
|
|
28
|
-
{
|
|
29
|
-
name: FIELD_TYPES.PHONE,
|
|
30
|
-
required: false,
|
|
31
|
-
readOnly: false,
|
|
32
|
-
label: '',
|
|
33
|
-
},
|
|
34
|
-
];
|
|
1
|
+
import type { OrderFormFieldType } from '../../types/general';
|
|
2
|
+
|
|
3
|
+
export const FIELD_TYPES = {
|
|
4
|
+
PHONE: 'phoneNumber',
|
|
5
|
+
EMAIL: 'email',
|
|
6
|
+
NAME: 'name',
|
|
7
|
+
COUNTRY: 'country',
|
|
8
|
+
CITY: 'city',
|
|
9
|
+
ADDRESS: 'address',
|
|
10
|
+
ZIP: 'zip',
|
|
11
|
+
CARE_OF: 'careOf',
|
|
12
|
+
ORGANIZATION_NUMBER: 'organizationNumber',
|
|
13
|
+
BUYER_REFERENCE: 'buyerReference',
|
|
14
|
+
ORDER_REFERENCE: 'orderReference',
|
|
15
|
+
INVOICE_NAME: 'invoiceName',
|
|
16
|
+
INVOICE_ADDRESS: 'invoiceAddress',
|
|
17
|
+
INVOICE_CITY: 'invoiceCity',
|
|
18
|
+
INVOICE_ZIP: 'invoiceZip',
|
|
19
|
+
INVOICE_COUNTRY: 'invoiceCountry',
|
|
20
|
+
INVOICE_PHONE: 'invoicePhoneNumber',
|
|
21
|
+
INVOICE_EMAIL: 'invoiceEmail',
|
|
22
|
+
INVOICE_CARE_OF: 'invoiceCareOf',
|
|
23
|
+
INVOICE_BUYER_REFERENCE: 'invoiceBuyerReference',
|
|
24
|
+
TERMS_CHECKBOX: 'termsCheckbox',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const DEFAULT_ORDER_FORM_FIELDS: OrderFormFieldType[] = [
|
|
28
|
+
{
|
|
29
|
+
name: FIELD_TYPES.PHONE,
|
|
30
|
+
required: false,
|
|
31
|
+
readOnly: false,
|
|
32
|
+
label: '',
|
|
33
|
+
},
|
|
34
|
+
];
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import EmailField from './EmailField';
|
|
2
|
-
import PhoneField from './PhoneField';
|
|
3
|
-
import NameField from './NameField';
|
|
4
|
-
import AddressField from './AddressField';
|
|
5
|
-
import InputField from './InputField';
|
|
6
|
-
import TermsCheckbox from './TermsCheckbox';
|
|
7
|
-
|
|
8
|
-
import { FIELD_TYPES } from './FormFields.helper';
|
|
9
|
-
|
|
10
|
-
const formFieldsMapper = {
|
|
11
|
-
[FIELD_TYPES.PHONE]: PhoneField,
|
|
12
|
-
[FIELD_TYPES.NAME]: NameField,
|
|
13
|
-
[FIELD_TYPES.EMAIL]: EmailField,
|
|
14
|
-
[FIELD_TYPES.ADDRESS]: AddressField,
|
|
15
|
-
[FIELD_TYPES.COUNTRY]: InputField,
|
|
16
|
-
[FIELD_TYPES.CITY]: InputField,
|
|
17
|
-
[FIELD_TYPES.ZIP]: InputField,
|
|
18
|
-
[FIELD_TYPES.CARE_OF]: InputField,
|
|
19
|
-
[FIELD_TYPES.ORGANIZATION_NUMBER]: InputField,
|
|
20
|
-
[FIELD_TYPES.BUYER_REFERENCE]: InputField,
|
|
21
|
-
[FIELD_TYPES.ORDER_REFERENCE]: InputField,
|
|
22
|
-
[FIELD_TYPES.INVOICE_PHONE]: PhoneField,
|
|
23
|
-
[FIELD_TYPES.INVOICE_NAME]: NameField,
|
|
24
|
-
[FIELD_TYPES.INVOICE_EMAIL]: EmailField,
|
|
25
|
-
[FIELD_TYPES.INVOICE_ADDRESS]: AddressField,
|
|
26
|
-
[FIELD_TYPES.INVOICE_COUNTRY]: InputField,
|
|
27
|
-
[FIELD_TYPES.INVOICE_CITY]: InputField,
|
|
28
|
-
[FIELD_TYPES.INVOICE_ZIP]: InputField,
|
|
29
|
-
[FIELD_TYPES.INVOICE_CARE_OF]: InputField,
|
|
30
|
-
[FIELD_TYPES.INVOICE_BUYER_REFERENCE]: InputField,
|
|
31
|
-
[FIELD_TYPES.TERMS_CHECKBOX]: TermsCheckbox,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export default formFieldsMapper;
|
|
1
|
+
import EmailField from './EmailField';
|
|
2
|
+
import PhoneField from './PhoneField';
|
|
3
|
+
import NameField from './NameField';
|
|
4
|
+
import AddressField from './AddressField';
|
|
5
|
+
import InputField from './InputField';
|
|
6
|
+
import TermsCheckbox from './TermsCheckbox';
|
|
7
|
+
|
|
8
|
+
import { FIELD_TYPES } from './FormFields.helper';
|
|
9
|
+
|
|
10
|
+
const formFieldsMapper = {
|
|
11
|
+
[FIELD_TYPES.PHONE]: PhoneField,
|
|
12
|
+
[FIELD_TYPES.NAME]: NameField,
|
|
13
|
+
[FIELD_TYPES.EMAIL]: EmailField,
|
|
14
|
+
[FIELD_TYPES.ADDRESS]: AddressField,
|
|
15
|
+
[FIELD_TYPES.COUNTRY]: InputField,
|
|
16
|
+
[FIELD_TYPES.CITY]: InputField,
|
|
17
|
+
[FIELD_TYPES.ZIP]: InputField,
|
|
18
|
+
[FIELD_TYPES.CARE_OF]: InputField,
|
|
19
|
+
[FIELD_TYPES.ORGANIZATION_NUMBER]: InputField,
|
|
20
|
+
[FIELD_TYPES.BUYER_REFERENCE]: InputField,
|
|
21
|
+
[FIELD_TYPES.ORDER_REFERENCE]: InputField,
|
|
22
|
+
[FIELD_TYPES.INVOICE_PHONE]: PhoneField,
|
|
23
|
+
[FIELD_TYPES.INVOICE_NAME]: NameField,
|
|
24
|
+
[FIELD_TYPES.INVOICE_EMAIL]: EmailField,
|
|
25
|
+
[FIELD_TYPES.INVOICE_ADDRESS]: AddressField,
|
|
26
|
+
[FIELD_TYPES.INVOICE_COUNTRY]: InputField,
|
|
27
|
+
[FIELD_TYPES.INVOICE_CITY]: InputField,
|
|
28
|
+
[FIELD_TYPES.INVOICE_ZIP]: InputField,
|
|
29
|
+
[FIELD_TYPES.INVOICE_CARE_OF]: InputField,
|
|
30
|
+
[FIELD_TYPES.INVOICE_BUYER_REFERENCE]: InputField,
|
|
31
|
+
[FIELD_TYPES.TERMS_CHECKBOX]: TermsCheckbox,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default formFieldsMapper;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { type FC, useId } from 'react';
|
|
2
|
-
import { useFormContext } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
-
import { Input } from '../ui/input';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
name: string;
|
|
9
|
-
required: boolean;
|
|
10
|
-
readOnly: boolean;
|
|
11
|
-
label?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const InputField: FC<Props> = ({
|
|
15
|
-
name,
|
|
16
|
-
required = false,
|
|
17
|
-
readOnly = false,
|
|
18
|
-
label = '',
|
|
19
|
-
}) => {
|
|
20
|
-
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
-
const { error } = getFieldState(name, formState);
|
|
22
|
-
const id = useId();
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
-
<FieldLabel htmlFor={id}>
|
|
27
|
-
<span>
|
|
28
|
-
{label}
|
|
29
|
-
{required && (
|
|
30
|
-
<span aria-hidden="true" className="text-destructive">
|
|
31
|
-
{' '}
|
|
32
|
-
*
|
|
33
|
-
</span>
|
|
34
|
-
)}
|
|
35
|
-
</span>
|
|
36
|
-
</FieldLabel>
|
|
37
|
-
<Input
|
|
38
|
-
id={id}
|
|
39
|
-
autoComplete={name}
|
|
40
|
-
readOnly={readOnly}
|
|
41
|
-
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
42
|
-
aria-invalid={!!error}
|
|
43
|
-
aria-required={required}
|
|
44
|
-
required={required}
|
|
45
|
-
{...register(name)}
|
|
46
|
-
/>
|
|
47
|
-
<FieldError errors={[error]} />
|
|
48
|
-
</Field>
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default InputField;
|
|
1
|
+
import { type FC, useId } from 'react';
|
|
2
|
+
import { useFormContext } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
+
import { Input } from '../ui/input';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
label?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const InputField: FC<Props> = ({
|
|
15
|
+
name,
|
|
16
|
+
required = false,
|
|
17
|
+
readOnly = false,
|
|
18
|
+
label = '',
|
|
19
|
+
}) => {
|
|
20
|
+
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
+
const { error } = getFieldState(name, formState);
|
|
22
|
+
const id = useId();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
+
<FieldLabel htmlFor={id}>
|
|
27
|
+
<span>
|
|
28
|
+
{label}
|
|
29
|
+
{required && (
|
|
30
|
+
<span aria-hidden="true" className="text-destructive">
|
|
31
|
+
{' '}
|
|
32
|
+
*
|
|
33
|
+
</span>
|
|
34
|
+
)}
|
|
35
|
+
</span>
|
|
36
|
+
</FieldLabel>
|
|
37
|
+
<Input
|
|
38
|
+
id={id}
|
|
39
|
+
autoComplete={name}
|
|
40
|
+
readOnly={readOnly}
|
|
41
|
+
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
42
|
+
aria-invalid={!!error}
|
|
43
|
+
aria-required={required}
|
|
44
|
+
required={required}
|
|
45
|
+
{...register(name)}
|
|
46
|
+
/>
|
|
47
|
+
<FieldError errors={[error]} />
|
|
48
|
+
</Field>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default InputField;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { type FC, useId } from 'react';
|
|
2
|
-
import { useFormContext } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
-
import { Input } from '../ui/input';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
name: string;
|
|
9
|
-
required: boolean;
|
|
10
|
-
readOnly: boolean;
|
|
11
|
-
label?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const NameField: FC<Props> = ({
|
|
15
|
-
name = 'name',
|
|
16
|
-
required = false,
|
|
17
|
-
readOnly = false,
|
|
18
|
-
label = 'Name',
|
|
19
|
-
}) => {
|
|
20
|
-
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
-
const { error } = getFieldState(name, formState);
|
|
22
|
-
const id = useId();
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
-
<FieldLabel htmlFor={id}>
|
|
27
|
-
<span>
|
|
28
|
-
{label}
|
|
29
|
-
{required && (
|
|
30
|
-
<span aria-hidden="true" className="text-destructive">
|
|
31
|
-
{' '}
|
|
32
|
-
*
|
|
33
|
-
</span>
|
|
34
|
-
)}
|
|
35
|
-
</span>
|
|
36
|
-
</FieldLabel>
|
|
37
|
-
<Input
|
|
38
|
-
id={id}
|
|
39
|
-
autoComplete="name"
|
|
40
|
-
readOnly={readOnly}
|
|
41
|
-
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
42
|
-
aria-invalid={!!error}
|
|
43
|
-
aria-required={required}
|
|
44
|
-
required={required}
|
|
45
|
-
{...register(name)}
|
|
46
|
-
/>
|
|
47
|
-
<FieldError errors={[error]} />
|
|
48
|
-
</Field>
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default NameField;
|
|
1
|
+
import { type FC, useId } from 'react';
|
|
2
|
+
import { useFormContext } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
+
import { Input } from '../ui/input';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
label?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const NameField: FC<Props> = ({
|
|
15
|
+
name = 'name',
|
|
16
|
+
required = false,
|
|
17
|
+
readOnly = false,
|
|
18
|
+
label = 'Name',
|
|
19
|
+
}) => {
|
|
20
|
+
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
+
const { error } = getFieldState(name, formState);
|
|
22
|
+
const id = useId();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
+
<FieldLabel htmlFor={id}>
|
|
27
|
+
<span>
|
|
28
|
+
{label}
|
|
29
|
+
{required && (
|
|
30
|
+
<span aria-hidden="true" className="text-destructive">
|
|
31
|
+
{' '}
|
|
32
|
+
*
|
|
33
|
+
</span>
|
|
34
|
+
)}
|
|
35
|
+
</span>
|
|
36
|
+
</FieldLabel>
|
|
37
|
+
<Input
|
|
38
|
+
id={id}
|
|
39
|
+
autoComplete="name"
|
|
40
|
+
readOnly={readOnly}
|
|
41
|
+
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
42
|
+
aria-invalid={!!error}
|
|
43
|
+
aria-required={required}
|
|
44
|
+
required={required}
|
|
45
|
+
{...register(name)}
|
|
46
|
+
/>
|
|
47
|
+
<FieldError errors={[error]} />
|
|
48
|
+
</Field>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default NameField;
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { type FC, useId } from 'react';
|
|
2
|
-
import { useFormContext } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
-
import { Input } from '../ui/input';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
name: string;
|
|
9
|
-
required: boolean;
|
|
10
|
-
readOnly: boolean;
|
|
11
|
-
label?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const PhoneField: FC<Props> = ({
|
|
15
|
-
name = 'phoneNumber',
|
|
16
|
-
required = false,
|
|
17
|
-
readOnly = false,
|
|
18
|
-
label = 'Phone number',
|
|
19
|
-
}) => {
|
|
20
|
-
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
-
const { error } = getFieldState(name, formState);
|
|
22
|
-
const id = useId();
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
-
<FieldLabel htmlFor={id}>
|
|
27
|
-
<span>
|
|
28
|
-
{label}
|
|
29
|
-
{required && (
|
|
30
|
-
<span aria-hidden="true" className="text-destructive">
|
|
31
|
-
{' '}
|
|
32
|
-
*
|
|
33
|
-
</span>
|
|
34
|
-
)}
|
|
35
|
-
</span>
|
|
36
|
-
</FieldLabel>
|
|
37
|
-
<Input
|
|
38
|
-
id={id}
|
|
39
|
-
type="tel"
|
|
40
|
-
autoComplete="tel"
|
|
41
|
-
readOnly={readOnly}
|
|
42
|
-
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
43
|
-
aria-invalid={!!error}
|
|
44
|
-
aria-required={required}
|
|
45
|
-
required={required}
|
|
46
|
-
{...register(name)}
|
|
47
|
-
/>
|
|
48
|
-
<FieldError errors={[error]} />
|
|
49
|
-
</Field>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export default PhoneField;
|
|
1
|
+
import { type FC, useId } from 'react';
|
|
2
|
+
import { useFormContext } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Field, FieldError, FieldLabel } from '../ui/field';
|
|
5
|
+
import { Input } from '../ui/input';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
label?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const PhoneField: FC<Props> = ({
|
|
15
|
+
name = 'phoneNumber',
|
|
16
|
+
required = false,
|
|
17
|
+
readOnly = false,
|
|
18
|
+
label = 'Phone number',
|
|
19
|
+
}) => {
|
|
20
|
+
const { register, getFieldState, formState } = useFormContext();
|
|
21
|
+
const { error } = getFieldState(name, formState);
|
|
22
|
+
const id = useId();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Field data-invalid={!!error} data-testid={`sdk-${name}-field-id`}>
|
|
26
|
+
<FieldLabel htmlFor={id}>
|
|
27
|
+
<span>
|
|
28
|
+
{label}
|
|
29
|
+
{required && (
|
|
30
|
+
<span aria-hidden="true" className="text-destructive">
|
|
31
|
+
{' '}
|
|
32
|
+
*
|
|
33
|
+
</span>
|
|
34
|
+
)}
|
|
35
|
+
</span>
|
|
36
|
+
</FieldLabel>
|
|
37
|
+
<Input
|
|
38
|
+
id={id}
|
|
39
|
+
type="tel"
|
|
40
|
+
autoComplete="tel"
|
|
41
|
+
readOnly={readOnly}
|
|
42
|
+
className="read-only:cursor-not-allowed read-only:bg-input/50"
|
|
43
|
+
aria-invalid={!!error}
|
|
44
|
+
aria-required={required}
|
|
45
|
+
required={required}
|
|
46
|
+
{...register(name)}
|
|
47
|
+
/>
|
|
48
|
+
<FieldError errors={[error]} />
|
|
49
|
+
</Field>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default PhoneField;
|