@open-tender/utils 0.5.24 → 0.5.25

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.
@@ -27,7 +27,7 @@ const makePayload = (fields, data) => {
27
27
  const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
28
28
  const submitRef = (0, react_1.useRef)(null);
29
29
  const [data, setData] = (0, react_1.useState)(profile);
30
- const [submitting, setSubmitting] = (0, react_1.useState)(false);
30
+ const isSubmitting = (0, react_1.useRef)(false);
31
31
  const [errors, setErrors] = (0, react_1.useState)({});
32
32
  const toRemove = (0, react_1.useMemo)(() => {
33
33
  const removed = [];
@@ -41,7 +41,7 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
41
41
  }, [toRemove]);
42
42
  (0, react_1.useEffect)(() => {
43
43
  if (loading === 'idle') {
44
- setSubmitting(false);
44
+ isSubmitting.current = false;
45
45
  if (error) {
46
46
  const errs = (0, utils_1.makeFormErrors)(error);
47
47
  if (errs.birth_date) {
@@ -50,13 +50,13 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
50
50
  }
51
51
  setErrors(errs);
52
52
  }
53
- else if (callback && submitting) {
53
+ else if (callback && isSubmitting.current) {
54
54
  const payload = makePayload(fields, data);
55
55
  if (payload)
56
56
  callback(payload);
57
57
  }
58
58
  }
59
- }, [loading, error, callback, submitting, fields, data]);
59
+ }, [loading, error, callback, fields, data]);
60
60
  (0, react_1.useEffect)(() => {
61
61
  if (profile)
62
62
  setData(profile);
@@ -79,7 +79,7 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
79
79
  if (!data)
80
80
  return;
81
81
  setErrors({});
82
- setSubmitting(true);
82
+ isSubmitting.current = true;
83
83
  const payload = makePayload(fields, data);
84
84
  if (payload)
85
85
  update(payload);
@@ -91,7 +91,7 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
91
91
  // order_notifications,
92
92
  data,
93
93
  errors,
94
- submitting,
94
+ submitting: isSubmitting.current,
95
95
  fields,
96
96
  handleChange,
97
97
  // handleRadio,
@@ -24,7 +24,7 @@ const makePayload = (fields, data) => {
24
24
  export const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
25
25
  const submitRef = useRef(null);
26
26
  const [data, setData] = useState(profile);
27
- const [submitting, setSubmitting] = useState(false);
27
+ const isSubmitting = useRef(false);
28
28
  const [errors, setErrors] = useState({});
29
29
  const toRemove = useMemo(() => {
30
30
  const removed = [];
@@ -38,7 +38,7 @@ export const useProfileForm = (profile, loading, error, update, callback, option
38
38
  }, [toRemove]);
39
39
  useEffect(() => {
40
40
  if (loading === 'idle') {
41
- setSubmitting(false);
41
+ isSubmitting.current = false;
42
42
  if (error) {
43
43
  const errs = makeFormErrors(error);
44
44
  if (errs.birth_date) {
@@ -47,13 +47,13 @@ export const useProfileForm = (profile, loading, error, update, callback, option
47
47
  }
48
48
  setErrors(errs);
49
49
  }
50
- else if (callback && submitting) {
50
+ else if (callback && isSubmitting.current) {
51
51
  const payload = makePayload(fields, data);
52
52
  if (payload)
53
53
  callback(payload);
54
54
  }
55
55
  }
56
- }, [loading, error, callback, submitting, fields, data]);
56
+ }, [loading, error, callback, fields, data]);
57
57
  useEffect(() => {
58
58
  if (profile)
59
59
  setData(profile);
@@ -76,7 +76,7 @@ export const useProfileForm = (profile, loading, error, update, callback, option
76
76
  if (!data)
77
77
  return;
78
78
  setErrors({});
79
- setSubmitting(true);
79
+ isSubmitting.current = true;
80
80
  const payload = makePayload(fields, data);
81
81
  if (payload)
82
82
  update(payload);
@@ -88,7 +88,7 @@ export const useProfileForm = (profile, loading, error, update, callback, option
88
88
  // order_notifications,
89
89
  data,
90
90
  errors,
91
- submitting,
91
+ submitting: isSubmitting.current,
92
92
  fields,
93
93
  handleChange,
94
94
  // handleRadio,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.5.24",
3
+ "version": "0.5.25",
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",