@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.
Files changed (51) hide show
  1. package/.editorconfig +8 -8
  2. package/.release-it.json +10 -10
  3. package/README.md +565 -471
  4. package/package.json +62 -58
  5. package/src/App.completion.test.tsx +738 -0
  6. package/src/App.tsx +753 -639
  7. package/src/ErrorBoundary.tsx +41 -41
  8. package/src/api/InvoiceApi.ts +23 -23
  9. package/src/api/OrdersApi.ts +74 -59
  10. package/src/api/SubscribeApi.ts +18 -18
  11. package/src/bundle.ts +4 -4
  12. package/src/components/Alert/Alert.tsx +23 -23
  13. package/src/components/Button/Button.tsx +39 -39
  14. package/src/components/EHFForm/EHFForm.tsx +253 -253
  15. package/src/components/FormFields/AddressField.tsx +55 -55
  16. package/src/components/FormFields/EmailField.tsx +53 -53
  17. package/src/components/FormFields/FormFields.helper.ts +34 -34
  18. package/src/components/FormFields/FormFieldsMapper.ts +34 -34
  19. package/src/components/FormFields/InputField.tsx +52 -52
  20. package/src/components/FormFields/NameField.tsx +52 -52
  21. package/src/components/FormFields/PhoneField.tsx +53 -53
  22. package/src/components/FormFields/TermsCheckbox.tsx +70 -70
  23. package/src/components/FormFields/ToggleFiled.tsx +52 -52
  24. package/src/components/FormFields/fieldValidators.ts +71 -71
  25. package/src/components/MainIframe/MainIframe.tsx +42 -42
  26. package/src/components/OIOForm/OIOForm.tsx +307 -307
  27. package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
  28. package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
  29. package/src/components/OrderForm/OrderForm.tsx +420 -420
  30. package/src/components/OrderForm/PaymentMethodContent.tsx +62 -62
  31. package/src/components/OrderForm/PaymentMethodSection.tsx +79 -79
  32. package/src/components/OrderForm/SubmitConfirmationDialog.tsx +55 -55
  33. package/src/components/OrderForm/orderFormState.ts +171 -171
  34. package/src/components/OrderForm/useSlotElement.tsx +89 -89
  35. package/src/constants/index.ts +13 -13
  36. package/src/enums/api.ts +5 -5
  37. package/src/enums/general.ts +40 -40
  38. package/src/hooks/useIframe.tsx +59 -59
  39. package/src/hooks/useMessageEvent.tsx +194 -194
  40. package/src/hooks/useOrderForm.tsx +403 -403
  41. package/src/hooks/useQueryParams.ts +5 -5
  42. package/src/index.tsx +30 -30
  43. package/src/lib/utils.ts +1 -1
  44. package/src/types/api.ts +28 -28
  45. package/src/types/general.ts +154 -136
  46. package/src/types/order.ts +91 -70
  47. package/src/utils/fetcher.ts +131 -113
  48. package/src/utils/helper.ts +78 -78
  49. package/src/utils/order.helper.ts +272 -272
  50. package/src/utils/waitForOrderCompletion.ts +125 -0
  51. 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;