@open-tender/utils 0.1.95 → 0.1.96
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,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void) => {
|
|
2
|
+
import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void, showPassword?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
fields:
|
|
6
|
+
fields: import("@open-tender/types").FormFieldType[];
|
|
7
7
|
data: LoginData;
|
|
8
8
|
errors: Record<string, string>;
|
|
9
9
|
submitting: boolean;
|
|
@@ -3,13 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useLoginForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const useLoginForm = (loading, error, login, callback) => {
|
|
6
|
+
const useLoginForm = (loading, error, login, callback, showPassword = true) => {
|
|
7
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
8
|
const inputRef = (0, react_1.useRef)(null);
|
|
9
9
|
const [data, setData] = (0, react_1.useState)({ email: '', password: '' });
|
|
10
10
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
11
11
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
12
|
-
const
|
|
12
|
+
const toRemove = [];
|
|
13
|
+
if (!showPassword)
|
|
14
|
+
toRemove.push('password');
|
|
15
|
+
const allFields = [
|
|
13
16
|
{
|
|
14
17
|
label: 'Email',
|
|
15
18
|
name: 'email',
|
|
@@ -24,6 +27,7 @@ const useLoginForm = (loading, error, login, callback) => {
|
|
|
24
27
|
autoComplete: 'new-password'
|
|
25
28
|
}
|
|
26
29
|
];
|
|
30
|
+
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
27
31
|
(0, react_1.useEffect)(() => {
|
|
28
32
|
var _a, _b;
|
|
29
33
|
if (loading === 'idle') {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void) => {
|
|
2
|
+
import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void, showPassword?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
fields:
|
|
6
|
+
fields: import("@open-tender/types").FormFieldType[];
|
|
7
7
|
data: LoginData;
|
|
8
8
|
errors: Record<string, string>;
|
|
9
9
|
submitting: boolean;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
import { makeFormErrors } from '../utils';
|
|
3
|
-
export const useLoginForm = (loading, error, login, callback) => {
|
|
3
|
+
export const useLoginForm = (loading, error, login, callback, showPassword = true) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const inputRef = useRef(null);
|
|
6
6
|
const [data, setData] = useState({ email: '', password: '' });
|
|
7
7
|
const [errors, setErrors] = useState({});
|
|
8
8
|
const [submitting, setSubmitting] = useState(false);
|
|
9
|
-
const
|
|
9
|
+
const toRemove = [];
|
|
10
|
+
if (!showPassword)
|
|
11
|
+
toRemove.push('password');
|
|
12
|
+
const allFields = [
|
|
10
13
|
{
|
|
11
14
|
label: 'Email',
|
|
12
15
|
name: 'email',
|
|
@@ -21,6 +24,7 @@ export const useLoginForm = (loading, error, login, callback) => {
|
|
|
21
24
|
autoComplete: 'new-password'
|
|
22
25
|
}
|
|
23
26
|
];
|
|
27
|
+
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
24
28
|
useEffect(() => {
|
|
25
29
|
var _a, _b;
|
|
26
30
|
if (loading === 'idle') {
|
package/package.json
CHANGED