feat : optimaze code by eslint
This commit is contained in:
@@ -15,7 +15,7 @@ import AuthLayout from "./layout/AuthLayout";
|
|||||||
import Login from "./pages/login";
|
import Login from "./pages/login";
|
||||||
import Profile from "./pages/profile";
|
import Profile from "./pages/profile";
|
||||||
import { Toaster } from "react-hot-toast";
|
import { Toaster } from "react-hot-toast";
|
||||||
import { isAuthenticated } from "./utils/auth";
|
import { IsAuthenticated } from "./utils/auth";
|
||||||
import { HelmetProvider } from "react-helmet-async";
|
import { HelmetProvider } from "react-helmet-async";
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
@@ -31,6 +31,7 @@ const App = () => {
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<Layout />}>
|
<Route path="/" element={<Layout />}>
|
||||||
<Route index element={<Shop />} />
|
<Route index element={<Shop />} />
|
||||||
|
<Route path="configs/:configs" element={<Navigate to="/" />} />
|
||||||
<Route path="tutorial" element={<Tutorial />} />
|
<Route path="tutorial" element={<Tutorial />} />
|
||||||
<Route path="rule" element={<Rule />} />
|
<Route path="rule" element={<Rule />} />
|
||||||
<Route path="about" element={<About />} />
|
<Route path="about" element={<About />} />
|
||||||
@@ -41,7 +42,7 @@ const App = () => {
|
|||||||
<Route
|
<Route
|
||||||
path="login"
|
path="login"
|
||||||
element={
|
element={
|
||||||
isAuthenticated() ? (
|
IsAuthenticated() ? (
|
||||||
<Navigate to="/" replace={true} />
|
<Navigate to="/" replace={true} />
|
||||||
) : (
|
) : (
|
||||||
<AuthLayout />
|
<AuthLayout />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Modal from "@mui/material/Modal";
|
import Modal from "@mui/material/Modal";
|
||||||
import { useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
import { IoClose } from "react-icons/io5";
|
import { IoClose } from "react-icons/io5";
|
||||||
import Button from "../../components/button";
|
import Button from "../../components/button";
|
||||||
@@ -17,15 +17,15 @@ export default function MuiModal({
|
|||||||
}: MuiModalProps) {
|
}: MuiModalProps) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const handleOpen = () => setOpen(true);
|
const handleOpen = () => setOpen(true);
|
||||||
const handleClose = () => {
|
const handleClose = useCallback(() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
setIsOpenModal(false);
|
setIsOpenModal(false);
|
||||||
};
|
}, [setIsOpenModal]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpenModal) handleOpen();
|
if (isOpenModal) handleOpen();
|
||||||
else handleClose();
|
else handleClose();
|
||||||
}, [isOpenModal]);
|
}, [isOpenModal, handleClose]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -63,7 +63,10 @@ export default function MuiModal({
|
|||||||
>
|
>
|
||||||
<Button onClick={() => handleClose()}> بستن </Button>
|
<Button onClick={() => handleClose()}> بستن </Button>
|
||||||
{submitText && (
|
{submitText && (
|
||||||
<Button onClick={submitOnClick} disabled={disabled}> {submitText} </Button>
|
<Button extra={`${disabled && '!bg-slate-300'}`} onClick={submitOnClick} disabled={disabled}>
|
||||||
|
{" "}
|
||||||
|
{submitText}{" "}
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import router from "../../../../routes/routes";
|
|||||||
import Button from "../../../button";
|
import Button from "../../../button";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { Route } from "../../../../types/props";
|
import { Route } from "../../../../types/props";
|
||||||
import { isAuthenticated } from "../../../../utils/auth";
|
import { IsAuthenticated } from "../../../../utils/auth";
|
||||||
|
|
||||||
const Navbar = ({extra}:{extra?:string}) => {
|
const Navbar = ({extra}:{extra?:string}) => {
|
||||||
const [isOpen, setIsOpen] = useState<boolean>(false);
|
const [isOpen, setIsOpen] = useState<boolean>(false);
|
||||||
const auth = isAuthenticated();
|
const auth = IsAuthenticated();
|
||||||
const [routes] = useState<Route[]>(router);
|
const [routes] = useState<Route[]>(router);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ const Navbar = ({extra}:{extra?:string}) => {
|
|||||||
{auth ? (
|
{auth ? (
|
||||||
<Button onClick={() => navigate("/profile")}>پروفایل</Button>
|
<Button onClick={() => navigate("/profile")}>پروفایل</Button>
|
||||||
) : (
|
) : (
|
||||||
<Button onClick={() => navigate("/login")}>ورود</Button>
|
<Button onClick={() => navigate("/login")}>ورود یا ثبت نام</Button>
|
||||||
)}
|
)}
|
||||||
<div className="md:hidden">
|
<div className="md:hidden">
|
||||||
<MobileMenuButton isOpen={isOpen} onClick={toggleMenu} />
|
<MobileMenuButton isOpen={isOpen} onClick={toggleMenu} />
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import React from "react";
|
|
||||||
|
|
||||||
const LoaderSpin = ({ children }: { children: React.ReactNode }) => {
|
const LoaderSpin = ({ children }: { children: React.ReactNode }) => {
|
||||||
return (
|
return (
|
||||||
<div className="relative w-full h-full flex justify-center items-center">
|
<div className="relative w-full h-full flex justify-center items-center">
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const useAxios = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const instance = axios.create({
|
const instance = axios.create({
|
||||||
baseURL: "https://api.soheilkhaledabadi.ir/api/v1",
|
baseURL: "https://api.persain-game.com/api/v1",
|
||||||
maxBodyLength: Infinity,
|
maxBodyLength: Infinity,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
41
src/http.ts
41
src/http.ts
@@ -1,41 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
import store from "./redux/store";
|
|
||||||
import { setToken } from "./redux/slices/token";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
|
|
||||||
|
|
||||||
const navigate = useNavigate()
|
|
||||||
|
|
||||||
const instance = axios.create({
|
|
||||||
baseURL: "https://api.soheilkhaledabadi.ir/api/v1",
|
|
||||||
maxBodyLength: Infinity,
|
|
||||||
});
|
|
||||||
|
|
||||||
axios.interceptors.request.use(
|
|
||||||
(config) => {
|
|
||||||
const state = store.getState();
|
|
||||||
const token = state.token.token;
|
|
||||||
if (token) {
|
|
||||||
config.headers.Authorization = `Bearer ${token}`;
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
axios.interceptors.response.use(
|
|
||||||
(response) => {
|
|
||||||
return response;
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
if (error.response && error.response.status === 401) {
|
|
||||||
navigate('/login')
|
|
||||||
store.dispatch(setToken(''));
|
|
||||||
}
|
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export default instance;
|
|
||||||
@@ -99,4 +99,13 @@
|
|||||||
input[type="number"] {
|
input[type="number"] {
|
||||||
-moz-appearance: textfield;
|
-moz-appearance: textfield;
|
||||||
}
|
}
|
||||||
|
button {
|
||||||
|
-webkit-appearance: none; /* غیرفعال کردن سبک پیشفرض Safari */
|
||||||
|
appearance: none; /* غیرفعال کردن سبک پیشفرض */
|
||||||
|
}
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user