@engagebay/engagebay-form-module 1.0.0-beta.1 → 1.0.0-beta.3-0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engagebay/engagebay-form-module",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.3-0",
4
4
  "description": "Provide base form components to reacho",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -26,5 +26,21 @@
26
26
  "react-redux": ">=8.0.4",
27
27
  "react-tailwindcss-datepicker": ">=1.6.6",
28
28
  "redux-saga": ">=1.3.0"
29
+ },
30
+ "devDependencies": {
31
+ "@headlessui/react": ">=2.1.2",
32
+ "@heroicons/react": ">=2.1.5",
33
+ "@reduxjs/toolkit": ">=2.2.7",
34
+ "@tippyjs/react": ">=4.2.6",
35
+ "@types/lodash": ">=4.17.7",
36
+ "@types/react-redux": ">=7.1.33",
37
+ "axios": ">=1.7.2",
38
+ "clsx": ">=2.1.1",
39
+ "moment": ">=2.30.1",
40
+ "react-hook-form": ">=7.52.1",
41
+ "react-popper": ">=2.3.0",
42
+ "react-redux": ">=8.0.4",
43
+ "react-tailwindcss-datepicker": ">=1.6.6",
44
+ "redux-saga": ">=1.3.0"
29
45
  }
30
46
  }
@@ -0,0 +1,53 @@
1
+ import React, { createContext, useContext, ReactNode } from 'react';
2
+ import { AxiosInstance } from 'axios';
3
+
4
+ interface AxiosConfigContextType {
5
+ axiosInstance: AxiosInstance;
6
+ baseURL?: string;
7
+ timeout?: number;
8
+ headers?: Record<string, string>;
9
+ }
10
+
11
+ const AxiosConfigContext = createContext<AxiosConfigContextType | null>(null);
12
+
13
+ interface AxiosConfigProviderProps {
14
+ children: ReactNode;
15
+ axiosInstance: AxiosInstance;
16
+ baseURL?: string;
17
+ timeout?: number;
18
+ headers?: Record<string, string>;
19
+ }
20
+
21
+ export const AxiosConfigProvider: React.FC<AxiosConfigProviderProps> = ({
22
+ children,
23
+ axiosInstance,
24
+ baseURL,
25
+ timeout,
26
+ headers,
27
+ }) => {
28
+ const config: AxiosConfigContextType = {
29
+ axiosInstance,
30
+ baseURL,
31
+ timeout,
32
+ headers,
33
+ };
34
+
35
+ return (
36
+ <AxiosConfigContext.Provider value={config}>
37
+ {children}
38
+ </AxiosConfigContext.Provider>
39
+ );
40
+ };
41
+
42
+ export const useAxiosConfig = (): AxiosConfigContextType => {
43
+ const context = useContext(AxiosConfigContext);
44
+ if (!context) {
45
+ throw new Error('useAxiosConfig must be used within an AxiosConfigProvider');
46
+ }
47
+ return context;
48
+ };
49
+
50
+ // Hook for optional usage (doesn't throw error if not provided)
51
+ export const useAxiosConfigOptional = (): AxiosConfigContextType | null => {
52
+ return useContext(AxiosConfigContext);
53
+ };
package/src/api/index.ts CHANGED
@@ -1,4 +1,5 @@
1
- import axios, { AxiosRequestConfig } from "axios";
1
+ import axios, {AxiosInstance, AxiosRequestConfig} from "axios";
2
+ import {FormFieldSchema} from "../form/schema/FormFieldSchema";
2
3
 
3
4
  const BASE_API: AxiosRequestConfig = {
4
5
  baseURL:
@@ -23,3 +24,16 @@ reachoAPI.interceptors.request.use(
23
24
  return Promise.reject(error);
24
25
  }
25
26
  );
27
+
28
+ export const getAxiosInstance = (axiosInstance: AxiosInstance | undefined, fieldConfig: FormFieldSchema): AxiosInstance => {
29
+
30
+ if (fieldConfig && fieldConfig.axiosInstance) {
31
+ return fieldConfig.axiosInstance;
32
+ }
33
+
34
+ if (axiosInstance) {
35
+ return axiosInstance;
36
+ }
37
+
38
+ return fieldConfig.disableHeaderInFetch ? axios : reachoAPI;
39
+ };
package/src/form/Form.tsx CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  } from "react-hook-form";
13
13
  import { FormFieldSchema } from "./schema/FormFieldSchema";
14
14
  import { FormContext } from "./context/FormContext";
15
+ import { AxiosInstance } from 'axios';
15
16
 
16
17
  /**
17
18
  * Props for the Form component
@@ -26,6 +27,7 @@ import { FormContext } from "./context/FormContext";
26
27
  */
27
28
  type FormPropsSchema = {
28
29
  fieldSchema: FormFieldSchema[];
30
+ axiosInstance?: AxiosInstance
29
31
  formData: any;
30
32
  onError?: (error: any) => void;
31
33
  onSubmit?: (data: FormData) => void;
@@ -132,6 +134,7 @@ export default function Form(props: FormPropsSchema): JSX.Element {
132
134
  setError,
133
135
  setFocus,
134
136
  unregister,
137
+ axiosInstance: props.axiosInstance,
135
138
  }}>
136
139
  {/* Form element */}
137
140
  <form
@@ -17,6 +17,7 @@ import {
17
17
  UseFormWatch,
18
18
  } from "react-hook-form";
19
19
  import { FormFieldSchema } from "../schema/FormFieldSchema";
20
+ import { AxiosInstance } from "axios";
20
21
 
21
22
  export interface FormContextType {
22
23
  formFields: FormFieldSchema[];
@@ -43,6 +44,7 @@ export interface FormContextType {
43
44
  // control: Control<TFieldValues, TContext>;
44
45
  // register: UseFormRegister<TFieldValues>;
45
46
  setFocus: UseFormSetFocus<any>;
47
+ axiosInstance?: AxiosInstance;
46
48
  }
47
49
 
48
50
  export const FormContext = createContext({
@@ -10,7 +10,6 @@ import {FormContext} from "../context/FormContext";
10
10
  import {RegisterOptions} from "react-hook-form";
11
11
  import {convertToTitleCase, registerFormField} from "../util";
12
12
  import axios from "axios";
13
- import {reachoAPI} from "../../api";
14
13
  import SwitchField from "./SwitchField";
15
14
  import FormField from "../FormField";
16
15
  import RenderFormField from "../util/RenderFormField";
@@ -138,9 +137,9 @@ export const BusinessHoursField: React.FC<FormFieldComponentPropSchema> = (props
138
137
  try {
139
138
  let response = await (props.fieldConfig.disableHeaderInFetch
140
139
  ? axios.get(url)
141
- : reachoAPI.get(url));
140
+ : formContext.axiosInstance?.get(url));
142
141
 
143
- if (response.data) {
142
+ if (response?.data) {
144
143
  const data: FieldOptionsSchema[] = response.data;
145
144
  setListOptions(data);
146
145
  setLoading(false);
@@ -149,7 +148,7 @@ export const BusinessHoursField: React.FC<FormFieldComponentPropSchema> = (props
149
148
  props.fieldConfig.fetchCallback(response);
150
149
  }
151
150
  } else {
152
- console.error(response.statusText);
151
+ console.error(response?.statusText);
153
152
  setLoading(false);
154
153
  }
155
154
  } catch (error) {
@@ -7,7 +7,7 @@ import { Field } from "@headlessui/react";
7
7
  import RenderFormField from "../util/RenderFormField";
8
8
  import { handleChange, registerFormField } from "../util";
9
9
 
10
- export const ColorPickerField: React.FC<FormFieldComponentPropSchema> = (
10
+ const ColorPickerField: React.FC<FormFieldComponentPropSchema> = (
11
11
  props: FormFieldComponentPropSchema
12
12
  ) => {
13
13
  const formContext = useContext(FormContext);
@@ -57,3 +57,5 @@ export const ColorPickerField: React.FC<FormFieldComponentPropSchema> = (
57
57
  <RenderFormField fieldConfig={props.fieldConfig} getInput={getInput} />
58
58
  );
59
59
  };
60
+
61
+ export default ColorPickerField;
@@ -10,13 +10,12 @@ import {Listbox, ListboxButton} from "@headlessui/react";
10
10
 
11
11
  import {FormContext} from "../context/FormContext";
12
12
  import {getListOptions} from "../FormFieldUtils";
13
- import axios from "axios";
14
13
  import useDymanicReducer from "../hooks/useDynamicReducer";
15
14
  import {useDispatch} from "react-redux";
16
15
  import RenderFormField from "../util/RenderFormField";
17
16
  import {handleChange, registerFormField} from "../util";
18
17
  import RenderListOptions, {renderListBoxValue,} from "../util/RenderListOptions";
19
- import {reachoAPI} from "../../api";
18
+ import {getAxiosInstance} from "../../api";
20
19
 
21
20
  const DynamicMultiSelect: React.FC<FormFieldComponentPropSchema> = (
22
21
  props: FormFieldComponentPropSchema
@@ -98,12 +97,12 @@ const DynamicMultiSelect: React.FC<FormFieldComponentPropSchema> = (
98
97
  let options = props.fieldConfig.options;
99
98
  setListOptions(prevState => [...options, ...prevState]);
100
99
  }
100
+
101
101
  const fetchData = async () => {
102
102
  if (!props.fieldConfig.fetchUrl) return;
103
+ const axiosInstance = getAxiosInstance(formContext.axiosInstance, props.fieldConfig);
104
+ let response = await axiosInstance.get(props.fieldConfig.fetchUrl);
103
105
 
104
- let response = await (props.fieldConfig.disableHeaderInFetch
105
- ? axios.get(props.fieldConfig.fetchUrl)
106
- : reachoAPI.get(props.fieldConfig.fetchUrl));
107
106
  if (response.data) {
108
107
  const data: FieldOptionsSchema[] = getListOptions(
109
108
  response.data,
@@ -15,8 +15,7 @@ import useDymanicReducer from "../hooks/useDynamicReducer";
15
15
  import RenderFormField from "../util/RenderFormField";
16
16
  import RenderListOptions, {renderListBoxValue,} from "../util/RenderListOptions";
17
17
  import {handleChange, registerFormField} from "../util";
18
- import {reachoAPI} from "../../api/index";
19
- import axios from "axios";
18
+ import {getAxiosInstance} from "../../api";
20
19
 
21
20
  const DynamicSelect: React.FC<FormFieldComponentPropSchema> = (
22
21
  props: FormFieldComponentPropSchema
@@ -97,10 +96,10 @@ const DynamicSelect: React.FC<FormFieldComponentPropSchema> = (
97
96
  const fetchData = useCallback(async () => {
98
97
  if (!props.fieldConfig.fetchUrl) return;
99
98
 
99
+ const axiosInstance = getAxiosInstance(formContext.axiosInstance, props.fieldConfig);
100
+
100
101
  try {
101
- let response = await (props.fieldConfig.disableHeaderInFetch
102
- ? axios.get(props.fieldConfig.fetchUrl)
103
- : reachoAPI.get(props.fieldConfig.fetchUrl));
102
+ let response = await axiosInstance.get(props.fieldConfig.fetchUrl);
104
103
 
105
104
  if (response.data) {
106
105
  const data: FieldOptionsSchema[] = getListOptions(response.data, props.fieldConfig.optionsConfig);
@@ -7,7 +7,7 @@ import { Input } from "@headlessui/react";
7
7
  import RenderFormField from "../util/RenderFormField";
8
8
  import { handleChange, registerFormField } from "../util";
9
9
 
10
- export const RangeField: React.FC<FormFieldComponentPropSchema> = (
10
+ const RangeField: React.FC<FormFieldComponentPropSchema> = (
11
11
  props: FormFieldComponentPropSchema
12
12
  ) => {
13
13
  const formContext = useContext(FormContext);
@@ -51,3 +51,5 @@ export const RangeField: React.FC<FormFieldComponentPropSchema> = (
51
51
  <RenderFormField fieldConfig={props.fieldConfig} getInput={getInput} />
52
52
  );
53
53
  };
54
+
55
+ export default RangeField;
@@ -9,7 +9,6 @@ import React, {
9
9
  import { Listbox, ListboxButton } from "@headlessui/react";
10
10
  import axios from "axios";
11
11
  import { RegisterOptions } from "react-hook-form";
12
- import { reachoAPI } from "../../api";
13
12
  import { FormContext } from "../context/FormContext";
14
13
  import { getListOption, getListOptions } from "../FormFieldUtils";
15
14
  import {
@@ -68,8 +67,8 @@ const Typeahead: React.FC<FormFieldComponentPropSchema> = (
68
67
 
69
68
  let response = await (props.fieldConfig.disableHeaderInFetch
70
69
  ? axios.get(url)
71
- : reachoAPI.get(url));
72
- if (response.data) {
70
+ : formContext.axiosInstance?.get(url));
71
+ if (response?.data) {
73
72
  const data: FieldOptionsSchema[] = getListOptions(
74
73
  response.data,
75
74
  props.fieldConfig.optionsConfig
@@ -87,7 +86,7 @@ const Typeahead: React.FC<FormFieldComponentPropSchema> = (
87
86
  props.fieldConfig.fetchCallback(response);
88
87
  }
89
88
  } else {
90
- console.error(response.statusText);
89
+ console.error(response?.statusText);
91
90
  }
92
91
  } catch (err) {
93
92
  } finally {
@@ -116,11 +115,11 @@ const Typeahead: React.FC<FormFieldComponentPropSchema> = (
116
115
  let response = await (
117
116
  props.fieldConfig.disableHeaderInFetch
118
117
  ? axios.get(url)
119
- : reachoAPI.get(url)
118
+ : formContext.axiosInstance?.get(url)
120
119
  );
121
- if (response.data) {
120
+ if (response?.data) {
122
121
  const data: FieldOptionsSchema[] = getListOptions(
123
- response.data,
122
+ response?.data,
124
123
  props.fieldConfig.optionsConfig
125
124
  );
126
125
  setSelectedValues([...data]);
@@ -23,7 +23,6 @@ import RenderListOptions, {
23
23
  } from "../util/RenderListOptions";
24
24
  // import _ from "lodash";
25
25
  import axios from "axios";
26
- import { reachoAPI } from "../../api";
27
26
 
28
27
  const TypeaheadMultiSelect: React.FC<FormFieldComponentPropSchema> = (
29
28
  props: FormFieldComponentPropSchema
@@ -69,10 +68,10 @@ const TypeaheadMultiSelect: React.FC<FormFieldComponentPropSchema> = (
69
68
 
70
69
  let response = await (props.fieldConfig.disableHeaderInFetch
71
70
  ? axios.get(url)
72
- : reachoAPI.get(url));
73
- if (response.data) {
71
+ : formContext.axiosInstance?.get(url));
72
+ if (response?.data) {
74
73
  const data: FieldOptionsSchema[] = getListOptions(
75
- response.data,
74
+ response?.data,
76
75
  props.fieldConfig.optionsConfig
77
76
  );
78
77
  setListOptions([...data]);
@@ -91,7 +90,7 @@ const TypeaheadMultiSelect: React.FC<FormFieldComponentPropSchema> = (
91
90
  props.fieldConfig.fetchCallback(response);
92
91
  }
93
92
  } else {
94
- console.error(response.statusText);
93
+ console.error(response?.statusText);
95
94
  }
96
95
  } catch (err) {
97
96
  } finally {
@@ -118,10 +117,10 @@ const TypeaheadMultiSelect: React.FC<FormFieldComponentPropSchema> = (
118
117
 
119
118
  let response = await (props.fieldConfig.disableHeaderInFetch
120
119
  ? axios.get(url)
121
- : reachoAPI.get(url));
122
- if (response.data) {
120
+ : formContext.axiosInstance?.get(url));
121
+ if (response?.data) {
123
122
  const data: FieldOptionsSchema[] = getListOptions(
124
- response.data,
123
+ response?.data,
125
124
  props.fieldConfig.optionsConfig
126
125
  );
127
126
  setSelectedValues([...data]);
@@ -10,6 +10,7 @@ import {
10
10
  } from "react-hook-form";
11
11
  import { Saga } from "redux-saga";
12
12
  import { emailIdsValidator, queryValidator } from "./CustomValidators";
13
+ import { AxiosInstance } from 'axios';
13
14
 
14
15
  export enum FormFieldType {
15
16
  INPUT = "INPUT",
@@ -136,6 +137,7 @@ export type FormFieldSchema = {
136
137
  forceUpdate?: boolean;
137
138
  disableHeaderInFetch?: boolean;
138
139
  dropdownFieldConfig?: DropdownFieldConfig;
140
+ axiosInstance?: AxiosInstance
139
141
 
140
142
  /**
141
143
  * Redux configuration attribute
package/src/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ // Main exports for EngageBay Form Module
2
+
3
+ // Core components
4
+ export { default as Form } from './form/Form';
5
+ export { default as FormField } from './form/FormField';
6
+
7
+ // Axios configuration
8
+ export { AxiosConfigProvider, useAxiosConfig, useAxiosConfigOptional } from './api/AxiosConfigProvider';
9
+
10
+ // Form context
11
+ export { FormContext } from './form/context/FormContext';
12
+
13
+ // Schema and types
14
+ export * from './form/schema/FormFieldSchema';
15
+
16
+ // Utilities
17
+ export * from './form/util';
18
+
19
+ // Form field components
20
+ export { default as ArrayField } from './form/formfields/ArrayField';
21
+ export { BusinessHoursField } from './form/formfields/BusinessHoursField';
22
+ export { default as CheckboxButtonsField } from './form/formfields/CheckboxButtonsField';
23
+ export { default as CheckboxField } from './form/formfields/CheckboxField';
24
+ export { default as ColorPickerField } from './form/formfields/ColorPickerField';
25
+ export { default as ComboMultiSelect } from './form/formfields/ComboMultiSelect';
26
+ export { default as ComboSelect } from './form/formfields/ComboSelect';
27
+ export { default as DatePickerField } from './form/formfields/DatePickerField';
28
+ export { default as DateRangePickerField } from './form/formfields/DateRangePickerField';
29
+ export { default as DynamicMultiSelect } from './form/formfields/DynamicMultiSelect';
30
+ export { default as DynamicSelect } from './form/formfields/DynamicSelect';
31
+ export { default as Error } from './form/formfields/Error';
32
+ export { default as ErrorContextHandler } from './form/formfields/ErrorContextHandler';
33
+ export { default as FileUploadField } from './form/formfields/FileUploadField';
34
+ export { default as IframeField } from './form/formfields/IframeField';
35
+ export { default as InputField } from './form/formfields/InputField';
36
+ export { default as InputGroupField } from './form/formfields/InputGroupField';
37
+ export { default as MultipleSelectField } from './form/formfields/MultipleSelectField';
38
+ export { default as NumberField } from './form/formfields/NumberField';
39
+ export { default as PasswordField } from './form/formfields/PasswordField';
40
+ export { default as PhoneNumberField } from './form/formfields/PhoneNumberField';
41
+ export { default as RadioField } from './form/formfields/RadioField';
42
+ export { default as RadioGroupComponent } from './form/formfields/RadioGroupComponent';
43
+ export { default as RangeField } from './form/formfields/RangeField';
44
+ export { default as SelectField } from './form/formfields/SelectField';
45
+ export { default as SwitchField } from './form/formfields/SwitchField';
46
+ export { default as TextAreaField } from './form/formfields/TextAreaField';
47
+ export { default as TimeField } from './form/formfields/TimeField';
48
+ export { default as Typeahead } from './form/formfields/Typeahead';
49
+ export { default as TypeaheadMultiSelect } from './form/formfields/TypeaheadMultiSelect';
50
+ export { default as UrlField } from './form/formfields/UrlField';
51
+
52
+ // Hooks
53
+ export { default as useDynamicReducer } from './form/hooks/useDynamicReducer';
54
+
55
+ // Utilities
56
+ export { default as LoaderWithText } from './util/LoaderWithText';
57
+ export { default as SVGIcon } from './util/svg/SVGIcon';
58
+ export * from './util/svg/HELPER_ICONS';
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
 
3
- export function LoaderWithText() {
3
+ export default function LoaderWithText() {
4
4
  return (
5
5
  <div
6
6
  id="loader-with-text"