From 740c1006c44eb0c8dd758dd3a3c4ed4b36f6aebc Mon Sep 17 00:00:00 2001 From: Amirhossein Mahmoodi Date: Sun, 14 Jul 2024 13:53:20 +0330 Subject: [PATCH] update --- .../{ => Actions}/Create/index.jsx | 4 +-- .../index.jsx => Forms/CreateOrUpdate.jsx} | 6 ++--- .../LocationOnMap}/MarkerLocation/index.jsx | 0 .../Form => Forms}/LocationOnMap/index.jsx | 3 +-- .../inquiryPrivacyFencing/Toolbar.jsx | 2 +- src/core/utils/routes.js | 2 -- src/lib/hooks/useRequest.js | 26 +------------------ 7 files changed, 8 insertions(+), 35 deletions(-) rename src/components/dashboard/inquiryPrivacyFencing/{ => Actions}/Create/index.jsx (88%) rename src/components/dashboard/inquiryPrivacyFencing/{Create/Form/index.jsx => Forms/CreateOrUpdate.jsx} (99%) rename src/{core/components/MapLayer => components/dashboard/inquiryPrivacyFencing/Forms/LocationOnMap}/MarkerLocation/index.jsx (100%) rename src/components/dashboard/inquiryPrivacyFencing/{Create/Form => Forms}/LocationOnMap/index.jsx (86%) diff --git a/src/components/dashboard/inquiryPrivacyFencing/Create/index.jsx b/src/components/dashboard/inquiryPrivacyFencing/Actions/Create/index.jsx similarity index 88% rename from src/components/dashboard/inquiryPrivacyFencing/Create/index.jsx rename to src/components/dashboard/inquiryPrivacyFencing/Actions/Create/index.jsx index 6a3032c..88dbb53 100644 --- a/src/components/dashboard/inquiryPrivacyFencing/Create/index.jsx +++ b/src/components/dashboard/inquiryPrivacyFencing/Actions/Create/index.jsx @@ -2,7 +2,7 @@ import DialogTransition from "@/core/components/DialogTransition"; import { Close } from "@mui/icons-material"; import { Dialog, DialogTitle, IconButton } from "@mui/material"; -import CreateForm from "./Form"; +import CreateOrUpdateForm from "../../Forms/CreateOrUpdate"; const InquiryPrivacyFencingCreate = ({ open, handleClose, mutate }) => { @@ -24,7 +24,7 @@ const InquiryPrivacyFencingCreate = ({ open, handleClose, mutate }) => { > - + ); diff --git a/src/components/dashboard/inquiryPrivacyFencing/Create/Form/index.jsx b/src/components/dashboard/inquiryPrivacyFencing/Forms/CreateOrUpdate.jsx similarity index 99% rename from src/components/dashboard/inquiryPrivacyFencing/Create/Form/index.jsx rename to src/components/dashboard/inquiryPrivacyFencing/Forms/CreateOrUpdate.jsx index 523d509..9d8761b 100644 --- a/src/components/dashboard/inquiryPrivacyFencing/Create/Form/index.jsx +++ b/src/components/dashboard/inquiryPrivacyFencing/Forms/CreateOrUpdate.jsx @@ -66,9 +66,9 @@ const initValues = { ronevesht: '', } -const CreateForm = ({ handleClose, mutate }) => { +const CreateOrUpdateForm = ({ handleClose, mutate, defaultValues }) => { 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 formData = new FormData() @@ -567,4 +567,4 @@ const CreateForm = ({ handleClose, mutate }) => { ); }; -export default CreateForm; +export default CreateOrUpdateForm; diff --git a/src/core/components/MapLayer/MarkerLocation/index.jsx b/src/components/dashboard/inquiryPrivacyFencing/Forms/LocationOnMap/MarkerLocation/index.jsx similarity index 100% rename from src/core/components/MapLayer/MarkerLocation/index.jsx rename to src/components/dashboard/inquiryPrivacyFencing/Forms/LocationOnMap/MarkerLocation/index.jsx diff --git a/src/components/dashboard/inquiryPrivacyFencing/Create/Form/LocationOnMap/index.jsx b/src/components/dashboard/inquiryPrivacyFencing/Forms/LocationOnMap/index.jsx similarity index 86% rename from src/components/dashboard/inquiryPrivacyFencing/Create/Form/LocationOnMap/index.jsx rename to src/components/dashboard/inquiryPrivacyFencing/Forms/LocationOnMap/index.jsx index be24704..e5b9860 100644 --- a/src/components/dashboard/inquiryPrivacyFencing/Create/Form/LocationOnMap/index.jsx +++ b/src/components/dashboard/inquiryPrivacyFencing/Forms/LocationOnMap/index.jsx @@ -1,8 +1,7 @@ import MapLoading from "@/core/components/MapLayer/Loading"; -import MarkerLocation from "@/core/components/MapLayer/MarkerLocation"; import { Paper, Stack } from "@mui/material"; -import { useFormikContext } from "formik"; import dynamic from "next/dynamic"; +import MarkerLocation from "./MarkerLocation"; const MapLayer = dynamic(() => import("@/core/components/MapLayer"), { loading: () => , diff --git a/src/components/dashboard/inquiryPrivacyFencing/Toolbar.jsx b/src/components/dashboard/inquiryPrivacyFencing/Toolbar.jsx index 9646db4..2c8b3e9 100644 --- a/src/components/dashboard/inquiryPrivacyFencing/Toolbar.jsx +++ b/src/components/dashboard/inquiryPrivacyFencing/Toolbar.jsx @@ -1,7 +1,7 @@ import { Button } from "@mui/material"; import AddCircleIcon from "@mui/icons-material/AddCircle"; import { useState } from "react"; -import InquiryPrivacyFencingCreate from "@/components/dashboard/inquiryPrivacyFencing/Create"; +import InquiryPrivacyFencingCreate from "./Actions/Create"; const Toolbar = ({ mutate }) => { const [open, setOpen] = useState(false); diff --git a/src/core/utils/routes.js b/src/core/utils/routes.js index 7c0f4dc..d33fa7d 100644 --- a/src/core/utils/routes.js +++ b/src/core/utils/routes.js @@ -1,7 +1,5 @@ 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"; export const GET_INQUIRY_PRIVACY_FENCING_ROUTE = api + "/api/v3/harim/divarkeshi"; diff --git a/src/lib/hooks/useRequest.js b/src/lib/hooks/useRequest.js index 477128e..48a2080 100644 --- a/src/lib/hooks/useRequest.js +++ b/src/lib/hooks/useRequest.js @@ -1,19 +1,8 @@ import { errorResponse } from "@/core/utils/errorResponse"; -import { GET_CSRF } from "@/core/utils/routes"; import { successRequest } from "@/core/utils/successRequest"; import axios from "axios"; 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 = { data: {}, requestOptions: { @@ -28,19 +17,6 @@ const defaultOptions = { const useRequest = (initOptions) => { 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); @@ -48,7 +24,7 @@ const useRequest = (initOptions) => { const mergedOptions = Object.assign({}, _options, options); try { - const response = await instance({ + const response = await axios({ url, method, data: method === "get" ? null : mergedOptions.data,