@open-tender/utils 0.0.33 → 0.0.35

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.
Files changed (63) hide show
  1. package/dist/cjs/hooks/index.d.ts +14 -0
  2. package/dist/cjs/hooks/index.js +14 -0
  3. package/dist/cjs/hooks/useAddressForm.d.ts +13 -0
  4. package/dist/cjs/hooks/useAddressForm.js +54 -0
  5. package/dist/cjs/hooks/useAllergenForm.d.ts +9 -0
  6. package/dist/cjs/hooks/useAllergenForm.js +44 -0
  7. package/dist/cjs/hooks/useCreditCard.d.ts +14 -0
  8. package/dist/cjs/hooks/useCreditCard.js +53 -0
  9. package/dist/cjs/hooks/useCurbside.d.ts +10 -0
  10. package/dist/cjs/hooks/useCurbside.js +37 -0
  11. package/dist/cjs/hooks/useDineInForm.d.ts +7 -0
  12. package/dist/cjs/hooks/useDineInForm.js +25 -0
  13. package/dist/cjs/hooks/useDonationForm.d.ts +25 -0
  14. package/dist/cjs/hooks/useDonationForm.js +155 -0
  15. package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +15 -0
  16. package/dist/cjs/hooks/useGiftCardAssignForm.js +38 -0
  17. package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +9 -0
  18. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +31 -0
  19. package/dist/cjs/hooks/useGiftCardForm.d.ts +13 -0
  20. package/dist/cjs/hooks/useGiftCardForm.js +48 -0
  21. package/dist/cjs/hooks/useGiftCardsForm.d.ts +23 -0
  22. package/dist/cjs/hooks/useGiftCardsForm.js +146 -0
  23. package/dist/cjs/hooks/useLatLng.d.ts +8 -0
  24. package/dist/cjs/hooks/useLatLng.js +13 -0
  25. package/dist/cjs/hooks/useLoyaltyPoints.d.ts +2 -0
  26. package/dist/cjs/hooks/useLoyaltyPoints.js +18 -0
  27. package/dist/cjs/hooks/useOrderRating.d.ts +11 -0
  28. package/dist/cjs/hooks/useOrderRating.js +32 -0
  29. package/dist/cjs/hooks/useProfileForm.d.ts +29 -0
  30. package/dist/cjs/hooks/useProfileForm.js +75 -0
  31. package/dist/cjs/utils/helpers.d.ts +1 -1
  32. package/dist/esm/hooks/index.d.ts +14 -0
  33. package/dist/esm/hooks/index.js +14 -0
  34. package/dist/esm/hooks/useAddressForm.d.ts +13 -0
  35. package/dist/esm/hooks/useAddressForm.js +50 -0
  36. package/dist/esm/hooks/useAllergenForm.d.ts +9 -0
  37. package/dist/esm/hooks/useAllergenForm.js +42 -0
  38. package/dist/esm/hooks/useCreditCard.d.ts +14 -0
  39. package/dist/esm/hooks/useCreditCard.js +51 -0
  40. package/dist/esm/hooks/useCurbside.d.ts +10 -0
  41. package/dist/esm/hooks/useCurbside.js +35 -0
  42. package/dist/esm/hooks/useDineInForm.d.ts +7 -0
  43. package/dist/esm/hooks/useDineInForm.js +23 -0
  44. package/dist/esm/hooks/useDonationForm.d.ts +25 -0
  45. package/dist/esm/hooks/useDonationForm.js +153 -0
  46. package/dist/esm/hooks/useGiftCardAssignForm.d.ts +15 -0
  47. package/dist/esm/hooks/useGiftCardAssignForm.js +36 -0
  48. package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +9 -0
  49. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +29 -0
  50. package/dist/esm/hooks/useGiftCardForm.d.ts +13 -0
  51. package/dist/esm/hooks/useGiftCardForm.js +46 -0
  52. package/dist/esm/hooks/useGiftCardsForm.d.ts +23 -0
  53. package/dist/esm/hooks/useGiftCardsForm.js +144 -0
  54. package/dist/esm/hooks/useLatLng.d.ts +8 -0
  55. package/dist/esm/hooks/useLatLng.js +11 -0
  56. package/dist/esm/hooks/useLoyaltyPoints.d.ts +2 -0
  57. package/dist/esm/hooks/useLoyaltyPoints.js +16 -0
  58. package/dist/esm/hooks/useOrderRating.d.ts +11 -0
  59. package/dist/esm/hooks/useOrderRating.js +30 -0
  60. package/dist/esm/hooks/useProfileForm.d.ts +29 -0
  61. package/dist/esm/hooks/useProfileForm.js +73 -0
  62. package/dist/esm/utils/helpers.d.ts +1 -1
  63. package/package.json +4 -2
@@ -0,0 +1,23 @@
1
+ import { useState } from 'react';
2
+ const useDineInForm = (initialData = {}, submitGuest) => {
3
+ const [data, setData] = useState(initialData);
4
+ const [errMsg, setErrMsg] = useState(null);
5
+ const handleChange = (id, value) => {
6
+ setData(Object.assign(Object.assign({}, data), { [id]: value }));
7
+ };
8
+ const handleSubmit = () => {
9
+ if (!data.first_name || !data.last_name) {
10
+ setErrMsg('Both first and last name are required');
11
+ }
12
+ else {
13
+ submitGuest({ customer: data });
14
+ }
15
+ };
16
+ return {
17
+ data,
18
+ errMsg,
19
+ handleChange,
20
+ handleSubmit,
21
+ };
22
+ };
23
+ export default useDineInForm;
@@ -0,0 +1,25 @@
1
+ import { Dispatch } from 'react';
2
+ import { CardType, CreditCard, CreditCardData, CreditCards, Profile, PurchaseDonationRequest, RequestStatus } from '@open-tender/types';
3
+ interface CreditCardOption {
4
+ label: string;
5
+ value: unknown;
6
+ }
7
+ declare const useDonationsForm: (purchase: (data: PurchaseDonationRequest, callback?: () => void) => void, reset: () => void, setAlert: Dispatch<any>, loading: RequestStatus, error: any, success: boolean, customer?: Partial<Profile>, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType) => {
8
+ recaptchaRef: import("react").MutableRefObject<any>;
9
+ amount: string | null;
10
+ handleAmount: (value: string) => void;
11
+ email: string | null;
12
+ handleEmail: (value: string) => void;
13
+ errors: any;
14
+ errMsg: any;
15
+ newCardErrors: {};
16
+ submitting: boolean;
17
+ isNewCard: boolean;
18
+ creditCard: CreditCard;
19
+ creditCardOptions: CreditCardOption[];
20
+ handleCreditCard: (value: string) => void;
21
+ handleSubmit: () => void;
22
+ handleReset: () => void;
23
+ setErrors: Dispatch<any>;
24
+ };
25
+ export default useDonationsForm;
@@ -0,0 +1,153 @@
1
+ import { useMemo, useEffect, useRef, useState } from 'react';
2
+ import { makeNumeric, validateCreditCard } from '../utils';
3
+ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType) => {
4
+ const recaptchaRef = useRef(null);
5
+ const [amount, setAmount] = useState('');
6
+ const [email, setEmail] = useState('');
7
+ const [isNewCard, setIsNewCard] = useState(true);
8
+ const [creditCard, setCreditCard] = useState({});
9
+ const [creditCardOptions, setCreditCardOptions] = useState([]);
10
+ const [errors, setErrors] = useState({});
11
+ const [submitting, setSubmitting] = useState(false);
12
+ const errMsg = errors.form && errors.form.includes('parameters')
13
+ ? 'There are one or more errors below'
14
+ : errors.form || null;
15
+ const newCardErrors = useMemo(() => errors
16
+ ? Object.entries(errors)
17
+ .filter(([key]) => key !== 'form')
18
+ .reduce((obj, [key, value]) => (Object.assign(Object.assign({}, obj), { [key]: value })), {})
19
+ : {}, [errors]);
20
+ useEffect(() => {
21
+ if (loading === 'idle') {
22
+ setSubmitting(false);
23
+ setAlert({ type: 'close' });
24
+ if (error) {
25
+ if (recaptchaRef.current)
26
+ recaptchaRef.current.reset();
27
+ setErrors(error);
28
+ }
29
+ else if (success) {
30
+ //
31
+ }
32
+ }
33
+ }, [loading, error, setAlert, success]);
34
+ useEffect(() => {
35
+ if ((creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) && loading !== 'pending') {
36
+ const options = creditCards.map(i => ({
37
+ label: `${i.card_type_name} ending in ${i.last4}`,
38
+ value: i.customer_card_id,
39
+ }));
40
+ setCreditCardOptions(options);
41
+ const defaultCard = creditCards.length
42
+ ? { customer_card_id: creditCards[0].customer_card_id }
43
+ : {};
44
+ setCreditCard(defaultCard);
45
+ setIsNewCard(false);
46
+ }
47
+ }, [creditCards, loading]);
48
+ useEffect(() => {
49
+ setEmail((customer === null || customer === void 0 ? void 0 : customer.email) ? customer.email : '');
50
+ }, [customer]);
51
+ const handleAmount = (value) => {
52
+ const cleanValue = makeNumeric(value);
53
+ setAmount(cleanValue);
54
+ };
55
+ const handleEmail = (value) => {
56
+ setEmail(value);
57
+ };
58
+ const handleCreditCard = (value) => {
59
+ const customerCardId = parseInt(value);
60
+ setCreditCard({ customer_card_id: customerCardId });
61
+ };
62
+ const purchaseWithCaptcha = (credit_card) => {
63
+ const alert = {
64
+ type: 'working',
65
+ args: { text: 'Submitting your contribution...' },
66
+ };
67
+ if (recaptchaKey) {
68
+ try {
69
+ const token = recaptchaRef.current.getValue();
70
+ if (!token) {
71
+ setSubmitting(false);
72
+ setErrors({ form: 'Please complete the recaptcha before submitting' });
73
+ }
74
+ else {
75
+ setSubmitting(true);
76
+ setAlert(alert);
77
+ purchase({
78
+ amount: amount,
79
+ email: email,
80
+ credit_card,
81
+ token: token,
82
+ });
83
+ }
84
+ }
85
+ catch (err) {
86
+ setSubmitting(false);
87
+ setErrors({ form: 'Please complete the recaptcha before submitting' });
88
+ }
89
+ }
90
+ else {
91
+ setSubmitting(true);
92
+ setAlert(alert);
93
+ purchase({
94
+ amount: amount,
95
+ email: email,
96
+ credit_card,
97
+ token: '',
98
+ });
99
+ }
100
+ };
101
+ const handleSubmit = () => {
102
+ if (!amount || !email) {
103
+ setErrors({ form: 'Both amount and email are required' });
104
+ }
105
+ else {
106
+ if (isNewCard) {
107
+ if (cardData && cardType) {
108
+ const { card, errors: errs } = validateCreditCard(cardData, cardType);
109
+ if (errs) {
110
+ setErrors(Object.assign(Object.assign({}, errs), { form: 'There are one or more credit card errors below' }));
111
+ setSubmitting(false);
112
+ }
113
+ else {
114
+ purchaseWithCaptcha(card);
115
+ }
116
+ }
117
+ }
118
+ else {
119
+ purchaseWithCaptcha(creditCard);
120
+ }
121
+ }
122
+ };
123
+ const handleReset = () => {
124
+ setErrors({});
125
+ setAmount(null);
126
+ if (!customer)
127
+ setEmail(null);
128
+ if (!customer)
129
+ setIsNewCard(true);
130
+ setCreditCard({});
131
+ setCreditCardOptions([]);
132
+ reset();
133
+ };
134
+ return {
135
+ recaptchaRef,
136
+ amount,
137
+ handleAmount,
138
+ email,
139
+ handleEmail,
140
+ errors,
141
+ errMsg,
142
+ newCardErrors,
143
+ submitting,
144
+ isNewCard,
145
+ creditCard,
146
+ creditCardOptions,
147
+ handleCreditCard,
148
+ handleSubmit,
149
+ handleReset,
150
+ setErrors,
151
+ };
152
+ };
153
+ export default useDonationsForm;
@@ -0,0 +1,15 @@
1
+ import { RequestStatus } from '@open-tender/types';
2
+ interface useGiftCardAssignFormProps {
3
+ loading: RequestStatus;
4
+ error: any;
5
+ assign: (card: string, callback?: () => void) => void;
6
+ callback: () => void;
7
+ }
8
+ declare const useGiftCardAssignForm: ({ loading, error, assign, callback, }: useGiftCardAssignFormProps) => {
9
+ cardNumber: string;
10
+ errors: any;
11
+ submitting: boolean;
12
+ handleChange: (value: string) => void;
13
+ handleSubmit: () => void;
14
+ };
15
+ export default useGiftCardAssignForm;
@@ -0,0 +1,36 @@
1
+ import { useState, useEffect } from 'react';
2
+ const useGiftCardAssignForm = ({ loading, error, assign, callback, }) => {
3
+ const [cardNumber, setCardNumber] = useState('');
4
+ const [errors, setErrors] = useState({});
5
+ const [submitting, setSubmitting] = useState(false);
6
+ useEffect(() => {
7
+ if (loading === 'idle') {
8
+ setSubmitting(false);
9
+ if (error) {
10
+ setErrors(error);
11
+ }
12
+ }
13
+ }, [loading, error]);
14
+ const handleChange = (value) => {
15
+ setCardNumber(value);
16
+ };
17
+ const handleSubmit = () => {
18
+ setSubmitting(true);
19
+ const card_number = parseInt(cardNumber);
20
+ if (isNaN(card_number)) {
21
+ setErrors({ card_number: 'Card numbers must be all digits' });
22
+ setSubmitting(false);
23
+ }
24
+ else {
25
+ assign(`${card_number}`, callback);
26
+ }
27
+ };
28
+ return {
29
+ cardNumber,
30
+ errors,
31
+ submitting,
32
+ handleChange,
33
+ handleSubmit,
34
+ };
35
+ };
36
+ export default useGiftCardAssignForm;
@@ -0,0 +1,9 @@
1
+ import { RequestStatus } from '@open-tender/types';
2
+ declare const useGiftCardAssignOtherForm: (loading: RequestStatus, error: any, giftCardId: number, assign: (giftCardId: number, email: string, callback: () => void) => void, callback: () => void) => {
3
+ email: string;
4
+ errors: any;
5
+ submitting: boolean;
6
+ handleChange: (value: string) => void;
7
+ handleSubmit: () => void;
8
+ };
9
+ export default useGiftCardAssignOtherForm;
@@ -0,0 +1,29 @@
1
+ import { useState, useEffect } from 'react';
2
+ const useGiftCardAssignOtherForm = (loading, error, giftCardId, assign, callback) => {
3
+ const [email, setEmail] = useState('');
4
+ const [errors, setErrors] = useState({});
5
+ const [submitting, setSubmitting] = useState(false);
6
+ useEffect(() => {
7
+ if (loading === 'idle') {
8
+ setSubmitting(false);
9
+ if (error) {
10
+ setErrors(error);
11
+ }
12
+ }
13
+ }, [loading, error]);
14
+ const handleChange = (value) => {
15
+ setEmail(value);
16
+ };
17
+ const handleSubmit = () => {
18
+ setSubmitting(true);
19
+ assign(giftCardId, email, callback);
20
+ };
21
+ return {
22
+ email,
23
+ errors,
24
+ submitting,
25
+ handleChange,
26
+ handleSubmit,
27
+ };
28
+ };
29
+ export default useGiftCardAssignOtherForm;
@@ -0,0 +1,13 @@
1
+ import { CreditCards, CustomerGiftCard, RequestStatus } from '@open-tender/types';
2
+ declare const useGiftCardForm: (giftCard: CustomerGiftCard, creditCards: CreditCards, loading: RequestStatus, error: any, update: (id: number, data: any, callback: () => void) => void, add: (data: any, callback: () => void) => void, callback: () => void) => {
3
+ options: {
4
+ label: string;
5
+ value: number | undefined;
6
+ }[];
7
+ errors: any;
8
+ data: any;
9
+ submitting: boolean;
10
+ handleChange: (id: string, value: unknown) => void;
11
+ handleSubmit: () => void;
12
+ };
13
+ export default useGiftCardForm;
@@ -0,0 +1,46 @@
1
+ import { useState, useEffect } from 'react';
2
+ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, callback) => {
3
+ const customerCardId = creditCards[0].customer_card_id;
4
+ const [data, setData] = useState({ customer_card_id: customerCardId });
5
+ const [errors, setErrors] = useState({});
6
+ const [submitting, setSubmitting] = useState(false);
7
+ const options = creditCards.map(i => {
8
+ return {
9
+ label: `${i.card_type_name} ending in ${i.last4}`,
10
+ value: i.customer_card_id,
11
+ };
12
+ });
13
+ useEffect(() => {
14
+ if (loading === 'idle') {
15
+ setSubmitting(false);
16
+ if (error) {
17
+ if (error.amount && error.amount.includes('money')) {
18
+ error.amount = 'Please enter a positive dollar amount';
19
+ }
20
+ setErrors(error);
21
+ }
22
+ }
23
+ }, [loading, error]);
24
+ const handleChange = (id, value) => {
25
+ setData(Object.assign(Object.assign({}, data), { [id]: value }));
26
+ };
27
+ const handleSubmit = () => {
28
+ setSubmitting(true);
29
+ if (!data.customer_card_id) {
30
+ data.customer_card_id = customerCardId;
31
+ }
32
+ data.customer_card_id = parseInt(`${data.customer_card_id}`);
33
+ giftCard
34
+ ? update(giftCard.gift_card_id, data, callback)
35
+ : add(data, callback);
36
+ };
37
+ return {
38
+ options,
39
+ errors,
40
+ data,
41
+ submitting,
42
+ handleChange,
43
+ handleSubmit,
44
+ };
45
+ };
46
+ export default useGiftCardForm;
@@ -0,0 +1,23 @@
1
+ import { Dispatch } from 'react';
2
+ import { CardType, CreditCard, CreditCardData, CreditCards, Profile, PurchaseGiftCardData, RequestStatus } from '@open-tender/types';
3
+ declare const useGiftCardsForm: (purchase: (data: any) => void, reset: () => void, loading: RequestStatus, error: any, success: boolean, setAlert: Dispatch<any>, customer: Partial<Profile> | undefined, creditCards: CreditCards | undefined, _recaptchaKey: string | null | undefined, initState: PurchaseGiftCardData, cardData: CreditCardData, cardType: CardType) => {
4
+ creditCardOptions: any[];
5
+ handleName: (value: string) => void;
6
+ handleEmail: (value: string) => void;
7
+ handleChange: (id: string, value: unknown) => void;
8
+ handleQuantity: (index: number, quantity: number) => void;
9
+ handleAddAnother: () => void;
10
+ handleCreditCard: (value: string) => void;
11
+ handleSubmit: () => void;
12
+ handleReset: () => void;
13
+ name: string | undefined;
14
+ email: string | undefined;
15
+ cards: PurchaseGiftCardData[];
16
+ isNewCard: boolean;
17
+ newCardErrors: {};
18
+ creditCard: Partial<CreditCard>;
19
+ setCreditCard: Dispatch<import("react").SetStateAction<Partial<CreditCard>>>;
20
+ errors: any;
21
+ submitting: boolean;
22
+ };
23
+ export default useGiftCardsForm;
@@ -0,0 +1,144 @@
1
+ import { useMemo, useState, useEffect } from 'react';
2
+ import { validateCreditCard } from '../utils';
3
+ const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, customer = {}, creditCards = [],
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
+ _recaptchaKey = null, initState, cardData, cardType) => {
6
+ const [name, setName] = useState(undefined);
7
+ const [email, setEmail] = useState(undefined);
8
+ const [cards, setCards] = useState([initState]);
9
+ const [isNewCard, setIsNewCard] = useState(true);
10
+ const [creditCard, setCreditCard] = useState({});
11
+ const [creditCardOptions, setCreditCardOptions] = useState([]);
12
+ const [errors, setErrors] = useState({});
13
+ const [submitting, setSubmitting] = useState(false);
14
+ const url = null;
15
+ const newCardErrors = useMemo(() => errors
16
+ ? Object.entries(errors)
17
+ .filter(([key]) => key !== 'form')
18
+ .reduce((obj, [key, value]) => (Object.assign(Object.assign({}, obj), { [key]: value })), {})
19
+ : {}, [errors]);
20
+ useEffect(() => {
21
+ if (loading === 'idle') {
22
+ setSubmitting(false);
23
+ setAlert({ type: 'close' });
24
+ if (error) {
25
+ setErrors(error);
26
+ }
27
+ }
28
+ }, [loading, error, setAlert, success]);
29
+ useEffect(() => {
30
+ if (creditCards.length && loading !== 'pending') {
31
+ const options = creditCards.map(i => ({
32
+ label: `${i.card_type_name} ending in ${i.last4}`,
33
+ value: i.customer_card_id,
34
+ }));
35
+ setCreditCardOptions(options);
36
+ const defaultCard = creditCards.length
37
+ ? { customer_card_id: creditCards[0].customer_card_id }
38
+ : {};
39
+ setCreditCard(defaultCard);
40
+ setIsNewCard(false);
41
+ }
42
+ }, [creditCards, loading]);
43
+ useEffect(() => {
44
+ if (customer) {
45
+ setEmail(customer.email);
46
+ setName(`${customer.first_name} ${customer.last_name}`);
47
+ }
48
+ }, [customer]);
49
+ const makeGiftCards = (giftCards) => {
50
+ return giftCards.reduce((arr, card) => {
51
+ const { amount, quantity, email: mail } = card;
52
+ const giftCard = !mail || !mail.length ? { amount, quantity } : card;
53
+ return [...arr, giftCard];
54
+ }, []);
55
+ };
56
+ const handleName = (value) => {
57
+ setName(value);
58
+ };
59
+ const handleEmail = (value) => {
60
+ setEmail(value);
61
+ };
62
+ const handleChange = (id, value) => {
63
+ const [field, index] = id.split('-');
64
+ const newCards = cards.map((card, idx) => {
65
+ return idx === parseInt(index) ? Object.assign(Object.assign({}, card), { [field]: value }) : card;
66
+ });
67
+ setCards(newCards);
68
+ };
69
+ const handleQuantity = (index, quantity) => {
70
+ const newCards = quantity > 0
71
+ ? cards.map((card, idx) => {
72
+ return idx === index ? Object.assign(Object.assign({}, card), { quantity: quantity }) : card;
73
+ })
74
+ : cards.filter((_i, idx) => idx !== index);
75
+ setCards(newCards);
76
+ };
77
+ const handleAddAnother = () => {
78
+ setCards([...cards, initState]);
79
+ };
80
+ const handleCreditCard = (value) => {
81
+ const customerCardId = parseInt(value);
82
+ setCreditCard({ customer_card_id: customerCardId });
83
+ };
84
+ const purchaseWithCaptcha = (credit_card) => {
85
+ const alert = {
86
+ type: 'working',
87
+ args: { text: 'Submitting your purchase...' },
88
+ };
89
+ setSubmitting(true);
90
+ setAlert(alert);
91
+ const gift_cards = makeGiftCards(cards);
92
+ purchase({ credit_card, name, email, url, gift_cards });
93
+ };
94
+ const handleSubmit = () => {
95
+ if (!name || !email) {
96
+ setErrors({ form: 'Both name and email are required' });
97
+ }
98
+ else {
99
+ if (isNewCard) {
100
+ const { card, errors: errs } = validateCreditCard(cardData, cardType);
101
+ if (errs) {
102
+ setErrors(Object.assign(Object.assign({}, errs), { form: 'There are one or more credit card errors below' }));
103
+ setSubmitting(false);
104
+ }
105
+ else {
106
+ purchaseWithCaptcha(card);
107
+ }
108
+ }
109
+ else {
110
+ purchaseWithCaptcha(creditCard);
111
+ }
112
+ }
113
+ };
114
+ const handleReset = () => {
115
+ if (!customer) {
116
+ setName(undefined);
117
+ setEmail(undefined);
118
+ }
119
+ setCards([initState]);
120
+ setErrors({});
121
+ reset();
122
+ };
123
+ return {
124
+ creditCardOptions,
125
+ handleName,
126
+ handleEmail,
127
+ handleChange,
128
+ handleQuantity,
129
+ handleAddAnother,
130
+ handleCreditCard,
131
+ handleSubmit,
132
+ handleReset,
133
+ name,
134
+ email,
135
+ cards,
136
+ isNewCard,
137
+ newCardErrors,
138
+ creditCard,
139
+ setCreditCard,
140
+ errors,
141
+ submitting,
142
+ };
143
+ };
144
+ export default useGiftCardsForm;
@@ -0,0 +1,8 @@
1
+ declare const useLatLng: () => import("immer/dist/internal").WritableDraft<import("@open-tender/types").Address> | {
2
+ lat: number;
3
+ lng: number;
4
+ } | {
5
+ lat: null;
6
+ lng: null;
7
+ };
8
+ export default useLatLng;
@@ -0,0 +1,11 @@
1
+ import { useSelector } from 'react-redux';
2
+ import { selectOrder, selectGeoLatLng } from '@open-tender/cloud';
3
+ const useLatLng = () => {
4
+ // geoLatLng will be null if we don't have the user's geolocation
5
+ const geoLatLng = useSelector(selectGeoLatLng);
6
+ // address will be null if we don't have the user's address
7
+ const { address } = useSelector(selectOrder);
8
+ // make sure we always return an object with lat and lng attributes
9
+ return address || geoLatLng || { lat: null, lng: null };
10
+ };
11
+ export default useLatLng;
@@ -0,0 +1,2 @@
1
+ declare const useLoyaltyPoints: () => import("@open-tender/types").CustomerLoyalty | null;
2
+ export default useLoyaltyPoints;
@@ -0,0 +1,16 @@
1
+ import { useEffect } from 'react';
2
+ import { useSelector } from 'react-redux';
3
+ import { fetchCustomerLoyalty, selectCustomer, selectPointsProgram, useAppDispatch, } from '@open-tender/cloud';
4
+ const useLoyaltyPoints = () => {
5
+ const dispatch = useAppDispatch();
6
+ const { profile } = useSelector(selectCustomer);
7
+ const { customer_id } = profile || {};
8
+ const pointsProgram = useSelector(selectPointsProgram);
9
+ useEffect(() => {
10
+ if (customer_id) {
11
+ dispatch(fetchCustomerLoyalty());
12
+ }
13
+ }, [customer_id, dispatch]);
14
+ return pointsProgram || null;
15
+ };
16
+ export default useLoyaltyPoints;
@@ -0,0 +1,11 @@
1
+ import { OrderRating } from '@open-tender/types';
2
+ declare const useOrderRatingForm: (orderId: number, orderRating: OrderRating, updateRating: (id: number, data: Partial<OrderRating>) => void) => {
3
+ rating: number;
4
+ handleRating: (star: number) => void;
5
+ comments: string;
6
+ handleComments: (inputComments: string) => void;
7
+ handleSubmit: () => void;
8
+ handleClose: () => void;
9
+ stars: number[];
10
+ };
11
+ export default useOrderRatingForm;
@@ -0,0 +1,30 @@
1
+ import { useState } from 'react';
2
+ const useOrderRatingForm = (orderId, orderRating, updateRating) => {
3
+ const [rating, setRating] = useState((orderRating && orderRating.rating) || 0);
4
+ const [comments, setComments] = useState((orderRating && orderRating.comments) || '');
5
+ const stars = [1, 2, 3, 4, 5];
6
+ const handleRating = (star) => {
7
+ setRating(star);
8
+ };
9
+ const handleComments = (inputComments) => {
10
+ setComments(inputComments);
11
+ };
12
+ const handleSubmit = () => {
13
+ const data = { rating, comments };
14
+ updateRating(orderId, data);
15
+ };
16
+ const handleClose = () => {
17
+ setComments((orderRating && orderRating.comments) || '');
18
+ setRating((orderRating && orderRating.rating) || 0);
19
+ };
20
+ return {
21
+ rating,
22
+ handleRating,
23
+ comments,
24
+ handleComments,
25
+ handleSubmit,
26
+ handleClose,
27
+ stars,
28
+ };
29
+ };
30
+ export default useOrderRatingForm;
@@ -0,0 +1,29 @@
1
+ import { Profile, RequestStatus } from '@open-tender/types';
2
+ declare const useProfileForm: (profile: Partial<Profile>, loading: RequestStatus, error: any, update: (data: Partial<Profile>) => void) => {
3
+ data: any;
4
+ errors: any;
5
+ submitting: boolean;
6
+ fields: ({
7
+ label: string;
8
+ name: string;
9
+ type: string;
10
+ required: boolean;
11
+ autoComplete?: undefined;
12
+ } | {
13
+ label: string;
14
+ name: string;
15
+ type: string;
16
+ required: boolean;
17
+ autoComplete: string;
18
+ } | {
19
+ label: string;
20
+ name: string;
21
+ type: string;
22
+ required?: undefined;
23
+ autoComplete?: undefined;
24
+ })[];
25
+ errMsg: string | null;
26
+ handleChange: (id: string, type: string | null, value: string, checked: boolean | null) => void;
27
+ handleSubmit: () => void;
28
+ };
29
+ export default useProfileForm;