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