mirror of
https://github.com/lemeow125/React-NotesApp.git
synced 2024-11-17 06:29:28 +08:00
Added user info page
This commit is contained in:
parent
16176aea9f
commit
eea71c8370
5 changed files with 89 additions and 3 deletions
|
@ -115,6 +115,7 @@ export function UserInfo() {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
console.log(response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import styles from "../../styles";
|
||||||
import AppIcon from "../AppIcon/AppIcon";
|
import AppIcon from "../AppIcon/AppIcon";
|
||||||
import Login from "../LoginButton/LoginButton";
|
import Login from "../LoginButton/LoginButton";
|
||||||
import HomeIcon from "../HomeIcon/HomeIcon";
|
import HomeIcon from "../HomeIcon/HomeIcon";
|
||||||
|
import UserIcon from "../UserIcon/UserIcon";
|
||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
return (
|
return (
|
||||||
|
@ -16,8 +17,7 @@ export default function Header() {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<HomeIcon size={32} color="white" />
|
<HomeIcon size={32} color="white" />
|
||||||
<HomeIcon size={32} color="white" />
|
<UserIcon size={32} color="white" />
|
||||||
<HomeIcon size={32} color="white" />
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
|
39
src/Components/UserIcon/UserIcon.tsx
Normal file
39
src/Components/UserIcon/UserIcon.tsx
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import { Button } from "@mui/material";
|
||||||
|
import * as React from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { IconProps } from "../../Interfaces/Interfaces";
|
||||||
|
|
||||||
|
export default function UserIcon(props: IconProps) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
style={{
|
||||||
|
backgroundColor: "#005997",
|
||||||
|
borderRadius: 16,
|
||||||
|
width: props.size + "px",
|
||||||
|
height: props.size + "px",
|
||||||
|
margin: 4,
|
||||||
|
alignContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
onClick={() => navigate("/User")}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width={props.size}
|
||||||
|
height={props.size}
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
strokeWidth="2"
|
||||||
|
stroke={props.color}
|
||||||
|
fill="none"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||||
|
<path d="M12 7m-4 0a4 4 0 1 0 8 0a4 4 0 1 0 -8 0"></path>
|
||||||
|
<path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"></path>
|
||||||
|
</svg>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
41
src/Routes/UserPage/UserPage.tsx
Normal file
41
src/Routes/UserPage/UserPage.tsx
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import styles from "../../styles";
|
||||||
|
import Header from "../../Components/Header/Header";
|
||||||
|
import { UserInfo } from "../../Components/Api/Api";
|
||||||
|
import { useQuery } from "react-query";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import { LoginState } from "../../Interfaces/Interfaces";
|
||||||
|
|
||||||
|
export default function UserPage() {
|
||||||
|
const { data, isLoading, error } = useQuery("user", UserInfo, { retry: 0 });
|
||||||
|
const logged_in = useSelector((state: LoginState) => state.Login.logged_in);
|
||||||
|
if (isLoading && !error) {
|
||||||
|
return (
|
||||||
|
<div style={styles.background}>
|
||||||
|
<Header />
|
||||||
|
<p style={styles.text_medium}>Loading...</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else if (error) {
|
||||||
|
return (
|
||||||
|
<div style={styles.background}>
|
||||||
|
<Header />
|
||||||
|
<p style={styles.text_medium_red}>An error has occured</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else if (!logged_in) {
|
||||||
|
return (
|
||||||
|
<div style={styles.background}>
|
||||||
|
<Header />
|
||||||
|
<p style={styles.text_medium_red}>Please login to view user info</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div style={styles.background}>
|
||||||
|
<Header />
|
||||||
|
<p style={styles.text_medium}>Username: {data.username}</p>
|
||||||
|
<p style={styles.text_medium}>Email: {data.email}</p>
|
||||||
|
<p style={styles.text_medium}>User ID: {data.id}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -9,12 +9,13 @@ import NewNote from "./Routes/NewNote/NewNote";
|
||||||
import Login from "./Routes/Login/Login";
|
import Login from "./Routes/Login/Login";
|
||||||
import Activation from "./Routes/Activation/Activation";
|
import Activation from "./Routes/Activation/Activation";
|
||||||
import Register from "./Routes/Register/Register";
|
import Register from "./Routes/Register/Register";
|
||||||
|
import UserPage from "./Routes/UserPage/UserPage";
|
||||||
|
import ViewEditNote from "./Routes/ViewEditNote/ViewEditNote";
|
||||||
|
|
||||||
import { QueryClient, QueryClientProvider } from "react-query";
|
import { QueryClient, QueryClientProvider } from "react-query";
|
||||||
|
|
||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
import Store from "./Features/Redux/Store/Store";
|
import Store from "./Features/Redux/Store/Store";
|
||||||
import ViewEditNote from "./Routes/ViewEditNote/ViewEditNote";
|
|
||||||
|
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
|
@ -43,6 +44,10 @@ const router = createBrowserRouter([
|
||||||
path: "/Note/:id",
|
path: "/Note/:id",
|
||||||
element: <ViewEditNote />,
|
element: <ViewEditNote />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/User",
|
||||||
|
element: <UserPage />,
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(
|
const root = ReactDOM.createRoot(
|
||||||
|
|
Loading…
Reference in a new issue