@engagebay/engagebay-form-module 1.0.0-beta.1 → 1.0.0-beta.2
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
package/src/api/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import axios, { AxiosRequestConfig
|
|
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,10 @@ reachoAPI.interceptors.request.use(
|
|
|
23
24
|
return Promise.reject(error);
|
|
24
25
|
}
|
|
25
26
|
);
|
|
27
|
+
|
|
28
|
+
export const getAxiosInstance = (fieldConfig: FormFieldSchema): AxiosInstance => {
|
|
29
|
+
if (fieldConfig.axiosInstance) {
|
|
30
|
+
return fieldConfig.axiosInstance;
|
|
31
|
+
}
|
|
32
|
+
return fieldConfig.disableHeaderInFetch ? axios : reachoAPI;
|
|
33
|
+
};
|
|
@@ -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 {
|
|
18
|
+
import {getAxiosInstance} from "../../api";
|
|
20
19
|
|
|
21
20
|
const DynamicMultiSelect: React.FC<FormFieldComponentPropSchema> = (
|
|
22
21
|
props: FormFieldComponentPropSchema
|
|
@@ -100,10 +99,9 @@ const DynamicMultiSelect: React.FC<FormFieldComponentPropSchema> = (
|
|
|
100
99
|
}
|
|
101
100
|
const fetchData = async () => {
|
|
102
101
|
if (!props.fieldConfig.fetchUrl) return;
|
|
102
|
+
const axiosInstance = getAxiosInstance(props.fieldConfig);
|
|
103
|
+
let response = await axiosInstance.get(props.fieldConfig.fetchUrl);
|
|
103
104
|
|
|
104
|
-
let response = await (props.fieldConfig.disableHeaderInFetch
|
|
105
|
-
? axios.get(props.fieldConfig.fetchUrl)
|
|
106
|
-
: reachoAPI.get(props.fieldConfig.fetchUrl));
|
|
107
105
|
if (response.data) {
|
|
108
106
|
const data: FieldOptionsSchema[] = getListOptions(
|
|
109
107
|
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 {
|
|
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(props.fieldConfig);
|
|
100
|
+
|
|
100
101
|
try {
|
|
101
|
-
let response = await (props.fieldConfig.
|
|
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);
|
|
@@ -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
|