@open-tender/utils 0.5.43 → 0.5.45

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.
@@ -6,7 +6,7 @@ export interface NotificationCheckbox {
6
6
  type: string;
7
7
  }
8
8
  export declare const notificationChannelFields: NotificationCheckbox[];
9
- export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string, loginToken?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>) => {
9
+ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string, loginToken?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>, require_home_store?: boolean) => {
10
10
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
11
11
  data: CustomerCreate;
12
12
  comms: NotificationChannel[];
@@ -27,7 +27,7 @@ exports.notificationChannelFields = [
27
27
  type: 'checkbox'
28
28
  }
29
29
  ];
30
- const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken) => {
30
+ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken, require_home_store) => {
31
31
  const submitRef = (0, react_1.useRef)(null);
32
32
  const [data, setData] = (0, react_1.useState)(initState);
33
33
  const [comms, setComms] = (0, react_1.useState)([]);
@@ -128,6 +128,12 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
128
128
  if (values.birth_date) {
129
129
  values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
130
130
  }
131
+ if (require_home_store && !data.home_store) {
132
+ setErrors({
133
+ home_store: 'Please select a home store'
134
+ });
135
+ return;
136
+ }
131
137
  const loginToken = includeLoginRecaptcha
132
138
  ? (_a = (yield (getLoginRecaptchaToken === null || getLoginRecaptchaToken === void 0 ? void 0 : getLoginRecaptchaToken()))) !== null && _a !== void 0 ? _a : undefined
133
139
  : undefined;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string, loginToken?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>) => {
3
+ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string, loginToken?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>, require_home_store?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  fields: import("@open-tender/types").FormFieldType[];
@@ -12,7 +12,7 @@ const initialData = {
12
12
  email: '',
13
13
  password: ''
14
14
  };
15
- const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken) => {
15
+ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken, require_home_store) => {
16
16
  const submitRef = (0, react_1.useRef)(null);
17
17
  const inputRef = (0, react_1.useRef)(null);
18
18
  const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
@@ -87,6 +87,12 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
87
87
  if (values.birth_date) {
88
88
  values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
89
89
  }
90
+ if (require_home_store && !data.home_store) {
91
+ setErrors({
92
+ home_store: 'Please select a home store'
93
+ });
94
+ return;
95
+ }
90
96
  const loginToken = includeLoginRecaptcha
91
97
  ? (_a = (yield (getLoginRecaptchaToken === null || getLoginRecaptchaToken === void 0 ? void 0 : getLoginRecaptchaToken()))) !== null && _a !== void 0 ? _a : undefined
92
98
  : undefined;
@@ -788,8 +788,8 @@ const validateCart = (cart, categories, soldOut, requestedAt) => {
788
788
  return option;
789
789
  }
790
790
  else {
791
- // update the old option price to the new option price
792
- const updatedOption = Object.assign(Object.assign({}, option), { price: newOption.price });
791
+ // update the new option quantity to the old option quantity
792
+ const updatedOption = Object.assign(Object.assign({}, newOption), { quantity: option.quantity });
793
793
  return updatedOption;
794
794
  }
795
795
  }
@@ -6,7 +6,7 @@ export interface NotificationCheckbox {
6
6
  type: string;
7
7
  }
8
8
  export declare const notificationChannelFields: NotificationCheckbox[];
9
- export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string, loginToken?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>) => {
9
+ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string, loginToken?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>, require_home_store?: boolean) => {
10
10
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
11
11
  data: CustomerCreate;
12
12
  comms: NotificationChannel[];
@@ -24,7 +24,7 @@ export const notificationChannelFields = [
24
24
  type: 'checkbox'
25
25
  }
26
26
  ];
27
- export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken) => {
27
+ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken, require_home_store) => {
28
28
  const submitRef = useRef(null);
29
29
  const [data, setData] = useState(initState);
30
30
  const [comms, setComms] = useState([]);
@@ -125,6 +125,12 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
125
125
  if (values.birth_date) {
126
126
  values.birth_date = slashesToDashes(values.birth_date);
127
127
  }
128
+ if (require_home_store && !data.home_store) {
129
+ setErrors({
130
+ home_store: 'Please select a home store'
131
+ });
132
+ return;
133
+ }
128
134
  const loginToken = includeLoginRecaptcha
129
135
  ? (_a = (yield (getLoginRecaptchaToken === null || getLoginRecaptchaToken === void 0 ? void 0 : getLoginRecaptchaToken()))) !== null && _a !== void 0 ? _a : undefined
130
136
  : undefined;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string, loginToken?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>) => {
3
+ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string, loginToken?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>, require_home_store?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  fields: import("@open-tender/types").FormFieldType[];
@@ -9,7 +9,7 @@ const initialData = {
9
9
  email: '',
10
10
  password: ''
11
11
  };
12
- export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken) => {
12
+ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken, require_home_store) => {
13
13
  const submitRef = useRef(null);
14
14
  const inputRef = useRef(null);
15
15
  const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
@@ -84,6 +84,12 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
84
84
  if (values.birth_date) {
85
85
  values.birth_date = slashesToDashes(values.birth_date);
86
86
  }
87
+ if (require_home_store && !data.home_store) {
88
+ setErrors({
89
+ home_store: 'Please select a home store'
90
+ });
91
+ return;
92
+ }
87
93
  const loginToken = includeLoginRecaptcha
88
94
  ? (_a = (yield (getLoginRecaptchaToken === null || getLoginRecaptchaToken === void 0 ? void 0 : getLoginRecaptchaToken()))) !== null && _a !== void 0 ? _a : undefined
89
95
  : undefined;
@@ -752,8 +752,8 @@ export const validateCart = (cart, categories, soldOut, requestedAt) => {
752
752
  return option;
753
753
  }
754
754
  else {
755
- // update the old option price to the new option price
756
- const updatedOption = Object.assign(Object.assign({}, option), { price: newOption.price });
755
+ // update the new option quantity to the old option quantity
756
+ const updatedOption = Object.assign(Object.assign({}, newOption), { quantity: option.quantity });
757
757
  return updatedOption;
758
758
  }
759
759
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.5.43",
3
+ "version": "0.5.45",
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",
@@ -57,7 +57,7 @@
57
57
  "typescript": "^4.8.2"
58
58
  },
59
59
  "peerDependencies": {
60
- "@open-tender/types": "^0.4.140",
60
+ "@open-tender/types": "^0.4.163",
61
61
  "@reduxjs/toolkit": "^1.8.5",
62
62
  "react": "^18.2.0"
63
63
  },