@open-tender/utils 0.4.65 → 0.4.67

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.
@@ -15,4 +15,5 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
15
15
  handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
16
16
  handleGuest: () => void;
17
17
  handleComms: (name: NotificationChannel, value: boolean) => void;
18
+ resetState: () => void;
18
19
  };
@@ -103,23 +103,26 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
103
103
  const updated = value ? [...other, name] : other;
104
104
  setComms(updated);
105
105
  };
106
- (0, react_1.useEffect)(() => {
106
+ const resetState = (0, react_1.useCallback)(() => {
107
107
  var _a, _b;
108
- if (loading === 'idle') {
109
- setSubmitting(false);
110
- if (error) {
111
- const errs = (0, utils_1.makeFormErrors)(error);
112
- if (errs.form.includes('parameters')) {
113
- errs.form = 'There are one or more errors below';
114
- }
115
- setErrors(errs);
116
- ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
117
- }
118
- else if (guestErrors) {
119
- setErrors(guestErrors);
108
+ if (loading !== 'idle')
109
+ return;
110
+ setSubmitting(false);
111
+ if (error) {
112
+ const errs = (0, utils_1.makeFormErrors)(error);
113
+ if (errs.form.includes('parameters')) {
114
+ errs.form = 'There are one or more errors below';
120
115
  }
116
+ setErrors(errs);
117
+ ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
118
+ }
119
+ else if (guestErrors) {
120
+ setErrors(guestErrors);
121
121
  }
122
122
  }, [loading, error, guestErrors]);
123
+ (0, react_1.useEffect)(() => {
124
+ resetState();
125
+ }, [resetState]);
123
126
  (0, react_1.useEffect)(() => {
124
127
  return () => {
125
128
  setData(Object.assign(Object.assign({}, initialData), { email: '' }));
@@ -140,7 +143,8 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
140
143
  handleChange,
141
144
  handleSubmit,
142
145
  handleGuest,
143
- handleComms
146
+ handleComms,
147
+ resetState
144
148
  };
145
149
  };
146
150
  exports.useSignUpGuestForm = useSignUpGuestForm;
@@ -129,7 +129,7 @@ const getRevenueCenterStatus = (revenueCenter, serviceType) => {
129
129
  const { first_times, status, timezone, revenue_center_type, is_outpost } = revenueCenter;
130
130
  if (revenue_center_type !== 'OLO' || is_outpost)
131
131
  return null;
132
- if (status !== 'OPEN')
132
+ if (status !== 'OPEN' && status !== 'HIDDEN')
133
133
  return 'Closed';
134
134
  const tz = datetimes_1.timezoneMap[timezone];
135
135
  const firstTimes = first_times ? first_times[serviceType] : null;
@@ -15,4 +15,5 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
15
15
  handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
16
16
  handleGuest: () => void;
17
17
  handleComms: (name: NotificationChannel, value: boolean) => void;
18
+ resetState: () => void;
18
19
  };
@@ -1,4 +1,4 @@
1
- import { useRef, useState, useEffect } from 'react';
1
+ import { useRef, useState, useEffect, useCallback } from 'react';
2
2
  import { checkGuestData, makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
3
3
  import { notificationChannelFields } from './useSignUpForm';
4
4
  const initialData = {
@@ -100,23 +100,26 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
100
100
  const updated = value ? [...other, name] : other;
101
101
  setComms(updated);
102
102
  };
103
- useEffect(() => {
103
+ const resetState = useCallback(() => {
104
104
  var _a, _b;
105
- if (loading === 'idle') {
106
- setSubmitting(false);
107
- if (error) {
108
- const errs = makeFormErrors(error);
109
- if (errs.form.includes('parameters')) {
110
- errs.form = 'There are one or more errors below';
111
- }
112
- setErrors(errs);
113
- ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
114
- }
115
- else if (guestErrors) {
116
- setErrors(guestErrors);
105
+ if (loading !== 'idle')
106
+ return;
107
+ setSubmitting(false);
108
+ if (error) {
109
+ const errs = makeFormErrors(error);
110
+ if (errs.form.includes('parameters')) {
111
+ errs.form = 'There are one or more errors below';
117
112
  }
113
+ setErrors(errs);
114
+ ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
115
+ }
116
+ else if (guestErrors) {
117
+ setErrors(guestErrors);
118
118
  }
119
119
  }, [loading, error, guestErrors]);
120
+ useEffect(() => {
121
+ resetState();
122
+ }, [resetState]);
120
123
  useEffect(() => {
121
124
  return () => {
122
125
  setData(Object.assign(Object.assign({}, initialData), { email: '' }));
@@ -137,6 +140,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
137
140
  handleChange,
138
141
  handleSubmit,
139
142
  handleGuest,
140
- handleComms
143
+ handleComms,
144
+ resetState
141
145
  };
142
146
  };
@@ -119,7 +119,7 @@ export const getRevenueCenterStatus = (revenueCenter, serviceType) => {
119
119
  const { first_times, status, timezone, revenue_center_type, is_outpost } = revenueCenter;
120
120
  if (revenue_center_type !== 'OLO' || is_outpost)
121
121
  return null;
122
- if (status !== 'OPEN')
122
+ if (status !== 'OPEN' && status !== 'HIDDEN')
123
123
  return 'Closed';
124
124
  const tz = timezoneMap[timezone];
125
125
  const firstTimes = first_times ? first_times[serviceType] : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.65",
3
+ "version": "0.4.67",
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",