add form create inquiryPrivacyFencing
This commit is contained in:
@@ -9,7 +9,7 @@ import moment from "jalali-moment";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import LocationOnMap from "./LocationOnMap";
|
||||
|
||||
const CreateForm = ({ handleClose }) => {
|
||||
const CreateForm = ({ handleClose, mutate }) => {
|
||||
const { control, watch, register, handleSubmit, setValue } = useForm({
|
||||
defaultValues: {
|
||||
dabirkhaneh_number: '',
|
||||
@@ -130,6 +130,7 @@ const CreateForm = ({ handleClose }) => {
|
||||
try {
|
||||
await request(SET_INQUIRE_PRIVACY_FENCING, 'post', { data: formData })
|
||||
handleClose()
|
||||
mutate()
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
@@ -441,7 +442,7 @@ const CreateForm = ({ handleClose }) => {
|
||||
value.map((option, index) => {
|
||||
const { key, ...tagProps } = getTagProps({ index });
|
||||
return (
|
||||
<Chip label={option} key={key} {...tagProps} />
|
||||
<Chip label={option} key={key} size="small" {...tagProps} />
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Close } from "@mui/icons-material";
|
||||
import { Dialog, DialogTitle, IconButton } from "@mui/material";
|
||||
import CreateForm from "./Form";
|
||||
|
||||
const InquiryPrivacyFencingCreate = ({ open, handleClose }) => {
|
||||
const InquiryPrivacyFencingCreate = ({ open, handleClose, mutate }) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -24,7 +24,7 @@ const InquiryPrivacyFencingCreate = ({ open, handleClose }) => {
|
||||
>
|
||||
<Close />
|
||||
</IconButton>
|
||||
<CreateForm handleClose={handleClose} />
|
||||
<CreateForm handleClose={handleClose} mutate={mutate} />
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const api = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
export const GET_CSRF = api + "/csrf";
|
||||
|
||||
export const GET_USER_ROUTE = api + "/webapi/user/get-permission";
|
||||
export const GET_LOGIN_ROUTE = api + "/login_dev";
|
||||
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
import { errorResponse } from "@/core/utils/errorResponse";
|
||||
import { GET_CSRF } from "@/core/utils/routes";
|
||||
import { successRequest } from "@/core/utils/successRequest";
|
||||
import axios from "axios";
|
||||
|
||||
const getCsrfToken = async () => {
|
||||
try {
|
||||
const response = await axios.get(GET_CSRF);
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching CSRF token:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const defaultOptions = {
|
||||
data: {},
|
||||
requestOptions: {
|
||||
@@ -15,13 +26,27 @@ const defaultOptions = {
|
||||
};
|
||||
|
||||
const useRequest = (initOptions) => {
|
||||
const instance = axios.create();
|
||||
instance.interceptors.request.use(
|
||||
async function (config) {
|
||||
if (config.method !== 'get') {
|
||||
const csrfToken = await getCsrfToken();
|
||||
config.headers['X-CSRF-TOKEN'] = csrfToken;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
function (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
const _options = Object.assign({}, defaultOptions, initOptions);
|
||||
|
||||
return async (url = "", method = "get", options) => {
|
||||
const mergedOptions = Object.assign({}, _options, options);
|
||||
|
||||
try {
|
||||
const response = await axios({
|
||||
const response = await instance({
|
||||
url,
|
||||
method,
|
||||
data: method === "get" ? null : mergedOptions.data,
|
||||
|
||||
Reference in New Issue
Block a user