diff --git a/src/frontend/src/components/PaginatorComponent/index.tsx b/src/frontend/src/components/PaginatorComponent/index.tsx
index 8fcd8683f..ebad18506 100644
--- a/src/frontend/src/components/PaginatorComponent/index.tsx
+++ b/src/frontend/src/components/PaginatorComponent/index.tsx
@@ -12,16 +12,16 @@ import { Button } from "../ui/button";
export default function PaginatorComponent({
pageSize = 10,
- pageIndex = 1,
- rowsCount = [10, 20, 30],
+ pageIndex = 0,
+ rowsCount = [10, 20, 50, 100],
totalRowsCount = 0,
paginate,
}: PaginatorComponentType) {
+
const [size, setPageSize] = useState(pageSize);
const [index, setPageIndex] = useState(pageIndex);
-
const [maxIndex, setMaxPageIndex] = useState(
- Math.ceil(totalRowsCount / pageSize)
+ 100
);
return (
@@ -34,8 +34,8 @@ export default function PaginatorComponent({
- Page {index} of {maxIndex}
+ Page {index+1} of {maxIndex}
{
- setUserName(input.target.value);
+ onChange={({ target: { value } }) => {
+ handleInput({ target: { name: "username", value } });
+ setUserName(value);
}}
value={username}
className="primary-input"
@@ -104,21 +122,38 @@ export default function UserManagementModal({
justifyContent: "space-between",
}}
>
-
+
Password{" "}
- *
+
+ *
+
+ {pwdVisible && (
+ setPwdVisible(!pwdVisible)}
+ className="h-5 cursor-pointer" strokeWidth={1.5} />
+ )}
+
+ {!pwdVisible && (
+ setPwdVisible(!pwdVisible)}
+ className="h-5 cursor-pointer" strokeWidth={1.5} />
+ )}
+
{
- setPassword(input.target.value);
+ onChange={({ target: { value } }) => {
+ handleInput({ target: { name: "password", value } });
+ setPassword(value);
}}
value={password}
className="primary-input"
required
+ type={pwdVisible ? "text" : "password"}
/>
+
Please enter a password
@@ -143,9 +178,22 @@ export default function UserManagementModal({
justifyContent: "space-between",
}}
>
-
+
Confirm password{" "}
- *
+
+ *
+
+ {confirmPwdVisible && (
+ setConfirmPwdVisible(!confirmPwdVisible)}
+ className="h-5 cursor-pointer" strokeWidth={1.5} />
+ )}
+
+ {!confirmPwdVisible && (
+ setConfirmPwdVisible(!confirmPwdVisible)}
+ className="h-5 cursor-pointer" strokeWidth={1.5} />
+ )}
@@ -156,6 +204,7 @@ export default function UserManagementModal({
value={confirmPassword}
className="primary-input"
required
+ type={confirmPwdVisible ? "text" : "password"}
/>
@@ -164,57 +213,49 @@ export default function UserManagementModal({
+
+
+
+
+ Disabled
+
+
+ {
+ handleInput({ target: { name: "is_disabled", value } });
+ setIsDisabled(value);
+ }}
+ />
+
+
+
- {/*
-
-
-
- Email *
-
-
- Please enter your email
-
-
- Please provide a valid email
-
-
-
-
-
- */}
-
- {/*
-
-
-
- Date of birth{" "}
- *
-
-
- Please enter your date of birth
-
-
-
-
-
- */}
+
+
+
+ Superuser
+
+
+ {
+ handleInput({
+ target: { name: "is_superuser", value },
+ });
+ setIsSuperUser(value);
+ }}
+ />
+
+
+
+
diff --git a/src/frontend/src/pages/AdminPage/LoginPage/index.tsx b/src/frontend/src/pages/AdminPage/LoginPage/index.tsx
index 74cc75d07..bcc545e9b 100644
--- a/src/frontend/src/pages/AdminPage/LoginPage/index.tsx
+++ b/src/frontend/src/pages/AdminPage/LoginPage/index.tsx
@@ -1,12 +1,49 @@
+import { useContext, useState } from "react";
import { useNavigate } from "react-router-dom";
import { Button } from "../../../components/ui/button";
import { Input } from "../../../components/ui/input";
+import { CONTROL_LOGIN_STATE } from "../../../constants/constants";
+import { alertContext } from "../../../contexts/alertContext";
+import { AuthContext } from "../../../contexts/authContext";
+import { onLogin } from "../../../controllers/API";
+import { LoginType } from "../../../types/api";
+import {
+ inputHandlerEventType,
+ loginInputStateType,
+} from "../../../types/components";
export default function LoginAdminPage() {
const navigate = useNavigate();
- function loginAdmin() {
- navigate("/admin/");
+ const [inputState, setInputState] =
+ useState
(CONTROL_LOGIN_STATE);
+ const { login } = useContext(AuthContext);
+
+ const { password, username } = inputState;
+ const { setErrorData } = useContext(alertContext);
+
+ function handleInput({
+ target: { name, value },
+ }: inputHandlerEventType): void {
+ setInputState((prev) => ({ ...prev, [name]: value }));
+ }
+
+ function signIn() {
+ const user: LoginType = {
+ username: username,
+ password: password,
+ };
+ onLogin(user)
+ .then((user) => {
+ login(user.access_token, user.refresh_token);
+ navigate("/admin/");
+ })
+ .catch((error) => {
+ setErrorData({
+ title: "Error signing in",
+ list: [error["response"]["data"]["detail"]],
+ });
+ });
}
return (
@@ -14,11 +51,24 @@ export default function LoginAdminPage() {
⛓️
Admin
-
-
+
{
+ handleInput({ target: { name: "username", value } });
+ }}
+ className="bg-background"
+ placeholder="Username"
+ />
+
{
+ handleInput({ target: { name: "password", value } });
+ }}
+ className="bg-background"
+ placeholder="Password"
+ />
- {userList.current.length === 0 && (
+ {userList.current.length === 0 && !loadingUsers && (
<>
-
There's no users left :)
+ There's no users registered :)
>
)}
- {userList.current.length > 0 && (
- <>
-
-
- handleFilterUsers(e.target.value)}
- />
- {inputValue.length > 0 && (
-
- )}
-
-
-
{
- handleNewUser(user);
+ <>
+
+
+ handleFilterUsers(e.target.value)}
+ />
+ {inputValue.length > 0 && (
+
+ Reset
+
+
+ )}
-
-
-
-
- User
- Password
-
-
-
+
+ {
+ handleNewUser(user);
+ }}
+ >
+ New User
+
+
+
+ {loadingUsers && (
+
+ Loading...
+
+ )}
+
+
+
+
+ Id
+ Username
+ Disabled
+ Superuser
+ Created At
+ Updated At
+
+
+
+ {!loadingUsers && (
{filterUserList.map((user, index) => (
-
+
- {user.user}
+
+
+ {user.id}
+
+
- {user.password}
+
+
+ {user.username}
+
+
+
+
+
+
+
+
+
+
+ {
+ new Date(user.create_at)
+ .toISOString()
+ .split("T")[0]
+ }
+
+
+ {
+ new Date(user.updated_at)
+ .toISOString()
+ .split("T")[0]
+ }
{
- handleEditUser(index, user);
+ onConfirm={(index, editUser) => {
+ handleEditUser(user.id, editUser);
}}
>
@@ -365,7 +307,7 @@ export default function AdminPage() {
data={user}
index={index}
onConfirm={(index, user) => {
- handleDeleteUser(index);
+ handleDeleteUser(user);
}}
>
@@ -380,18 +322,19 @@ export default function AdminPage() {
))}
-
-
- {
- handleChangePagination(pageSize, pageIndex);
- }}
- >
- >
- )}
+ )}
+
+
+
+ {
+ handleChangePagination(pageSize, pageIndex);
+ }}
+ >
+ >
diff --git a/src/frontend/src/pages/loginPage/index.tsx b/src/frontend/src/pages/loginPage/index.tsx
index de9f9342f..aaa07096a 100644
--- a/src/frontend/src/pages/loginPage/index.tsx
+++ b/src/frontend/src/pages/loginPage/index.tsx
@@ -6,15 +6,14 @@ import InputComponent from "../../components/inputComponent";
import { Button } from "../../components/ui/button";
import { Input } from "../../components/ui/input";
import { CONTROL_LOGIN_STATE } from "../../constants/constants";
+import { alertContext } from "../../contexts/alertContext";
+import { AuthContext } from "../../contexts/authContext";
+import { onLogin } from "../../controllers/API";
+import { LoginType } from "../../types/api";
import {
inputHandlerEventType,
loginInputStateType,
} from "../../types/components";
-import { onLogin } from "../../controllers/API";
-import { LoginType } from "../../types/api";
-import { AuthContext } from "../../contexts/authContext";
-import { alertContext } from "../../contexts/alertContext";
-import { error } from "console";
export default function LoginPage(): JSX.Element {
const [inputState, setInputState] =
@@ -31,25 +30,22 @@ export default function LoginPage(): JSX.Element {
setInputState((prev) => ({ ...prev, [name]: value }));
}
- function signIn(){
-
+ function signIn() {
const user: LoginType = {
username: username,
- password: password
+ password: password,
};
-
- onLogin(
- user
- ).then((user) => {
+ onLogin(user)
+ .then((user) => {
login(user.access_token, user.refresh_token);
navigate("/");
- }).catch(error => {
+ })
+ .catch((error) => {
setErrorData({
title: "Error signing in",
- list: [error['response']['data']['detail']],
- })
+ list: [error["response"]["data"]["detail"]],
+ });
});
-
}
return (
@@ -137,9 +133,9 @@ export default function LoginPage(): JSX.Element {
- signIn()}
- className="mr-3 mt-6 w-full">Sign in
+ signIn()} className="mr-3 mt-6 w-full">
+ Sign in
+
diff --git a/src/frontend/src/routes.tsx b/src/frontend/src/routes.tsx
index db0c47770..4875478f9 100644
--- a/src/frontend/src/routes.tsx
+++ b/src/frontend/src/routes.tsx
@@ -1,5 +1,6 @@
import { Route, Routes } from "react-router-dom";
import { ProtectedRoute } from "./components/authGuard";
+import { ProtectedLoginRoute } from "./components/authLoginGuard";
import AdminPage from "./pages/AdminPage";
import LoginAdminPage from "./pages/AdminPage/LoginPage";
import CommunityPage from "./pages/CommunityPage";
@@ -47,9 +48,30 @@ const Router = () => {
}
/>
- } />
- } />
- } />
+
+
+
+ }
+ />
+
+
+
+ }
+ />
+
+
+
+ }
+ />