add validation and basic api && change design sidebar
This commit is contained in:
@@ -42,6 +42,7 @@ function UploadFile({ image, setImage }) {
|
|||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
ref={fileRef}
|
ref={fileRef}
|
||||||
|
accept="image/*"
|
||||||
className="contents"
|
className="contents"
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -280,6 +280,10 @@ html {
|
|||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hover-sidebar .logout-btn {
|
||||||
|
max-width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.res-field-account .MuiInputBase-input.MuiOutlinedInput-input {
|
.res-field-account .MuiInputBase-input.MuiOutlinedInput-input {
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ function LogoutOrangeP() {
|
|||||||
height="20"
|
height="20"
|
||||||
viewBox="0 0 20 20"
|
viewBox="0 0 20 20"
|
||||||
fill="none"
|
fill="none"
|
||||||
|
className="min-w-[20px] min-h-[20px] max-w-[20px] max-h-[20px]"
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
d="M14.5334 12.1837L16.6668 10.0503L14.5334 7.91699"
|
d="M14.5334 12.1837L16.6668 10.0503L14.5334 7.91699"
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import { styleDefault } from "@/mui";
|
import { styleDefault } from "@/mui";
|
||||||
import { Box, Button, Modal } from "@mui/material";
|
import { Box, Button, Modal } from "@mui/material";
|
||||||
import CloseModalD from "@/components/icons/CloseModalD";
|
import CloseModalD from "@/components/icons/CloseModalD";
|
||||||
|
import { removeToken } from "@/utils";
|
||||||
|
|
||||||
function ModalLogout({ open, handleClose }) {
|
function ModalLogout({ open, handleClose }) {
|
||||||
|
const logout = () => {
|
||||||
|
removeToken();
|
||||||
|
window.location.pathname = '/login'
|
||||||
|
handleClose();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onClose={handleClose}>
|
<Modal open={open} onClose={handleClose}>
|
||||||
<Box
|
<Box
|
||||||
@@ -31,7 +38,7 @@ function ModalLogout({ open, handleClose }) {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={handleClose}
|
onClick={logout}
|
||||||
className="!py-[4px] md:!py-[6px] !min-h-[32px] md:!min-h-[39px] lg:!min-h-[46px] lg:!py-[8px] !px-[10px] md:!px-[14px] lg:!px-[18px] !rounded-[4px] !text-[#EFEFEF] !text-[12px] md:!text-[14px] lg:!text-[16px] !font-medium"
|
className="!py-[4px] md:!py-[6px] !min-h-[32px] md:!min-h-[39px] lg:!min-h-[46px] lg:!py-[8px] !px-[10px] md:!px-[14px] lg:!px-[18px] !rounded-[4px] !text-[#EFEFEF] !text-[12px] md:!text-[14px] lg:!text-[16px] !font-medium"
|
||||||
>
|
>
|
||||||
خروج
|
خروج
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ function Sidebar({ active, setActive, open, setOpen }) {
|
|||||||
<Links open={open} setActive={setActive} />
|
<Links open={open} setActive={setActive} />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={`w-full flex justify-center overflow-hidden transition-all duration-500 ${
|
className={`w-full flex logout-btn justify-center overflow-hidden transition-all duration-500 ${
|
||||||
open ? "!max-w-full" : "!max-w-0"
|
open ? "!max-w-full" : "!max-w-[36px]"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
variant="text"
|
variant="text"
|
||||||
onClick={handleOpen}
|
onClick={handleOpen}
|
||||||
className="!flex !w-fit !items-center !justify-center !gap-[10px] !py-[8px] !px-[16px] !text-[#F17732] !text-[16px] !font-medium"
|
className="!flex !w-fit !items-center !justify-start !gap-[10px] !py-[8px] !px-[16px] !text-[#F17732] !text-[16px] !font-medium"
|
||||||
>
|
>
|
||||||
<LogoutOrangeP />
|
<LogoutOrangeP />
|
||||||
خروج از حساب
|
خروج از حساب
|
||||||
|
|||||||
@@ -24,13 +24,12 @@ function ModalAddCard() {
|
|||||||
|
|
||||||
const updateNum = (value, type, name) => {
|
const updateNum = (value, type, name) => {
|
||||||
const parseValue = +value;
|
const parseValue = +value;
|
||||||
const { max } = validate_phone_number;
|
|
||||||
|
|
||||||
const validateValue = parseValue > max ? data[name].value : value;
|
changeData(parseValue, name);
|
||||||
|
|
||||||
changeData(validateValue, name);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isValidData = data.card && data.shaba && data.value && data.value.value;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Button Modal */}
|
{/* Button Modal */}
|
||||||
@@ -69,6 +68,7 @@ function ModalAddCard() {
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={handleClose}
|
onClick={handleClose}
|
||||||
|
disabled={!isValidData}
|
||||||
className="!min-w-[134px] !rounded-[4px] !h-[40px] md:!h-[44px] lg:!h-[48px] !text-[#EFEFEF] !text-[16px] !font-medium"
|
className="!min-w-[134px] !rounded-[4px] !h-[40px] md:!h-[44px] lg:!h-[48px] !text-[#EFEFEF] !text-[16px] !font-medium"
|
||||||
>
|
>
|
||||||
ذخیره
|
ذخیره
|
||||||
|
|||||||
+13
-4
@@ -13,8 +13,18 @@ const api = axios.create({
|
|||||||
|
|
||||||
api.interceptors.request.use(
|
api.interceptors.request.use(
|
||||||
(request) => {
|
(request) => {
|
||||||
if (cookies.get("token")) {
|
const token = cookies.get("token");
|
||||||
request.headers.authorization = `Bearer ${cookies.get("token")}`;
|
const isLoginPage = window.location.pathname === "/login";
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
if (!isLoginPage) {
|
||||||
|
window.location.pathname = "/login";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isLoginPage) {
|
||||||
|
window.location.pathname = "/";
|
||||||
|
}
|
||||||
|
request.headers.authorization = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
return request;
|
return request;
|
||||||
},
|
},
|
||||||
@@ -26,10 +36,9 @@ api.interceptors.response.use(
|
|||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
console.log(error);
|
|
||||||
if (error.data.status === 400) {
|
if (error.data.status === 400) {
|
||||||
cookies.remove("token", { path: "/" });
|
cookies.remove("token", { path: "/" });
|
||||||
window.location.reload();
|
window.location.pathname = "/login";
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import Cookies from "universal-cookie";
|
||||||
|
|
||||||
|
const cookies = new Cookies();
|
||||||
|
|
||||||
|
const removeToken = () => cookies.remove("token", { path: "/" });
|
||||||
|
|
||||||
|
export { removeToken };
|
||||||
|
|||||||
Reference in New Issue
Block a user