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 { Controller, useForm } from "react-hook-form";
|
||||||
import LocationOnMap from "./LocationOnMap";
|
import LocationOnMap from "./LocationOnMap";
|
||||||
|
|
||||||
const CreateForm = ({ handleClose }) => {
|
const CreateForm = ({ handleClose, mutate }) => {
|
||||||
const { control, watch, register, handleSubmit, setValue } = useForm({
|
const { control, watch, register, handleSubmit, setValue } = useForm({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
dabirkhaneh_number: '',
|
dabirkhaneh_number: '',
|
||||||
@@ -130,6 +130,7 @@ const CreateForm = ({ handleClose }) => {
|
|||||||
try {
|
try {
|
||||||
await request(SET_INQUIRE_PRIVACY_FENCING, 'post', { data: formData })
|
await request(SET_INQUIRE_PRIVACY_FENCING, 'post', { data: formData })
|
||||||
handleClose()
|
handleClose()
|
||||||
|
mutate()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -441,7 +442,7 @@ const CreateForm = ({ handleClose }) => {
|
|||||||
value.map((option, index) => {
|
value.map((option, index) => {
|
||||||
const { key, ...tagProps } = getTagProps({ index });
|
const { key, ...tagProps } = getTagProps({ index });
|
||||||
return (
|
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 { Dialog, DialogTitle, IconButton } from "@mui/material";
|
||||||
import CreateForm from "./Form";
|
import CreateForm from "./Form";
|
||||||
|
|
||||||
const InquiryPrivacyFencingCreate = ({ open, handleClose }) => {
|
const InquiryPrivacyFencingCreate = ({ open, handleClose, mutate }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -24,7 +24,7 @@ const InquiryPrivacyFencingCreate = ({ open, handleClose }) => {
|
|||||||
>
|
>
|
||||||
<Close />
|
<Close />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<CreateForm handleClose={handleClose} />
|
<CreateForm handleClose={handleClose} mutate={mutate} />
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
const api = process.env.NEXT_PUBLIC_API_URL;
|
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_USER_ROUTE = api + "/webapi/user/get-permission";
|
||||||
export const GET_LOGIN_ROUTE = api + "/login_dev";
|
export const GET_LOGIN_ROUTE = api + "/login_dev";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
import { errorResponse } from "@/core/utils/errorResponse";
|
import { errorResponse } from "@/core/utils/errorResponse";
|
||||||
|
import { GET_CSRF } from "@/core/utils/routes";
|
||||||
import { successRequest } from "@/core/utils/successRequest";
|
import { successRequest } from "@/core/utils/successRequest";
|
||||||
import axios from "axios";
|
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 = {
|
const defaultOptions = {
|
||||||
data: {},
|
data: {},
|
||||||
requestOptions: {
|
requestOptions: {
|
||||||
@@ -15,13 +26,27 @@ const defaultOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useRequest = (initOptions) => {
|
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);
|
const _options = Object.assign({}, defaultOptions, initOptions);
|
||||||
|
|
||||||
return async (url = "", method = "get", options) => {
|
return async (url = "", method = "get", options) => {
|
||||||
const mergedOptions = Object.assign({}, _options, options);
|
const mergedOptions = Object.assign({}, _options, options);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
const response = await instance({
|
||||||
url,
|
url,
|
||||||
method,
|
method,
|
||||||
data: method === "get" ? null : mergedOptions.data,
|
data: method === "get" ? null : mergedOptions.data,
|
||||||
|
|||||||
Reference in New Issue
Block a user