Skip to content

Commit

Permalink
add dynamic urls in admin dashboard based on tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
radekm2000 committed Apr 7, 2024
1 parent e981fd4 commit b49a785
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/ecommerce/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function App() {
<Route path="/inbox/:userId*">
<Inbox />
</Route>
<Route path="/dashboard">
<Route path="/dashboard/:tab">
<AdminDashboard />
</Route>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ export const FeedbackNotifications = () => {
const { data, isLoading } = useFetchFeedbacks();
const [featureType, setFeatureType] = useState<featureType>();
const [location, setLocation] = useLocation();

console.log(location);
useEffect(() => {
const params = new URLSearchParams();
if (featureType !== undefined) {
params.set("featureType", featureType);
setLocation(`${location}?${params.toString()}`);
setLocation(`/dashboard/feedbacks?${params.toString()}`);
} else {
setLocation(location);
}
}, [featureType, setLocation, location]);
}, [featureType]);

if (isLoading) {
return <AdminDashboardSkeleton />;
Expand Down
5 changes: 3 additions & 2 deletions client/ecommerce/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export const Navbar = () => {
display: below800 ? "none" : null,
}}
>
<Link href="/dashboard">
<Link href="/dashboard/notifications">
<Typography
color="white"
fontFamily="Maison Neue"
Expand Down Expand Up @@ -426,7 +426,8 @@ export const Navbar = () => {
</Button>

<Box sx={{ display: { xs: "none", md: "flex", gap: "5px" } }}>
<IconButton size="large"
<IconButton
size="large"
disableFocusRipple
onClick={handleClickOpen}
>
Expand Down
14 changes: 12 additions & 2 deletions client/ecommerce/src/components/pages/AdminDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import DisplayAdminNotifications from "../DisplayAdminNotifications";
import { SyntheticEvent, useEffect, useState } from "react";
import { FeedbackNotifications } from "../AdminDashboard/FeedbackNotifications";
import { AdminDashboardSkeleton } from "../AdminDashboard/AdminDashboardSkeleton";
import { useLocation } from "wouter";
import { CatchingPokemonSharp } from "@mui/icons-material";
import { useLocation, useRoute } from "wouter";
const Container = styled(Box)({
backgroundColor: "rgba(37,44,51,0.05)",
display: "flex",
Expand All @@ -30,9 +29,20 @@ const Sidebar = styled(Box)({
export const AdminDashboard = () => {
const { data: adminNotifications, isLoading } = useFetchAdminNotifications();
const [tabValue, setTabValue] = useState("notifications");
const [, setLocation] = useLocation();
const [, params] = useRoute("/dashboard/:tab");

useEffect(() => {
if (!params || !params.tab) {
setLocation(`/dashboard/${tabValue}`);
} else {
setTabValue(params.tab);
}
}, [params, setLocation, tabValue]);

const handleTabChange = (e: SyntheticEvent, newValue: string) => {
setTabValue(newValue);
setLocation(`/dashboard/${newValue}`);
};

if (isLoading) {
Expand Down
2 changes: 1 addition & 1 deletion server/ecommerce/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class AuthService {
}
const payload = { sub: user.id, username: user.username };
const accessToken = await this.jwtService.signAsync(payload, {
expiresIn: '10s',
expiresIn: '24h',
});
const refreshToken = await this.jwtService.signAsync(payload, {
expiresIn: '24h',
Expand Down

0 comments on commit b49a785

Please sign in to comment.