This commit is contained in:
Amirhossein Mahmoodi
2024-07-14 13:53:20 +03:30
parent c63c8c46ac
commit 740c1006c4
7 changed files with 8 additions and 35 deletions

View File

@@ -2,7 +2,7 @@
import DialogTransition from "@/core/components/DialogTransition"; import DialogTransition from "@/core/components/DialogTransition";
import { Close } from "@mui/icons-material"; 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 CreateOrUpdateForm from "../../Forms/CreateOrUpdate";
const InquiryPrivacyFencingCreate = ({ open, handleClose, mutate }) => { const InquiryPrivacyFencingCreate = ({ open, handleClose, mutate }) => {
@@ -24,7 +24,7 @@ const InquiryPrivacyFencingCreate = ({ open, handleClose, mutate }) => {
> >
<Close /> <Close />
</IconButton> </IconButton>
<CreateForm handleClose={handleClose} mutate={mutate} /> <CreateOrUpdateForm handleClose={handleClose} mutate={mutate} />
</Dialog> </Dialog>
</> </>
); );

View File

@@ -66,9 +66,9 @@ const initValues = {
ronevesht: '', ronevesht: '',
} }
const CreateForm = ({ handleClose, mutate }) => { const CreateOrUpdateForm = ({ handleClose, mutate, defaultValues }) => {
const request = useRequest() const request = useRequest()
const { control, watch, register, handleSubmit, setValue, formState: { isSubmitting } } = useForm({ defaultValues: initValues }); const { control, watch, register, handleSubmit, setValue, formState: { isSubmitting } } = useForm({ defaultValues: defaultValues || initValues });
const onSubmit = async (data) => { const onSubmit = async (data) => {
const formData = new FormData() const formData = new FormData()
@@ -567,4 +567,4 @@ const CreateForm = ({ handleClose, mutate }) => {
</LocalizationProvider > </LocalizationProvider >
); );
}; };
export default CreateForm; export default CreateOrUpdateForm;

View File

@@ -1,8 +1,7 @@
import MapLoading from "@/core/components/MapLayer/Loading"; import MapLoading from "@/core/components/MapLayer/Loading";
import MarkerLocation from "@/core/components/MapLayer/MarkerLocation";
import { Paper, Stack } from "@mui/material"; import { Paper, Stack } from "@mui/material";
import { useFormikContext } from "formik";
import dynamic from "next/dynamic"; import dynamic from "next/dynamic";
import MarkerLocation from "./MarkerLocation";
const MapLayer = dynamic(() => import("@/core/components/MapLayer"), { const MapLayer = dynamic(() => import("@/core/components/MapLayer"), {
loading: () => <MapLoading />, loading: () => <MapLoading />,

View File

@@ -1,7 +1,7 @@
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import AddCircleIcon from "@mui/icons-material/AddCircle"; import AddCircleIcon from "@mui/icons-material/AddCircle";
import { useState } from "react"; import { useState } from "react";
import InquiryPrivacyFencingCreate from "@/components/dashboard/inquiryPrivacyFencing/Create"; import InquiryPrivacyFencingCreate from "./Actions/Create";
const Toolbar = ({ mutate }) => { const Toolbar = ({ mutate }) => {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);

View File

@@ -1,7 +1,5 @@
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";
export const GET_INQUIRY_PRIVACY_FENCING_ROUTE = api + "/api/v3/harim/divarkeshi"; export const GET_INQUIRY_PRIVACY_FENCING_ROUTE = api + "/api/v3/harim/divarkeshi";

View File

@@ -1,19 +1,8 @@
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";
import { useAuth } from "../contexts/auth"; import { useAuth } from "../contexts/auth";
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: {
@@ -28,19 +17,6 @@ const defaultOptions = {
const useRequest = (initOptions) => { const useRequest = (initOptions) => {
const { logout } = useAuth() const { logout } = useAuth()
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);
@@ -48,7 +24,7 @@ const useRequest = (initOptions) => {
const mergedOptions = Object.assign({}, _options, options); const mergedOptions = Object.assign({}, _options, options);
try { try {
const response = await instance({ const response = await axios({
url, url,
method, method,
data: method === "get" ? null : mergedOptions.data, data: method === "get" ? null : mergedOptions.data,