@open-tender/utils 0.1.22 → 0.1.23

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,8 @@ 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
+ const errors = (0, utils_1.makeFormErrors)(error);
34
+ setErrors(errors);
34
35
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
35
36
  windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
36
37
  }
@@ -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,8 @@ 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
+ const errors = makeFormErrors(error);
31
+ setErrors(errors);
31
32
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
32
33
  windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
33
34
  }
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.23",
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",