@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.
- package/.editorconfig +8 -8
- package/.release-it.json +10 -10
- package/README.md +13 -6
- package/build/postcss-scope-tailwind.cjs +0 -0
- package/components.json +0 -0
- package/package.json +1 -1
- package/src/App.completion.test.tsx +46 -107
- package/src/App.css +0 -14
- package/src/App.paymentReturn.test.tsx +341 -0
- package/src/App.tsx +20 -51
- package/src/ErrorBoundary.tsx +41 -41
- package/src/api/InvoiceApi.ts +23 -23
- 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 +0 -3
- 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/OIOForm/OIOForm.tsx +0 -3
- package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
- package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
- package/src/components/OrderForm/OrderForm.tsx +0 -3
- 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/components/ui/alert-dialog.tsx +0 -0
- package/src/components/ui/alert.tsx +0 -0
- package/src/components/ui/button.tsx +0 -0
- package/src/components/ui/card.tsx +0 -0
- package/src/components/ui/checkbox.tsx +0 -0
- package/src/components/ui/field.tsx +0 -0
- package/src/components/ui/input.tsx +0 -0
- package/src/components/ui/label.tsx +0 -0
- package/src/components/ui/radio-group.tsx +0 -0
- package/src/components/ui/separator.tsx +0 -0
- package/src/components/ui/skeleton.tsx +0 -0
- package/src/components/ui/spinner.tsx +0 -0
- package/src/components/ui/switch.tsx +0 -0
- package/src/components/ui/textarea.tsx +0 -0
- package/src/constants/index.ts +13 -13
- package/src/custom.d.ts +0 -0
- package/src/enums/api.ts +5 -5
- package/src/enums/general.ts +4 -2
- package/src/hooks/useOrderForm.tsx +0 -3
- package/src/hooks/usePaymentReturn.tsx +139 -0
- 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 +0 -1
- package/src/utils/helper.ts +78 -78
- package/src/utils/order.helper.test.ts +81 -0
- package/src/utils/order.helper.ts +38 -25
- package/tsconfig.json +1 -0
- package/src/components/MainIframe/MainIframe.tsx +0 -42
- package/src/hooks/useIframe.tsx +0 -59
- package/src/hooks/useMessageEvent.tsx +0 -194
|
@@ -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;
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { type FC, type ReactNode, useId } from 'react';
|
|
2
|
-
import { Controller, useFormContext } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Checkbox } from '../ui/checkbox';
|
|
5
|
-
import { Field, FieldContent, FieldError, FieldLabel } from '../ui/field';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
name: string;
|
|
9
|
-
required: boolean;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
label?: string | ReactNode;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const TermsCheckbox: FC<Props> = ({
|
|
15
|
-
name,
|
|
16
|
-
required = true,
|
|
17
|
-
disabled = false,
|
|
18
|
-
label = 'I accept the terms and conditions',
|
|
19
|
-
}) => {
|
|
20
|
-
const { control } = useFormContext();
|
|
21
|
-
const id = useId();
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<Controller
|
|
25
|
-
name={name}
|
|
26
|
-
control={control}
|
|
27
|
-
defaultValue={false}
|
|
28
|
-
render={({ field, fieldState }) => (
|
|
29
|
-
<Field
|
|
30
|
-
orientation="horizontal"
|
|
31
|
-
data-invalid={fieldState.invalid}
|
|
32
|
-
data-disabled={disabled}
|
|
33
|
-
data-testid={`sdk-${name}-field-id`}
|
|
34
|
-
>
|
|
35
|
-
<Checkbox
|
|
36
|
-
id={id}
|
|
37
|
-
name={field.name}
|
|
38
|
-
checked={!!field.value}
|
|
39
|
-
onCheckedChange={(checked) => field.onChange(checked)}
|
|
40
|
-
onBlur={field.onBlur}
|
|
41
|
-
inputRef={field.ref}
|
|
42
|
-
disabled={disabled}
|
|
43
|
-
aria-invalid={fieldState.invalid}
|
|
44
|
-
aria-required={required}
|
|
45
|
-
required={required}
|
|
46
|
-
/>
|
|
47
|
-
<FieldContent>
|
|
48
|
-
<FieldLabel htmlFor={id}>
|
|
49
|
-
<span>
|
|
50
|
-
{label}
|
|
51
|
-
{required && (
|
|
52
|
-
<span
|
|
53
|
-
aria-hidden="true"
|
|
54
|
-
className="text-destructive"
|
|
55
|
-
>
|
|
56
|
-
{' '}
|
|
57
|
-
*
|
|
58
|
-
</span>
|
|
59
|
-
)}
|
|
60
|
-
</span>
|
|
61
|
-
</FieldLabel>
|
|
62
|
-
<FieldError errors={[fieldState.error]} />
|
|
63
|
-
</FieldContent>
|
|
64
|
-
</Field>
|
|
65
|
-
)}
|
|
66
|
-
/>
|
|
67
|
-
);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export default TermsCheckbox;
|
|
1
|
+
import { type FC, type ReactNode, useId } from 'react';
|
|
2
|
+
import { Controller, useFormContext } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Checkbox } from '../ui/checkbox';
|
|
5
|
+
import { Field, FieldContent, FieldError, FieldLabel } from '../ui/field';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
label?: string | ReactNode;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const TermsCheckbox: FC<Props> = ({
|
|
15
|
+
name,
|
|
16
|
+
required = true,
|
|
17
|
+
disabled = false,
|
|
18
|
+
label = 'I accept the terms and conditions',
|
|
19
|
+
}) => {
|
|
20
|
+
const { control } = useFormContext();
|
|
21
|
+
const id = useId();
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Controller
|
|
25
|
+
name={name}
|
|
26
|
+
control={control}
|
|
27
|
+
defaultValue={false}
|
|
28
|
+
render={({ field, fieldState }) => (
|
|
29
|
+
<Field
|
|
30
|
+
orientation="horizontal"
|
|
31
|
+
data-invalid={fieldState.invalid}
|
|
32
|
+
data-disabled={disabled}
|
|
33
|
+
data-testid={`sdk-${name}-field-id`}
|
|
34
|
+
>
|
|
35
|
+
<Checkbox
|
|
36
|
+
id={id}
|
|
37
|
+
name={field.name}
|
|
38
|
+
checked={!!field.value}
|
|
39
|
+
onCheckedChange={(checked) => field.onChange(checked)}
|
|
40
|
+
onBlur={field.onBlur}
|
|
41
|
+
inputRef={field.ref}
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
aria-invalid={fieldState.invalid}
|
|
44
|
+
aria-required={required}
|
|
45
|
+
required={required}
|
|
46
|
+
/>
|
|
47
|
+
<FieldContent>
|
|
48
|
+
<FieldLabel htmlFor={id}>
|
|
49
|
+
<span>
|
|
50
|
+
{label}
|
|
51
|
+
{required && (
|
|
52
|
+
<span
|
|
53
|
+
aria-hidden="true"
|
|
54
|
+
className="text-destructive"
|
|
55
|
+
>
|
|
56
|
+
{' '}
|
|
57
|
+
*
|
|
58
|
+
</span>
|
|
59
|
+
)}
|
|
60
|
+
</span>
|
|
61
|
+
</FieldLabel>
|
|
62
|
+
<FieldError errors={[fieldState.error]} />
|
|
63
|
+
</FieldContent>
|
|
64
|
+
</Field>
|
|
65
|
+
)}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default TermsCheckbox;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { type FC, useId } from 'react';
|
|
2
|
-
import { Controller, useFormContext } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Field, FieldLabel } from '../ui/field';
|
|
5
|
-
import { Switch } from '../ui/switch';
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
name: string;
|
|
9
|
-
readOnly?: boolean;
|
|
10
|
-
label?: string;
|
|
11
|
-
toggleCallback?: (value: boolean) => void;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const ToggleField: FC<Props> = ({
|
|
15
|
-
name,
|
|
16
|
-
readOnly = false,
|
|
17
|
-
label = '',
|
|
18
|
-
toggleCallback,
|
|
19
|
-
}) => {
|
|
20
|
-
const { control } = useFormContext();
|
|
21
|
-
const id = useId();
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<Controller
|
|
25
|
-
name={name}
|
|
26
|
-
control={control}
|
|
27
|
-
defaultValue={false}
|
|
28
|
-
render={({ field }) => (
|
|
29
|
-
<Field
|
|
30
|
-
orientation="horizontal"
|
|
31
|
-
data-testid={`sdk-${name}-field-id`}
|
|
32
|
-
>
|
|
33
|
-
<FieldLabel htmlFor={id}>{label}</FieldLabel>
|
|
34
|
-
<Switch
|
|
35
|
-
id={id}
|
|
36
|
-
name={field.name}
|
|
37
|
-
checked={!!field.value}
|
|
38
|
-
onCheckedChange={(checked) => {
|
|
39
|
-
field.onChange(checked);
|
|
40
|
-
toggleCallback?.(checked);
|
|
41
|
-
}}
|
|
42
|
-
onBlur={field.onBlur}
|
|
43
|
-
inputRef={field.ref}
|
|
44
|
-
readOnly={readOnly}
|
|
45
|
-
/>
|
|
46
|
-
</Field>
|
|
47
|
-
)}
|
|
48
|
-
/>
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default ToggleField;
|
|
1
|
+
import { type FC, useId } from 'react';
|
|
2
|
+
import { Controller, useFormContext } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Field, FieldLabel } from '../ui/field';
|
|
5
|
+
import { Switch } from '../ui/switch';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
readOnly?: boolean;
|
|
10
|
+
label?: string;
|
|
11
|
+
toggleCallback?: (value: boolean) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const ToggleField: FC<Props> = ({
|
|
15
|
+
name,
|
|
16
|
+
readOnly = false,
|
|
17
|
+
label = '',
|
|
18
|
+
toggleCallback,
|
|
19
|
+
}) => {
|
|
20
|
+
const { control } = useFormContext();
|
|
21
|
+
const id = useId();
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Controller
|
|
25
|
+
name={name}
|
|
26
|
+
control={control}
|
|
27
|
+
defaultValue={false}
|
|
28
|
+
render={({ field }) => (
|
|
29
|
+
<Field
|
|
30
|
+
orientation="horizontal"
|
|
31
|
+
data-testid={`sdk-${name}-field-id`}
|
|
32
|
+
>
|
|
33
|
+
<FieldLabel htmlFor={id}>{label}</FieldLabel>
|
|
34
|
+
<Switch
|
|
35
|
+
id={id}
|
|
36
|
+
name={field.name}
|
|
37
|
+
checked={!!field.value}
|
|
38
|
+
onCheckedChange={(checked) => {
|
|
39
|
+
field.onChange(checked);
|
|
40
|
+
toggleCallback?.(checked);
|
|
41
|
+
}}
|
|
42
|
+
onBlur={field.onBlur}
|
|
43
|
+
inputRef={field.ref}
|
|
44
|
+
readOnly={readOnly}
|
|
45
|
+
/>
|
|
46
|
+
</Field>
|
|
47
|
+
)}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default ToggleField;
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { z, type ZodTypeAny } from 'zod';
|
|
2
|
-
|
|
3
|
-
import EmailField from './EmailField';
|
|
4
|
-
import PhoneField from './PhoneField';
|
|
5
|
-
import NameField from './NameField';
|
|
6
|
-
import AddressField from './AddressField';
|
|
7
|
-
import TermsCheckbox from './TermsCheckbox';
|
|
8
|
-
import formFieldsMapper from './FormFieldsMapper';
|
|
9
|
-
|
|
10
|
-
export const EMAIL_PATTERN =
|
|
11
|
-
/^[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_`{|}~-]{2,20})+$/i;
|
|
12
|
-
export const PHONE_PATTERN = /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\./0-9]{6,14}$/;
|
|
13
|
-
const NON_BLANK_PATTERN = /\S/;
|
|
14
|
-
|
|
15
|
-
export type FieldValidationMessages = {
|
|
16
|
-
errorReqMsg?: string;
|
|
17
|
-
errorInvalidEmailMsg?: string;
|
|
18
|
-
errorInvalidPhoneMsg?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const matchesWhenFilled = (pattern: RegExp) => (value: string) =>
|
|
22
|
-
value === '' || pattern.test(value);
|
|
23
|
-
|
|
24
|
-
export const buildFieldSchema = (
|
|
25
|
-
fieldName: string,
|
|
26
|
-
required: boolean,
|
|
27
|
-
messages: FieldValidationMessages = {}
|
|
28
|
-
): ZodTypeAny => {
|
|
29
|
-
const reqMsg = messages.errorReqMsg || 'This field is required!';
|
|
30
|
-
const Component = formFieldsMapper[fieldName];
|
|
31
|
-
|
|
32
|
-
if (Component === EmailField) {
|
|
33
|
-
const emailMsg =
|
|
34
|
-
messages.errorInvalidEmailMsg || 'Invalid email address!';
|
|
35
|
-
const base = required ? z.string().min(1, reqMsg) : z.string();
|
|
36
|
-
return base.refine(matchesWhenFilled(EMAIL_PATTERN), emailMsg);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (Component === PhoneField) {
|
|
40
|
-
const phoneMsg =
|
|
41
|
-
messages.errorInvalidPhoneMsg || 'Invalid phone number!';
|
|
42
|
-
const base = required ? z.string().min(1, reqMsg) : z.string();
|
|
43
|
-
return base.refine(matchesWhenFilled(PHONE_PATTERN), phoneMsg);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (Component === AddressField) {
|
|
47
|
-
const trimmed = z
|
|
48
|
-
.string()
|
|
49
|
-
.transform((value) => (typeof value === 'string' ? value.trim() : value));
|
|
50
|
-
return required
|
|
51
|
-
? trimmed.refine((value) => value.length > 0, { message: reqMsg })
|
|
52
|
-
: trimmed;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (Component === NameField) {
|
|
56
|
-
return required
|
|
57
|
-
? z.string().min(1, reqMsg).regex(NON_BLANK_PATTERN, reqMsg)
|
|
58
|
-
: z.string();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (Component === TermsCheckbox) {
|
|
62
|
-
const schema = z.boolean();
|
|
63
|
-
return required
|
|
64
|
-
? schema.refine((value) => value === true, { message: reqMsg })
|
|
65
|
-
: schema;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return required
|
|
69
|
-
? z.string().min(1, reqMsg).regex(NON_BLANK_PATTERN, reqMsg)
|
|
70
|
-
: z.string();
|
|
71
|
-
};
|
|
1
|
+
import { z, type ZodTypeAny } from 'zod';
|
|
2
|
+
|
|
3
|
+
import EmailField from './EmailField';
|
|
4
|
+
import PhoneField from './PhoneField';
|
|
5
|
+
import NameField from './NameField';
|
|
6
|
+
import AddressField from './AddressField';
|
|
7
|
+
import TermsCheckbox from './TermsCheckbox';
|
|
8
|
+
import formFieldsMapper from './FormFieldsMapper';
|
|
9
|
+
|
|
10
|
+
export const EMAIL_PATTERN =
|
|
11
|
+
/^[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[A-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_`{|}~-]{2,20})+$/i;
|
|
12
|
+
export const PHONE_PATTERN = /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\./0-9]{6,14}$/;
|
|
13
|
+
const NON_BLANK_PATTERN = /\S/;
|
|
14
|
+
|
|
15
|
+
export type FieldValidationMessages = {
|
|
16
|
+
errorReqMsg?: string;
|
|
17
|
+
errorInvalidEmailMsg?: string;
|
|
18
|
+
errorInvalidPhoneMsg?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const matchesWhenFilled = (pattern: RegExp) => (value: string) =>
|
|
22
|
+
value === '' || pattern.test(value);
|
|
23
|
+
|
|
24
|
+
export const buildFieldSchema = (
|
|
25
|
+
fieldName: string,
|
|
26
|
+
required: boolean,
|
|
27
|
+
messages: FieldValidationMessages = {}
|
|
28
|
+
): ZodTypeAny => {
|
|
29
|
+
const reqMsg = messages.errorReqMsg || 'This field is required!';
|
|
30
|
+
const Component = formFieldsMapper[fieldName];
|
|
31
|
+
|
|
32
|
+
if (Component === EmailField) {
|
|
33
|
+
const emailMsg =
|
|
34
|
+
messages.errorInvalidEmailMsg || 'Invalid email address!';
|
|
35
|
+
const base = required ? z.string().min(1, reqMsg) : z.string();
|
|
36
|
+
return base.refine(matchesWhenFilled(EMAIL_PATTERN), emailMsg);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (Component === PhoneField) {
|
|
40
|
+
const phoneMsg =
|
|
41
|
+
messages.errorInvalidPhoneMsg || 'Invalid phone number!';
|
|
42
|
+
const base = required ? z.string().min(1, reqMsg) : z.string();
|
|
43
|
+
return base.refine(matchesWhenFilled(PHONE_PATTERN), phoneMsg);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (Component === AddressField) {
|
|
47
|
+
const trimmed = z
|
|
48
|
+
.string()
|
|
49
|
+
.transform((value) => (typeof value === 'string' ? value.trim() : value));
|
|
50
|
+
return required
|
|
51
|
+
? trimmed.refine((value) => value.length > 0, { message: reqMsg })
|
|
52
|
+
: trimmed;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Component === NameField) {
|
|
56
|
+
return required
|
|
57
|
+
? z.string().min(1, reqMsg).regex(NON_BLANK_PATTERN, reqMsg)
|
|
58
|
+
: z.string();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (Component === TermsCheckbox) {
|
|
62
|
+
const schema = z.boolean();
|
|
63
|
+
return required
|
|
64
|
+
? schema.refine((value) => value === true, { message: reqMsg })
|
|
65
|
+
: schema;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return required
|
|
69
|
+
? z.string().min(1, reqMsg).regex(NON_BLANK_PATTERN, reqMsg)
|
|
70
|
+
: z.string();
|
|
71
|
+
};
|
|
@@ -44,7 +44,6 @@ type Props = {
|
|
|
44
44
|
identityProviderId?: string;
|
|
45
45
|
organizationId: string;
|
|
46
46
|
redirectUrl?: string;
|
|
47
|
-
showIframe?: boolean;
|
|
48
47
|
language: string;
|
|
49
48
|
merchantAgreementUrl: string;
|
|
50
49
|
orderValues?: OrderFormInputsType;
|
|
@@ -120,7 +119,6 @@ const OIOForm: FC<Props> = ({
|
|
|
120
119
|
identityProviderId,
|
|
121
120
|
organizationId,
|
|
122
121
|
redirectUrl,
|
|
123
|
-
showIframe,
|
|
124
122
|
language,
|
|
125
123
|
merchantAgreementUrl,
|
|
126
124
|
orderValues,
|
|
@@ -182,7 +180,6 @@ const OIOForm: FC<Props> = ({
|
|
|
182
180
|
identityProviderId,
|
|
183
181
|
orderFields,
|
|
184
182
|
redirectUrl,
|
|
185
|
-
showIframe,
|
|
186
183
|
language,
|
|
187
184
|
merchantAgreementUrl,
|
|
188
185
|
paymentMethodsOptions,
|