@open-tender/utils 0.1.36 → 0.1.38

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,6 +1,9 @@
1
1
  export * from './menu';
2
+ export * from './types';
2
3
  export * from './useAddressForm';
3
4
  export * from './useAllergenForm';
5
+ export * from './useCartGuestForm';
6
+ export * from './useCheckoutLoginForm';
4
7
  export * from './useCreditCard';
5
8
  export * from './useCreditCardForm';
6
9
  export * from './useCurbside';
@@ -10,18 +13,14 @@ export * from './useGiftCardAssignForm';
10
13
  export * from './useGiftCardAssignOtherForm';
11
14
  export * from './useGiftCardForm';
12
15
  export * from './useGiftCardsForm';
13
- export * from './useOrderRating';
14
- export * from './useProfileForm';
15
- export * from './useSignUpGuestForm';
16
- export * from './useSignUpForm';
17
- export * from './useCartGuestForm';
18
- export * from './useCheckoutLoginForm';
19
16
  export * from './useGuestForm';
17
+ export * from './useImage';
20
18
  export * from './useOrderFulfillmentForm';
19
+ export * from './useOrderRating';
21
20
  export * from './useOrderRatingForm';
21
+ export * from './useProfileForm';
22
22
  export * from './useResetPasswordForm';
23
23
  export * from './useSendResetForm';
24
24
  export * from './useSigninForm';
25
- export * from './types';
26
- export * from './useImage';
27
- export * from './useLevelUpForm';
25
+ export * from './useSignUpGuestForm';
26
+ export * from './useSignUpForm';
@@ -2,8 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./menu"), exports);
5
+ tslib_1.__exportStar(require("./types"), exports);
5
6
  tslib_1.__exportStar(require("./useAddressForm"), exports);
6
7
  tslib_1.__exportStar(require("./useAllergenForm"), exports);
8
+ tslib_1.__exportStar(require("./useCartGuestForm"), exports);
9
+ tslib_1.__exportStar(require("./useCheckoutLoginForm"), exports);
7
10
  tslib_1.__exportStar(require("./useCreditCard"), exports);
8
11
  tslib_1.__exportStar(require("./useCreditCardForm"), exports);
9
12
  tslib_1.__exportStar(require("./useCurbside"), exports);
@@ -13,18 +16,14 @@ tslib_1.__exportStar(require("./useGiftCardAssignForm"), exports);
13
16
  tslib_1.__exportStar(require("./useGiftCardAssignOtherForm"), exports);
14
17
  tslib_1.__exportStar(require("./useGiftCardForm"), exports);
15
18
  tslib_1.__exportStar(require("./useGiftCardsForm"), exports);
16
- tslib_1.__exportStar(require("./useOrderRating"), exports);
17
- tslib_1.__exportStar(require("./useProfileForm"), exports);
18
- tslib_1.__exportStar(require("./useSignUpGuestForm"), exports);
19
- tslib_1.__exportStar(require("./useSignUpForm"), exports);
20
- tslib_1.__exportStar(require("./useCartGuestForm"), exports);
21
- tslib_1.__exportStar(require("./useCheckoutLoginForm"), exports);
22
19
  tslib_1.__exportStar(require("./useGuestForm"), exports);
20
+ tslib_1.__exportStar(require("./useImage"), exports);
23
21
  tslib_1.__exportStar(require("./useOrderFulfillmentForm"), exports);
22
+ tslib_1.__exportStar(require("./useOrderRating"), exports);
24
23
  tslib_1.__exportStar(require("./useOrderRatingForm"), exports);
24
+ tslib_1.__exportStar(require("./useProfileForm"), exports);
25
25
  tslib_1.__exportStar(require("./useResetPasswordForm"), exports);
26
26
  tslib_1.__exportStar(require("./useSendResetForm"), exports);
27
27
  tslib_1.__exportStar(require("./useSigninForm"), exports);
28
- tslib_1.__exportStar(require("./types"), exports);
29
- tslib_1.__exportStar(require("./useImage"), exports);
30
- tslib_1.__exportStar(require("./useLevelUpForm"), exports);
28
+ tslib_1.__exportStar(require("./useSignUpGuestForm"), exports);
29
+ tslib_1.__exportStar(require("./useSignUpForm"), exports);
@@ -1,20 +1,12 @@
1
1
  /// <reference types="react" />
2
- import { RequestStatus } from '@open-tender/types';
3
- interface CartGuestFormField {
4
- label?: string;
5
- name: string;
6
- type?: string;
7
- required?: boolean;
8
- }
9
- export declare const useCartGuestForm: (loading: RequestStatus, errMsg: string, cartId: number, joinCart: (data: any, callback?: any) => void) => {
2
+ import { FormFields, GroupOrderGuestCreate, RequestError, RequestStatus } from '@open-tender/types';
3
+ export declare const useCartGuestForm: (loading: RequestStatus, error: RequestError, cartId: number, joinCart: (data: GroupOrderGuestCreate, callback?: () => void) => void) => {
10
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
11
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
12
- fields: CartGuestFormField[];
13
- data: {
14
- cart_id?: number | undefined;
15
- };
6
+ data: GroupOrderGuestCreate;
7
+ errors: Record<string, string>;
16
8
  submitting: boolean;
17
- handleChange: (name: string, value: string) => void;
18
- handleSubmit: (evt?: any) => void;
9
+ fields: FormFields;
10
+ handleChange: (name: string, value: string | number | boolean) => void;
11
+ handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
19
12
  };
20
- export {};
@@ -2,35 +2,44 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCartGuestForm = void 0;
4
4
  const react_1 = require("react");
5
- const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
5
+ const utils_1 = require("../utils");
6
+ const initState = {
7
+ first_name: '',
8
+ last_name: ''
9
+ };
10
+ const useCartGuestForm = (loading, error, cartId, joinCart) => {
6
11
  const submitRef = (0, react_1.useRef)(null);
7
12
  const inputRef = (0, react_1.useRef)(null);
8
- const [data, setData] = (0, react_1.useState)({ cart_id: cartId });
13
+ const [data, setData] = (0, react_1.useState)(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
9
14
  const [submitting, setSubmitting] = (0, react_1.useState)(false);
15
+ const [errors, setErrors] = (0, react_1.useState)({});
10
16
  const fields = [
11
17
  { label: 'First Name', name: 'first_name', type: 'text', required: true },
12
18
  { label: 'Last Name', name: 'last_name', type: 'text', required: true }
13
19
  ];
14
20
  (0, react_1.useEffect)(() => {
15
21
  return () => {
16
- setData({});
22
+ setData(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
23
+ setErrors({});
17
24
  };
18
- }, []);
25
+ }, [cartId]);
19
26
  (0, react_1.useEffect)(() => {
20
27
  var _a, _b;
21
28
  if (loading === 'idle') {
22
29
  setSubmitting(false);
23
- if (errMsg) {
30
+ if (error) {
31
+ setErrors((0, utils_1.makeFormErrors)(error));
24
32
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
25
33
  }
26
34
  }
27
- }, [loading, errMsg]);
35
+ }, [loading, error]);
28
36
  const handleChange = (name, value) => {
29
37
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
30
38
  };
31
39
  const handleSubmit = (evt) => {
32
40
  var _a, _b;
33
41
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
42
+ setErrors({});
34
43
  setSubmitting(true);
35
44
  joinCart(data);
36
45
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
@@ -38,9 +47,10 @@ const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
38
47
  return {
39
48
  submitRef,
40
49
  inputRef,
41
- fields,
42
50
  data,
51
+ errors,
43
52
  submitting,
53
+ fields,
44
54
  handleChange,
45
55
  handleSubmit
46
56
  };
@@ -35,7 +35,7 @@ const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
35
35
  setErrors(Object.assign(Object.assign({}, errors), { [name]: error }));
36
36
  }
37
37
  else {
38
- setErrors(Object.assign(Object.assign({}, errors), { [name]: null }));
38
+ setErrors({});
39
39
  }
40
40
  };
41
41
  return {
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { CardType, CreditCardData, RequestStatus } from '@open-tender/types';
3
- export declare const useCreditCardForm: (loading: RequestStatus, error: any, data: CreditCardData, cardType: CardType, setErrors: (errors: any) => void, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null, windowRef?: Window) => {
2
+ import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
3
+ export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData, cardType: CardType, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  recaptchaRef: import("react").MutableRefObject<any>;
6
6
  data: CreditCardData;
7
+ errors: CreditCardErrors | Record<string, string>;
7
8
  submitting: boolean;
8
- handleSubmit: (evt?: any) => void;
9
+ handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
9
10
  };
@@ -3,22 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCreditCardForm = void 0;
4
4
  const react_1 = require("react");
5
5
  const __1 = require("../");
6
- const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, callback, recaptchaKey, revenue_center_id, windowRef) => {
6
+ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id) => {
7
7
  const submitRef = (0, react_1.useRef)(null);
8
8
  const recaptchaRef = (0, react_1.useRef)(null);
9
9
  const [submitting, setSubmitting] = (0, react_1.useState)(false);
10
+ const [errors, setErrors] = (0, react_1.useState)({});
10
11
  (0, react_1.useEffect)(() => {
11
12
  if (loading === 'idle') {
12
13
  setSubmitting(false);
13
14
  if (error) {
15
+ setErrors((0, __1.makeFormErrors)(error));
14
16
  if (recaptchaRef.current)
15
17
  recaptchaRef.current.reset();
16
- setErrors(error);
17
- if (windowRef)
18
- windowRef.scrollTo({ top: 0 });
19
18
  }
20
19
  }
21
- }, [windowRef, loading, error, setErrors]);
20
+ }, [loading, error]);
22
21
  const handleSubmit = (evt) => {
23
22
  var _a, _b, _c;
24
23
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
@@ -27,8 +26,6 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
27
26
  if (cardErrors) {
28
27
  setErrors(cardErrors);
29
28
  setSubmitting(false);
30
- if (windowRef)
31
- windowRef.scrollTo({ top: 0 });
32
29
  }
33
30
  else {
34
31
  const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
@@ -40,8 +37,6 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
40
37
  setErrors({
41
38
  form: 'Please complete the recaptcha before submitting'
42
39
  });
43
- if (windowRef)
44
- windowRef.scrollTo({ top: 0 });
45
40
  }
46
41
  else {
47
42
  setSubmitting(true);
@@ -53,8 +48,6 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
53
48
  setErrors({
54
49
  form: 'Please complete the recaptcha before submitting'
55
50
  });
56
- if (windowRef)
57
- windowRef.scrollTo({ top: 0 });
58
51
  }
59
52
  }
60
53
  else {
@@ -68,6 +61,7 @@ const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, c
68
61
  submitRef,
69
62
  recaptchaRef,
70
63
  data,
64
+ errors,
71
65
  submitting,
72
66
  handleSubmit
73
67
  };
@@ -47,9 +47,6 @@ const useProfileForm = (profile, loading, error, update
47
47
  }
48
48
  setErrors(errs);
49
49
  }
50
- else {
51
- setErrors({});
52
- }
53
50
  }
54
51
  }, [loading, error]);
55
52
  (0, react_1.useEffect)(() => {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { CheckoutConfig, CustomerCreate, RequestError } from '@open-tender/types';
3
- export declare const useSignUpForm: (loading: RequestInfo, error: RequestError, signUp: (data: CustomerCreate, callback?: () => void) => void, callback?: () => void, checkConfig?: Partial<CheckoutConfig>, hasThanx?: boolean) => {
2
+ import { CheckoutConfig, CustomerCreate, RequestError, RequestStatus } from '@open-tender/types';
3
+ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: () => void) => void, callback?: () => void, checkConfig?: Partial<CheckoutConfig>, hasThanx?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  data: CustomerCreate;
6
6
  errors: Record<string, string>;
@@ -80,9 +80,6 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig = {}, hasTh
80
80
  if (error) {
81
81
  setErrors((0, utils_1.makeFormErrors)(error));
82
82
  }
83
- else {
84
- setErrors({});
85
- }
86
83
  }
87
84
  }, [loading, error]);
88
85
  const handleChange = (name, value) => {
@@ -1,10 +1,5 @@
1
1
  import { DateString, FirstTime, GroupOrderTime, Holidays, ISOString, Order, OrderTime, OrderTimeWithDate, RequestedAt, RevenueCenter, ServiceType, TimeInterval, TimeObject, Timezone, TimezonePython, ValidTimes, Weekday } from '@open-tender/types';
2
- export declare const timezoneMap: {
3
- 'US/Eastern': string;
4
- 'US/Central': string;
5
- 'US/Mountain': string;
6
- 'US/Pacific': string;
7
- };
2
+ export declare const timezoneMap: Record<TimezonePython, Timezone>;
8
3
  export declare const weekdays: string[];
9
4
  export declare const weekdaysUpper: string[];
10
5
  export declare const weekdaysLower: string[];
@@ -1,6 +1,9 @@
1
1
  export * from './menu';
2
+ export * from './types';
2
3
  export * from './useAddressForm';
3
4
  export * from './useAllergenForm';
5
+ export * from './useCartGuestForm';
6
+ export * from './useCheckoutLoginForm';
4
7
  export * from './useCreditCard';
5
8
  export * from './useCreditCardForm';
6
9
  export * from './useCurbside';
@@ -10,18 +13,14 @@ export * from './useGiftCardAssignForm';
10
13
  export * from './useGiftCardAssignOtherForm';
11
14
  export * from './useGiftCardForm';
12
15
  export * from './useGiftCardsForm';
13
- export * from './useOrderRating';
14
- export * from './useProfileForm';
15
- export * from './useSignUpGuestForm';
16
- export * from './useSignUpForm';
17
- export * from './useCartGuestForm';
18
- export * from './useCheckoutLoginForm';
19
16
  export * from './useGuestForm';
17
+ export * from './useImage';
20
18
  export * from './useOrderFulfillmentForm';
19
+ export * from './useOrderRating';
21
20
  export * from './useOrderRatingForm';
21
+ export * from './useProfileForm';
22
22
  export * from './useResetPasswordForm';
23
23
  export * from './useSendResetForm';
24
24
  export * from './useSigninForm';
25
- export * from './types';
26
- export * from './useImage';
27
- export * from './useLevelUpForm';
25
+ export * from './useSignUpGuestForm';
26
+ export * from './useSignUpForm';
@@ -1,6 +1,9 @@
1
1
  export * from './menu';
2
+ export * from './types';
2
3
  export * from './useAddressForm';
3
4
  export * from './useAllergenForm';
5
+ export * from './useCartGuestForm';
6
+ export * from './useCheckoutLoginForm';
4
7
  export * from './useCreditCard';
5
8
  export * from './useCreditCardForm';
6
9
  export * from './useCurbside';
@@ -10,18 +13,14 @@ export * from './useGiftCardAssignForm';
10
13
  export * from './useGiftCardAssignOtherForm';
11
14
  export * from './useGiftCardForm';
12
15
  export * from './useGiftCardsForm';
13
- export * from './useOrderRating';
14
- export * from './useProfileForm';
15
- export * from './useSignUpGuestForm';
16
- export * from './useSignUpForm';
17
- export * from './useCartGuestForm';
18
- export * from './useCheckoutLoginForm';
19
16
  export * from './useGuestForm';
17
+ export * from './useImage';
20
18
  export * from './useOrderFulfillmentForm';
19
+ export * from './useOrderRating';
21
20
  export * from './useOrderRatingForm';
21
+ export * from './useProfileForm';
22
22
  export * from './useResetPasswordForm';
23
23
  export * from './useSendResetForm';
24
24
  export * from './useSigninForm';
25
- export * from './types';
26
- export * from './useImage';
27
- export * from './useLevelUpForm';
25
+ export * from './useSignUpGuestForm';
26
+ export * from './useSignUpForm';
@@ -1,20 +1,12 @@
1
1
  /// <reference types="react" />
2
- import { RequestStatus } from '@open-tender/types';
3
- interface CartGuestFormField {
4
- label?: string;
5
- name: string;
6
- type?: string;
7
- required?: boolean;
8
- }
9
- export declare const useCartGuestForm: (loading: RequestStatus, errMsg: string, cartId: number, joinCart: (data: any, callback?: any) => void) => {
2
+ import { FormFields, GroupOrderGuestCreate, RequestError, RequestStatus } from '@open-tender/types';
3
+ export declare const useCartGuestForm: (loading: RequestStatus, error: RequestError, cartId: number, joinCart: (data: GroupOrderGuestCreate, callback?: () => void) => void) => {
10
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
11
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
12
- fields: CartGuestFormField[];
13
- data: {
14
- cart_id?: number | undefined;
15
- };
6
+ data: GroupOrderGuestCreate;
7
+ errors: Record<string, string>;
16
8
  submitting: boolean;
17
- handleChange: (name: string, value: string) => void;
18
- handleSubmit: (evt?: any) => void;
9
+ fields: FormFields;
10
+ handleChange: (name: string, value: string | number | boolean) => void;
11
+ handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
19
12
  };
20
- export {};
@@ -1,33 +1,42 @@
1
1
  import { useRef, useState, useEffect } from 'react';
2
- export const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
2
+ import { makeFormErrors } from '../utils';
3
+ const initState = {
4
+ first_name: '',
5
+ last_name: ''
6
+ };
7
+ export const useCartGuestForm = (loading, error, cartId, joinCart) => {
3
8
  const submitRef = useRef(null);
4
9
  const inputRef = useRef(null);
5
- const [data, setData] = useState({ cart_id: cartId });
10
+ const [data, setData] = useState(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
6
11
  const [submitting, setSubmitting] = useState(false);
12
+ const [errors, setErrors] = useState({});
7
13
  const fields = [
8
14
  { label: 'First Name', name: 'first_name', type: 'text', required: true },
9
15
  { label: 'Last Name', name: 'last_name', type: 'text', required: true }
10
16
  ];
11
17
  useEffect(() => {
12
18
  return () => {
13
- setData({});
19
+ setData(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
20
+ setErrors({});
14
21
  };
15
- }, []);
22
+ }, [cartId]);
16
23
  useEffect(() => {
17
24
  var _a, _b;
18
25
  if (loading === 'idle') {
19
26
  setSubmitting(false);
20
- if (errMsg) {
27
+ if (error) {
28
+ setErrors(makeFormErrors(error));
21
29
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
22
30
  }
23
31
  }
24
- }, [loading, errMsg]);
32
+ }, [loading, error]);
25
33
  const handleChange = (name, value) => {
26
34
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
27
35
  };
28
36
  const handleSubmit = (evt) => {
29
37
  var _a, _b;
30
38
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
39
+ setErrors({});
31
40
  setSubmitting(true);
32
41
  joinCart(data);
33
42
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
@@ -35,9 +44,10 @@ export const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
35
44
  return {
36
45
  submitRef,
37
46
  inputRef,
38
- fields,
39
47
  data,
48
+ errors,
40
49
  submitting,
50
+ fields,
41
51
  handleChange,
42
52
  handleSubmit
43
53
  };
@@ -32,7 +32,7 @@ export const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
32
32
  setErrors(Object.assign(Object.assign({}, errors), { [name]: error }));
33
33
  }
34
34
  else {
35
- setErrors(Object.assign(Object.assign({}, errors), { [name]: null }));
35
+ setErrors({});
36
36
  }
37
37
  };
38
38
  return {
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { CardType, CreditCardData, RequestStatus } from '@open-tender/types';
3
- export declare const useCreditCardForm: (loading: RequestStatus, error: any, data: CreditCardData, cardType: CardType, setErrors: (errors: any) => void, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null, windowRef?: Window) => {
2
+ import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
3
+ export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData, cardType: CardType, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  recaptchaRef: import("react").MutableRefObject<any>;
6
6
  data: CreditCardData;
7
+ errors: CreditCardErrors | Record<string, string>;
7
8
  submitting: boolean;
8
- handleSubmit: (evt?: any) => void;
9
+ handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
9
10
  };
@@ -1,21 +1,20 @@
1
1
  import { useState, useEffect, useRef } from 'react';
2
- import { validateCreditCard } from '../';
3
- export const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, callback, recaptchaKey, revenue_center_id, windowRef) => {
2
+ import { makeFormErrors, validateCreditCard } from '../';
3
+ export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id) => {
4
4
  const submitRef = useRef(null);
5
5
  const recaptchaRef = useRef(null);
6
6
  const [submitting, setSubmitting] = useState(false);
7
+ const [errors, setErrors] = useState({});
7
8
  useEffect(() => {
8
9
  if (loading === 'idle') {
9
10
  setSubmitting(false);
10
11
  if (error) {
12
+ setErrors(makeFormErrors(error));
11
13
  if (recaptchaRef.current)
12
14
  recaptchaRef.current.reset();
13
- setErrors(error);
14
- if (windowRef)
15
- windowRef.scrollTo({ top: 0 });
16
15
  }
17
16
  }
18
- }, [windowRef, loading, error, setErrors]);
17
+ }, [loading, error]);
19
18
  const handleSubmit = (evt) => {
20
19
  var _a, _b, _c;
21
20
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
@@ -24,8 +23,6 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
24
23
  if (cardErrors) {
25
24
  setErrors(cardErrors);
26
25
  setSubmitting(false);
27
- if (windowRef)
28
- windowRef.scrollTo({ top: 0 });
29
26
  }
30
27
  else {
31
28
  const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
@@ -37,8 +34,6 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
37
34
  setErrors({
38
35
  form: 'Please complete the recaptcha before submitting'
39
36
  });
40
- if (windowRef)
41
- windowRef.scrollTo({ top: 0 });
42
37
  }
43
38
  else {
44
39
  setSubmitting(true);
@@ -50,8 +45,6 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
50
45
  setErrors({
51
46
  form: 'Please complete the recaptcha before submitting'
52
47
  });
53
- if (windowRef)
54
- windowRef.scrollTo({ top: 0 });
55
48
  }
56
49
  }
57
50
  else {
@@ -65,6 +58,7 @@ export const useCreditCardForm = (loading, error, data, cardType, setErrors, add
65
58
  submitRef,
66
59
  recaptchaRef,
67
60
  data,
61
+ errors,
68
62
  submitting,
69
63
  handleSubmit
70
64
  };
@@ -44,9 +44,6 @@ export const useProfileForm = (profile, loading, error, update
44
44
  }
45
45
  setErrors(errs);
46
46
  }
47
- else {
48
- setErrors({});
49
- }
50
47
  }
51
48
  }, [loading, error]);
52
49
  useEffect(() => {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { CheckoutConfig, CustomerCreate, RequestError } from '@open-tender/types';
3
- export declare const useSignUpForm: (loading: RequestInfo, error: RequestError, signUp: (data: CustomerCreate, callback?: () => void) => void, callback?: () => void, checkConfig?: Partial<CheckoutConfig>, hasThanx?: boolean) => {
2
+ import { CheckoutConfig, CustomerCreate, RequestError, RequestStatus } from '@open-tender/types';
3
+ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: () => void) => void, callback?: () => void, checkConfig?: Partial<CheckoutConfig>, hasThanx?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  data: CustomerCreate;
6
6
  errors: Record<string, string>;
@@ -77,9 +77,6 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig = {}
77
77
  if (error) {
78
78
  setErrors(makeFormErrors(error));
79
79
  }
80
- else {
81
- setErrors({});
82
- }
83
80
  }
84
81
  }, [loading, error]);
85
82
  const handleChange = (name, value) => {
@@ -1,10 +1,5 @@
1
1
  import { DateString, FirstTime, GroupOrderTime, Holidays, ISOString, Order, OrderTime, OrderTimeWithDate, RequestedAt, RevenueCenter, ServiceType, TimeInterval, TimeObject, Timezone, TimezonePython, ValidTimes, Weekday } from '@open-tender/types';
2
- export declare const timezoneMap: {
3
- 'US/Eastern': string;
4
- 'US/Central': string;
5
- 'US/Mountain': string;
6
- 'US/Pacific': string;
7
- };
2
+ export declare const timezoneMap: Record<TimezonePython, Timezone>;
8
3
  export declare const weekdays: string[];
9
4
  export declare const weekdaysUpper: string[];
10
5
  export declare const weekdaysLower: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
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",
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- import { RequestStatus } from '@open-tender/types';
3
- export declare const useLevelUpForm: (email: string, loading: RequestStatus, error: any, connect: (data: any, callback: any) => void, callback: any) => {
4
- submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
- inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
- data: any;
7
- errors: {};
8
- submitting: boolean;
9
- handleChange: (evt?: any) => void;
10
- handleSubmit: (evt?: any) => void;
11
- };
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useLevelUpForm = void 0;
4
- const react_1 = require("react");
5
- const useLevelUpForm = (email, loading, error, connect, callback) => {
6
- const submitRef = (0, react_1.useRef)(null);
7
- const inputRef = (0, react_1.useRef)(null);
8
- const [data, setData] = (0, react_1.useState)({ email });
9
- const [errors, setErrors] = (0, react_1.useState)({});
10
- const [submitting, setSubmitting] = (0, react_1.useState)(false);
11
- (0, react_1.useEffect)(() => {
12
- var _a;
13
- if (loading === 'idle') {
14
- setSubmitting(false);
15
- if (error) {
16
- setErrors(error);
17
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
18
- }
19
- }
20
- }, [loading, error]);
21
- const handleChange = (evt) => {
22
- const { id, type, value, checked } = evt === null || evt === void 0 ? void 0 : evt.target;
23
- const inputValue = type === 'checkbox' ? checked : value;
24
- setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
25
- };
26
- const handleSubmit = (evt) => {
27
- var _a;
28
- evt === null || evt === void 0 ? void 0 : evt.preventDefault();
29
- setSubmitting(true);
30
- connect(data, callback);
31
- (_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur();
32
- };
33
- return {
34
- submitRef,
35
- inputRef,
36
- data,
37
- errors,
38
- submitting,
39
- handleChange,
40
- handleSubmit
41
- };
42
- };
43
- exports.useLevelUpForm = useLevelUpForm;
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- import { RequestStatus } from '@open-tender/types';
3
- export declare const useLevelUpForm: (email: string, loading: RequestStatus, error: any, connect: (data: any, callback: any) => void, callback: any) => {
4
- submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
- inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
- data: any;
7
- errors: {};
8
- submitting: boolean;
9
- handleChange: (evt?: any) => void;
10
- handleSubmit: (evt?: any) => void;
11
- };
@@ -1,39 +0,0 @@
1
- import { useState, useEffect, useRef } from 'react';
2
- export const useLevelUpForm = (email, loading, error, connect, callback) => {
3
- const submitRef = useRef(null);
4
- const inputRef = useRef(null);
5
- const [data, setData] = useState({ email });
6
- const [errors, setErrors] = useState({});
7
- const [submitting, setSubmitting] = useState(false);
8
- useEffect(() => {
9
- var _a;
10
- if (loading === 'idle') {
11
- setSubmitting(false);
12
- if (error) {
13
- setErrors(error);
14
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
15
- }
16
- }
17
- }, [loading, error]);
18
- const handleChange = (evt) => {
19
- const { id, type, value, checked } = evt === null || evt === void 0 ? void 0 : evt.target;
20
- const inputValue = type === 'checkbox' ? checked : value;
21
- setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
22
- };
23
- const handleSubmit = (evt) => {
24
- var _a;
25
- evt === null || evt === void 0 ? void 0 : evt.preventDefault();
26
- setSubmitting(true);
27
- connect(data, callback);
28
- (_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur();
29
- };
30
- return {
31
- submitRef,
32
- inputRef,
33
- data,
34
- errors,
35
- submitting,
36
- handleChange,
37
- handleSubmit
38
- };
39
- };