@open-tender/utils 0.1.23 → 0.1.24
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/useDonationForm.js +1 -2
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +3 -3
- package/dist/cjs/hooks/useGiftCardsForm.js +1 -1
- package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +3 -3
- package/dist/cjs/hooks/useOrderFulfillmentForm.js +2 -1
- package/dist/cjs/utils/theme.d.ts +1 -10
- package/dist/esm/hooks/useDonationForm.js +1 -2
- package/dist/esm/hooks/useGiftCardsForm.d.ts +3 -3
- package/dist/esm/hooks/useGiftCardsForm.js +2 -2
- package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +3 -3
- package/dist/esm/hooks/useOrderFulfillmentForm.js +2 -1
- package/dist/esm/utils/theme.d.ts +1 -10
- package/package.json +1 -1
|
@@ -30,8 +30,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
30
30
|
if (error) {
|
|
31
31
|
if (recaptchaRef.current)
|
|
32
32
|
recaptchaRef.current.reset();
|
|
33
|
-
|
|
34
|
-
setErrors(errors);
|
|
33
|
+
setErrors((0, utils_1.makeFormErrors)(error));
|
|
35
34
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
36
35
|
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
37
36
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftCardPurchaseData, GiftCardsPurchase, RequestStatus } from '@open-tender/types';
|
|
2
|
+
import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftCardPurchaseData, GiftCardsPurchase, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
3
|
export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error:
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -26,6 +26,6 @@ export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase) => v
|
|
|
26
26
|
newCardErrors: {};
|
|
27
27
|
creditCard: CreditCardSaved | null;
|
|
28
28
|
setCreditCard: import("react").Dispatch<import("react").SetStateAction<CreditCardSaved | null>>;
|
|
29
|
-
errors:
|
|
29
|
+
errors: Record<string, string>;
|
|
30
30
|
submitting: boolean;
|
|
31
31
|
};
|
|
@@ -29,7 +29,7 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
|
|
|
29
29
|
if (error) {
|
|
30
30
|
if (recaptchaRef.current)
|
|
31
31
|
recaptchaRef.current.reset();
|
|
32
|
-
setErrors(error);
|
|
32
|
+
setErrors((0, utils_1.makeFormErrors)(error));
|
|
33
33
|
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
34
34
|
}
|
|
35
35
|
else if (success) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ConfigFulfillment, OrderFulfillment, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useOrderFulfillmentForm: (orderId: number, fulfillment: Partial<OrderFulfillment>, loading: RequestStatus, error:
|
|
2
|
+
import { ConfigFulfillment, OrderFulfillment, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useOrderFulfillmentForm: (orderId: number, fulfillment: Partial<OrderFulfillment>, loading: RequestStatus, error: RequestError, update: (orderId: number, data: Partial<OrderFulfillment>) => void, settings?: ConfigFulfillment, showAllFields?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
fields: import("@open-tender/types").ConfigFulfillmentField[] | undefined;
|
|
6
6
|
data: Partial<OrderFulfillment>;
|
|
7
|
-
errors:
|
|
7
|
+
errors: Record<string, string>;
|
|
8
8
|
submitting: boolean;
|
|
9
9
|
handleChange: (name: string, type: string, value: string | null, checked: boolean | null) => void;
|
|
10
10
|
handleSubmit: (evt?: any) => void;
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useOrderFulfillmentForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
5
6
|
const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, update, settings, showAllFields = false) => {
|
|
6
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
7
8
|
const [data, setData] = (0, react_1.useState)({});
|
|
8
9
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
9
|
-
const errors = error
|
|
10
|
+
const errors = (0, utils_1.makeFormErrors)(error);
|
|
10
11
|
const empty = Object.values(fulfillment).every(i => !i);
|
|
11
12
|
const fields = !empty && !showAllFields
|
|
12
13
|
? settings === null || settings === void 0 ? void 0 : settings.fields.filter(i => i.name.startsWith('arrival'))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ThemeLayout, Theme
|
|
1
|
+
import { AppTheme, ThemeLayout, Theme } from '@open-tender/types';
|
|
2
2
|
export declare const makeLineHeight: (lineHeight?: string, fontSize?: string) => string;
|
|
3
3
|
export declare const remsToPixels: (rems?: string, responsive?: boolean) => string;
|
|
4
4
|
export declare const remsToNumber: (rems: string) => number;
|
|
@@ -22,14 +22,5 @@ export declare const objRemsToPixels: <T extends Partial<ThemeLayout & {
|
|
|
22
22
|
}>>(object: T, responsive?: boolean) => Partial<T>;
|
|
23
23
|
export declare const pixelsToInt: (pixels: string) => string | number;
|
|
24
24
|
export declare const pixelsToFloat: (pixels: string) => string | number;
|
|
25
|
-
interface ThemeWelcomeStylesApp extends Omit<ThemeWelcomeStyles, 'titleLineHeight' | 'subtitleLineHeight'> {
|
|
26
|
-
titleLineHeight: string;
|
|
27
|
-
subtitleLineHeight: string;
|
|
28
|
-
}
|
|
29
|
-
interface AppTheme extends Omit<Theme, 'welcome' | 'item'> {
|
|
30
|
-
welcome: ThemeWelcomeStylesApp;
|
|
31
|
-
item: ThemeItemStyles;
|
|
32
|
-
}
|
|
33
25
|
export declare const decorateTheme: (theme: Theme) => AppTheme;
|
|
34
26
|
export declare const hexToRgbA: (hex: string, opacity: number) => string | null;
|
|
35
|
-
export {};
|
|
@@ -27,8 +27,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
27
27
|
if (error) {
|
|
28
28
|
if (recaptchaRef.current)
|
|
29
29
|
recaptchaRef.current.reset();
|
|
30
|
-
|
|
31
|
-
setErrors(errors);
|
|
30
|
+
setErrors(makeFormErrors(error));
|
|
32
31
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
33
32
|
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
34
33
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftCardPurchaseData, GiftCardsPurchase, RequestStatus } from '@open-tender/types';
|
|
2
|
+
import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftCardPurchaseData, GiftCardsPurchase, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
3
|
export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error:
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -26,6 +26,6 @@ export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase) => v
|
|
|
26
26
|
newCardErrors: {};
|
|
27
27
|
creditCard: CreditCardSaved | null;
|
|
28
28
|
setCreditCard: import("react").Dispatch<import("react").SetStateAction<CreditCardSaved | null>>;
|
|
29
|
-
errors:
|
|
29
|
+
errors: Record<string, string>;
|
|
30
30
|
submitting: boolean;
|
|
31
31
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMemo, useRef, useState, useEffect } from 'react';
|
|
2
|
-
import { validateCreditCard } from '../utils';
|
|
2
|
+
import { makeFormErrors, validateCreditCard } from '../utils';
|
|
3
3
|
export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
|
|
4
4
|
var _a, _b;
|
|
5
5
|
const submitRef = useRef(null);
|
|
@@ -26,7 +26,7 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
26
26
|
if (error) {
|
|
27
27
|
if (recaptchaRef.current)
|
|
28
28
|
recaptchaRef.current.reset();
|
|
29
|
-
setErrors(error);
|
|
29
|
+
setErrors(makeFormErrors(error));
|
|
30
30
|
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
31
31
|
}
|
|
32
32
|
else if (success) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ConfigFulfillment, OrderFulfillment, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useOrderFulfillmentForm: (orderId: number, fulfillment: Partial<OrderFulfillment>, loading: RequestStatus, error:
|
|
2
|
+
import { ConfigFulfillment, OrderFulfillment, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useOrderFulfillmentForm: (orderId: number, fulfillment: Partial<OrderFulfillment>, loading: RequestStatus, error: RequestError, update: (orderId: number, data: Partial<OrderFulfillment>) => void, settings?: ConfigFulfillment, showAllFields?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
fields: import("@open-tender/types").ConfigFulfillmentField[] | undefined;
|
|
6
6
|
data: Partial<OrderFulfillment>;
|
|
7
|
-
errors:
|
|
7
|
+
errors: Record<string, string>;
|
|
8
8
|
submitting: boolean;
|
|
9
9
|
handleChange: (name: string, type: string, value: string | null, checked: boolean | null) => void;
|
|
10
10
|
handleSubmit: (evt?: any) => void;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { makeFormErrors } from '../utils';
|
|
2
3
|
export const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, update, settings, showAllFields = false) => {
|
|
3
4
|
const submitRef = useRef(null);
|
|
4
5
|
const [data, setData] = useState({});
|
|
5
6
|
const [submitting, setSubmitting] = useState(false);
|
|
6
|
-
const errors = error
|
|
7
|
+
const errors = makeFormErrors(error);
|
|
7
8
|
const empty = Object.values(fulfillment).every(i => !i);
|
|
8
9
|
const fields = !empty && !showAllFields
|
|
9
10
|
? settings === null || settings === void 0 ? void 0 : settings.fields.filter(i => i.name.startsWith('arrival'))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ThemeLayout, Theme
|
|
1
|
+
import { AppTheme, ThemeLayout, Theme } from '@open-tender/types';
|
|
2
2
|
export declare const makeLineHeight: (lineHeight?: string, fontSize?: string) => string;
|
|
3
3
|
export declare const remsToPixels: (rems?: string, responsive?: boolean) => string;
|
|
4
4
|
export declare const remsToNumber: (rems: string) => number;
|
|
@@ -22,14 +22,5 @@ export declare const objRemsToPixels: <T extends Partial<ThemeLayout & {
|
|
|
22
22
|
}>>(object: T, responsive?: boolean) => Partial<T>;
|
|
23
23
|
export declare const pixelsToInt: (pixels: string) => string | number;
|
|
24
24
|
export declare const pixelsToFloat: (pixels: string) => string | number;
|
|
25
|
-
interface ThemeWelcomeStylesApp extends Omit<ThemeWelcomeStyles, 'titleLineHeight' | 'subtitleLineHeight'> {
|
|
26
|
-
titleLineHeight: string;
|
|
27
|
-
subtitleLineHeight: string;
|
|
28
|
-
}
|
|
29
|
-
interface AppTheme extends Omit<Theme, 'welcome' | 'item'> {
|
|
30
|
-
welcome: ThemeWelcomeStylesApp;
|
|
31
|
-
item: ThemeItemStyles;
|
|
32
|
-
}
|
|
33
25
|
export declare const decorateTheme: (theme: Theme) => AppTheme;
|
|
34
26
|
export declare const hexToRgbA: (hex: string, opacity: number) => string | null;
|
|
35
|
-
export {};
|
package/package.json
CHANGED