feat: support page previous page

This commit is contained in:
IlyaDoronin 2023-08-08 18:47:02 +03:00
parent 1037ee7afd
commit 1d6f545e8f
4 changed files with 80 additions and 71 deletions

@ -14,7 +14,6 @@ export default function Menu() {
const location = useLocation();
const color = location.pathname === "/" ? "white" : "black";
console.log(location)
const arrayMenu: MenuItem[] = [
{
@ -42,49 +41,50 @@ export default function Menu() {
overflow: "hidden",
}}
>
{location.pathname !== "/" ? arrayMenu.map(({ name, url, subMenu = [] }) => (
<Link
key={name}
style={{
textDecoration: "none",
height: "100%",
display: "flex",
alignItems: "center",
}}
to={url}
onMouseEnter={() => setActiveSubMenu(subMenu)}
>
<Typography
color={
location.pathname === url
? theme.palette.brightPurple.main
: color
}
variant="body2"
sx={{
whiteSpace: "nowrap",
}}
>
{name}
</Typography>
</Link>
))
:arrayMenu.map(({ name, url, subMenu = [] }) => (
<Typography
color={
location.pathname === url
? theme.palette.brightPurple.main
: color
}
variant="body2"
sx={{
whiteSpace: "nowrap",
}}
>
{name}
</Typography>
))
}
{location.pathname !== "/"
? arrayMenu.map(({ name, url, subMenu = [] }) => (
<Link
key={name}
style={{
textDecoration: "none",
height: "100%",
display: "flex",
alignItems: "center",
}}
to={url}
onMouseEnter={() => setActiveSubMenu(subMenu)}
state={{ previousUrl: location.pathname }}
>
<Typography
color={
location.pathname === url
? theme.palette.brightPurple.main
: color
}
variant="body2"
sx={{
whiteSpace: "nowrap",
}}
>
{name}
</Typography>
</Link>
))
: arrayMenu.map(({ name, url, subMenu = [] }) => (
<Typography
color={
location.pathname === url
? theme.palette.brightPurple.main
: color
}
variant="body2"
sx={{
whiteSpace: "nowrap",
}}
>
{name}
</Typography>
))}
<Box
sx={{
zIndex: "10",
@ -96,29 +96,30 @@ export default function Menu() {
}}
onMouseLeave={() => setActiveSubMenu([])}
>
{location.pathname !== "/" && activeSubMenu.map(({ name, url }) => (
<Link key={name} style={{ textDecoration: "none" }} to={url}>
<Typography
color={
location.pathname === url
? theme.palette.brightPurple.main
: color
}
variant="body2"
sx={{
padding: "15px",
whiteSpace: "nowrap",
paddingLeft: "185px",
"&:hover": {
color: theme.palette.brightPurple.main,
background: theme.palette.background.default,
},
}}
>
{name}
</Typography>
</Link>
))}
{location.pathname !== "/" &&
activeSubMenu.map(({ name, url }) => (
<Link key={name} style={{ textDecoration: "none" }} to={url}>
<Typography
color={
location.pathname === url
? theme.palette.brightPurple.main
: color
}
variant="body2"
sx={{
padding: "15px",
whiteSpace: "nowrap",
paddingLeft: "185px",
"&:hover": {
color: theme.palette.brightPurple.main,
background: theme.palette.background.default,
},
}}
>
{name}
</Typography>
</Link>
))}
</Box>
</Box>
);

@ -85,7 +85,7 @@ export default function DialogMenu({ handleClose }: DialogMenuProps) {
key={index}
component={Link}
to={url}
state={user ? undefined : { backgroundLocation: location }}
state={{ previousUrl: location.pathname }}
disableRipple
variant="text"
onClick={() =>
@ -134,6 +134,7 @@ export default function DialogMenu({ handleClose }: DialogMenuProps) {
}}
to={url}
onClick={closeDialogMenu}
state={{ previousUrl: location.pathname }}
>
<Typography
variant="body2"

@ -58,6 +58,7 @@ export default function NavbarFull({ isLoggedIn, children }: Props) {
disableGutters
maxWidth={false}
sx={{
zIndex: 1,
position: "fixed",
top: "0",
px: "16px",

@ -6,12 +6,12 @@ import {
IconButton,
} from "@mui/material";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import { Link, useParams } from "react-router-dom";
import { Link, useParams, useLocation } from "react-router-dom";
import SectionWrapper from "@components/SectionWrapper";
import SupportChat from "./SupportChat";
import CreateTicket from "./CreateTicket";
import TicketList from "./TicketList/TicketList";
import { useCallback } from "react";
import { useState, useCallback, useEffect } from "react";
import { Ticket, getMessageFromFetchError, useToken } from "@frontend/kitui";
import {
updateTickets,
@ -23,12 +23,14 @@ import { enqueueSnackbar } from "notistack";
import { useSSESubscription, useTickets } from "@frontend/kitui";
export default function Support() {
const [previousPage, setPreviousPage] = useState<string>("");
const theme = useTheme();
const upMd = useMediaQuery(theme.breakpoints.up("md"));
const ticketId = useParams().ticketId;
const ticketApiPage = useTicketStore((state) => state.apiPage);
const ticketsPerPage = useTicketStore((state) => state.ticketsPerPage);
const token = useToken();
const location = useLocation();
const fetchState = useTickets({
url: "https://hub.pena.digital/heruvym/getTickets",
@ -44,6 +46,10 @@ export default function Support() {
}, []),
});
useEffect(() => {
setPreviousPage(location.state?.previousUrl || "/");
}, []);
useSSESubscription<Ticket>({
enabled: Boolean(token),
url: `https://admin.pena.digital/heruvym/subscribe?Authorization=${token}`,
@ -73,7 +79,7 @@ export default function Support() {
}}
>
<Link
to="/support"
to={previousPage}
style={{
textDecoration: "none",
display: "flex",