@infosoftas/s4-orders-js-sdk 0.1.19 → 0.1.21-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 (62) hide show
  1. package/README.md +471 -426
  2. package/build/postcss-scope-tailwind.cjs +66 -0
  3. package/components.json +21 -0
  4. package/package.json +59 -43
  5. package/src/App.css +409 -0
  6. package/src/App.tsx +639 -569
  7. package/src/api/OrdersApi.ts +2 -2
  8. package/src/components/Alert/Alert.tsx +23 -22
  9. package/src/components/Button/Button.tsx +18 -22
  10. package/src/components/EHFForm/EHFForm.tsx +253 -235
  11. package/src/components/FormFields/AddressField.tsx +55 -62
  12. package/src/components/FormFields/EmailField.tsx +53 -58
  13. package/src/components/FormFields/InputField.tsx +52 -53
  14. package/src/components/FormFields/NameField.tsx +52 -53
  15. package/src/components/FormFields/PhoneField.tsx +53 -58
  16. package/src/components/FormFields/TermsCheckbox.tsx +70 -58
  17. package/src/components/FormFields/ToggleFiled.tsx +52 -63
  18. package/src/components/FormFields/fieldValidators.ts +71 -0
  19. package/src/components/OIOForm/OIOForm.tsx +132 -71
  20. package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -89
  21. package/src/components/OrderForm/ContactDetailsSection.tsx +71 -0
  22. package/src/components/OrderForm/OrderForm.tsx +177 -224
  23. package/src/components/OrderForm/PaymentMethodContent.tsx +62 -0
  24. package/src/components/OrderForm/PaymentMethodSection.tsx +79 -0
  25. package/src/components/OrderForm/SubmitConfirmationDialog.tsx +55 -0
  26. package/src/components/OrderForm/orderFormState.ts +171 -0
  27. package/src/components/OrderForm/useSlotElement.tsx +89 -0
  28. package/src/components/ui/alert-dialog.tsx +185 -0
  29. package/src/components/ui/alert.tsx +75 -0
  30. package/src/components/ui/button.tsx +55 -0
  31. package/src/components/ui/card.tsx +99 -0
  32. package/src/components/ui/checkbox.tsx +28 -0
  33. package/src/components/ui/field.tsx +238 -0
  34. package/src/components/ui/input.tsx +19 -0
  35. package/src/components/ui/label.tsx +19 -0
  36. package/src/components/ui/radio-group.tsx +37 -0
  37. package/src/components/ui/separator.tsx +24 -0
  38. package/src/components/ui/skeleton.tsx +13 -0
  39. package/src/components/ui/spinner.tsx +10 -0
  40. package/src/components/ui/switch.tsx +29 -0
  41. package/src/components/ui/textarea.tsx +17 -0
  42. package/src/constants/index.ts +0 -2
  43. package/src/custom.d.ts +4 -4
  44. package/src/enums/general.ts +1 -0
  45. package/src/hooks/useMessageEvent.tsx +54 -3
  46. package/src/hooks/useOrderForm.tsx +9 -2
  47. package/src/index.tsx +2 -0
  48. package/src/lib/utils.ts +1 -0
  49. package/src/types/general.ts +136 -111
  50. package/src/types/order.ts +8 -0
  51. package/src/utils/order.helper.ts +14 -3
  52. package/tsconfig.json +37 -38
  53. package/src/App.scss +0 -23
  54. package/src/assets/styles/forms.scss +0 -164
  55. package/src/assets/styles/general.scss +0 -46
  56. package/src/assets/styles/variables.scss +0 -29
  57. package/src/components/Alert/alert.scss +0 -21
  58. package/src/components/Button/button.scss +0 -48
  59. package/src/components/Loader/Loader.tsx +0 -22
  60. package/src/components/Loader/loader.scss +0 -37
  61. package/src/components/OrderDenialModal/orderDenialModal.scss +0 -42
  62. package/src/components/OrderForm/orderForm.scss +0 -10
@@ -1,62 +1,55 @@
1
- import { FC } from 'react';
2
- import { useFormContext } from 'react-hook-form';
3
-
4
- import { uuidv4 } from '../../utils/helper';
5
-
6
- type Props = {
7
- name: string;
8
- required: boolean;
9
- readOnly: boolean;
10
- label?: string;
11
- errorReqMsg?: string;
12
- errors?: {
13
- [key: string]: {
14
- message?: string;
15
- };
16
- };
17
- };
18
-
19
- const AddressField: FC<Props> = ({
20
- name = 'address',
21
- required = false,
22
- readOnly = false,
23
- label = 'Address',
24
- errorReqMsg = 'This field is required!',
25
- errors,
26
- }) => {
27
- const { register, setValue, watch } = useFormContext();
28
-
29
- const value = watch(name);
30
-
31
- const id = uuidv4();
32
- return (
33
- <div className="field-wrapper" data-testid={`sdk-${name}-field-id`}>
34
- <textarea
35
- id={id}
36
- autoComplete="address"
37
- placeholder=" "
38
- readOnly={readOnly}
39
- className={`input-control ${readOnly ? 'read-only' : ''}`}
40
- {...register(name, {
41
- required: required ? errorReqMsg : false,
42
- })}
43
- {...(required
44
- ? {
45
- onBlur: () => {
46
- const newValue = value?.trim() || '';
47
- setValue(name, newValue);
48
- },
49
- }
50
- : '')}
51
- />
52
- <label className="label-control" htmlFor={id}>
53
- {label} {required && <span className="text-error">*</span>}
54
- </label>
55
- {errors && errors[name] && (
56
- <div className="text-error caption">{errors[name].message}</div>
57
- )}
58
- </div>
59
- );
60
- };
61
-
62
- export default AddressField;
1
+ import { 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,58 +1,53 @@
1
- import { FC } from 'react';
2
- import { useFormContext } from 'react-hook-form';
3
-
4
- import { uuidv4 } from '../../utils/helper';
5
-
6
- type Props = {
7
- name: string;
8
- required: boolean;
9
- readOnly: boolean;
10
- label?: string;
11
- errorReqMsg?: string;
12
- errorInvalidEmailMsg?: string;
13
- errors?: {
14
- [key: string]: {
15
- message?: string;
16
- };
17
- };
18
- };
19
-
20
- const EmailField: FC<Props> = ({
21
- name = 'email',
22
- required = false,
23
- readOnly = false,
24
- label = 'Email',
25
- errorReqMsg = 'This field is required!',
26
- errorInvalidEmailMsg = 'Invalid email address!',
27
- errors,
28
- }) => {
29
- const { register } = useFormContext();
30
- const id = uuidv4();
31
- return (
32
- <div className="field-wrapper" data-testid={`sdk-${name}-field-id`}>
33
- <input
34
- id={id}
35
- autoComplete="email"
36
- placeholder=" "
37
- className={`input-control ${readOnly ? 'read-only' : ''}`}
38
- readOnly={readOnly}
39
- type="email"
40
- {...register(name, {
41
- required: required ? errorReqMsg : false,
42
- pattern: {
43
- value: /^[-!#-'*+/-9=?^-~]+(?:\.[-!#-'*+/-9=?^-~]+)*@[-!#-'*+/-9=?^-~]+(?:\.[-!#-'*+/-9=?^-~]{2,20})+$/i,
44
- message: errorInvalidEmailMsg,
45
- },
46
- })}
47
- />
48
- <label className="label-control" htmlFor={id}>
49
- {label} {required && <span className="text-error">*</span>}
50
- </label>
51
- {errors && errors[name] && (
52
- <div className="text-error caption">{errors[name].message}</div>
53
- )}
54
- </div>
55
- );
56
- };
57
-
58
- export default EmailField;
1
+ import { 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,53 +1,52 @@
1
- import { FC } from 'react';
2
- import { useFormContext } from 'react-hook-form';
3
-
4
- import { uuidv4 } from '../../utils/helper';
5
- import { REQUIRED_VALIDATION_REGEXP } from '../../constants/index';
6
-
7
- type Props = {
8
- name: string;
9
- required: boolean;
10
- readOnly: boolean;
11
- label?: string;
12
- errorReqMsg?: string;
13
- errors?: {
14
- [key: string]: {
15
- message?: string;
16
- };
17
- };
18
- };
19
-
20
- const NameField: FC<Props> = ({
21
- name,
22
- required = false,
23
- readOnly = false,
24
- label = '',
25
- errorReqMsg = 'This field is required!',
26
- errors,
27
- }) => {
28
- const { register } = useFormContext();
29
- const id = uuidv4();
30
- return (
31
- <div className="field-wrapper" data-testid={`sdk-${name}-field-id`}>
32
- <input
33
- id={id}
34
- autoComplete={name}
35
- placeholder=" "
36
- readOnly={readOnly}
37
- className={`input-control ${readOnly ? 'read-only' : ''}`}
38
- {...register(name, {
39
- required: required ? errorReqMsg : false,
40
- })}
41
- {...(required ? { pattern: REQUIRED_VALIDATION_REGEXP } : '')}
42
- />
43
- <label className="label-control" htmlFor={id}>
44
- {label} {required && <span className="text-error">*</span>}
45
- </label>
46
- {errors && errors[name] && (
47
- <div className="text-error caption">{errors[name].message}</div>
48
- )}
49
- </div>
50
- );
51
- };
52
-
53
- export default NameField;
1
+ import { 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,53 +1,52 @@
1
- import { FC } from 'react';
2
- import { useFormContext } from 'react-hook-form';
3
-
4
- import { uuidv4 } from '../../utils/helper';
5
- import { REQUIRED_VALIDATION_REGEXP } from '../../constants/index';
6
-
7
- type Props = {
8
- name: string;
9
- required: boolean;
10
- readOnly: boolean;
11
- label?: string;
12
- errorReqMsg?: string;
13
- errors?: {
14
- [key: string]: {
15
- message?: string;
16
- };
17
- };
18
- };
19
-
20
- const NameField: FC<Props> = ({
21
- name = 'name',
22
- required = false,
23
- readOnly = false,
24
- label = 'Name',
25
- errorReqMsg = 'This field is required!',
26
- errors,
27
- }) => {
28
- const { register } = useFormContext();
29
- const id = uuidv4();
30
- return (
31
- <div className="field-wrapper" data-testid={`sdk-${name}-field-id`}>
32
- <input
33
- id={id}
34
- autoComplete="name"
35
- placeholder=" "
36
- readOnly={readOnly}
37
- className={`input-control ${readOnly ? 'read-only' : ''}`}
38
- {...register(name, {
39
- required: required ? errorReqMsg : false,
40
- })}
41
- {...(required ? { pattern: REQUIRED_VALIDATION_REGEXP } : '')}
42
- />
43
- <label className="label-control" htmlFor={id}>
44
- {label} {required && <span className="text-error">*</span>}
45
- </label>
46
- {errors && errors[name] && (
47
- <div className="text-error caption">{errors[name].message}</div>
48
- )}
49
- </div>
50
- );
51
- };
52
-
53
- export default NameField;
1
+ import { 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,58 +1,53 @@
1
- import { FC } from 'react';
2
- import { useFormContext } from 'react-hook-form';
3
-
4
- import { uuidv4 } from '../../utils/helper';
5
-
6
- type Props = {
7
- name: string;
8
- required: boolean;
9
- readOnly: boolean;
10
- label?: string;
11
- errorReqMsg?: string;
12
- errorInvalidPhoneMsg?: string;
13
- errors?: {
14
- [key: string]: {
15
- message?: string;
16
- };
17
- };
18
- };
19
-
20
- const PhoneFiled: FC<Props> = ({
21
- name = 'phoneNumber',
22
- required = false,
23
- readOnly = false,
24
- label = 'Phone number',
25
- errorReqMsg = 'This field is required!',
26
- errorInvalidPhoneMsg = 'Invalid phone address!',
27
- errors,
28
- }) => {
29
- const { register } = useFormContext();
30
- const id = uuidv4();
31
- return (
32
- <div className="field-wrapper" data-testid={`sdk-${name}-field-id`}>
33
- <input
34
- id={id}
35
- autoComplete="tel"
36
- className={`input-control ${readOnly ? 'read-only' : ''}`}
37
- placeholder=" "
38
- readOnly={readOnly}
39
- type="tel"
40
- {...register(name, {
41
- required: required ? errorReqMsg : false,
42
- pattern: {
43
- value: /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\./0-9]{6,14}$/g,
44
- message: errorInvalidPhoneMsg,
45
- },
46
- })}
47
- />
48
- <label className="label-control" htmlFor={id}>
49
- {label} {required && <span className="text-error">*</span>}
50
- </label>
51
- {errors && errors[name] && (
52
- <div className="text-error caption">{errors[name].message}</div>
53
- )}
54
- </div>
55
- );
56
- };
57
-
58
- export default PhoneFiled;
1
+ import { 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;