@open-tender/utils 0.1.28 → 0.1.30

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.
@@ -2,7 +2,7 @@
2
2
  import { Customer, CustomerCreate, FormFields, RequestError, RequestStatus } from '@open-tender/types';
3
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 | null;
5
+ data: Customer | null;
6
6
  errors: Record<string, string>;
7
7
  submitting: boolean;
8
8
  fields: FormFields;
@@ -35,7 +35,10 @@ const useProfileForm = (profile, loading, error, update
35
35
  if (loading === 'idle') {
36
36
  setSubmitting(false);
37
37
  if (error) {
38
- setErrors((0, utils_1.makeFormErrors)(error));
38
+ const errs = (0, utils_1.makeFormErrors)(error);
39
+ if (errs)
40
+ errs.form = 'There are one or more errors below.';
41
+ setErrors(errs);
39
42
  }
40
43
  }
41
44
  }, [loading, error]);
@@ -61,19 +64,13 @@ const useProfileForm = (profile, loading, error, update
61
64
  if (!data)
62
65
  return;
63
66
  setSubmitting(true);
64
- // const updatedData: any = fields.reduce(
65
- // (obj: Partial<ProfileFormField>, i: Partial<ProfileFormField>) => ({
66
- // ...obj,
67
- // [i.name!]: data[i.name!]
68
- // }),
69
- // {}
70
- // )
71
- const updatedData = Object.assign({}, data);
72
- updatedData.birth_date = data.birth_date
73
- ? (0, utils_1.slashesToDashes)(data.birth_date)
74
- : null;
75
- updatedData.gender = data.gender || null;
76
- update(updatedData);
67
+ // remove read-only properties
68
+ const rest = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
69
+ // const rest = { ...data }
70
+ // const { customer_id, is_notification_set, is_verified, ...rest } = data
71
+ rest.birth_date = data.birth_date ? (0, utils_1.slashesToDashes)(data.birth_date) : null;
72
+ rest.gender = data.gender || null;
73
+ update(rest);
77
74
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
78
75
  };
79
76
  return {
@@ -2,7 +2,7 @@
2
2
  import { Customer, CustomerCreate, FormFields, RequestError, RequestStatus } from '@open-tender/types';
3
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 | null;
5
+ data: Customer | null;
6
6
  errors: Record<string, string>;
7
7
  submitting: boolean;
8
8
  fields: FormFields;
@@ -32,7 +32,10 @@ export const useProfileForm = (profile, loading, error, update
32
32
  if (loading === 'idle') {
33
33
  setSubmitting(false);
34
34
  if (error) {
35
- setErrors(makeFormErrors(error));
35
+ const errs = makeFormErrors(error);
36
+ if (errs)
37
+ errs.form = 'There are one or more errors below.';
38
+ setErrors(errs);
36
39
  }
37
40
  }
38
41
  }, [loading, error]);
@@ -58,19 +61,13 @@ export const useProfileForm = (profile, loading, error, update
58
61
  if (!data)
59
62
  return;
60
63
  setSubmitting(true);
61
- // const updatedData: any = fields.reduce(
62
- // (obj: Partial<ProfileFormField>, i: Partial<ProfileFormField>) => ({
63
- // ...obj,
64
- // [i.name!]: data[i.name!]
65
- // }),
66
- // {}
67
- // )
68
- const updatedData = Object.assign({}, data);
69
- updatedData.birth_date = data.birth_date
70
- ? slashesToDashes(data.birth_date)
71
- : null;
72
- updatedData.gender = data.gender || null;
73
- update(updatedData);
64
+ // remove read-only properties
65
+ const rest = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
66
+ // const rest = { ...data }
67
+ // const { customer_id, is_notification_set, is_verified, ...rest } = data
68
+ rest.birth_date = data.birth_date ? slashesToDashes(data.birth_date) : null;
69
+ rest.gender = data.gender || null;
70
+ update(rest);
74
71
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
75
72
  };
76
73
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
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",