@open-tender/utils 0.1.67 → 0.1.69

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,18 +1,12 @@
1
1
  /// <reference types="react" />
2
- import { RequestStatus, ResetPasswordData } from '@open-tender/types';
3
- export interface ResetPasswordFormField {
4
- label: string;
5
- name: string;
6
- type: string;
7
- required?: boolean;
8
- }
9
- export declare const useResetPasswordForm: (loading: RequestStatus, error: any, reset: (newPassword: string, callback: () => void) => void, resetForm: () => void, resetToken: () => void) => {
2
+ import { FormFields, RequestError, RequestStatus, ResetPasswordData } from '@open-tender/types';
3
+ export declare const useResetPasswordForm: (loading: RequestStatus, error: RequestError, reset: (newPassword: string, resetToken: string) => void, resetToken: string) => {
10
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
11
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
12
- fields: ResetPasswordFormField[];
6
+ fields: FormFields;
13
7
  data: Partial<ResetPasswordData>;
14
- errors: {};
8
+ errors: Record<string, string>;
15
9
  submitting: boolean;
16
- handleChange: (name: string, value: string) => void;
17
- handleSubmit: (evt?: any) => void;
10
+ handleChange: (name: string, value: string | number | boolean) => void;
11
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
18
12
  };
@@ -2,32 +2,41 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useResetPasswordForm = void 0;
4
4
  const react_1 = require("react");
5
- const useResetPasswordForm = (loading, error, reset, resetForm, resetToken) => {
5
+ const utils_1 = require("../utils");
6
+ const useResetPasswordForm = (loading, error, reset, resetToken) => {
6
7
  const submitRef = (0, react_1.useRef)(null);
7
8
  const inputRef = (0, react_1.useRef)(null);
8
9
  const [data, setData] = (0, react_1.useState)({});
9
10
  const [errors, setErrors] = (0, react_1.useState)({});
10
11
  const [submitting, setSubmitting] = (0, react_1.useState)(false);
11
12
  const fields = [
12
- { label: 'New Password', name: 'new_password', type: 'password' },
13
- { label: 'Confirm Password', name: 'confirm', type: 'password' }
13
+ {
14
+ label: 'New Password',
15
+ name: 'new_password',
16
+ type: 'password',
17
+ required: true
18
+ },
19
+ {
20
+ label: 'Confirm Password',
21
+ name: 'confirm',
22
+ type: 'password',
23
+ required: true
24
+ }
14
25
  ];
15
26
  (0, react_1.useEffect)(() => {
16
27
  setData({});
17
28
  setErrors({});
18
- resetForm();
19
29
  return () => {
20
30
  setData({});
21
31
  setErrors({});
22
- resetForm();
23
32
  };
24
- }, [resetForm]);
33
+ }, []);
25
34
  (0, react_1.useEffect)(() => {
26
35
  var _a, _b;
27
36
  if (loading === 'idle') {
28
37
  setSubmitting(false);
29
38
  if (error) {
30
- setErrors(error);
39
+ setErrors((0, utils_1.makeFormErrors)(error));
31
40
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
32
41
  }
33
42
  }
@@ -1,18 +1,12 @@
1
1
  /// <reference types="react" />
2
- import { RequestStatus, ResetPasswordData } from '@open-tender/types';
3
- export interface ResetPasswordFormField {
4
- label: string;
5
- name: string;
6
- type: string;
7
- required?: boolean;
8
- }
9
- export declare const useResetPasswordForm: (loading: RequestStatus, error: any, reset: (newPassword: string, callback: () => void) => void, resetForm: () => void, resetToken: () => void) => {
2
+ import { FormFields, RequestError, RequestStatus, ResetPasswordData } from '@open-tender/types';
3
+ export declare const useResetPasswordForm: (loading: RequestStatus, error: RequestError, reset: (newPassword: string, resetToken: string) => void, resetToken: string) => {
10
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
11
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
12
- fields: ResetPasswordFormField[];
6
+ fields: FormFields;
13
7
  data: Partial<ResetPasswordData>;
14
- errors: {};
8
+ errors: Record<string, string>;
15
9
  submitting: boolean;
16
- handleChange: (name: string, value: string) => void;
17
- handleSubmit: (evt?: any) => void;
10
+ handleChange: (name: string, value: string | number | boolean) => void;
11
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
18
12
  };
@@ -1,30 +1,39 @@
1
1
  import { useState, useEffect, useRef } from 'react';
2
- export const useResetPasswordForm = (loading, error, reset, resetForm, resetToken) => {
2
+ import { makeFormErrors } from '../utils';
3
+ export const useResetPasswordForm = (loading, error, reset, resetToken) => {
3
4
  const submitRef = useRef(null);
4
5
  const inputRef = useRef(null);
5
6
  const [data, setData] = useState({});
6
7
  const [errors, setErrors] = useState({});
7
8
  const [submitting, setSubmitting] = useState(false);
8
9
  const fields = [
9
- { label: 'New Password', name: 'new_password', type: 'password' },
10
- { label: 'Confirm Password', name: 'confirm', type: 'password' }
10
+ {
11
+ label: 'New Password',
12
+ name: 'new_password',
13
+ type: 'password',
14
+ required: true
15
+ },
16
+ {
17
+ label: 'Confirm Password',
18
+ name: 'confirm',
19
+ type: 'password',
20
+ required: true
21
+ }
11
22
  ];
12
23
  useEffect(() => {
13
24
  setData({});
14
25
  setErrors({});
15
- resetForm();
16
26
  return () => {
17
27
  setData({});
18
28
  setErrors({});
19
- resetForm();
20
29
  };
21
- }, [resetForm]);
30
+ }, []);
22
31
  useEffect(() => {
23
32
  var _a, _b;
24
33
  if (loading === 'idle') {
25
34
  setSubmitting(false);
26
35
  if (error) {
27
- setErrors(error);
36
+ setErrors(makeFormErrors(error));
28
37
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
29
38
  }
30
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.67",
3
+ "version": "0.1.69",
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",