@open-tender/utils 0.4.44 → 0.4.46

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,9 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { Customer, CustomerCreate, FormFieldType, Gender, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const genderOptions: {
4
- name: string;
5
- value: Gender;
6
- }[];
2
+ import { Customer, CustomerCreate, FormFieldType, RequestError, RequestStatus } from '@open-tender/types';
7
3
  export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void, callback?: ((data: CustomerCreate) => void) | undefined, optionalFields?: string[]) => {
8
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
9
5
  data: Customer | null;
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useProfileForm = exports.genderOptions = void 0;
3
+ exports.useProfileForm = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
- exports.genderOptions = [
7
- { name: 'not specified', value: 'DECLINED' },
8
- { name: 'Male', value: 'MALE' },
9
- { name: 'Female', value: 'FEMALE' }
10
- ];
11
6
  const allFields = [
12
7
  { label: 'First Name', name: 'first_name', type: 'text', required: true },
13
8
  { label: 'Last Name', name: 'last_name', type: 'text', required: true },
@@ -20,21 +15,13 @@ const allFields = [
20
15
  },
21
16
  { label: 'Phone', name: 'phone', type: 'tel', required: true },
22
17
  { label: 'Company', name: 'company', type: 'text' },
23
- { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' },
24
- {
25
- label: 'Gender',
26
- name: 'gender',
27
- type: 'select',
28
- showLabel: true,
29
- options: exports.genderOptions
30
- }
18
+ { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' }
31
19
  ];
32
20
  const makePayload = (fields, data) => {
33
21
  if (!data)
34
22
  return null;
35
23
  const rest = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
36
24
  rest.birth_date = data.birth_date ? (0, utils_1.slashesToDashes)(data.birth_date) : null;
37
- rest.gender = data.gender || null;
38
25
  return rest;
39
26
  };
40
27
  const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
@@ -46,8 +33,6 @@ const useProfileForm = (profile, loading, error, update, callback, optionalField
46
33
  const removed = [];
47
34
  if (optionalFields && !optionalFields.includes('birth_date'))
48
35
  removed.push('birth_date');
49
- if (optionalFields && !optionalFields.includes('gender'))
50
- removed.push('gender');
51
36
  return removed;
52
37
  }, [optionalFields]);
53
38
  // const fields = allFields.filter((i) => !toRemove.includes(i.name))
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutConfig, ConfigBrand, Customer, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
3
- interface NotificationCheckbox {
3
+ export interface NotificationCheckbox {
4
4
  label: string;
5
5
  name: NotificationChannel;
6
6
  type: string;
7
7
  }
8
+ export declare const notificationChannelFields: NotificationCheckbox[];
8
9
  export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls']) => {
9
10
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
10
11
  data: CustomerCreate;
@@ -17,4 +18,3 @@ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError
17
18
  handleComms: (name: NotificationChannel, value: boolean) => void;
18
19
  handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
19
20
  };
20
- export {};
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSignUpForm = void 0;
3
+ exports.useSignUpForm = exports.notificationChannelFields = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
- const useProfileForm_1 = require("./useProfileForm");
7
6
  const initState = {
8
7
  first_name: '',
9
8
  last_name: '',
10
9
  email: '',
11
10
  phone: ''
12
11
  };
13
- const notificationChannelFields = [
12
+ exports.notificationChannelFields = [
14
13
  {
15
14
  label: 'Email',
16
15
  name: 'EMAIL',
@@ -45,8 +44,6 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
45
44
  toRemove.push('password');
46
45
  if (optionalFields && !optionalFields.includes('birth_date'))
47
46
  toRemove.push('birth_date');
48
- if (optionalFields && !optionalFields.includes('gender'))
49
- toRemove.push('gender');
50
47
  const allFields = [
51
48
  {
52
49
  label: 'First Name',
@@ -86,17 +83,10 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
86
83
  name: 'birth_date',
87
84
  type: 'tel',
88
85
  required: hasPunchh
89
- },
90
- {
91
- label: 'Gender',
92
- name: 'gender',
93
- type: 'select',
94
- showLabel: true,
95
- options: useProfileForm_1.genderOptions
96
86
  }
97
87
  ];
98
88
  const fields = allFields.filter(i => !toRemove.includes(i.name));
99
- const notificationFields = notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
89
+ const notificationFields = exports.notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
100
90
  (0, react_1.useEffect)(() => {
101
91
  return () => {
102
92
  setData(initState);
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, 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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls']) => {
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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[]) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  fields: import("@open-tender/types").FormFieldType[];
7
+ notificationFields: import("./useSignUpForm").NotificationCheckbox[];
7
8
  data: CustomerCreate;
8
9
  errors: Record<string, string>;
9
10
  disabled: boolean;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useSignUpGuestForm = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
+ const useSignUpForm_1 = require("./useSignUpForm");
6
7
  const initialData = {
7
8
  first_name: '',
8
9
  last_name: '',
@@ -10,7 +11,7 @@ const initialData = {
10
11
  email: '',
11
12
  password: ''
12
13
  };
13
- const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls) => {
14
+ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = []) => {
14
15
  const submitRef = (0, react_1.useRef)(null);
15
16
  const inputRef = (0, react_1.useRef)(null);
16
17
  const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
@@ -66,6 +67,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
66
67
  }
67
68
  ];
68
69
  const fields = allFields.filter(i => !toRemove.includes(i.name));
70
+ const notificationFields = useSignUpForm_1.notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
69
71
  const handleChange = (name, value) => {
70
72
  const val = name === 'phone'
71
73
  ? (0, utils_1.makePhone)(value)
@@ -122,6 +124,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
122
124
  submitRef,
123
125
  inputRef,
124
126
  fields,
127
+ notificationFields,
125
128
  data,
126
129
  errors,
127
130
  disabled,
@@ -11,7 +11,6 @@ exports.profileFields = [
11
11
  'phone',
12
12
  'company',
13
13
  'birth_date',
14
- 'gender',
15
14
  'is_verified',
16
15
  'is_notification_set'
17
16
  ];
@@ -1,9 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { Customer, CustomerCreate, FormFieldType, Gender, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const genderOptions: {
4
- name: string;
5
- value: Gender;
6
- }[];
2
+ import { Customer, CustomerCreate, FormFieldType, RequestError, RequestStatus } from '@open-tender/types';
7
3
  export declare const useProfileForm: (profile: Customer | null, loading: RequestStatus, error: RequestError, update: (data: CustomerCreate) => void, callback?: ((data: CustomerCreate) => void) | undefined, optionalFields?: string[]) => {
8
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
9
5
  data: Customer | null;
@@ -1,10 +1,5 @@
1
1
  import { useRef, useState, useEffect, useMemo } from 'react';
2
2
  import { makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
3
- export const genderOptions = [
4
- { name: 'not specified', value: 'DECLINED' },
5
- { name: 'Male', value: 'MALE' },
6
- { name: 'Female', value: 'FEMALE' }
7
- ];
8
3
  const allFields = [
9
4
  { label: 'First Name', name: 'first_name', type: 'text', required: true },
10
5
  { label: 'Last Name', name: 'last_name', type: 'text', required: true },
@@ -17,21 +12,13 @@ const allFields = [
17
12
  },
18
13
  { label: 'Phone', name: 'phone', type: 'tel', required: true },
19
14
  { label: 'Company', name: 'company', type: 'text' },
20
- { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' },
21
- {
22
- label: 'Gender',
23
- name: 'gender',
24
- type: 'select',
25
- showLabel: true,
26
- options: genderOptions
27
- }
15
+ { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' }
28
16
  ];
29
17
  const makePayload = (fields, data) => {
30
18
  if (!data)
31
19
  return null;
32
20
  const rest = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
33
21
  rest.birth_date = data.birth_date ? slashesToDashes(data.birth_date) : null;
34
- rest.gender = data.gender || null;
35
22
  return rest;
36
23
  };
37
24
  export const useProfileForm = (profile, loading, error, update, callback, optionalFields) => {
@@ -43,8 +30,6 @@ export const useProfileForm = (profile, loading, error, update, callback, option
43
30
  const removed = [];
44
31
  if (optionalFields && !optionalFields.includes('birth_date'))
45
32
  removed.push('birth_date');
46
- if (optionalFields && !optionalFields.includes('gender'))
47
- removed.push('gender');
48
33
  return removed;
49
34
  }, [optionalFields]);
50
35
  // const fields = allFields.filter((i) => !toRemove.includes(i.name))
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutConfig, ConfigBrand, Customer, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
3
- interface NotificationCheckbox {
3
+ export interface NotificationCheckbox {
4
4
  label: string;
5
5
  name: NotificationChannel;
6
6
  type: string;
7
7
  }
8
+ export declare const notificationChannelFields: NotificationCheckbox[];
8
9
  export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls']) => {
9
10
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
10
11
  data: CustomerCreate;
@@ -17,4 +18,3 @@ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError
17
18
  handleComms: (name: NotificationChannel, value: boolean) => void;
18
19
  handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
19
20
  };
20
- export {};
@@ -1,13 +1,12 @@
1
1
  import { useRef, useState, useEffect } from 'react';
2
2
  import { makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
3
- import { genderOptions } from './useProfileForm';
4
3
  const initState = {
5
4
  first_name: '',
6
5
  last_name: '',
7
6
  email: '',
8
7
  phone: ''
9
8
  };
10
- const notificationChannelFields = [
9
+ export const notificationChannelFields = [
11
10
  {
12
11
  label: 'Email',
13
12
  name: 'EMAIL',
@@ -42,8 +41,6 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
42
41
  toRemove.push('password');
43
42
  if (optionalFields && !optionalFields.includes('birth_date'))
44
43
  toRemove.push('birth_date');
45
- if (optionalFields && !optionalFields.includes('gender'))
46
- toRemove.push('gender');
47
44
  const allFields = [
48
45
  {
49
46
  label: 'First Name',
@@ -83,13 +80,6 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
83
80
  name: 'birth_date',
84
81
  type: 'tel',
85
82
  required: hasPunchh
86
- },
87
- {
88
- label: 'Gender',
89
- name: 'gender',
90
- type: 'select',
91
- showLabel: true,
92
- options: genderOptions
93
83
  }
94
84
  ];
95
85
  const fields = allFields.filter(i => !toRemove.includes(i.name));
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, 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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls']) => {
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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[]) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  fields: import("@open-tender/types").FormFieldType[];
7
+ notificationFields: import("./useSignUpForm").NotificationCheckbox[];
7
8
  data: CustomerCreate;
8
9
  errors: Record<string, string>;
9
10
  disabled: boolean;
@@ -1,5 +1,6 @@
1
1
  import { useRef, useState, useEffect } from 'react';
2
2
  import { checkGuestData, makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
3
+ import { notificationChannelFields } from './useSignUpForm';
3
4
  const initialData = {
4
5
  first_name: '',
5
6
  last_name: '',
@@ -7,7 +8,7 @@ const initialData = {
7
8
  email: '',
8
9
  password: ''
9
10
  };
10
- export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls) => {
11
+ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = []) => {
11
12
  const submitRef = useRef(null);
12
13
  const inputRef = useRef(null);
13
14
  const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
@@ -63,6 +64,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
63
64
  }
64
65
  ];
65
66
  const fields = allFields.filter(i => !toRemove.includes(i.name));
67
+ const notificationFields = notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
66
68
  const handleChange = (name, value) => {
67
69
  const val = name === 'phone'
68
70
  ? makePhone(value)
@@ -119,6 +121,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
119
121
  submitRef,
120
122
  inputRef,
121
123
  fields,
124
+ notificationFields,
122
125
  data,
123
126
  errors,
124
127
  disabled,
@@ -8,7 +8,6 @@ export const profileFields = [
8
8
  'phone',
9
9
  'company',
10
10
  'birth_date',
11
- 'gender',
12
11
  'is_verified',
13
12
  'is_notification_set'
14
13
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.44",
3
+ "version": "0.4.46",
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",
@@ -36,7 +36,6 @@
36
36
  "private": false,
37
37
  "devDependencies": {
38
38
  "@emotion/react": "^11.10.4",
39
- "@open-tender/types": "^0.4.59",
40
39
  "@reduxjs/toolkit": "^1.8.5",
41
40
  "@types/google.maps": "^3.53.5",
42
41
  "@types/jest": "^29.5.11",
@@ -58,7 +57,7 @@
58
57
  "typescript": "^4.8.2"
59
58
  },
60
59
  "peerDependencies": {
61
- "@open-tender/types": "^0.4.59",
60
+ "@open-tender/types": "^0.4.70",
62
61
  "@reduxjs/toolkit": "^1.8.5",
63
62
  "react": "^18.2.0"
64
63
  },