@infosoftas/s4-orders-js-sdk 0.1.5 → 0.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosoftas/s4-orders-js-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "scripts": {
5
5
  "build": "rimraf lib && webpack --mode production",
6
6
  "release": "release-it"
@@ -24,7 +24,10 @@ const AddressField: FC<Props> = ({
24
24
  errorReqMsg = 'This field is required!',
25
25
  errors,
26
26
  }) => {
27
- const { register } = useFormContext();
27
+ const { register, setValue, watch } = useFormContext();
28
+
29
+ const value = watch(name);
30
+
28
31
  const id = uuidv4();
29
32
  return (
30
33
  <div className="field-wrapper" data-testid={`sdk-${name}-field-id`}>
@@ -37,6 +40,12 @@ const AddressField: FC<Props> = ({
37
40
  {...register(name, {
38
41
  required: required ? errorReqMsg : false,
39
42
  })}
43
+ {...(required ? {
44
+ onBlur: () => {
45
+ const newValue = value?.trim() || '';
46
+ setValue(name, newValue);
47
+ },
48
+ } : '')}
40
49
  />
41
50
  <label className="label-control" htmlFor={id}>
42
51
  {label} {required && <span className="text-error">*</span>}
@@ -2,6 +2,7 @@ import { FC } from 'react';
2
2
  import { useFormContext } from 'react-hook-form';
3
3
 
4
4
  import { uuidv4 } from '../../utils/helper';
5
+ import { REQUIRED_VALIDATION_REGEXP } from '../../constants/index';
5
6
 
6
7
  type Props = {
7
8
  name: string;
@@ -37,6 +38,7 @@ const NameField: FC<Props> = ({
37
38
  {...register(name, {
38
39
  required: required ? errorReqMsg : false,
39
40
  })}
41
+ {...(required ? { pattern: REQUIRED_VALIDATION_REGEXP } : '')}
40
42
  />
41
43
  <label className="label-control" htmlFor={id}>
42
44
  {label} {required && <span className="text-error">*</span>}
@@ -2,6 +2,7 @@ import { FC } from 'react';
2
2
  import { useFormContext } from 'react-hook-form';
3
3
 
4
4
  import { uuidv4 } from '../../utils/helper';
5
+ import { REQUIRED_VALIDATION_REGEXP } from '../../constants/index';
5
6
 
6
7
  type Props = {
7
8
  name: string;
@@ -37,6 +38,7 @@ const NameField: FC<Props> = ({
37
38
  {...register(name, {
38
39
  required: required ? errorReqMsg : false,
39
40
  })}
41
+ {...(required ? { pattern: REQUIRED_VALIDATION_REGEXP } : '')}
40
42
  />
41
43
  <label className="label-control" htmlFor={id}>
42
44
  {label} {required && <span className="text-error">*</span>}
@@ -4,6 +4,8 @@ export const BASE_API = '/';
4
4
 
5
5
  export const WRONG_MSG = 'Something went wrong!';
6
6
 
7
+ export const REQUIRED_VALIDATION_REGEXP = '.*\\S.*';
8
+
7
9
  export const PAYMENT_METHOD_DEFAULT: PaymentMethodEnum =
8
10
  PaymentMethodEnum.Vipps;
9
11