@open-tender/utils 0.1.27 → 0.1.28

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.
@@ -1,12 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { Customer, CustomerCreate, FormFields, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useProfileForm: (profile: Customer, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void) => {
3
+ export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
- data: CustomerCreate;
5
+ data: CustomerCreate | null;
6
6
  errors: Record<string, string>;
7
7
  submitting: boolean;
8
8
  fields: FormFields;
9
9
  handleChange: (name: string, value: string | number | boolean) => void;
10
- handleRadio: (name: string, value: string) => void;
11
10
  handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
12
11
  };
@@ -40,7 +40,8 @@ const useProfileForm = (profile, loading, error, update
40
40
  }
41
41
  }, [loading, error]);
42
42
  (0, react_1.useEffect)(() => {
43
- setData(profile);
43
+ if (profile)
44
+ setData(profile);
44
45
  }, [profile]);
45
46
  const handleChange = (name, value) => {
46
47
  const inputValue = name === 'phone'
@@ -48,14 +49,17 @@ const useProfileForm = (profile, loading, error, update
48
49
  : name === 'birth_date'
49
50
  ? (0, utils_1.makeBirthDate)(value)
50
51
  : value;
51
- setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
52
- };
53
- const handleRadio = (name, value) => {
54
- setData(Object.assign(Object.assign({}, data), { [name]: value }));
52
+ if (data)
53
+ setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
55
54
  };
55
+ // const handleRadio = (name: string, value: string) => {
56
+ // if (data) setData({ ...data, [name]: value })
57
+ // }
56
58
  const handleSubmit = (evt) => {
57
59
  var _a, _b;
58
60
  evt.preventDefault();
61
+ if (!data)
62
+ return;
59
63
  setSubmitting(true);
60
64
  // const updatedData: any = fields.reduce(
61
65
  // (obj: Partial<ProfileFormField>, i: Partial<ProfileFormField>) => ({
@@ -81,7 +85,7 @@ const useProfileForm = (profile, loading, error, update
81
85
  submitting,
82
86
  fields,
83
87
  handleChange,
84
- handleRadio,
88
+ // handleRadio,
85
89
  handleSubmit
86
90
  };
87
91
  };
@@ -1,12 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { Customer, CustomerCreate, FormFields, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useProfileForm: (profile: Customer, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void) => {
3
+ export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
- data: CustomerCreate;
5
+ data: CustomerCreate | null;
6
6
  errors: Record<string, string>;
7
7
  submitting: boolean;
8
8
  fields: FormFields;
9
9
  handleChange: (name: string, value: string | number | boolean) => void;
10
- handleRadio: (name: string, value: string) => void;
11
10
  handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
12
11
  };
@@ -37,7 +37,8 @@ export const useProfileForm = (profile, loading, error, update
37
37
  }
38
38
  }, [loading, error]);
39
39
  useEffect(() => {
40
- setData(profile);
40
+ if (profile)
41
+ setData(profile);
41
42
  }, [profile]);
42
43
  const handleChange = (name, value) => {
43
44
  const inputValue = name === 'phone'
@@ -45,14 +46,17 @@ export const useProfileForm = (profile, loading, error, update
45
46
  : name === 'birth_date'
46
47
  ? makeBirthDate(value)
47
48
  : value;
48
- setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
49
- };
50
- const handleRadio = (name, value) => {
51
- setData(Object.assign(Object.assign({}, data), { [name]: value }));
49
+ if (data)
50
+ setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
52
51
  };
52
+ // const handleRadio = (name: string, value: string) => {
53
+ // if (data) setData({ ...data, [name]: value })
54
+ // }
53
55
  const handleSubmit = (evt) => {
54
56
  var _a, _b;
55
57
  evt.preventDefault();
58
+ if (!data)
59
+ return;
56
60
  setSubmitting(true);
57
61
  // const updatedData: any = fields.reduce(
58
62
  // (obj: Partial<ProfileFormField>, i: Partial<ProfileFormField>) => ({
@@ -78,7 +82,7 @@ export const useProfileForm = (profile, loading, error, update
78
82
  submitting,
79
83
  fields,
80
84
  handleChange,
81
- handleRadio,
85
+ // handleRadio,
82
86
  handleSubmit
83
87
  };
84
88
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",