@open-tender/utils 0.5.17 → 0.5.19
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.
- package/dist/cjs/hooks/useLoginForm.d.ts +2 -2
- package/dist/cjs/hooks/useLoginForm.js +11 -7
- package/dist/cjs/hooks/useMenuItemsFilter.d.ts +2 -2
- package/dist/cjs/hooks/useMenuItemsFilter.js +1 -7
- package/dist/esm/hooks/useLoginForm.d.ts +2 -2
- package/dist/esm/hooks/useLoginForm.js +11 -7
- package/dist/esm/hooks/useMenuItemsFilter.d.ts +2 -2
- package/dist/esm/hooks/useMenuItemsFilter.js +1 -7
- package/package.json +1 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void,
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean, callback?: () => void, showPassword?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -9,5 +9,5 @@ export declare const useLoginForm: (loading: RequestStatus, error: RequestError,
|
|
|
9
9
|
errors: Record<string, string>;
|
|
10
10
|
submitting: boolean;
|
|
11
11
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
12
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
12
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
13
13
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLoginForm = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
|
-
const useLoginForm = (loading, error, login,
|
|
7
|
+
const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true) => {
|
|
7
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
9
|
const inputRef = (0, react_1.useRef)(null);
|
|
9
10
|
const recaptchaRef = (0, react_1.useRef)(null);
|
|
@@ -47,13 +48,16 @@ const useLoginForm = (loading, error, login, recaptchaKey, callback, showPasswor
|
|
|
47
48
|
const handleChange = (name, value) => {
|
|
48
49
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
49
50
|
};
|
|
50
|
-
const handleSubmit = (evt) => {
|
|
51
|
-
var _a, _b, _c;
|
|
51
|
+
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
var _a, _b, _c, _d, _e;
|
|
52
53
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
53
54
|
const { email, password } = data;
|
|
54
|
-
if (
|
|
55
|
+
if (includeRecaptcha) {
|
|
55
56
|
try {
|
|
56
|
-
const
|
|
57
|
+
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
58
|
+
const token = isEnterpriseRecaptcha
|
|
59
|
+
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
60
|
+
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
57
61
|
if (!token) {
|
|
58
62
|
setSubmitting(false);
|
|
59
63
|
setErrors({
|
|
@@ -78,8 +82,8 @@ const useLoginForm = (loading, error, login, recaptchaKey, callback, showPasswor
|
|
|
78
82
|
login(email, password);
|
|
79
83
|
setSubmitting(true);
|
|
80
84
|
}
|
|
81
|
-
((
|
|
82
|
-
};
|
|
85
|
+
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
86
|
+
});
|
|
83
87
|
return {
|
|
84
88
|
submitRef,
|
|
85
89
|
inputRef,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MenuItem } from '@open-tender/types';
|
|
2
|
-
export declare const useMenuItemsFilter: () => {
|
|
1
|
+
import { AllergesTagFilter, ConfigBrand, MenuItem, RequestedAt } from '@open-tender/types';
|
|
2
|
+
export declare const useMenuItemsFilter: (requestedAt: RequestedAt | null, selectedTagsNames: string[], selectedAllergens: string[], view_suspended_item: ConfigBrand['view_suspended_item'], tagsFilter: AllergesTagFilter | undefined, allergensFilter: AllergesTagFilter | undefined) => {
|
|
3
3
|
filterItems: (items: MenuItem[]) => MenuItem[];
|
|
4
4
|
};
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useMenuItemsFilter = void 0;
|
|
4
|
-
const cloud_1 = require("@open-tender/cloud");
|
|
5
4
|
const utils_1 = require("../utils");
|
|
6
|
-
const useMenuItemsFilter = () => {
|
|
7
|
-
const { tagsFilter, allergensFilter } = (0, cloud_1.useAppSelector)(cloud_1.selectDisplaySettings) || {};
|
|
8
|
-
const { view_suspended_item } = (0, cloud_1.useAppSelector)(cloud_1.selectBrand) || {};
|
|
9
|
-
const { requestedAt } = (0, cloud_1.useAppSelector)(cloud_1.selectOrder);
|
|
5
|
+
const useMenuItemsFilter = (requestedAt, selectedTagsNames, selectedAllergens, view_suspended_item, tagsFilter, allergensFilter) => {
|
|
10
6
|
const now = new Date();
|
|
11
7
|
const requestedDate = requestedAt === null || requestedAt === 'asap'
|
|
12
8
|
? now
|
|
13
9
|
: (0, utils_1.isoToDate)(requestedAt);
|
|
14
|
-
const selectedTagsNames = (0, cloud_1.useAppSelector)(cloud_1.selectSelectedTagNames);
|
|
15
|
-
const selectedAllergens = (0, cloud_1.useAppSelector)(cloud_1.selectSelectedAllergenNames);
|
|
16
10
|
const filterItems = (items) => {
|
|
17
11
|
if (!items)
|
|
18
12
|
return [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void,
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean, callback?: () => void, showPassword?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -9,5 +9,5 @@ export declare const useLoginForm: (loading: RequestStatus, error: RequestError,
|
|
|
9
9
|
errors: Record<string, string>;
|
|
10
10
|
submitting: boolean;
|
|
11
11
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
12
|
-
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void
|
|
12
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
13
13
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import { useState, useEffect, useRef } from 'react';
|
|
2
3
|
import { makeFormErrors } from '../utils';
|
|
3
|
-
export const useLoginForm = (loading, error, login,
|
|
4
|
+
export const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true) => {
|
|
4
5
|
const submitRef = useRef(null);
|
|
5
6
|
const inputRef = useRef(null);
|
|
6
7
|
const recaptchaRef = useRef(null);
|
|
@@ -44,13 +45,16 @@ export const useLoginForm = (loading, error, login, recaptchaKey, callback, show
|
|
|
44
45
|
const handleChange = (name, value) => {
|
|
45
46
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
46
47
|
};
|
|
47
|
-
const handleSubmit = (evt) => {
|
|
48
|
-
var _a, _b, _c;
|
|
48
|
+
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
var _a, _b, _c, _d, _e;
|
|
49
50
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
50
51
|
const { email, password } = data;
|
|
51
|
-
if (
|
|
52
|
+
if (includeRecaptcha) {
|
|
52
53
|
try {
|
|
53
|
-
const
|
|
54
|
+
const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
|
|
55
|
+
const token = isEnterpriseRecaptcha
|
|
56
|
+
? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
|
|
57
|
+
: (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
|
|
54
58
|
if (!token) {
|
|
55
59
|
setSubmitting(false);
|
|
56
60
|
setErrors({
|
|
@@ -75,8 +79,8 @@ export const useLoginForm = (loading, error, login, recaptchaKey, callback, show
|
|
|
75
79
|
login(email, password);
|
|
76
80
|
setSubmitting(true);
|
|
77
81
|
}
|
|
78
|
-
((
|
|
79
|
-
};
|
|
82
|
+
((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
|
|
83
|
+
});
|
|
80
84
|
return {
|
|
81
85
|
submitRef,
|
|
82
86
|
inputRef,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MenuItem } from '@open-tender/types';
|
|
2
|
-
export declare const useMenuItemsFilter: () => {
|
|
1
|
+
import { AllergesTagFilter, ConfigBrand, MenuItem, RequestedAt } from '@open-tender/types';
|
|
2
|
+
export declare const useMenuItemsFilter: (requestedAt: RequestedAt | null, selectedTagsNames: string[], selectedAllergens: string[], view_suspended_item: ConfigBrand['view_suspended_item'], tagsFilter: AllergesTagFilter | undefined, allergensFilter: AllergesTagFilter | undefined) => {
|
|
3
3
|
filterItems: (items: MenuItem[]) => MenuItem[];
|
|
4
4
|
};
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { selectBrand, selectDisplaySettings, selectOrder, selectSelectedAllergenNames, selectSelectedTagNames, useAppSelector } from '@open-tender/cloud';
|
|
2
1
|
import { containsAny, isoToDate } from '../utils';
|
|
3
|
-
export const useMenuItemsFilter = () => {
|
|
4
|
-
const { tagsFilter, allergensFilter } = useAppSelector(selectDisplaySettings) || {};
|
|
5
|
-
const { view_suspended_item } = useAppSelector(selectBrand) || {};
|
|
6
|
-
const { requestedAt } = useAppSelector(selectOrder);
|
|
2
|
+
export const useMenuItemsFilter = (requestedAt, selectedTagsNames, selectedAllergens, view_suspended_item, tagsFilter, allergensFilter) => {
|
|
7
3
|
const now = new Date();
|
|
8
4
|
const requestedDate = requestedAt === null || requestedAt === 'asap'
|
|
9
5
|
? now
|
|
10
6
|
: isoToDate(requestedAt);
|
|
11
|
-
const selectedTagsNames = useAppSelector(selectSelectedTagNames);
|
|
12
|
-
const selectedAllergens = useAppSelector(selectSelectedAllergenNames);
|
|
13
7
|
const filterItems = (items) => {
|
|
14
8
|
if (!items)
|
|
15
9
|
return [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.19",
|
|
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",
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
"typescript": "^4.8.2"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@open-tender/cloud": "^0.5.15",
|
|
61
60
|
"@open-tender/types": "^0.4.139",
|
|
62
61
|
"@reduxjs/toolkit": "^1.8.5",
|
|
63
62
|
"react": "^18.2.0"
|