@open-tender/utils 0.1.53 → 0.1.55

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,15 +1,12 @@
1
1
  /// <reference types="react" />
2
- import { CreditCards, GiftCard, GiftCardPurchase, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useGiftCardForm: (giftCard: GiftCard, creditCards: CreditCards, loading: RequestStatus, error: RequestError, update: (id: number, data: GiftCardPurchase, callback: () => void) => void, add: (data: GiftCardPurchase, callback: () => void) => void, callback: () => void) => {
2
+ import { CreditCards, FormFields, GiftCardPurchase, RequestError, RequestStatus } from '@open-tender/types';
3
+ export declare const useGiftCardForm: (creditCards: CreditCards, loading: RequestStatus, error: RequestError, update: (id: number, data: GiftCardPurchase, callback?: () => void) => void, add: (data: GiftCardPurchase, callback?: () => void) => void, callback?: () => void, giftCardId?: number) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
- options: {
7
- name: string;
8
- value: number;
9
- }[];
10
- errors: {};
6
+ fields: FormFields;
11
7
  data: GiftCardPurchase;
8
+ errors: {};
12
9
  submitting: boolean;
13
10
  handleChange: (name: string, value: string | number | boolean) => void;
14
- handleSubmit: (evt?: any) => void;
11
+ handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
15
12
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useGiftCardForm = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
- const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, callback) => {
6
+ const useGiftCardForm = (creditCards, loading, error, update, add, callback, giftCardId) => {
7
7
  const submitRef = (0, react_1.useRef)(null);
8
8
  const inputRef = (0, react_1.useRef)(null);
9
9
  const customerCardId = creditCards[0].customer_card_id;
@@ -16,9 +16,22 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
16
16
  const options = creditCards.map(i => {
17
17
  return {
18
18
  name: `${i.card_type_name} ending in ${i.last4}`,
19
- value: i.customer_card_id
19
+ value: `${i.customer_card_id}`
20
20
  };
21
21
  });
22
+ const fields = [
23
+ {
24
+ label: 'Amount',
25
+ name: 'amount',
26
+ type: 'text'
27
+ },
28
+ {
29
+ label: 'Credit Card',
30
+ name: 'customer_card_id',
31
+ type: 'select',
32
+ options
33
+ }
34
+ ];
22
35
  (0, react_1.useEffect)(() => {
23
36
  var _a, _b;
24
37
  if (loading === 'idle') {
@@ -44,17 +57,15 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
44
57
  data.customer_card_id = customerCardId;
45
58
  }
46
59
  data.customer_card_id = parseInt(`${data.customer_card_id}`);
47
- giftCard
48
- ? update(giftCard.gift_card_id, data, callback)
49
- : add(data, callback);
60
+ giftCardId ? update(giftCardId, data, callback) : add(data, callback);
50
61
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
51
62
  };
52
63
  return {
53
64
  submitRef,
54
65
  inputRef,
55
- options,
56
- errors,
66
+ fields,
57
67
  data,
68
+ errors,
58
69
  submitting,
59
70
  handleChange,
60
71
  handleSubmit
@@ -1,15 +1,12 @@
1
1
  /// <reference types="react" />
2
- import { CreditCards, GiftCard, GiftCardPurchase, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useGiftCardForm: (giftCard: GiftCard, creditCards: CreditCards, loading: RequestStatus, error: RequestError, update: (id: number, data: GiftCardPurchase, callback: () => void) => void, add: (data: GiftCardPurchase, callback: () => void) => void, callback: () => void) => {
2
+ import { CreditCards, FormFields, GiftCardPurchase, RequestError, RequestStatus } from '@open-tender/types';
3
+ export declare const useGiftCardForm: (creditCards: CreditCards, loading: RequestStatus, error: RequestError, update: (id: number, data: GiftCardPurchase, callback?: () => void) => void, add: (data: GiftCardPurchase, callback?: () => void) => void, callback?: () => void, giftCardId?: number) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
- options: {
7
- name: string;
8
- value: number;
9
- }[];
10
- errors: {};
6
+ fields: FormFields;
11
7
  data: GiftCardPurchase;
8
+ errors: {};
12
9
  submitting: boolean;
13
10
  handleChange: (name: string, value: string | number | boolean) => void;
14
- handleSubmit: (evt?: any) => void;
11
+ handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
15
12
  };
@@ -1,6 +1,6 @@
1
1
  import { useState, useEffect, useRef } from 'react';
2
2
  import { makeFormErrors } from '../utils';
3
- export const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, callback) => {
3
+ export const useGiftCardForm = (creditCards, loading, error, update, add, callback, giftCardId) => {
4
4
  const submitRef = useRef(null);
5
5
  const inputRef = useRef(null);
6
6
  const customerCardId = creditCards[0].customer_card_id;
@@ -13,9 +13,22 @@ export const useGiftCardForm = (giftCard, creditCards, loading, error, update, a
13
13
  const options = creditCards.map(i => {
14
14
  return {
15
15
  name: `${i.card_type_name} ending in ${i.last4}`,
16
- value: i.customer_card_id
16
+ value: `${i.customer_card_id}`
17
17
  };
18
18
  });
19
+ const fields = [
20
+ {
21
+ label: 'Amount',
22
+ name: 'amount',
23
+ type: 'text'
24
+ },
25
+ {
26
+ label: 'Credit Card',
27
+ name: 'customer_card_id',
28
+ type: 'select',
29
+ options
30
+ }
31
+ ];
19
32
  useEffect(() => {
20
33
  var _a, _b;
21
34
  if (loading === 'idle') {
@@ -41,17 +54,15 @@ export const useGiftCardForm = (giftCard, creditCards, loading, error, update, a
41
54
  data.customer_card_id = customerCardId;
42
55
  }
43
56
  data.customer_card_id = parseInt(`${data.customer_card_id}`);
44
- giftCard
45
- ? update(giftCard.gift_card_id, data, callback)
46
- : add(data, callback);
57
+ giftCardId ? update(giftCardId, data, callback) : add(data, callback);
47
58
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
48
59
  };
49
60
  return {
50
61
  submitRef,
51
62
  inputRef,
52
- options,
53
- errors,
63
+ fields,
54
64
  data,
65
+ errors,
55
66
  submitting,
56
67
  handleChange,
57
68
  handleSubmit
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
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",