@open-tender/utils 0.1.21 → 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
  }
@@ -28,7 +28,11 @@ export declare const checkGuestData: (data: GuestData, email: string) => {
28
28
  export declare const makeRandomNumberString: () => string;
29
29
  export declare const getWidth: () => number;
30
30
  export declare const getHeight: () => number;
31
- export declare const makeImageMap: (images: Images) => {};
31
+ export declare const makeImageMap: (images: Images) => {
32
+ APP_IMAGE?: string | undefined;
33
+ LARGE_IMAGE?: string | undefined;
34
+ SMALL_IMAGE?: string | undefined;
35
+ };
32
36
  export declare const makeImageUrl: (images: ContentImages, isMobile: boolean) => string | null | undefined;
33
37
  export declare const makeSlides: (items: Announcements, isMobile: boolean) => Announcements | null;
34
38
  export declare const displayPrice: (price: string) => string;
@@ -140,9 +140,10 @@ const getHeight = () => {
140
140
  };
141
141
  exports.getHeight = getHeight;
142
142
  const makeImageMap = (images) => {
143
- return images
143
+ const imagesMap = images
144
144
  .filter(i => i.url)
145
145
  .reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.type]: i.url })), {});
146
+ return imagesMap;
146
147
  };
147
148
  exports.makeImageMap = makeImageMap;
148
149
  const makeImageUrl = (images, isMobile) => {
@@ -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
  }
@@ -28,7 +28,11 @@ export declare const checkGuestData: (data: GuestData, email: string) => {
28
28
  export declare const makeRandomNumberString: () => string;
29
29
  export declare const getWidth: () => number;
30
30
  export declare const getHeight: () => number;
31
- export declare const makeImageMap: (images: Images) => {};
31
+ export declare const makeImageMap: (images: Images) => {
32
+ APP_IMAGE?: string | undefined;
33
+ LARGE_IMAGE?: string | undefined;
34
+ SMALL_IMAGE?: string | undefined;
35
+ };
32
36
  export declare const makeImageUrl: (images: ContentImages, isMobile: boolean) => string | null | undefined;
33
37
  export declare const makeSlides: (items: Announcements, isMobile: boolean) => Announcements | null;
34
38
  export declare const displayPrice: (price: string) => string;
@@ -116,9 +116,10 @@ export const getHeight = () => {
116
116
  return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.documentElement.clientHeight);
117
117
  };
118
118
  export const makeImageMap = (images) => {
119
- return images
119
+ const imagesMap = images
120
120
  .filter(i => i.url)
121
121
  .reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.type]: i.url })), {});
122
+ return imagesMap;
122
123
  };
123
124
  export const makeImageUrl = (images, isMobile) => {
124
125
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.21",
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",