@infosoftas/s4-orders-js-sdk 0.2.0 → 0.2.1

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.
Files changed (68) hide show
  1. package/.editorconfig +8 -8
  2. package/.release-it.json +10 -10
  3. package/README.md +13 -6
  4. package/build/postcss-scope-tailwind.cjs +0 -0
  5. package/components.json +0 -0
  6. package/package.json +1 -1
  7. package/src/App.completion.test.tsx +46 -107
  8. package/src/App.css +0 -14
  9. package/src/App.paymentReturn.test.tsx +341 -0
  10. package/src/App.tsx +20 -51
  11. package/src/ErrorBoundary.tsx +41 -41
  12. package/src/api/InvoiceApi.ts +23 -23
  13. package/src/api/SubscribeApi.ts +18 -18
  14. package/src/bundle.ts +4 -4
  15. package/src/components/Alert/Alert.tsx +23 -23
  16. package/src/components/Button/Button.tsx +39 -39
  17. package/src/components/EHFForm/EHFForm.tsx +0 -3
  18. package/src/components/FormFields/AddressField.tsx +55 -55
  19. package/src/components/FormFields/EmailField.tsx +53 -53
  20. package/src/components/FormFields/FormFields.helper.ts +34 -34
  21. package/src/components/FormFields/FormFieldsMapper.ts +34 -34
  22. package/src/components/FormFields/InputField.tsx +52 -52
  23. package/src/components/FormFields/NameField.tsx +52 -52
  24. package/src/components/FormFields/PhoneField.tsx +53 -53
  25. package/src/components/FormFields/TermsCheckbox.tsx +70 -70
  26. package/src/components/FormFields/ToggleFiled.tsx +52 -52
  27. package/src/components/FormFields/fieldValidators.ts +71 -71
  28. package/src/components/OIOForm/OIOForm.tsx +0 -3
  29. package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
  30. package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
  31. package/src/components/OrderForm/OrderForm.tsx +0 -3
  32. package/src/components/OrderForm/PaymentMethodContent.tsx +62 -62
  33. package/src/components/OrderForm/PaymentMethodSection.tsx +79 -79
  34. package/src/components/OrderForm/SubmitConfirmationDialog.tsx +55 -55
  35. package/src/components/OrderForm/orderFormState.ts +171 -171
  36. package/src/components/OrderForm/useSlotElement.tsx +89 -89
  37. package/src/components/ui/alert-dialog.tsx +0 -0
  38. package/src/components/ui/alert.tsx +0 -0
  39. package/src/components/ui/button.tsx +0 -0
  40. package/src/components/ui/card.tsx +0 -0
  41. package/src/components/ui/checkbox.tsx +0 -0
  42. package/src/components/ui/field.tsx +0 -0
  43. package/src/components/ui/input.tsx +0 -0
  44. package/src/components/ui/label.tsx +0 -0
  45. package/src/components/ui/radio-group.tsx +0 -0
  46. package/src/components/ui/separator.tsx +0 -0
  47. package/src/components/ui/skeleton.tsx +0 -0
  48. package/src/components/ui/spinner.tsx +0 -0
  49. package/src/components/ui/switch.tsx +0 -0
  50. package/src/components/ui/textarea.tsx +0 -0
  51. package/src/constants/index.ts +13 -13
  52. package/src/custom.d.ts +0 -0
  53. package/src/enums/api.ts +5 -5
  54. package/src/enums/general.ts +4 -2
  55. package/src/hooks/useOrderForm.tsx +0 -3
  56. package/src/hooks/usePaymentReturn.tsx +139 -0
  57. package/src/hooks/useQueryParams.ts +5 -5
  58. package/src/index.tsx +30 -30
  59. package/src/lib/utils.ts +1 -1
  60. package/src/types/api.ts +28 -28
  61. package/src/types/general.ts +0 -1
  62. package/src/utils/helper.ts +78 -78
  63. package/src/utils/order.helper.test.ts +81 -0
  64. package/src/utils/order.helper.ts +38 -25
  65. package/tsconfig.json +1 -0
  66. package/src/components/MainIframe/MainIframe.tsx +0 -42
  67. package/src/hooks/useIframe.tsx +0 -59
  68. package/src/hooks/useMessageEvent.tsx +0 -194
@@ -1,23 +1,23 @@
1
- import type { FC } from 'react';
2
-
3
- import { Alert as UIAlert, AlertDescription } from '../ui/alert';
4
-
5
- type Props = {
6
- msg?: string;
7
- type?: 'danger' | 'success';
8
- className?: string;
9
- };
10
-
11
- const Alert: FC<Props> = ({ msg, type = 'danger', className }) => {
12
- return msg ? (
13
- <UIAlert
14
- variant={type === 'danger' ? 'destructive' : 'default'}
15
- className={className}
16
- data-testid="sdk-alert-id"
17
- >
18
- <AlertDescription>{msg}</AlertDescription>
19
- </UIAlert>
20
- ) : null;
21
- };
22
-
23
- export default Alert;
1
+ import type { FC } from 'react';
2
+
3
+ import { Alert as UIAlert, AlertDescription } from '../ui/alert';
4
+
5
+ type Props = {
6
+ msg?: string;
7
+ type?: 'danger' | 'success';
8
+ className?: string;
9
+ };
10
+
11
+ const Alert: FC<Props> = ({ msg, type = 'danger', className }) => {
12
+ return msg ? (
13
+ <UIAlert
14
+ variant={type === 'danger' ? 'destructive' : 'default'}
15
+ className={className}
16
+ data-testid="sdk-alert-id"
17
+ >
18
+ <AlertDescription>{msg}</AlertDescription>
19
+ </UIAlert>
20
+ ) : null;
21
+ };
22
+
23
+ export default Alert;
@@ -1,39 +1,39 @@
1
- import type { FC, MouseEvent } from 'react';
2
-
3
- import { Button as UIButton } from '../ui/button';
4
- import { Spinner } from '../ui/spinner';
5
-
6
- type Props = {
7
- onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
8
- type?: 'button' | 'submit' | 'reset';
9
- btnType?: 'primary' | 'default';
10
- buttonText?: string;
11
- loading?: boolean;
12
- disable?: boolean;
13
- className?: string;
14
- };
15
-
16
- const Button: FC<Props> = ({
17
- onClick,
18
- type = 'button',
19
- btnType = 'primary',
20
- buttonText = 'Start',
21
- loading = false,
22
- disable = false,
23
- className,
24
- }) => (
25
- <UIButton
26
- data-testid="sdk-button-id"
27
- type={type}
28
- variant={btnType === 'primary' ? 'default' : 'ghost'}
29
- disabled={loading || disable}
30
- aria-busy={loading || undefined}
31
- className={className}
32
- onClick={onClick}
33
- >
34
- {loading && <Spinner data-icon="inline-start" />}
35
- {buttonText}
36
- </UIButton>
37
- );
38
-
39
- export default Button;
1
+ import type { FC, MouseEvent } from 'react';
2
+
3
+ import { Button as UIButton } from '../ui/button';
4
+ import { Spinner } from '../ui/spinner';
5
+
6
+ type Props = {
7
+ onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
8
+ type?: 'button' | 'submit' | 'reset';
9
+ btnType?: 'primary' | 'default';
10
+ buttonText?: string;
11
+ loading?: boolean;
12
+ disable?: boolean;
13
+ className?: string;
14
+ };
15
+
16
+ const Button: FC<Props> = ({
17
+ onClick,
18
+ type = 'button',
19
+ btnType = 'primary',
20
+ buttonText = 'Start',
21
+ loading = false,
22
+ disable = false,
23
+ className,
24
+ }) => (
25
+ <UIButton
26
+ data-testid="sdk-button-id"
27
+ type={type}
28
+ variant={btnType === 'primary' ? 'default' : 'ghost'}
29
+ disabled={loading || disable}
30
+ aria-busy={loading || undefined}
31
+ className={className}
32
+ onClick={onClick}
33
+ >
34
+ {loading && <Spinner data-icon="inline-start" />}
35
+ {buttonText}
36
+ </UIButton>
37
+ );
38
+
39
+ export default Button;
@@ -43,7 +43,6 @@ type Props = {
43
43
  identityProviderId?: string;
44
44
  organizationId: string;
45
45
  redirectUrl?: string;
46
- showIframe?: boolean;
47
46
  language: string;
48
47
  merchantAgreementUrl: string;
49
48
  orderValues?: OrderFormInputsType;
@@ -100,7 +99,6 @@ const EHFForm: FC<Props> = ({
100
99
  identityProviderId,
101
100
  organizationId,
102
101
  redirectUrl,
103
- showIframe,
104
102
  language,
105
103
  merchantAgreementUrl,
106
104
  orderValues,
@@ -159,7 +157,6 @@ const EHFForm: FC<Props> = ({
159
157
  identityProviderId,
160
158
  orderFields,
161
159
  redirectUrl,
162
- showIframe,
163
160
  language,
164
161
  merchantAgreementUrl,
165
162
  paymentMethodsOptions,
@@ -1,55 +1,55 @@
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 { Textarea } from '../ui/textarea';
6
-
7
- type Props = {
8
- name: string;
9
- required: boolean;
10
- readOnly: boolean;
11
- label?: string;
12
- };
13
-
14
- const AddressField: FC<Props> = ({
15
- name = 'address',
16
- required = false,
17
- readOnly = false,
18
- label = 'Address',
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
- <Textarea
38
- id={id}
39
- autoComplete="street-address"
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
- setValueAs: (value) =>
47
- typeof value === 'string' ? value.trim() : value,
48
- })}
49
- />
50
- <FieldError errors={[error]} />
51
- </Field>
52
- );
53
- };
54
-
55
- export default AddressField;
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 { Textarea } from '../ui/textarea';
6
+
7
+ type Props = {
8
+ name: string;
9
+ required: boolean;
10
+ readOnly: boolean;
11
+ label?: string;
12
+ };
13
+
14
+ const AddressField: FC<Props> = ({
15
+ name = 'address',
16
+ required = false,
17
+ readOnly = false,
18
+ label = 'Address',
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
+ <Textarea
38
+ id={id}
39
+ autoComplete="street-address"
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
+ setValueAs: (value) =>
47
+ typeof value === 'string' ? value.trim() : value,
48
+ })}
49
+ />
50
+ <FieldError errors={[error]} />
51
+ </Field>
52
+ );
53
+ };
54
+
55
+ export default AddressField;
@@ -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;