@open-tender/utils 0.1.22 → 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.
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, DonationPurchase, RequestError, RequestStatus } from '@open-tender/types';
2
+ import { CardType, CreditCardData, CreditCardSaved, CreditCards, DonationPurchase, Profile, RequestError, RequestStatus } from '@open-tender/types';
3
3
  export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
4
4
  type: string;
5
5
  args?: unknown;
6
- }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Partial<Profile>, creditCards?: CreditCards, recaptchaKey?: string | null, 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>;
@@ -11,8 +11,8 @@ export declare const useDonationsForm: (purchase: (data: DonationPurchase, callb
11
11
  handleAmount: (value: string) => void;
12
12
  email: string | null;
13
13
  handleEmail: (value: string) => void;
14
- errors: any;
15
- errMsg: any;
14
+ errors: Record<string, string>;
15
+ errMsg: string | null;
16
16
  newCardErrors: {};
17
17
  submitting: boolean;
18
18
  isNewCard: boolean;
@@ -24,5 +24,5 @@ export declare const useDonationsForm: (purchase: (data: DonationPurchase, callb
24
24
  handleCreditCard: (value: string) => void;
25
25
  handleSubmit: () => void;
26
26
  handleReset: () => void;
27
- setErrors: import("react").Dispatch<any>;
27
+ setErrors: import("react").Dispatch<import("react").SetStateAction<Record<string, string>>>;
28
28
  };
@@ -30,7 +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
- setErrors(error);
33
+ setErrors((0, utils_1.makeFormErrors)(error));
34
34
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
35
35
  windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
36
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: any, success: boolean, initState: GiftCardPurchaseData, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
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: any, update: (orderId: number, data: Partial<OrderFulfillment>) => void, settings?: ConfigFulfillment, showAllFields?: boolean) => {
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: any;
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, ThemeWelcomeStyles, ThemeItemStyles } from '@open-tender/types';
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 {};
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, DonationPurchase, RequestError, RequestStatus } from '@open-tender/types';
2
+ import { CardType, CreditCardData, CreditCardSaved, CreditCards, DonationPurchase, Profile, RequestError, RequestStatus } from '@open-tender/types';
3
3
  export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
4
4
  type: string;
5
5
  args?: unknown;
6
- }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Partial<Profile>, creditCards?: CreditCards, recaptchaKey?: string | null, 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>;
@@ -11,8 +11,8 @@ export declare const useDonationsForm: (purchase: (data: DonationPurchase, callb
11
11
  handleAmount: (value: string) => void;
12
12
  email: string | null;
13
13
  handleEmail: (value: string) => void;
14
- errors: any;
15
- errMsg: any;
14
+ errors: Record<string, string>;
15
+ errMsg: string | null;
16
16
  newCardErrors: {};
17
17
  submitting: boolean;
18
18
  isNewCard: boolean;
@@ -24,5 +24,5 @@ export declare const useDonationsForm: (purchase: (data: DonationPurchase, callb
24
24
  handleCreditCard: (value: string) => void;
25
25
  handleSubmit: () => void;
26
26
  handleReset: () => void;
27
- setErrors: import("react").Dispatch<any>;
27
+ setErrors: import("react").Dispatch<import("react").SetStateAction<Record<string, string>>>;
28
28
  };
@@ -1,5 +1,5 @@
1
1
  import { useMemo, useEffect, useRef, useState } from 'react';
2
- import { makeNumeric, validateCreditCard } from '../utils';
2
+ import { makeFormErrors, makeNumeric, validateCreditCard } from '../utils';
3
3
  export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
4
4
  const submitRef = useRef(null);
5
5
  const inputRef = useRef(null);
@@ -27,7 +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
- setErrors(error);
30
+ setErrors(makeFormErrors(error));
31
31
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
32
32
  windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
33
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: any, success: boolean, initState: GiftCardPurchaseData, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
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: any, update: (orderId: number, data: Partial<OrderFulfillment>) => void, settings?: ConfigFulfillment, showAllFields?: boolean) => {
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: any;
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, ThemeWelcomeStyles, ThemeItemStyles } from '@open-tender/types';
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
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",