mirror of
https://github.com/lemeow125/EquipmentTracker-Frontend.git
synced 2024-11-17 06:09:25 +08:00
Improved registration and activation functionality
This commit is contained in:
parent
8a2c702da3
commit
742a1af9f8
7 changed files with 111 additions and 5 deletions
10
src/App.tsx
10
src/App.tsx
|
@ -9,6 +9,7 @@ import "react-toastify/dist/ReactToastify.css";
|
||||||
import ErrorPage from "./Pages/ErrorPage/ErrorPage";
|
import ErrorPage from "./Pages/ErrorPage/ErrorPage";
|
||||||
import DashboardPage from "./Pages/DashboardPage/DashboardPage";
|
import DashboardPage from "./Pages/DashboardPage/DashboardPage";
|
||||||
import Revalidator from "./Components/Revalidator/Revalidator";
|
import Revalidator from "./Components/Revalidator/Revalidator";
|
||||||
|
import ActivationPage from "./Pages/ActivationPage/ActivationPage";
|
||||||
|
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
const router = createHashRouter([
|
const router = createHashRouter([
|
||||||
|
@ -32,6 +33,15 @@ const router = createHashRouter([
|
||||||
),
|
),
|
||||||
errorElement: <ErrorPage />,
|
errorElement: <ErrorPage />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/activation/:uid/:token",
|
||||||
|
element: (
|
||||||
|
<>
|
||||||
|
<ActivationPage />
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
errorElement: <ErrorPage />,
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
|
|
@ -121,7 +121,7 @@ export async function UserAPI() {
|
||||||
export function ActivationAPI(activation: ActivationType) {
|
export function ActivationAPI(activation: ActivationType) {
|
||||||
return instance
|
return instance
|
||||||
.post("api/v1/accounts/users/activation/", activation)
|
.post("api/v1/accounts/users/activation/", activation)
|
||||||
.then(async () => {
|
.then(() => {
|
||||||
console.log("Activation Success");
|
console.log("Activation Success");
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { useDispatch } from "react-redux";
|
||||||
import { auth_toggle } from "../Plugins/Redux/Slices/AuthSlice/AuthSlice";
|
import { auth_toggle } from "../Plugins/Redux/Slices/AuthSlice/AuthSlice";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
export default function Sidebar() {
|
export default function Drawer() {
|
||||||
const user = useQuery({ queryKey: ["user"], queryFn: UserAPI });
|
const user = useQuery({ queryKey: ["user"], queryFn: UserAPI });
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
|
@ -1,7 +1,7 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import styles, { colors } from "../../styles";
|
import styles, { colors } from "../../styles";
|
||||||
import MenuIcon from "@mui/icons-material/Menu";
|
import MenuIcon from "@mui/icons-material/Menu";
|
||||||
import SidebarModal from "../Sidebar/Sidebar";
|
import SidebarModal from "../Drawer/Drawer";
|
||||||
import { Drawer } from "@mui/material";
|
import { Drawer } from "@mui/material";
|
||||||
export interface props {
|
export interface props {
|
||||||
label: string;
|
label: string;
|
||||||
|
|
|
@ -29,7 +29,11 @@ export default function LoginModal() {
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
...styles.flex_row,
|
...styles.flex_row,
|
||||||
...{ alignItems: "center", justifyContent: "center" },
|
...{
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
overflowY: "scroll",
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<LoginIcon
|
<LoginIcon
|
||||||
|
|
|
@ -29,7 +29,11 @@ export default function RegisterModal() {
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
...styles.flex_row,
|
...styles.flex_row,
|
||||||
...{ alignItems: "center", justifyContent: "center" },
|
...{
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
overflowY: "scroll",
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AppRegistration
|
<AppRegistration
|
||||||
|
|
88
src/Pages/ActivationPage/ActivationPage.tsx
Normal file
88
src/Pages/ActivationPage/ActivationPage.tsx
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
|
import styles, { colors } from "../../styles";
|
||||||
|
import { ActivationAPI } from "../../Components/API/API";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { CircularProgress } from "@mui/material";
|
||||||
|
import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline";
|
||||||
|
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
export default function ActivationPage() {
|
||||||
|
const { uid, token } = useParams();
|
||||||
|
const [feedback, setFeedback] = useState("");
|
||||||
|
const [error, setError] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
useEffect(() => {
|
||||||
|
if (uid && token && feedback == "") {
|
||||||
|
ActivationAPI({ uid, token }).then((response) => {
|
||||||
|
if (response) {
|
||||||
|
setFeedback("Activation successful");
|
||||||
|
toast("Activation successful", {
|
||||||
|
position: "top-right",
|
||||||
|
autoClose: 2000,
|
||||||
|
hideProgressBar: false,
|
||||||
|
closeOnClick: true,
|
||||||
|
pauseOnHover: true,
|
||||||
|
draggable: true,
|
||||||
|
progress: undefined,
|
||||||
|
theme: "light",
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
navigate("/dashboard");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setFeedback("Invalid activation link");
|
||||||
|
setError(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!uid || !token) {
|
||||||
|
setFeedback("Missing uid or token");
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
}, [uid, token, feedback, navigate]);
|
||||||
|
return (
|
||||||
|
<div style={styles.background}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
...styles.flex_column,
|
||||||
|
...{
|
||||||
|
alignItems: "center",
|
||||||
|
alignSelf: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
height: "100%",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<CircularProgress style={{ height: "128px", width: "128px" }} />
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
{error && !loading ? (
|
||||||
|
<ErrorOutlineIcon
|
||||||
|
style={{ height: "128px", width: "128px", color: colors.red }}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<CheckCircleOutlineIcon
|
||||||
|
style={{ height: "128px", width: "128px", color: colors.green }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<p style={{ ...styles.text_dark, ...styles.text_L }}>{feedback}</p>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
backgroundColor: colors.header_color,
|
||||||
|
marginTop: "16px",
|
||||||
|
width: "30%",
|
||||||
|
height: "4px",
|
||||||
|
marginBottom: 8,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<p style={{ ...styles.text_dark, ...styles.text_L }}>
|
||||||
|
Activating your CITC Equipment Tracker Account
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue