@open-tender/utils 0.0.48 → 0.0.50

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,5 +1,10 @@
1
+ /// <reference types="react" />
1
2
  import { Address, RequestStatus } from '@open-tender/types';
2
- export declare const useAddressForm: (address: Address, loading: RequestStatus, error: any, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
3
+ interface Field {
4
+ blur?: () => void;
5
+ focus?: () => void;
6
+ }
7
+ export declare const useAddressForm: <InputRef extends Field, SubmitRef extends Field>(address: Address, loading: RequestStatus, error: any, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
3
8
  fields: {
4
9
  label: string;
5
10
  name: string;
@@ -10,4 +15,7 @@ export declare const useAddressForm: (address: Address, loading: RequestStatus,
10
15
  submitting: boolean;
11
16
  handleChange: (id: string, type: string, value: string | null, checked: boolean | null) => void;
12
17
  handleSubmit: () => void;
18
+ submitRef: import("react").MutableRefObject<SubmitRef | null>;
19
+ inputRef: import("react").MutableRefObject<InputRef | null>;
13
20
  };
21
+ export {};
@@ -4,6 +4,8 @@ exports.useAddressForm = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
6
  const useAddressForm = (address, loading, error, update, callback) => {
7
+ const submitRef = (0, react_1.useRef)(null);
8
+ const inputRef = (0, react_1.useRef)(null);
7
9
  const [data, setData] = (0, react_1.useState)(address);
8
10
  const [errors, setErrors] = (0, react_1.useState)({});
9
11
  const [submitting, setSubmitting] = (0, react_1.useState)(false);
@@ -16,10 +18,12 @@ const useAddressForm = (address, loading, error, update, callback) => {
16
18
  { label: 'Is Default', name: 'is_default', type: 'checkbox' },
17
19
  ];
18
20
  (0, react_1.useEffect)(() => {
21
+ var _a, _b;
19
22
  if (loading === 'idle') {
20
23
  setSubmitting(false);
21
24
  if (error) {
22
25
  setErrors(error);
26
+ ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
23
27
  }
24
28
  }
25
29
  }, [loading, error]);
@@ -32,6 +36,7 @@ const useAddressForm = (address, loading, error, update, callback) => {
32
36
  setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
33
37
  };
34
38
  const handleSubmit = () => {
39
+ var _a, _b;
35
40
  setSubmitting(true);
36
41
  const updatedData = Object.assign({}, data);
37
42
  delete updatedData.customer_address_id;
@@ -40,6 +45,7 @@ const useAddressForm = (address, loading, error, update, callback) => {
40
45
  const addressId = data.customer_address_id;
41
46
  if (addressId) {
42
47
  update(addressId, updatedData, callback);
48
+ ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
43
49
  }
44
50
  };
45
51
  return {
@@ -49,6 +55,8 @@ const useAddressForm = (address, loading, error, update, callback) => {
49
55
  submitting,
50
56
  handleChange,
51
57
  handleSubmit,
58
+ submitRef,
59
+ inputRef
52
60
  };
53
61
  };
54
62
  exports.useAddressForm = useAddressForm;
@@ -1,5 +1,10 @@
1
+ /// <reference types="react" />
1
2
  import { Address, RequestStatus } from '@open-tender/types';
2
- export declare const useAddressForm: (address: Address, loading: RequestStatus, error: any, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
3
+ interface Field {
4
+ blur?: () => void;
5
+ focus?: () => void;
6
+ }
7
+ export declare const useAddressForm: <InputRef extends Field, SubmitRef extends Field>(address: Address, loading: RequestStatus, error: any, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
3
8
  fields: {
4
9
  label: string;
5
10
  name: string;
@@ -10,4 +15,7 @@ export declare const useAddressForm: (address: Address, loading: RequestStatus,
10
15
  submitting: boolean;
11
16
  handleChange: (id: string, type: string, value: string | null, checked: boolean | null) => void;
12
17
  handleSubmit: () => void;
18
+ submitRef: import("react").MutableRefObject<SubmitRef | null>;
19
+ inputRef: import("react").MutableRefObject<InputRef | null>;
13
20
  };
21
+ export {};
@@ -1,6 +1,8 @@
1
- import { useState, useEffect } from 'react';
1
+ import { useState, useEffect, useRef } from 'react';
2
2
  import { makePhone } from '../utils';
3
3
  export const useAddressForm = (address, loading, error, update, callback) => {
4
+ const submitRef = useRef(null);
5
+ const inputRef = useRef(null);
4
6
  const [data, setData] = useState(address);
5
7
  const [errors, setErrors] = useState({});
6
8
  const [submitting, setSubmitting] = useState(false);
@@ -13,10 +15,12 @@ export const useAddressForm = (address, loading, error, update, callback) => {
13
15
  { label: 'Is Default', name: 'is_default', type: 'checkbox' },
14
16
  ];
15
17
  useEffect(() => {
18
+ var _a, _b;
16
19
  if (loading === 'idle') {
17
20
  setSubmitting(false);
18
21
  if (error) {
19
22
  setErrors(error);
23
+ ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
20
24
  }
21
25
  }
22
26
  }, [loading, error]);
@@ -29,6 +33,7 @@ export const useAddressForm = (address, loading, error, update, callback) => {
29
33
  setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
30
34
  };
31
35
  const handleSubmit = () => {
36
+ var _a, _b;
32
37
  setSubmitting(true);
33
38
  const updatedData = Object.assign({}, data);
34
39
  delete updatedData.customer_address_id;
@@ -37,6 +42,7 @@ export const useAddressForm = (address, loading, error, update, callback) => {
37
42
  const addressId = data.customer_address_id;
38
43
  if (addressId) {
39
44
  update(addressId, updatedData, callback);
45
+ ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
40
46
  }
41
47
  };
42
48
  return {
@@ -46,5 +52,7 @@ export const useAddressForm = (address, loading, error, update, callback) => {
46
52
  submitting,
47
53
  handleChange,
48
54
  handleSubmit,
55
+ submitRef,
56
+ inputRef
49
57
  };
50
58
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
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",
@@ -59,7 +59,7 @@
59
59
  "@open-tender/cloud": "^0.0.79"
60
60
  },
61
61
  "dependencies": {
62
- "@open-tender/types": "^0.0.123",
62
+ "@open-tender/types": "^0.0.124",
63
63
  "date-fns": "^2.29.3",
64
64
  "date-fns-tz": "^1.3.7",
65
65
  "react-native-responsive-screen": "^1.4.2"