Compare commits
No commits in common. "7f5270f536597c31acfff8e0614d1ab516c1d0b0" and "49209663886040d52fb7554e37c1523c8b6ffe94" have entirely different histories.
7f5270f536
...
4920966388
16 changed files with 151 additions and 459 deletions
|
@ -118,7 +118,3 @@ uml: plantuml.jar
|
||||||
install-just:
|
install-just:
|
||||||
@echo "Installing just"
|
@echo "Installing just"
|
||||||
@curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
|
@curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
|
||||||
|
|
||||||
.PHONY: types
|
|
||||||
types:
|
|
||||||
tygo generate
|
|
|
@ -21,14 +21,13 @@ type Database interface {
|
||||||
AddProject(name string, description string, username string) error
|
AddProject(name string, description string, username string) error
|
||||||
Migrate(dirname string) error
|
Migrate(dirname string) error
|
||||||
GetProjectId(projectname string) (int, error)
|
GetProjectId(projectname string) (int, error)
|
||||||
AddTimeReport(projectName string, userName string, activityType string, start time.Time, end time.Time) error
|
AddTimeReport(projectName string, userName string, start time.Time, end time.Time) error
|
||||||
AddUserToProject(username string, projectname string, role string) error
|
AddUserToProject(username string, projectname string, role string) error
|
||||||
ChangeUserRole(username string, projectname string, role string) error
|
ChangeUserRole(username string, projectname string, role string) error
|
||||||
GetAllUsersProject(projectname string) ([]UserProjectMember, error)
|
GetAllUsersProject(projectname string) ([]UserProjectMember, error)
|
||||||
GetAllUsersApplication() ([]string, error)
|
GetAllUsersApplication() ([]string, error)
|
||||||
GetProjectsForUser(username string) ([]types.Project, error)
|
GetProjectsForUser(username string) ([]types.Project, error)
|
||||||
GetAllProjects() ([]types.Project, error)
|
GetAllProjects() ([]types.Project, error)
|
||||||
GetProject(projectId int) (types.Project, error)
|
|
||||||
GetUserRole(username string, projectname string) (string, error)
|
GetUserRole(username string, projectname string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +51,8 @@ const projectInsert = "INSERT INTO projects (name, description, owner_user_id) S
|
||||||
const promoteToAdmin = "INSERT INTO site_admin (admin_id) SELECT id FROM users WHERE username = ?"
|
const promoteToAdmin = "INSERT INTO site_admin (admin_id) SELECT id FROM users WHERE username = ?"
|
||||||
const addTimeReport = `WITH UserLookup AS (SELECT id FROM users WHERE username = ?),
|
const addTimeReport = `WITH UserLookup AS (SELECT id FROM users WHERE username = ?),
|
||||||
ProjectLookup AS (SELECT id FROM projects WHERE name = ?)
|
ProjectLookup AS (SELECT id FROM projects WHERE name = ?)
|
||||||
INSERT INTO time_reports (project_id, user_id, activity_type, start, end)
|
INSERT INTO time_reports (project_id, user_id, start, end)
|
||||||
VALUES ((SELECT id FROM ProjectLookup), (SELECT id FROM UserLookup),?, ?, ?);`
|
VALUES ((SELECT id FROM ProjectLookup), (SELECT id FROM UserLookup), ?, ?);`
|
||||||
const addUserToProject = "INSERT INTO user_roles (user_id, project_id, p_role) VALUES (?, ?, ?)" // WIP
|
const addUserToProject = "INSERT INTO user_roles (user_id, project_id, p_role) VALUES (?, ?, ?)" // WIP
|
||||||
const changeUserRole = "UPDATE user_roles SET p_role = ? WHERE user_id = ? AND project_id = ?"
|
const changeUserRole = "UPDATE user_roles SET p_role = ? WHERE user_id = ? AND project_id = ?"
|
||||||
|
|
||||||
|
@ -89,34 +88,23 @@ func DbConnect(dbpath string) Database {
|
||||||
return &Db{db}
|
return &Db{db}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProjectsForUser retrieves all projects associated with a specific user.
|
|
||||||
func (d *Db) GetProjectsForUser(username string) ([]types.Project, error) {
|
func (d *Db) GetProjectsForUser(username string) ([]types.Project, error) {
|
||||||
var projects []types.Project
|
var projects []types.Project
|
||||||
err := d.Select(&projects, getProjectsForUser, username)
|
err := d.Select(&projects, getProjectsForUser, username)
|
||||||
return projects, err
|
return projects, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllProjects retrieves all projects from the database.
|
|
||||||
func (d *Db) GetAllProjects() ([]types.Project, error) {
|
func (d *Db) GetAllProjects() ([]types.Project, error) {
|
||||||
var projects []types.Project
|
var projects []types.Project
|
||||||
err := d.Select(&projects, "SELECT * FROM projects")
|
err := d.Select(&projects, "SELECT * FROM projects")
|
||||||
return projects, err
|
return projects, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProject retrieves a specific project by its ID.
|
func (d *Db) AddTimeReport(projectName string, userName string, start time.Time, end time.Time) error { // WIP
|
||||||
func (d *Db) GetProject(projectId int) (types.Project, error) {
|
_, err := d.Exec(addTimeReport, userName, projectName, start, end)
|
||||||
var project types.Project
|
|
||||||
err := d.Select(&project, "SELECT * FROM projects WHERE id = ?")
|
|
||||||
return project, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddTimeReport adds a time report for a specific project and user.
|
|
||||||
func (d *Db) AddTimeReport(projectName string, userName string, activityType string, start time.Time, end time.Time) error { // WIP
|
|
||||||
_, err := d.Exec(addTimeReport, userName, projectName, activityType, start, end)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUserToProject adds a user to a project with a specified role.
|
|
||||||
func (d *Db) AddUserToProject(username string, projectname string, role string) error { // WIP
|
func (d *Db) AddUserToProject(username string, projectname string, role string) error { // WIP
|
||||||
var userid int
|
var userid int
|
||||||
userid, err := d.GetUserId(username)
|
userid, err := d.GetUserId(username)
|
||||||
|
@ -134,28 +122,23 @@ func (d *Db) AddUserToProject(username string, projectname string, role string)
|
||||||
return err3
|
return err3
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeUserRole changes the role of a user within a project.
|
|
||||||
func (d *Db) ChangeUserRole(username string, projectname string, role string) error {
|
func (d *Db) ChangeUserRole(username string, projectname string, role string) error {
|
||||||
// Get the user ID
|
|
||||||
var userid int
|
var userid int
|
||||||
userid, err := d.GetUserId(username)
|
userid, err := d.GetUserId(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the project ID
|
|
||||||
var projectid int
|
var projectid int
|
||||||
projectid, err2 := d.GetProjectId(projectname)
|
projectid, err2 := d.GetProjectId(projectname)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
panic(err2)
|
panic(err2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the SQL query to change the user's role
|
|
||||||
_, err3 := d.Exec(changeUserRole, role, userid, projectid)
|
_, err3 := d.Exec(changeUserRole, role, userid, projectid)
|
||||||
return err3
|
return err3
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserRole retrieves the role of a user within a project.
|
|
||||||
func (d *Db) GetUserRole(username string, projectname string) (string, error) {
|
func (d *Db) GetUserRole(username string, projectname string) (string, error) {
|
||||||
var role string
|
var role string
|
||||||
err := d.Get(&role, "SELECT p_role FROM user_roles WHERE user_id = (SELECT id FROM users WHERE username = ?) AND project_id = (SELECT id FROM projects WHERE name = ?)", username, projectname)
|
err := d.Get(&role, "SELECT p_role FROM user_roles WHERE user_id = (SELECT id FROM users WHERE username = ?) AND project_id = (SELECT id FROM projects WHERE name = ?)", username, projectname)
|
||||||
|
|
|
@ -112,7 +112,7 @@ func TestAddTimeReport(t *testing.T) {
|
||||||
var now = time.Now()
|
var now = time.Now()
|
||||||
var then = now.Add(time.Hour)
|
var then = now.Add(time.Hour)
|
||||||
|
|
||||||
err = db.AddTimeReport("testproject", "testuser", "activity", now, then)
|
err = db.AddTimeReport("testproject", "testuser", now, then)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("AddTimeReport failed:", err)
|
t.Error("AddTimeReport failed:", err)
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ func TestAddUserToProject(t *testing.T) {
|
||||||
var now = time.Now()
|
var now = time.Now()
|
||||||
var then = now.Add(time.Hour)
|
var then = now.Add(time.Hour)
|
||||||
|
|
||||||
err = db.AddTimeReport("testproject", "testuser", "activity", now, then)
|
err = db.AddTimeReport("testproject", "testuser", now, then)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("AddTimeReport failed:", err)
|
t.Error("AddTimeReport failed:", err)
|
||||||
}
|
}
|
||||||
|
@ -343,38 +343,3 @@ func TestGetProjectsForUser(t *testing.T) {
|
||||||
t.Error("GetProjectsForUser failed: expected 1, got", len(projects))
|
t.Error("GetProjectsForUser failed: expected 1, got", len(projects))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddProject(t *testing.T) {
|
|
||||||
db, err := setupState()
|
|
||||||
if err != nil {
|
|
||||||
t.Error("setupState failed:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = db.AddUser("testuser", "password")
|
|
||||||
if err != nil {
|
|
||||||
t.Error("AddUser failed:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = db.AddProject("testproject", "description", "testuser")
|
|
||||||
if err != nil {
|
|
||||||
t.Error("AddProject failed:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve the added project to verify its existence
|
|
||||||
projects, err := db.GetAllProjects()
|
|
||||||
if err != nil {
|
|
||||||
t.Error("GetAllProjects failed:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the project was added successfully
|
|
||||||
found := false
|
|
||||||
for _, project := range projects {
|
|
||||||
if project.Name == "testproject" {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
t.Error("Added project not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,12 +2,10 @@ CREATE TABLE IF NOT EXISTS time_reports (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
project_id INTEGER NOT NULL,
|
project_id INTEGER NOT NULL,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
activity_type TEXT NOT NULL,
|
|
||||||
start DATETIME NOT NULL,
|
start DATETIME NOT NULL,
|
||||||
end DATETIME NOT NULL,
|
end DATETIME NOT NULL,
|
||||||
FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE
|
FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE
|
||||||
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
||||||
FOREIGN KEY (activity_type) REFERENCES activity_types (name) ON DELETE CASCADE
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TRIGGER IF NOT EXISTS time_reports_start_before_end
|
CREATE TRIGGER IF NOT EXISTS time_reports_start_before_end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
-- It is unclear weather this table will be used
|
-- It is unclear weather this table will be used
|
||||||
|
|
||||||
-- Create the table to store hash salts
|
-- Create the table to store hash salts
|
||||||
CREATE TABLE IF NOT EXISTS salts (
|
CREATE TABLE salts (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
salt TEXT NOT NULL
|
salt TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS activity_types (
|
|
||||||
name TEXT PRIMARY KEY
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Development');
|
|
||||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Meeting');
|
|
||||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Administration');
|
|
||||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Own Work');
|
|
||||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Studies');
|
|
||||||
INSErt OR IGNORE INTO activity_types (name) VALUES ('Testing');
|
|
|
@ -1,7 +1,6 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
"ttime/internal/database"
|
"ttime/internal/database"
|
||||||
"ttime/internal/types"
|
"ttime/internal/types"
|
||||||
|
@ -226,24 +225,3 @@ func (gs *GState) ProjectRoleChange(c *fiber.Ctx) error {
|
||||||
// Return a success message
|
// Return a success message
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProject retrieves a specific project by its ID
|
|
||||||
func (gs *GState) GetProject(c *fiber.Ctx) error {
|
|
||||||
// Extract the project ID from the request parameters or body
|
|
||||||
projectID := c.Params("projectID")
|
|
||||||
|
|
||||||
// Parse the project ID into an integer
|
|
||||||
projectIDInt, err := strconv.Atoi(projectID)
|
|
||||||
if err != nil {
|
|
||||||
return c.Status(400).SendString("Invalid project ID")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the project from the database by its ID
|
|
||||||
project, err := gs.Db.GetProject(projectIDInt)
|
|
||||||
if err != nil {
|
|
||||||
return c.Status(500).SendString(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the project as JSON
|
|
||||||
return c.JSON(project)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
packages:
|
|
||||||
- path: "ttime/internal/types"
|
|
||||||
output_path: "../frontend/src/Types/goTypes.ts"
|
|
||||||
type_mappings:
|
|
||||||
time.Time: "string /* RFC3339 */"
|
|
||||||
null.String: "null | string"
|
|
||||||
null.Bool: "null | boolean"
|
|
||||||
uuid.UUID: "string /* uuid */"
|
|
||||||
uuid.NullUUID: "null | string /* uuid */"
|
|
|
@ -9,7 +9,7 @@ module.exports = {
|
||||||
'plugin:react-hooks/recommended',
|
'plugin:react-hooks/recommended',
|
||||||
'plugin:prettier/recommended',
|
'plugin:prettier/recommended',
|
||||||
],
|
],
|
||||||
ignorePatterns: ['dist', '.eslintrc.cjs', 'tailwind.config.js', 'postcss.config.js', 'jest.config.cjs', 'goTypes.ts'],
|
ignorePatterns: ['dist', '.eslintrc.cjs', 'tailwind.config.js', 'postcss.config.js', 'jest.config.cjs'],
|
||||||
parser: '@typescript-eslint/parser',
|
parser: '@typescript-eslint/parser',
|
||||||
plugins: ['react-refresh', 'prettier'],
|
plugins: ['react-refresh', 'prettier'],
|
||||||
rules: {
|
rules: {
|
||||||
|
|
|
@ -1,120 +1,57 @@
|
||||||
import { NewProject, Project } from "../Types/Project";
|
import { NewProject, Project } from "../Types/Project";
|
||||||
import { NewUser, User } from "../Types/Users";
|
import { NewUser, User } from "../Types/Users";
|
||||||
|
|
||||||
// This type of pattern should be hard to misuse
|
|
||||||
interface APIResponse<T> {
|
|
||||||
success: boolean;
|
|
||||||
message?: string;
|
|
||||||
data?: T;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note that all protected routes also require a token
|
|
||||||
// Defines all the methods that an instance of the API must implement
|
// Defines all the methods that an instance of the API must implement
|
||||||
interface API {
|
interface API {
|
||||||
/** Register a new user */
|
/** Register a new user */
|
||||||
registerUser(user: NewUser): Promise<APIResponse<User>>;
|
registerUser(user: NewUser): Promise<User>;
|
||||||
/** Remove a user */
|
/** Remove a user */
|
||||||
removeUser(username: string, token: string): Promise<APIResponse<User>>;
|
removeUser(username: string): Promise<User>;
|
||||||
/** Create a project */
|
/** Create a project */
|
||||||
createProject(
|
createProject(project: NewProject): Promise<Project>;
|
||||||
project: NewProject,
|
|
||||||
token: string,
|
|
||||||
): Promise<APIResponse<Project>>;
|
|
||||||
/** Renew the token */
|
/** Renew the token */
|
||||||
renewToken(token: string): Promise<APIResponse<string>>;
|
renewToken(token: string): Promise<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export an instance of the API
|
// Export an instance of the API
|
||||||
export const api: API = {
|
export const api: API = {
|
||||||
async registerUser(user: NewUser): Promise<APIResponse<User>> {
|
async registerUser(user: NewUser): Promise<User> {
|
||||||
try {
|
return fetch("/api/register", {
|
||||||
const response = await fetch("/api/register", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(user),
|
body: JSON.stringify(user),
|
||||||
});
|
}).then((res) => res.json() as Promise<User>);
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
return { success: false, message: "Failed to register user" };
|
|
||||||
} else {
|
|
||||||
const data = (await response.json()) as User;
|
|
||||||
return { success: true, data };
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return { success: false, message: "Failed to register user" };
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async removeUser(
|
async removeUser(username: string): Promise<User> {
|
||||||
username: string,
|
return fetch("/api/userdelete", {
|
||||||
token: string,
|
|
||||||
): Promise<APIResponse<User>> {
|
|
||||||
try {
|
|
||||||
const response = await fetch("/api/userdelete", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify(username),
|
body: JSON.stringify(username),
|
||||||
});
|
}).then((res) => res.json() as Promise<User>);
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
return { success: false, message: "Failed to remove user" };
|
|
||||||
} else {
|
|
||||||
const data = (await response.json()) as User;
|
|
||||||
return { success: true, data };
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return { success: false, message: "Failed to remove user" };
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async createProject(
|
async createProject(project: NewProject): Promise<Project> {
|
||||||
project: NewProject,
|
return fetch("/api/project", {
|
||||||
token: string,
|
|
||||||
): Promise<APIResponse<Project>> {
|
|
||||||
try {
|
|
||||||
const response = await fetch("/api/project", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify(project),
|
body: JSON.stringify(project),
|
||||||
});
|
}).then((res) => res.json() as Promise<Project>);
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
return { success: false, message: "Failed to create project" };
|
|
||||||
} else {
|
|
||||||
const data = (await response.json()) as Project;
|
|
||||||
return { success: true, data };
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return { success: false, message: "Failed to create project" };
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async renewToken(token: string): Promise<APIResponse<string>> {
|
async renewToken(token: string): Promise<string> {
|
||||||
try {
|
return fetch("/api/loginrenew", {
|
||||||
const response = await fetch("/api/loginrenew", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + token,
|
Authorization: "Bearer " + token,
|
||||||
},
|
},
|
||||||
});
|
}).then((res) => res.json() as Promise<string>);
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
return { success: false, message: "Failed to renew token" };
|
|
||||||
} else {
|
|
||||||
const data = (await response.json()) as string;
|
|
||||||
return { success: true, data };
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return { success: false, message: "Failed to renew token" };
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,32 +4,6 @@ import { api } from "../API/API";
|
||||||
import Logo from "../assets/Logo.svg";
|
import Logo from "../assets/Logo.svg";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
|
|
||||||
function InputField(props: {
|
|
||||||
label: string;
|
|
||||||
type: string;
|
|
||||||
value: string;
|
|
||||||
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
||||||
}): JSX.Element {
|
|
||||||
return (
|
|
||||||
<div className="mb-4">
|
|
||||||
<label
|
|
||||||
className="block text-gray-700 text-sm font-sans font-bold mb-2"
|
|
||||||
htmlFor={props.label}
|
|
||||||
>
|
|
||||||
{props.label}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
className="appearance-none border-2 border-black rounded-2xl w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
|
|
||||||
id={props.label}
|
|
||||||
type={props.type}
|
|
||||||
placeholder={props.label}
|
|
||||||
value={props.value}
|
|
||||||
onChange={props.onChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Register(): JSX.Element {
|
export default function Register(): JSX.Element {
|
||||||
const [username, setUsername] = useState("");
|
const [username, setUsername] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
|
@ -40,7 +14,7 @@ export default function Register(): JSX.Element {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-fit w-screen items-center justify-center">
|
<div className="flex flex-col h-screen w-screen items-center justify-center">
|
||||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center h-fit w-fit rounded-3xl content-center pl-20 pr-20">
|
<div className="border-4 border-black bg-white flex flex-col items-center justify-center h-fit w-fit rounded-3xl content-center pl-20 pr-20">
|
||||||
<form
|
<form
|
||||||
className="bg-white rounded px-8 pt-6 pb-8 mb-4 items-center justify-center flex flex-col w-fit h-fit"
|
className="bg-white rounded px-8 pt-6 pb-8 mb-4 items-center justify-center flex flex-col w-fit h-fit"
|
||||||
|
@ -57,22 +31,42 @@ export default function Register(): JSX.Element {
|
||||||
<h3 className="pb-4 mb-2 text-center font-bold text-[18px]">
|
<h3 className="pb-4 mb-2 text-center font-bold text-[18px]">
|
||||||
Register New User
|
Register New User
|
||||||
</h3>
|
</h3>
|
||||||
<InputField
|
<div className="mb-4">
|
||||||
label="Username"
|
<label
|
||||||
|
className="block text-gray-700 text-sm font-sans font-bold mb-2"
|
||||||
|
htmlFor="username"
|
||||||
|
>
|
||||||
|
Username
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
className="appearance-none border-2 border-black rounded-2xl w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
|
||||||
|
id="username"
|
||||||
type="text"
|
type="text"
|
||||||
|
placeholder="Username"
|
||||||
value={username}
|
value={username}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setUsername(e.target.value);
|
setUsername(e.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<InputField
|
</div>
|
||||||
label="Password"
|
<div className="mb-6">
|
||||||
|
<label
|
||||||
|
className="block text-gray-700 text-sm font-sans font-bold mb-2"
|
||||||
|
htmlFor="password"
|
||||||
|
>
|
||||||
|
Password
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
className="appearance-none border-2 border-black rounded-2xl w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
|
||||||
|
id="password"
|
||||||
type="password"
|
type="password"
|
||||||
|
placeholder="Choose your password"
|
||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setPassword(e.target.value);
|
setPassword(e.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<Button
|
<Button
|
||||||
text="Register"
|
text="Register"
|
||||||
|
|
|
@ -1,58 +1,20 @@
|
||||||
import { useState } from "react";
|
function NewTimeReport(): JSX.Element {
|
||||||
import { TimeReport } from "../Types/TimeReport";
|
const activities = [
|
||||||
import { api } from "../API/API";
|
"Development",
|
||||||
import { useNavigate } from "react-router-dom";
|
"Meeting",
|
||||||
import Button from "./Button";
|
"Administration",
|
||||||
|
"Own Work",
|
||||||
export default function NewTimeReport(): JSX.Element {
|
"Studies",
|
||||||
const [week, setWeek] = useState("");
|
"Testing",
|
||||||
const [development, setDevelopment] = useState("0");
|
];
|
||||||
const [meeting, setMeeting] = useState("0");
|
|
||||||
const [administration, setAdministration] = useState("0");
|
|
||||||
const [ownwork, setOwnWork] = useState("0");
|
|
||||||
const [studies, setStudies] = useState("0");
|
|
||||||
const [testing, setTesting] = useState("0");
|
|
||||||
|
|
||||||
const handleNewTimeReport = async (): Promise<void> => {
|
|
||||||
const newTimeReport: TimeReport = {
|
|
||||||
week,
|
|
||||||
development,
|
|
||||||
meeting,
|
|
||||||
administration,
|
|
||||||
ownwork,
|
|
||||||
studies,
|
|
||||||
testing,
|
|
||||||
};
|
|
||||||
await Promise.resolve();
|
|
||||||
// await api.registerTimeReport(newTimeReport); This needs to be implemented!
|
|
||||||
};
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
||||||
<form
|
|
||||||
onSubmit={(e) => {
|
|
||||||
if (week === "") {
|
|
||||||
alert("Please enter a week number");
|
|
||||||
e.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
e.preventDefault();
|
|
||||||
void handleNewTimeReport();
|
|
||||||
navigate("/project");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div className="flex flex-col items-center">
|
|
||||||
<input
|
<input
|
||||||
className="w-fill h-[5vh] font-sans text-[3vh] pl-[1vw] rounded-full text-center pt-[1vh] pb-[1vh] border-2 border-black"
|
className="w-fill h-[5vh] font-sans text-[3vh] pl-[1vw] rounded-full text-center pt-[1vh] pb-[1vh] border-2 border-black"
|
||||||
type="week"
|
type="week"
|
||||||
placeholder="Week"
|
placeholder="Week"
|
||||||
onChange={(e) => {
|
|
||||||
const weekNumber = e.target.value.split("-W")[1];
|
|
||||||
setWeek(weekNumber);
|
|
||||||
}}
|
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
|
@ -63,121 +25,21 @@ export default function NewTimeReport(): JSX.Element {
|
||||||
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th className="w-1/2 py-2 border-b-2 border-black">
|
<th className="w-1/2 py-2 border-b-2 border-black">Activity</th>
|
||||||
Activity
|
|
||||||
</th>
|
|
||||||
<th className="w-1/2 py-2 border-b-2 border-black">
|
<th className="w-1/2 py-2 border-b-2 border-black">
|
||||||
Total Time (min)
|
Total Time (min)
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="divide-y divide-black">
|
<tbody className="divide-y divide-black">
|
||||||
<tr className="h-[10vh]">
|
{activities.map((activity, index) => (
|
||||||
<td>Development</td>
|
<tr key={index} className="h-[10vh]">
|
||||||
|
<td>{activity}</td>
|
||||||
<td>
|
<td>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
className="border-2 border-black rounded-md text-center w-1/2"
|
||||||
value={development}
|
|
||||||
onChange={(e) => {
|
|
||||||
setDevelopment(e.target.value);
|
|
||||||
}}
|
|
||||||
onKeyDown={(event) => {
|
|
||||||
const keyValue = event.key;
|
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr className="h-[10vh]">
|
|
||||||
<td>Meeting</td>
|
|
||||||
<td>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
|
||||||
value={meeting}
|
|
||||||
onChange={(e) => {
|
|
||||||
setMeeting(e.target.value);
|
|
||||||
}}
|
|
||||||
onKeyDown={(event) => {
|
|
||||||
const keyValue = event.key;
|
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr className="h-[10vh]">
|
|
||||||
<td>Administration</td>
|
|
||||||
<td>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
|
||||||
value={administration}
|
|
||||||
onChange={(e) => {
|
|
||||||
setAdministration(e.target.value);
|
|
||||||
}}
|
|
||||||
onKeyDown={(event) => {
|
|
||||||
const keyValue = event.key;
|
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr className="h-[10vh]">
|
|
||||||
<td>Own Work</td>
|
|
||||||
<td>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
|
||||||
value={ownwork}
|
|
||||||
onChange={(e) => {
|
|
||||||
setOwnWork(e.target.value);
|
|
||||||
}}
|
|
||||||
onKeyDown={(event) => {
|
|
||||||
const keyValue = event.key;
|
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr className="h-[10vh]">
|
|
||||||
<td>Studies</td>
|
|
||||||
<td>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
|
||||||
value={studies}
|
|
||||||
onChange={(e) => {
|
|
||||||
setStudies(e.target.value);
|
|
||||||
}}
|
|
||||||
onKeyDown={(event) => {
|
|
||||||
const keyValue = event.key;
|
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr className="h-[10vh]">
|
|
||||||
<td>Testing</td>
|
|
||||||
<td>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
className="border-2 border-black rounded-md text-center w-1/2"
|
|
||||||
value={testing}
|
|
||||||
onChange={(e) => {
|
|
||||||
setTesting(e.target.value);
|
|
||||||
}}
|
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
|
@ -186,18 +48,12 @@ export default function NewTimeReport(): JSX.Element {
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<Button
|
|
||||||
text="Submit"
|
|
||||||
onClick={(): void => {
|
|
||||||
return;
|
|
||||||
}}
|
|
||||||
type="submit"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default NewTimeReport;
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
import BasicWindow from "../../Components/BasicWindow";
|
||||||
import Button from "../../Components/Button";
|
import Button from "../../Components/Button";
|
||||||
import Register from "../../Components/Register";
|
|
||||||
|
|
||||||
function AdminAddUser(): JSX.Element {
|
function AdminAddUser(): JSX.Element {
|
||||||
const content = (
|
const content = <></>;
|
||||||
<>
|
|
||||||
<Register />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
const buttons = (
|
const buttons = (
|
||||||
<>
|
<>
|
||||||
|
<Button
|
||||||
|
text="Finish"
|
||||||
|
onClick={(): void => {
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
/>
|
||||||
<Button
|
<Button
|
||||||
text="Back"
|
text="Back"
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
|
|
|
@ -13,6 +13,13 @@ function UserNewTimeReportPage(): JSX.Element {
|
||||||
|
|
||||||
const buttons = (
|
const buttons = (
|
||||||
<>
|
<>
|
||||||
|
<Button
|
||||||
|
text="Submit"
|
||||||
|
onClick={(): void => {
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
/>
|
||||||
<Link to="/project">
|
<Link to="/project">
|
||||||
<Button
|
<Button
|
||||||
text="Back"
|
text="Back"
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
export interface TimeReport {
|
|
||||||
week: string;
|
|
||||||
development: string;
|
|
||||||
meeting: string;
|
|
||||||
administration: string;
|
|
||||||
ownwork: string;
|
|
||||||
studies: string;
|
|
||||||
testing: string;
|
|
||||||
}
|
|
|
@ -57,6 +57,10 @@ const router = createBrowserRouter([
|
||||||
path: "/register",
|
path: "/register",
|
||||||
element: <Register />,
|
element: <Register />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/admin-menu",
|
||||||
|
element: <AdminMenuPage />,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/project-page",
|
path: "/project-page",
|
||||||
element: <UserViewTimeReportsPage />,
|
element: <UserViewTimeReportsPage />,
|
||||||
|
|
Loading…
Reference in a new issue