Compare commits
57 commits
c1f49915ba
...
4d7b3e0d57
Author | SHA1 | Date | |
---|---|---|---|
|
4d7b3e0d57 | ||
|
1b4e521508 | ||
|
a7cc48d392 | ||
|
ff37236cf6 | ||
|
eb741ba20d | ||
|
00ca5514e5 | ||
|
7c7755085e | ||
|
1e1677fc57 | ||
|
0b8b430f38 | ||
|
93659a72dc | ||
|
8d6da684bf | ||
|
762a1b7368 | ||
|
398305d3ed | ||
|
6c2213b488 | ||
|
b3e363f391 | ||
|
51a4d2a0b7 | ||
|
524bd6c691 | ||
|
b50d88f670 | ||
|
3ed4393c77 | ||
|
75876e43da | ||
|
ea5bbf5f0a | ||
|
948dcce1ca | ||
|
cb68a6323b | ||
|
ca88daf493 | ||
|
644d0ee12c | ||
|
6efc961774 | ||
|
7df1654bdc | ||
|
6dfa917cf0 | ||
|
17a571fd7c | ||
|
f3466854c7 | ||
|
1212b3c5ef | ||
|
dc98fb510e | ||
|
58deef400a | ||
|
cc039d27ae | ||
|
3981190c7a | ||
|
9b0a231701 | ||
|
e06aced6dd | ||
|
68fbbb4b19 | ||
|
378dd99592 | ||
|
6fa8135e32 | ||
|
60fb333090 | ||
|
e7911574be | ||
|
0c8a394f74 | ||
|
5f42fa7818 | ||
|
8b6462abee | ||
|
4ab23b3c3c | ||
|
bc9b01d85a | ||
|
d2b4bf2a89 | ||
|
8d5329146d | ||
|
77f028fd39 | ||
|
f1e15137d6 | ||
|
87a19bfd4e | ||
|
c2fa9aa0c1 | ||
|
1385011769 | ||
|
374e357820 | ||
|
b036ef906c | ||
|
85795f5406 |
54 changed files with 1542 additions and 882 deletions
|
@ -34,6 +34,7 @@ clean:
|
||||||
rm -f plantuml.jar
|
rm -f plantuml.jar
|
||||||
rm -f erd.png
|
rm -f erd.png
|
||||||
rm -f config.toml
|
rm -f config.toml
|
||||||
|
rm -f database.txt
|
||||||
|
|
||||||
# Test target
|
# Test target
|
||||||
test: db.sqlite3
|
test: db.sqlite3
|
||||||
|
@ -105,6 +106,7 @@ docs:
|
||||||
swag init -outputTypes go
|
swag init -outputTypes go
|
||||||
|
|
||||||
api: ./docs/swagger.json
|
api: ./docs/swagger.json
|
||||||
|
rm ../frontend/src/API/GenApi.ts
|
||||||
npx swagger-typescript-api \
|
npx swagger-typescript-api \
|
||||||
--api-class-name GenApi \
|
--api-class-name GenApi \
|
||||||
--path ./docs/swagger.json \
|
--path ./docs/swagger.json \
|
||||||
|
|
|
@ -21,21 +21,21 @@ const docTemplate = `{
|
||||||
"paths": {
|
"paths": {
|
||||||
"/login": {
|
"/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "logs the user in and returns a jwt token",
|
"description": "Logs in a user and returns a JWT token",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"produces": [
|
"produces": [
|
||||||
"text/plain"
|
"application/json"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"User"
|
"Auth"
|
||||||
],
|
],
|
||||||
"summary": "login",
|
"summary": "Login",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "login info",
|
"description": "User credentials",
|
||||||
"name": "NewUser",
|
"name": "body",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
|
@ -45,9 +45,9 @@ const docTemplate = `{
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Successfully signed token for user",
|
"description": "JWT token",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "Token"
|
"$ref": "#/definitions/types.Token"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
|
@ -71,29 +71,26 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/loginerenew": {
|
"/loginrenew": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"bererToken": []
|
"JWT": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "renews the users token",
|
"description": "Renews the users token.",
|
||||||
"consumes": [
|
"produces": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"produces": [
|
|
||||||
"text/plain"
|
|
||||||
],
|
|
||||||
"tags": [
|
"tags": [
|
||||||
"User"
|
"Auth"
|
||||||
],
|
],
|
||||||
"summary": "LoginRenews",
|
"summary": "LoginRenews",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Successfully signed token for user",
|
"description": "Successfully signed token for user",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "Token"
|
"$ref": "#/definitions/types.Token"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
|
@ -113,7 +110,12 @@ const docTemplate = `{
|
||||||
},
|
},
|
||||||
"/promoteToAdmin": {
|
"/promoteToAdmin": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "promote chosen user to admin",
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Promote chosen user to site admin",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
@ -139,7 +141,7 @@ const docTemplate = `{
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Successfully promoted user",
|
"description": "Successfully promoted user",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "json"
|
"$ref": "#/definitions/types.Token"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
|
@ -173,7 +175,7 @@ const docTemplate = `{
|
||||||
"text/plain"
|
"text/plain"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"User"
|
"Auth"
|
||||||
],
|
],
|
||||||
"summary": "Register",
|
"summary": "Register",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
@ -211,6 +213,11 @@ const docTemplate = `{
|
||||||
},
|
},
|
||||||
"/userdelete/{username}": {
|
"/userdelete/{username}": {
|
||||||
"delete": {
|
"delete": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"JWT": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"description": "UserDelete deletes a user from the database",
|
"description": "UserDelete deletes a user from the database",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
|
@ -252,12 +259,14 @@ const docTemplate = `{
|
||||||
},
|
},
|
||||||
"/users/all": {
|
"/users/all": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "lists all users",
|
"security": [
|
||||||
"consumes": [
|
{
|
||||||
"application/json"
|
"JWT": []
|
||||||
|
}
|
||||||
],
|
],
|
||||||
|
"description": "lists all users",
|
||||||
"produces": [
|
"produces": [
|
||||||
"text/plain"
|
"application/json"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"User"
|
"User"
|
||||||
|
@ -265,9 +274,12 @@ const docTemplate = `{
|
||||||
"summary": "ListsAllUsers",
|
"summary": "ListsAllUsers",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Successfully signed token for user",
|
"description": "Successfully returned all users",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "json"
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
|
@ -291,16 +303,27 @@ const docTemplate = `{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"password": {
|
"password": {
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"example": "password123"
|
||||||
},
|
},
|
||||||
"username": {
|
"username": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "username123"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"types.Token": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"token": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
"bererToken": {
|
"JWT": {
|
||||||
|
"description": "Use the JWT token provided by the login endpoint to authenticate requests. **Prefix the token with \"Bearer \".**",
|
||||||
"type": "apiKey",
|
"type": "apiKey",
|
||||||
"name": "Authorization",
|
"name": "Authorization",
|
||||||
"in": "header"
|
"in": "header"
|
||||||
|
|
|
@ -4,15 +4,16 @@ import (
|
||||||
db "ttime/internal/database"
|
db "ttime/internal/database"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/gofiber/fiber/v2/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetUserProjects returns all projects that the user is a member of
|
// GetUserProjects returns all projects that the user is a member of
|
||||||
func GetUserProjects(c *fiber.Ctx) error {
|
func GetUserProjects(c *fiber.Ctx) error {
|
||||||
// First we get the username from the token
|
username := c.Params("username")
|
||||||
user := c.Locals("user").(*jwt.Token)
|
if username == "" {
|
||||||
claims := user.Claims.(jwt.MapClaims)
|
log.Info("No username provided")
|
||||||
username := claims["name"].(string)
|
return c.Status(400).SendString("No username provided")
|
||||||
|
}
|
||||||
|
|
||||||
// Then dip into the database to get the projects
|
// Then dip into the database to get the projects
|
||||||
projects, err := db.GetDb(c).GetProjectsForUser(username)
|
projects, err := db.GetDb(c).GetProjectsForUser(username)
|
||||||
|
|
|
@ -24,7 +24,13 @@ func ProjectRoleChange(c *fiber.Ctx) error {
|
||||||
return c.Status(400).SendString(err.Error())
|
return c.Status(400).SendString(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Changing role for user: ", username, " in project: ", data.Projectname, " to: ", data.Role)
|
// Check if user is trying to change its own role
|
||||||
|
if username == data.UserName {
|
||||||
|
log.Info("Can't change your own role")
|
||||||
|
return c.Status(403).SendString("Can't change your own role")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("Changing role for user: ", data.UserName, " in project: ", data.Projectname, " to: ", data.Role)
|
||||||
|
|
||||||
// Dubble diping and checcking if current user is
|
// Dubble diping and checcking if current user is
|
||||||
if ismanager, err := db.GetDb(c).IsProjectManager(username, data.Projectname); err != nil {
|
if ismanager, err := db.GetDb(c).IsProjectManager(username, data.Projectname); err != nil {
|
||||||
|
@ -36,7 +42,7 @@ func ProjectRoleChange(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change the user's role within the project in the database
|
// Change the user's role within the project in the database
|
||||||
if err := db.GetDb(c).ChangeUserRole(username, data.Projectname, data.Role); err != nil {
|
if err := db.GetDb(c).ChangeUserRole(data.UserName, data.Projectname, data.Role); err != nil {
|
||||||
return c.Status(500).SendString(err.Error())
|
return c.Status(500).SendString(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,17 @@ import (
|
||||||
"github.com/gofiber/fiber/v2/log"
|
"github.com/gofiber/fiber/v2/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListAllUsers is a handler that returns a list of all users in the application database
|
|
||||||
// @Summary ListsAllUsers
|
// @Summary ListsAllUsers
|
||||||
// @Description lists all users
|
// @Description lists all users
|
||||||
// @Tags User
|
// @Tags User
|
||||||
// @Accept json
|
// @Produce json
|
||||||
// @Produce plain
|
// @Security JWT
|
||||||
// @Success 200 {json} json "Successfully signed token for user"
|
// @Success 200 {array} string "Successfully returned all users"
|
||||||
// @Failure 401 {string} string "Unauthorized"
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
// @Failure 500 {string} string "Internal server error"
|
// @Failure 500 {string} string "Internal server error"
|
||||||
// @Router /users/all [get]
|
// @Router /users/all [get]
|
||||||
|
//
|
||||||
|
// ListAllUsers returns a list of all users in the application database
|
||||||
func ListAllUsers(c *fiber.Ctx) error {
|
func ListAllUsers(c *fiber.Ctx) error {
|
||||||
// Get all users from the database
|
// Get all users from the database
|
||||||
users, err := db.GetDb(c).GetAllUsersApplication()
|
users, err := db.GetDb(c).GetAllUsersApplication()
|
||||||
|
|
|
@ -10,18 +10,19 @@ import (
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Login is a simple login handler that returns a JWT token
|
// @Summary Login
|
||||||
// @Summary login
|
// @Description Logs in a user and returns a JWT token
|
||||||
// @Description logs the user in and returns a jwt token
|
// @Tags Auth
|
||||||
// @Tags User
|
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Param NewUser body types.NewUser true "login info"
|
// @Produce json
|
||||||
// @Produce plain
|
// @Param body body types.NewUser true "User credentials"
|
||||||
// @Success 200 Token types.Token "Successfully signed token for user"
|
// @Success 200 {object} types.Token "JWT token"
|
||||||
// @Failure 400 {string} string "Bad request"
|
// @Failure 400 {string} string "Bad request"
|
||||||
// @Failure 401 {string} string "Unauthorized"
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
// @Failure 500 {string} string "Internal server error"
|
// @Failure 500 {string} string "Internal server error"
|
||||||
// @Router /login [post]
|
// @Router /login [post]
|
||||||
|
//
|
||||||
|
// Login logs in a user and returns a JWT token
|
||||||
func Login(c *fiber.Ctx) error {
|
func Login(c *fiber.Ctx) error {
|
||||||
// The body type is identical to a NewUser
|
// The body type is identical to a NewUser
|
||||||
|
|
||||||
|
|
|
@ -9,34 +9,40 @@ import (
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LoginRenew is a simple handler that renews the token
|
|
||||||
// @Summary LoginRenews
|
// @Summary LoginRenews
|
||||||
// @Description renews the users token
|
// @Description Renews the users token.
|
||||||
// @Security bererToken
|
// @Tags Auth
|
||||||
// @Tags User
|
// @Produce json
|
||||||
// @Accept json
|
// @Security JWT
|
||||||
// @Produce plain
|
// @Success 200 {object} types.Token "Successfully signed token for user"
|
||||||
// @Success 200 Token types.Token "Successfully signed token for user"
|
|
||||||
// @Failure 401 {string} string "Unauthorized"
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
// @Failure 500 {string} string "Internal server error"
|
// @Failure 500 {string} string "Internal server error"
|
||||||
// @Router /loginerenew [post]
|
// @Router /loginrenew [post]
|
||||||
|
//
|
||||||
|
// LoginRenew renews the users token
|
||||||
func LoginRenew(c *fiber.Ctx) error {
|
func LoginRenew(c *fiber.Ctx) error {
|
||||||
user := c.Locals("user").(*jwt.Token)
|
user := c.Locals("user").(*jwt.Token)
|
||||||
|
|
||||||
log.Info("Renewing token for user:", user.Claims.(jwt.MapClaims)["name"])
|
log.Info("Renewing token for user:", user.Claims.(jwt.MapClaims)["name"])
|
||||||
|
|
||||||
|
// Renewing the token means we trust whatever is already in the token
|
||||||
claims := user.Claims.(jwt.MapClaims)
|
claims := user.Claims.(jwt.MapClaims)
|
||||||
|
|
||||||
|
// 72 hour expiration time
|
||||||
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
|
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
|
||||||
renewed := jwt.MapClaims{
|
|
||||||
|
// Create token with old claims, but new expiration time
|
||||||
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||||
"name": claims["name"],
|
"name": claims["name"],
|
||||||
"admin": claims["admin"],
|
"admin": claims["admin"],
|
||||||
"exp": claims["exp"],
|
"exp": claims["exp"],
|
||||||
}
|
})
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, renewed)
|
|
||||||
|
// Sign it with top secret key
|
||||||
t, err := token.SignedString([]byte("secret"))
|
t, err := token.SignedString([]byte("secret"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("Error signing token")
|
log.Warn("Error signing token")
|
||||||
return c.SendStatus(fiber.StatusInternalServerError)
|
return c.SendStatus(fiber.StatusInternalServerError) // 500
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Successfully renewed token for user:", user.Claims.(jwt.MapClaims)["name"])
|
log.Info("Successfully renewed token for user:", user.Claims.(jwt.MapClaims)["name"])
|
||||||
|
|
|
@ -9,16 +9,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// @Summary PromoteToAdmin
|
// @Summary PromoteToAdmin
|
||||||
// @Description promote chosen user to admin
|
// @Description Promote chosen user to site admin
|
||||||
// @Tags User
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce plain
|
// @Produce plain
|
||||||
|
// @Security JWT
|
||||||
// @Param NewUser body types.NewUser true "user info"
|
// @Param NewUser body types.NewUser true "user info"
|
||||||
// @Success 200 {json} json "Successfully promoted user"
|
// @Success 200 {object} types.Token "Successfully promoted user"
|
||||||
// @Failure 400 {string} string "Bad request"
|
// @Failure 400 {string} string "Bad request"
|
||||||
// @Failure 401 {string} string "Unauthorized"
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
// @Failure 500 {string} string "Internal server error"
|
// @Failure 500 {string} string "Internal server error"
|
||||||
// @Router /promoteToAdmin [post]
|
// @Router /promoteToAdmin [post]
|
||||||
|
//
|
||||||
|
// PromoteToAdmin promotes a user to a site admin
|
||||||
func PromoteToAdmin(c *fiber.Ctx) error {
|
func PromoteToAdmin(c *fiber.Ctx) error {
|
||||||
// Extract the username from the request body
|
// Extract the username from the request body
|
||||||
var newUser types.NewUser
|
var newUser types.NewUser
|
||||||
|
|
|
@ -8,11 +8,9 @@ import (
|
||||||
"github.com/gofiber/fiber/v2/log"
|
"github.com/gofiber/fiber/v2/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Register is a simple handler that registers a new user
|
|
||||||
//
|
|
||||||
// @Summary Register
|
// @Summary Register
|
||||||
// @Description Register a new user
|
// @Description Register a new user
|
||||||
// @Tags User
|
// @Tags Auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce plain
|
// @Produce plain
|
||||||
// @Param NewUser body types.NewUser true "User to register"
|
// @Param NewUser body types.NewUser true "User to register"
|
||||||
|
@ -20,6 +18,8 @@ import (
|
||||||
// @Failure 400 {string} string "Bad request"
|
// @Failure 400 {string} string "Bad request"
|
||||||
// @Failure 500 {string} string "Internal server error"
|
// @Failure 500 {string} string "Internal server error"
|
||||||
// @Router /register [post]
|
// @Router /register [post]
|
||||||
|
//
|
||||||
|
// Register is a simple handler that registers a new user
|
||||||
func Register(c *fiber.Ctx) error {
|
func Register(c *fiber.Ctx) error {
|
||||||
u := new(types.NewUser)
|
u := new(types.NewUser)
|
||||||
if err := c.BodyParser(u); err != nil {
|
if err := c.BodyParser(u); err != nil {
|
||||||
|
|
|
@ -8,19 +8,19 @@ import (
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This path should obviously be protected in the future
|
|
||||||
// UserDelete deletes a user from the database
|
|
||||||
//
|
|
||||||
// @Summary UserDelete
|
// @Summary UserDelete
|
||||||
// @Description UserDelete deletes a user from the database
|
// @Description UserDelete deletes a user from the database
|
||||||
// @Tags User
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce plain
|
// @Produce plain
|
||||||
|
// @Security JWT
|
||||||
// @Success 200 {string} string "User deleted"
|
// @Success 200 {string} string "User deleted"
|
||||||
// @Failure 403 {string} string "You can only delete yourself"
|
// @Failure 403 {string} string "You can only delete yourself"
|
||||||
// @Failure 500 {string} string "Internal server error"
|
// @Failure 500 {string} string "Internal server error"
|
||||||
// @Failure 401 {string} string "Unauthorized"
|
// @Failure 401 {string} string "Unauthorized"
|
||||||
// @Router /userdelete/{username} [delete]
|
// @Router /userdelete/{username} [delete]
|
||||||
|
//
|
||||||
|
// UserDelete deletes a user from the database
|
||||||
func UserDelete(c *fiber.Ctx) error {
|
func UserDelete(c *fiber.Ctx) error {
|
||||||
// Read from path parameters
|
// Read from path parameters
|
||||||
username := c.Params("username")
|
username := c.Params("username")
|
||||||
|
|
|
@ -18,8 +18,8 @@ func (u *User) ToPublicUser() (*PublicUser, error) {
|
||||||
|
|
||||||
// Should be used when registering, for example
|
// Should be used when registering, for example
|
||||||
type NewUser struct {
|
type NewUser struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username" example:"username123"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password" example:"password123"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublicUser represents a user that is safe to send over the API (no password)
|
// PublicUser represents a user that is safe to send over the API (no password)
|
||||||
|
|
|
@ -25,9 +25,10 @@ import (
|
||||||
// @license.name AGPL
|
// @license.name AGPL
|
||||||
// @license.url https://www.gnu.org/licenses/agpl-3.0.html
|
// @license.url https://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
|
||||||
//@securityDefinitions.apikey bererToken
|
// @securityDefinitions.apikey JWT
|
||||||
//@in header
|
// @in header
|
||||||
//@name Authorization
|
// @name Authorization
|
||||||
|
// @description Use the JWT token provided by the login endpoint to authenticate requests. **Prefix the token with "Bearer ".**
|
||||||
|
|
||||||
// @host localhost:8080
|
// @host localhost:8080
|
||||||
// @BasePath /api
|
// @BasePath /api
|
||||||
|
@ -111,7 +112,8 @@ func main() {
|
||||||
|
|
||||||
// All project related routes
|
// All project related routes
|
||||||
// projectGroup := api.Group("/project") // Not currently in use
|
// projectGroup := api.Group("/project") // Not currently in use
|
||||||
api.Get("/getUserProjects", projects.GetUserProjects)
|
api.Get("/getProjectTimes/:projectName", projects.GetProjectTimesHandler)
|
||||||
|
api.Get("/getUserProjects/:username", projects.GetUserProjects)
|
||||||
api.Get("/project/:projectId", projects.GetProject)
|
api.Get("/project/:projectId", projects.GetProject)
|
||||||
api.Get("/checkIfProjectManager/:projectName", projects.IsProjectManagerHandler)
|
api.Get("/checkIfProjectManager/:projectName", projects.IsProjectManagerHandler)
|
||||||
api.Get("/getUsersProject/:projectName", projects.ListAllUsersProject)
|
api.Get("/getUsersProject/:projectName", projects.ListAllUsersProject)
|
||||||
|
|
2
frontend/.prettierignore
Normal file
2
frontend/.prettierignore
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
goTypes.ts
|
||||||
|
GenApi.ts
|
|
@ -1,13 +1,16 @@
|
||||||
|
import { NewProjMember } from "../Components/AddMember";
|
||||||
|
import { ProjectRoleChange } from "../Components/ChangeRole";
|
||||||
|
import { projectTimes } from "../Components/GetProjectTimes";
|
||||||
|
import { ProjectMember } from "../Components/GetUsersInProject";
|
||||||
import {
|
import {
|
||||||
|
UpdateWeeklyReport,
|
||||||
NewWeeklyReport,
|
NewWeeklyReport,
|
||||||
NewUser,
|
NewUser,
|
||||||
User,
|
User,
|
||||||
Project,
|
Project,
|
||||||
NewProject,
|
NewProject,
|
||||||
UserProjectMember,
|
|
||||||
WeeklyReport,
|
WeeklyReport,
|
||||||
StrNameChange,
|
StrNameChange,
|
||||||
NewProjMember,
|
|
||||||
} from "../Types/goTypes";
|
} from "../Types/goTypes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,10 +76,7 @@ interface API {
|
||||||
* @param {string} token The authentication token.
|
* @param {string} token The authentication token.
|
||||||
* @returns {Promise<APIResponse<Project>>} A promise resolving to an API response with the created project.
|
* @returns {Promise<APIResponse<Project>>} A promise resolving to an API response with the created project.
|
||||||
*/
|
*/
|
||||||
createProject(
|
createProject(project: NewProject, token: string): Promise<APIResponse<void>>;
|
||||||
project: NewProject,
|
|
||||||
token: string,
|
|
||||||
): Promise<APIResponse<Project>>;
|
|
||||||
|
|
||||||
/** Submits a weekly report
|
/** Submits a weekly report
|
||||||
* @param {NewWeeklyReport} weeklyReport The weekly report object.
|
* @param {NewWeeklyReport} weeklyReport The weekly report object.
|
||||||
|
@ -88,6 +88,17 @@ interface API {
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<string>>;
|
): Promise<APIResponse<string>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a weekly report.
|
||||||
|
* @param {UpdateWeeklyReport} weeklyReport The updated weekly report object.
|
||||||
|
* @param {string} token The authentication token.
|
||||||
|
* @returns {Promise<APIResponse<string>>} A promise containing the API response with the updated report.
|
||||||
|
*/
|
||||||
|
updateWeeklyReport(
|
||||||
|
weeklyReport: UpdateWeeklyReport,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<string>>;
|
||||||
|
|
||||||
/** Gets a weekly report for a specific user, project and week
|
/** Gets a weekly report for a specific user, project and week
|
||||||
* @param {string} projectName The name of the project.
|
* @param {string} projectName The name of the project.
|
||||||
* @param {string} week The week number.
|
* @param {string} week The week number.
|
||||||
|
@ -113,10 +124,14 @@ interface API {
|
||||||
): Promise<APIResponse<WeeklyReport[]>>;
|
): Promise<APIResponse<WeeklyReport[]>>;
|
||||||
|
|
||||||
/** Gets all the projects of a user
|
/** Gets all the projects of a user
|
||||||
|
* @param {string} username - The authentication token.
|
||||||
* @param {string} token - The authentication token.
|
* @param {string} token - The authentication token.
|
||||||
* @returns {Promise<APIResponse<Project[]>>} A promise containing the API response with the user's projects.
|
* @returns {Promise<APIResponse<Project[]>>} A promise containing the API response with the user's projects.
|
||||||
*/
|
*/
|
||||||
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
|
getUserProjects(
|
||||||
|
username: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<Project[]>>;
|
||||||
|
|
||||||
/** Gets a project by its id.
|
/** Gets a project by its id.
|
||||||
* @param {number} id The id of the project to retrieve.
|
* @param {number} id The id of the project to retrieve.
|
||||||
|
@ -124,6 +139,16 @@ interface API {
|
||||||
*/
|
*/
|
||||||
getProject(id: number): Promise<APIResponse<Project>>;
|
getProject(id: number): Promise<APIResponse<Project>>;
|
||||||
|
|
||||||
|
/** Gets a projects reported time
|
||||||
|
* @param {string} projectName The name of the project.
|
||||||
|
* @param {string} token The usertoken.
|
||||||
|
* @returns {Promise<APIResponse<Times>>} A promise resolving to an API response containing the project times.
|
||||||
|
*/
|
||||||
|
getProjectTimes(
|
||||||
|
projectName: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<projectTimes>>;
|
||||||
|
|
||||||
/** Gets a list of all users.
|
/** Gets a list of all users.
|
||||||
* @param {string} token The authentication token of the requesting user.
|
* @param {string} token The authentication token of the requesting user.
|
||||||
* @returns {Promise<APIResponse<string[]>>} A promise resolving to an API response containing the list of users.
|
* @returns {Promise<APIResponse<string[]>>} A promise resolving to an API response containing the list of users.
|
||||||
|
@ -133,7 +158,18 @@ interface API {
|
||||||
getAllUsersProject(
|
getAllUsersProject(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<UserProjectMember[]>>;
|
): Promise<APIResponse<ProjectMember[]>>;
|
||||||
|
|
||||||
|
/** Gets all unsigned reports in a project.
|
||||||
|
* @param {string} projectName The name of the project.
|
||||||
|
* @param {string} token The authentication token.
|
||||||
|
* @returns {Promise<APIResponse<WeeklyReport[]>>} A promise resolving to an API response containing the list of unsigned reports.
|
||||||
|
*/
|
||||||
|
getUnsignedReportsInProject(
|
||||||
|
projectName: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<WeeklyReport[]>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the username of a user in the database.
|
* Changes the username of a user in the database.
|
||||||
* @param {StrNameChange} data The object containing the previous and new username.
|
* @param {StrNameChange} data The object containing the previous and new username.
|
||||||
|
@ -144,10 +180,21 @@ interface API {
|
||||||
data: StrNameChange,
|
data: StrNameChange,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<void>>;
|
): Promise<APIResponse<void>>;
|
||||||
|
/**
|
||||||
|
* Changes the role of a user in the database.
|
||||||
|
* @param {RoleChange} roleInfo The object containing the previous and new username.
|
||||||
|
* @param {string} token The authentication token.
|
||||||
|
* @returns {Promise<APIResponse<void>>} A promise resolving to an API response.
|
||||||
|
*/
|
||||||
|
changeUserRole(
|
||||||
|
roleInfo: ProjectRoleChange,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<void>>;
|
||||||
|
|
||||||
addUserToProject(
|
addUserToProject(
|
||||||
user: NewProjMember,
|
user: NewProjMember,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<NewProjMember>>;
|
): Promise<APIResponse<void>>;
|
||||||
|
|
||||||
removeProject(
|
removeProject(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
|
@ -249,7 +296,7 @@ export const api: API = {
|
||||||
async createProject(
|
async createProject(
|
||||||
project: NewProject,
|
project: NewProject,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<Project>> {
|
): Promise<APIResponse<void>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/project", {
|
const response = await fetch("/api/project", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -263,18 +310,17 @@ export const api: API = {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return { success: false, message: "Failed to create project" };
|
return { success: false, message: "Failed to create project" };
|
||||||
} else {
|
} else {
|
||||||
const data = (await response.json()) as Project;
|
return { success: true };
|
||||||
return { success: true, data };
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return { success: false, message: "Failed to create project" };
|
return { success: false, message: "Failed to create project!" };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async addUserToProject(
|
async addUserToProject(
|
||||||
user: NewProjMember,
|
user: NewProjMember,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<NewProjMember>> {
|
): Promise<APIResponse<void>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/addUserToProject", {
|
const response = await fetch("/api/addUserToProject", {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
@ -316,9 +362,39 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getUserProjects(token: string): Promise<APIResponse<Project[]>> {
|
async changeUserRole(
|
||||||
|
roleInfo: ProjectRoleChange,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<void>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/getUserProjects", {
|
const response = await fetch("/api/ProjectRoleChange", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + token,
|
||||||
|
},
|
||||||
|
body: JSON.stringify(roleInfo),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
if (response.status === 403) {
|
||||||
|
return { success: false, message: "Cannot change your own role" };
|
||||||
|
}
|
||||||
|
return { success: false, message: "Could not change role" };
|
||||||
|
} else {
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return { success: false, message: "Could not change role" };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async getUserProjects(
|
||||||
|
username: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<Project[]>> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/getUserProjects/${username}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -343,6 +419,37 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getProjectTimes(
|
||||||
|
projectName: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<projectTimes>> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/getProjectTimes/${projectName}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + token,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return Promise.resolve({
|
||||||
|
success: false,
|
||||||
|
message:
|
||||||
|
"Fetch error: " + response.status + ", failed to get project times",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const data = (await response.json()) as projectTimes;
|
||||||
|
return Promise.resolve({ success: true, data });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return Promise.resolve({
|
||||||
|
success: false,
|
||||||
|
message: "API error! Could not get times.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async submitWeeklyReport(
|
async submitWeeklyReport(
|
||||||
weeklyReport: NewWeeklyReport,
|
weeklyReport: NewWeeklyReport,
|
||||||
token: string,
|
token: string,
|
||||||
|
@ -374,6 +481,37 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async updateWeeklyReport(
|
||||||
|
weeklyReport: UpdateWeeklyReport,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<string>> {
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/updateWeeklyReport", {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + token,
|
||||||
|
},
|
||||||
|
body: JSON.stringify(weeklyReport),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Failed to update weekly report",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.text();
|
||||||
|
return { success: true, message: data };
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Failed to update weekly report",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async getWeeklyReport(
|
async getWeeklyReport(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
week: string,
|
week: string,
|
||||||
|
@ -510,7 +648,7 @@ export const api: API = {
|
||||||
async getAllUsersProject(
|
async getAllUsersProject(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<UserProjectMember[]>> {
|
): Promise<APIResponse<ProjectMember[]>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/getUsersProject/${projectName}`, {
|
const response = await fetch(`/api/getUsersProject/${projectName}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
@ -526,7 +664,7 @@ export const api: API = {
|
||||||
message: "Failed to get users",
|
message: "Failed to get users",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const data = (await response.json()) as UserProjectMember[];
|
const data = (await response.json()) as ProjectMember[];
|
||||||
return Promise.resolve({ success: true, data });
|
return Promise.resolve({ success: true, data });
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -537,6 +675,38 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getUnsignedReportsInProject(
|
||||||
|
projectName: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<WeeklyReport[]>> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/getUnsignedReports/${projectName}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + token,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message:
|
||||||
|
"Failed to get unsigned reports for project: Response code " +
|
||||||
|
response.status,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const data = (await response.json()) as WeeklyReport[];
|
||||||
|
return { success: true, data };
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Failed to get unsigned reports for project, unknown error",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async changeUserName(
|
async changeUserName(
|
||||||
data: StrNameChange,
|
data: StrNameChange,
|
||||||
token: string,
|
token: string,
|
||||||
|
@ -566,7 +736,7 @@ export const api: API = {
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<string>> {
|
): Promise<APIResponse<string>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/projectdelete/${projectName}`, {
|
const response = await fetch(`/api/removeProject/${projectName}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
358
frontend/src/API/GenApi.ts
Normal file
358
frontend/src/API/GenApi.ts
Normal file
|
@ -0,0 +1,358 @@
|
||||||
|
/* eslint-disable */
|
||||||
|
/* tslint:disable */
|
||||||
|
/*
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
||||||
|
* ## ##
|
||||||
|
* ## AUTHOR: acacode ##
|
||||||
|
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
||||||
|
* ---------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface TypesNewUser {
|
||||||
|
/** @example "password123" */
|
||||||
|
password?: string;
|
||||||
|
/** @example "username123" */
|
||||||
|
username?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TypesToken {
|
||||||
|
token?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type QueryParamsType = Record<string | number, any>;
|
||||||
|
export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
|
||||||
|
|
||||||
|
export interface FullRequestParams extends Omit<RequestInit, "body"> {
|
||||||
|
/** set parameter to `true` for call `securityWorker` for this request */
|
||||||
|
secure?: boolean;
|
||||||
|
/** request path */
|
||||||
|
path: string;
|
||||||
|
/** content type of request body */
|
||||||
|
type?: ContentType;
|
||||||
|
/** query params */
|
||||||
|
query?: QueryParamsType;
|
||||||
|
/** format of response (i.e. response.json() -> format: "json") */
|
||||||
|
format?: ResponseFormat;
|
||||||
|
/** request body */
|
||||||
|
body?: unknown;
|
||||||
|
/** base url */
|
||||||
|
baseUrl?: string;
|
||||||
|
/** request cancellation token */
|
||||||
|
cancelToken?: CancelToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
||||||
|
|
||||||
|
export interface ApiConfig<SecurityDataType = unknown> {
|
||||||
|
baseUrl?: string;
|
||||||
|
baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
|
||||||
|
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
|
||||||
|
customFetch?: typeof fetch;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
|
||||||
|
data: D;
|
||||||
|
error: E;
|
||||||
|
}
|
||||||
|
|
||||||
|
type CancelToken = Symbol | string | number;
|
||||||
|
|
||||||
|
export enum ContentType {
|
||||||
|
Json = "application/json",
|
||||||
|
FormData = "multipart/form-data",
|
||||||
|
UrlEncoded = "application/x-www-form-urlencoded",
|
||||||
|
Text = "text/plain",
|
||||||
|
}
|
||||||
|
|
||||||
|
export class HttpClient<SecurityDataType = unknown> {
|
||||||
|
public baseUrl: string = "//localhost:8080/api";
|
||||||
|
private securityData: SecurityDataType | null = null;
|
||||||
|
private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"];
|
||||||
|
private abortControllers = new Map<CancelToken, AbortController>();
|
||||||
|
private customFetch = (...fetchParams: Parameters<typeof fetch>) => fetch(...fetchParams);
|
||||||
|
|
||||||
|
private baseApiParams: RequestParams = {
|
||||||
|
credentials: "same-origin",
|
||||||
|
headers: {},
|
||||||
|
redirect: "follow",
|
||||||
|
referrerPolicy: "no-referrer",
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(apiConfig: ApiConfig<SecurityDataType> = {}) {
|
||||||
|
Object.assign(this, apiConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public setSecurityData = (data: SecurityDataType | null) => {
|
||||||
|
this.securityData = data;
|
||||||
|
};
|
||||||
|
|
||||||
|
protected encodeQueryParam(key: string, value: any) {
|
||||||
|
const encodedKey = encodeURIComponent(key);
|
||||||
|
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected addQueryParam(query: QueryParamsType, key: string) {
|
||||||
|
return this.encodeQueryParam(key, query[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected addArrayQueryParam(query: QueryParamsType, key: string) {
|
||||||
|
const value = query[key];
|
||||||
|
return value.map((v: any) => this.encodeQueryParam(key, v)).join("&");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected toQueryString(rawQuery?: QueryParamsType): string {
|
||||||
|
const query = rawQuery || {};
|
||||||
|
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
|
||||||
|
return keys
|
||||||
|
.map((key) => (Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key)))
|
||||||
|
.join("&");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected addQueryParams(rawQuery?: QueryParamsType): string {
|
||||||
|
const queryString = this.toQueryString(rawQuery);
|
||||||
|
return queryString ? `?${queryString}` : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private contentFormatters: Record<ContentType, (input: any) => any> = {
|
||||||
|
[ContentType.Json]: (input: any) =>
|
||||||
|
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
|
||||||
|
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
|
||||||
|
[ContentType.FormData]: (input: any) =>
|
||||||
|
Object.keys(input || {}).reduce((formData, key) => {
|
||||||
|
const property = input[key];
|
||||||
|
formData.append(
|
||||||
|
key,
|
||||||
|
property instanceof Blob
|
||||||
|
? property
|
||||||
|
: typeof property === "object" && property !== null
|
||||||
|
? JSON.stringify(property)
|
||||||
|
: `${property}`,
|
||||||
|
);
|
||||||
|
return formData;
|
||||||
|
}, new FormData()),
|
||||||
|
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
|
||||||
|
};
|
||||||
|
|
||||||
|
protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams {
|
||||||
|
return {
|
||||||
|
...this.baseApiParams,
|
||||||
|
...params1,
|
||||||
|
...(params2 || {}),
|
||||||
|
headers: {
|
||||||
|
...(this.baseApiParams.headers || {}),
|
||||||
|
...(params1.headers || {}),
|
||||||
|
...((params2 && params2.headers) || {}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected createAbortSignal = (cancelToken: CancelToken): AbortSignal | undefined => {
|
||||||
|
if (this.abortControllers.has(cancelToken)) {
|
||||||
|
const abortController = this.abortControllers.get(cancelToken);
|
||||||
|
if (abortController) {
|
||||||
|
return abortController.signal;
|
||||||
|
}
|
||||||
|
return void 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const abortController = new AbortController();
|
||||||
|
this.abortControllers.set(cancelToken, abortController);
|
||||||
|
return abortController.signal;
|
||||||
|
};
|
||||||
|
|
||||||
|
public abortRequest = (cancelToken: CancelToken) => {
|
||||||
|
const abortController = this.abortControllers.get(cancelToken);
|
||||||
|
|
||||||
|
if (abortController) {
|
||||||
|
abortController.abort();
|
||||||
|
this.abortControllers.delete(cancelToken);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public request = async <T = any, E = any>({
|
||||||
|
body,
|
||||||
|
secure,
|
||||||
|
path,
|
||||||
|
type,
|
||||||
|
query,
|
||||||
|
format,
|
||||||
|
baseUrl,
|
||||||
|
cancelToken,
|
||||||
|
...params
|
||||||
|
}: FullRequestParams): Promise<HttpResponse<T, E>> => {
|
||||||
|
const secureParams =
|
||||||
|
((typeof secure === "boolean" ? secure : this.baseApiParams.secure) &&
|
||||||
|
this.securityWorker &&
|
||||||
|
(await this.securityWorker(this.securityData))) ||
|
||||||
|
{};
|
||||||
|
const requestParams = this.mergeRequestParams(params, secureParams);
|
||||||
|
const queryString = query && this.toQueryString(query);
|
||||||
|
const payloadFormatter = this.contentFormatters[type || ContentType.Json];
|
||||||
|
const responseFormat = format || requestParams.format;
|
||||||
|
|
||||||
|
return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, {
|
||||||
|
...requestParams,
|
||||||
|
headers: {
|
||||||
|
...(requestParams.headers || {}),
|
||||||
|
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
|
||||||
|
},
|
||||||
|
signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null,
|
||||||
|
body: typeof body === "undefined" || body === null ? null : payloadFormatter(body),
|
||||||
|
}).then(async (response) => {
|
||||||
|
const r = response as HttpResponse<T, E>;
|
||||||
|
r.data = null as unknown as T;
|
||||||
|
r.error = null as unknown as E;
|
||||||
|
|
||||||
|
const data = !responseFormat
|
||||||
|
? r
|
||||||
|
: await response[responseFormat]()
|
||||||
|
.then((data) => {
|
||||||
|
if (r.ok) {
|
||||||
|
r.data = data;
|
||||||
|
} else {
|
||||||
|
r.error = data;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
r.error = e;
|
||||||
|
return r;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (cancelToken) {
|
||||||
|
this.abortControllers.delete(cancelToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) throw data;
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title TTime API
|
||||||
|
* @version 0.0.1
|
||||||
|
* @license AGPL (https://www.gnu.org/licenses/agpl-3.0.html)
|
||||||
|
* @baseUrl //localhost:8080/api
|
||||||
|
* @externalDocs https://swagger.io/resources/open-api/
|
||||||
|
* @contact
|
||||||
|
*
|
||||||
|
* This is the API for TTime, a time tracking application.
|
||||||
|
*/
|
||||||
|
export class GenApi<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
||||||
|
login = {
|
||||||
|
/**
|
||||||
|
* @description Logs in a user and returns a JWT token
|
||||||
|
*
|
||||||
|
* @tags Auth
|
||||||
|
* @name LoginCreate
|
||||||
|
* @summary Login
|
||||||
|
* @request POST:/login
|
||||||
|
*/
|
||||||
|
loginCreate: (body: TypesNewUser, params: RequestParams = {}) =>
|
||||||
|
this.request<TypesToken, string>({
|
||||||
|
path: `/login`,
|
||||||
|
method: "POST",
|
||||||
|
body: body,
|
||||||
|
type: ContentType.Json,
|
||||||
|
format: "json",
|
||||||
|
...params,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
loginrenew = {
|
||||||
|
/**
|
||||||
|
* @description Renews the users token.
|
||||||
|
*
|
||||||
|
* @tags Auth
|
||||||
|
* @name LoginrenewCreate
|
||||||
|
* @summary LoginRenews
|
||||||
|
* @request POST:/loginrenew
|
||||||
|
* @secure
|
||||||
|
*/
|
||||||
|
loginrenewCreate: (params: RequestParams = {}) =>
|
||||||
|
this.request<TypesToken, string>({
|
||||||
|
path: `/loginrenew`,
|
||||||
|
method: "POST",
|
||||||
|
secure: true,
|
||||||
|
format: "json",
|
||||||
|
...params,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
promoteToAdmin = {
|
||||||
|
/**
|
||||||
|
* @description Promote chosen user to site admin
|
||||||
|
*
|
||||||
|
* @tags User
|
||||||
|
* @name PromoteToAdminCreate
|
||||||
|
* @summary PromoteToAdmin
|
||||||
|
* @request POST:/promoteToAdmin
|
||||||
|
* @secure
|
||||||
|
*/
|
||||||
|
promoteToAdminCreate: (NewUser: TypesNewUser, params: RequestParams = {}) =>
|
||||||
|
this.request<TypesToken, string>({
|
||||||
|
path: `/promoteToAdmin`,
|
||||||
|
method: "POST",
|
||||||
|
body: NewUser,
|
||||||
|
secure: true,
|
||||||
|
type: ContentType.Json,
|
||||||
|
...params,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
register = {
|
||||||
|
/**
|
||||||
|
* @description Register a new user
|
||||||
|
*
|
||||||
|
* @tags Auth
|
||||||
|
* @name RegisterCreate
|
||||||
|
* @summary Register
|
||||||
|
* @request POST:/register
|
||||||
|
*/
|
||||||
|
registerCreate: (NewUser: TypesNewUser, params: RequestParams = {}) =>
|
||||||
|
this.request<string, string>({
|
||||||
|
path: `/register`,
|
||||||
|
method: "POST",
|
||||||
|
body: NewUser,
|
||||||
|
type: ContentType.Json,
|
||||||
|
...params,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
userdelete = {
|
||||||
|
/**
|
||||||
|
* @description UserDelete deletes a user from the database
|
||||||
|
*
|
||||||
|
* @tags User
|
||||||
|
* @name UserdeleteDelete
|
||||||
|
* @summary UserDelete
|
||||||
|
* @request DELETE:/userdelete/{username}
|
||||||
|
* @secure
|
||||||
|
*/
|
||||||
|
userdeleteDelete: (username: string, params: RequestParams = {}) =>
|
||||||
|
this.request<string, string>({
|
||||||
|
path: `/userdelete/${username}`,
|
||||||
|
method: "DELETE",
|
||||||
|
secure: true,
|
||||||
|
type: ContentType.Json,
|
||||||
|
...params,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
users = {
|
||||||
|
/**
|
||||||
|
* @description lists all users
|
||||||
|
*
|
||||||
|
* @tags User
|
||||||
|
* @name GetUsers
|
||||||
|
* @summary ListsAllUsers
|
||||||
|
* @request GET:/users/all
|
||||||
|
* @secure
|
||||||
|
*/
|
||||||
|
getUsers: (params: RequestParams = {}) =>
|
||||||
|
this.request<string[], string>({
|
||||||
|
path: `/users/all`,
|
||||||
|
method: "GET",
|
||||||
|
secure: true,
|
||||||
|
format: "json",
|
||||||
|
...params,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,5 +1,10 @@
|
||||||
import { APIResponse, api } from "../API/API";
|
import { APIResponse, api } from "../API/API";
|
||||||
import { NewProjMember } from "../Types/goTypes";
|
|
||||||
|
export interface NewProjMember {
|
||||||
|
username: string;
|
||||||
|
role: string;
|
||||||
|
projectname: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to add a member to a project
|
* Tries to add a member to a project
|
||||||
|
@ -21,7 +26,7 @@ function AddMember(props: { memberToAdd: NewProjMember }): boolean {
|
||||||
props.memberToAdd,
|
props.memberToAdd,
|
||||||
localStorage.getItem("accessToken") ?? "",
|
localStorage.getItem("accessToken") ?? "",
|
||||||
)
|
)
|
||||||
.then((response: APIResponse<NewProjMember>) => {
|
.then((response: APIResponse<void>) => {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
alert("Member added");
|
alert("Member added");
|
||||||
added = true;
|
added = true;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { APIResponse, api } from "../API/API";
|
import { APIResponse, api } from "../API/API";
|
||||||
import { NewProject, Project } from "../Types/goTypes";
|
import { NewProject } from "../Types/goTypes";
|
||||||
import InputField from "./InputField";
|
import InputField from "./InputField";
|
||||||
import Logo from "../assets/Logo.svg";
|
import Logo from "../assets/Logo.svg";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
|
@ -10,27 +10,26 @@ import Button from "./Button";
|
||||||
* @param {Object} props - Project name and description
|
* @param {Object} props - Project name and description
|
||||||
* @returns {boolean} True if created, false if not
|
* @returns {boolean} True if created, false if not
|
||||||
*/
|
*/
|
||||||
function CreateProject(props: { name: string; description: string }): boolean {
|
function CreateProject(props: { name: string; description: string }): void {
|
||||||
const project: NewProject = {
|
const project: NewProject = {
|
||||||
name: props.name,
|
name: props.name,
|
||||||
description: props.description,
|
description: props.description,
|
||||||
};
|
};
|
||||||
|
|
||||||
let created = false;
|
|
||||||
|
|
||||||
api
|
api
|
||||||
.createProject(project, localStorage.getItem("accessToken") ?? "")
|
.createProject(project, localStorage.getItem("accessToken") ?? "")
|
||||||
.then((response: APIResponse<Project>) => {
|
.then((response: APIResponse<void>) => {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
created = true;
|
alert("Project added!");
|
||||||
} else {
|
} else {
|
||||||
|
alert("Project NOT added!");
|
||||||
console.error(response.message);
|
console.error(response.message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
alert("Project NOT added!");
|
||||||
console.error("An error occurred during creation:", error);
|
console.error("An error occurred during creation:", error);
|
||||||
});
|
});
|
||||||
return created;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +47,10 @@ function AddProject(): JSX.Element {
|
||||||
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"
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
CreateProject({ name: name, description: description });
|
CreateProject({
|
||||||
|
name: name,
|
||||||
|
description: description,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
|
@ -59,11 +61,13 @@ function AddProject(): 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]">
|
||||||
Create a new project
|
Create a new project
|
||||||
</h3>
|
</h3>
|
||||||
|
<div className="space-y-3">
|
||||||
<InputField
|
<InputField
|
||||||
label="Name"
|
label="Name"
|
||||||
type="text"
|
type="text"
|
||||||
value={name}
|
value={name}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
setName(e.target.value);
|
setName(e.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -72,9 +76,11 @@ function AddProject(): JSX.Element {
|
||||||
type="text"
|
type="text"
|
||||||
value={description}
|
value={description}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
setDescription(e.target.value);
|
setDescription(e.target.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<Button
|
<Button
|
||||||
text="Create"
|
text="Create"
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { NewProjMember } from "../Types/goTypes";
|
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import GetAllUsers from "./GetAllUsers";
|
import GetAllUsers from "./GetAllUsers";
|
||||||
import AddMember from "./AddMember";
|
import AddMember, { NewProjMember } from "./AddMember";
|
||||||
import BackButton from "./BackButton";
|
import BackButton from "./BackButton";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides UI for adding a member to a project.
|
* Provides UI for adding a member to a project.
|
||||||
* @returns {JSX.Element} - Returns the component UI for adding a member
|
* @returns {JSX.Element} - Returns the component UI for adding a member
|
||||||
*/
|
*/
|
||||||
function AddUserToProject(): JSX.Element {
|
function AddUserToProject(props: { projectName: string }): JSX.Element {
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [users, setUsers] = useState<string[]>([]);
|
const [users, setUsers] = useState<string[]>([]);
|
||||||
const [role, setRole] = useState("");
|
const [role, setRole] = useState("");
|
||||||
|
@ -18,7 +17,7 @@ function AddUserToProject(): JSX.Element {
|
||||||
const handleClick = (): boolean => {
|
const handleClick = (): boolean => {
|
||||||
const newMember: NewProjMember = {
|
const newMember: NewProjMember = {
|
||||||
username: name,
|
username: name,
|
||||||
projectname: localStorage.getItem("projectName") ?? "",
|
projectname: props.projectName,
|
||||||
role: role,
|
role: role,
|
||||||
};
|
};
|
||||||
return AddMember({ memberToAdd: newMember });
|
return AddMember({ memberToAdd: newMember });
|
||||||
|
@ -33,13 +32,13 @@ function AddUserToProject(): JSX.Element {
|
||||||
Role chosen: [{role}]
|
Role chosen: [{role}]
|
||||||
</p>
|
</p>
|
||||||
<p className="pb-4 mb-2 text-center font-bold text-[18px]">
|
<p className="pb-4 mb-2 text-center font-bold text-[18px]">
|
||||||
Project chosen: [{localStorage.getItem("projectName") ?? ""}]
|
Project chosen: [{props.projectName}]
|
||||||
</p>
|
</p>
|
||||||
<p className="p-1">Choose role:</p>
|
<p className="p-1">Choose role:</p>
|
||||||
<div className="border-2 border-black p-2 rounded-xl text-center h-[10h] w-[16vh]">
|
<div className="border-2 border-black p-2 rounded-xl text-center h-[10h] w-[16] overflow-auto">
|
||||||
<ul className="text-center items-center font-medium space-y-2">
|
<ul className="text-center items-center font-medium space-y-2">
|
||||||
<li
|
<li
|
||||||
className="h-[10h] w-[14vh] items-start p-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
className="h-[10] w-[14] items-start px-2 py-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setRole("member");
|
setRole("member");
|
||||||
}}
|
}}
|
||||||
|
@ -47,7 +46,7 @@ function AddUserToProject(): JSX.Element {
|
||||||
{"Member"}
|
{"Member"}
|
||||||
</li>
|
</li>
|
||||||
<li
|
<li
|
||||||
className="h-[10h] w-[14vh] items-start p-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
className="h-[10] w-[14] items-start px-2 py-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setRole("project_manager");
|
setRole("project_manager");
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
//Info: This component is used to display all the time reports for a project. It will display the week number,
|
//Info: This component is used to display all the time reports for a project. It will display the week number,
|
||||||
//total time spent, and if the report has been signed or not. The user can click on a report to edit it.
|
//total time spent, and if the report has been signed or not. The user can click on a report to edit it.
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { NewWeeklyReport } from "../Types/goTypes";
|
import { WeeklyReport } from "../Types/goTypes";
|
||||||
import { Link, useParams } from "react-router-dom";
|
import { Link, useParams } from "react-router-dom";
|
||||||
|
import { api } from "../API/API";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a component that displays all the time reports for a specific project.
|
* Renders a component that displays all the time reports for a specific project.
|
||||||
|
@ -11,14 +12,14 @@ import { Link, useParams } from "react-router-dom";
|
||||||
function AllTimeReportsInProject(): JSX.Element {
|
function AllTimeReportsInProject(): JSX.Element {
|
||||||
const { username } = useParams();
|
const { username } = useParams();
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
const [weeklyReports, setWeeklyReports] = useState<NewWeeklyReport[]>([]);
|
const [weeklyReports, setWeeklyReports] = useState<WeeklyReport[]>([]);
|
||||||
|
|
||||||
/* // Call getProjects when the component mounts
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getWeeklyReports = async (): Promise<void> => {
|
const getWeeklyReports = async (): Promise<void> => {
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
const response = await api.getWeeklyReportsForUser(
|
const response = await api.getWeeklyReportsForDifferentUser(
|
||||||
projectName ?? "",
|
projectName ?? "",
|
||||||
|
username ?? "",
|
||||||
token,
|
token,
|
||||||
);
|
);
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
@ -27,39 +28,8 @@ function AllTimeReportsInProject(): JSX.Element {
|
||||||
} else {
|
} else {
|
||||||
console.error(response.message);
|
console.error(response.message);
|
||||||
}
|
}
|
||||||
}; */
|
|
||||||
// Mock data
|
|
||||||
const getWeeklyReports = async (): Promise<void> => {
|
|
||||||
// Simulate a delay
|
|
||||||
await Promise.resolve();
|
|
||||||
const mockWeeklyReports: NewWeeklyReport[] = [
|
|
||||||
{
|
|
||||||
projectName: "Project 1",
|
|
||||||
week: 1,
|
|
||||||
developmentTime: 10,
|
|
||||||
meetingTime: 2,
|
|
||||||
adminTime: 1,
|
|
||||||
ownWorkTime: 3,
|
|
||||||
studyTime: 4,
|
|
||||||
testingTime: 5,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
projectName: "Project 1",
|
|
||||||
week: 2,
|
|
||||||
developmentTime: 8,
|
|
||||||
meetingTime: 2,
|
|
||||||
adminTime: 1,
|
|
||||||
ownWorkTime: 3,
|
|
||||||
studyTime: 4,
|
|
||||||
testingTime: 5,
|
|
||||||
},
|
|
||||||
// Add more reports as needed
|
|
||||||
];
|
|
||||||
|
|
||||||
// Use the mock data instead of the real data
|
|
||||||
setWeeklyReports(mockWeeklyReports);
|
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
|
||||||
void getWeeklyReports();
|
void getWeeklyReports();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
37
frontend/src/Components/ChangeRole.tsx
Normal file
37
frontend/src/Components/ChangeRole.tsx
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import { APIResponse, api } from "../API/API";
|
||||||
|
|
||||||
|
export interface ProjectRoleChange {
|
||||||
|
username: string;
|
||||||
|
role: "project_manager" | "member" | "";
|
||||||
|
projectname: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ChangeRole(roleChangeInfo: ProjectRoleChange): void {
|
||||||
|
if (
|
||||||
|
roleChangeInfo.username === "" ||
|
||||||
|
roleChangeInfo.role === "" ||
|
||||||
|
roleChangeInfo.projectname === ""
|
||||||
|
) {
|
||||||
|
// FOR DEBUG
|
||||||
|
// console.log(roleChangeInfo.role + ": Role");
|
||||||
|
// console.log(roleChangeInfo.projectname + ": P-Name");
|
||||||
|
// console.log(roleChangeInfo.username + ": U-name");
|
||||||
|
alert("You have to select a role");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api
|
||||||
|
.changeUserRole(roleChangeInfo, localStorage.getItem("accessToken") ?? "")
|
||||||
|
.then((response: APIResponse<void>) => {
|
||||||
|
if (response.success) {
|
||||||
|
alert("Role changed successfully");
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert(response.message);
|
||||||
|
console.error(response.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
alert(error);
|
||||||
|
console.error("An error occurred during change:", error);
|
||||||
|
});
|
||||||
|
}
|
73
frontend/src/Components/ChangeRoleView.tsx
Normal file
73
frontend/src/Components/ChangeRoleView.tsx
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import { useState } from "react";
|
||||||
|
import Button from "./Button";
|
||||||
|
import ChangeRole, { ProjectRoleChange } from "./ChangeRole";
|
||||||
|
|
||||||
|
export default function ChangeRoles(props: {
|
||||||
|
projectName: string;
|
||||||
|
username: string;
|
||||||
|
}): JSX.Element {
|
||||||
|
const [selectedRole, setSelectedRole] = useState<
|
||||||
|
"project_manager" | "member" | ""
|
||||||
|
>("");
|
||||||
|
|
||||||
|
const handleRoleChange = (
|
||||||
|
event: React.ChangeEvent<HTMLInputElement>,
|
||||||
|
): void => {
|
||||||
|
if (event.target.value === "member") {
|
||||||
|
setSelectedRole(event.target.value);
|
||||||
|
} else if (event.target.value === "project_manager") {
|
||||||
|
setSelectedRole(event.target.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = (event: React.FormEvent<HTMLFormElement>): void => {
|
||||||
|
event.preventDefault();
|
||||||
|
const roleChangeInfo: ProjectRoleChange = {
|
||||||
|
username: props.username,
|
||||||
|
projectname: props.projectName,
|
||||||
|
role: selectedRole,
|
||||||
|
};
|
||||||
|
ChangeRole(roleChangeInfo);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="overflow-auto rounded-lg">
|
||||||
|
<h1 className="font-bold text-[20px]">Select role:</h1>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className="h-[7vh] self-start text-left font-medium overflow-auto border-2 border-black rounded-lg p-2">
|
||||||
|
<div className="hover:font-bold">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
value="project_manager"
|
||||||
|
checked={selectedRole === "project_manager"}
|
||||||
|
onChange={handleRoleChange}
|
||||||
|
className="ml-2 mr-2 mb-3"
|
||||||
|
/>
|
||||||
|
Project manager
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="hover:font-bold">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
value="member"
|
||||||
|
checked={selectedRole === "member"}
|
||||||
|
onChange={handleRoleChange}
|
||||||
|
className="ml-2 mr-2"
|
||||||
|
/>
|
||||||
|
Member
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
text="Change"
|
||||||
|
onClick={(): void => {
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
type="submit"
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,61 +1,26 @@
|
||||||
import React, { useState } from "react";
|
import { APIResponse, api } from "../API/API";
|
||||||
import InputField from "./InputField";
|
import { StrNameChange } from "../Types/goTypes";
|
||||||
import { api } from "../API/API";
|
|
||||||
|
|
||||||
function ChangeUsername(): JSX.Element {
|
function ChangeUsername(props: { nameChange: StrNameChange }): void {
|
||||||
const [newUsername, setNewUsername] = useState("");
|
if (props.nameChange.newName === "") {
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
alert("You have to select a new name");
|
||||||
|
return;
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
|
|
||||||
setNewUsername(e.target.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSubmit = async (): Promise<void> => {
|
|
||||||
try {
|
|
||||||
// Call the API function to change the username
|
|
||||||
const token = localStorage.getItem("accessToken");
|
|
||||||
if (!token) {
|
|
||||||
throw new Error("Access token not found");
|
|
||||||
}
|
}
|
||||||
|
api
|
||||||
const response = await api.changeUserName(
|
.changeUserName(props.nameChange, localStorage.getItem("accessToken") ?? "")
|
||||||
{ prevName: "currentName", newName: newUsername },
|
.then((response: APIResponse<void>) => {
|
||||||
token,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
// Optionally, add a success message or redirect the user
|
alert("Name changed successfully");
|
||||||
console.log("Username changed successfully");
|
location.reload();
|
||||||
} else {
|
} else {
|
||||||
// Handle the error message
|
alert("Name not changed");
|
||||||
console.error("Failed to change username:", response.message);
|
console.error(response.message);
|
||||||
setErrorMessage(response.message ?? "Failed to change username");
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
})
|
||||||
console.error("Error changing username:", error);
|
.catch((error) => {
|
||||||
// Optionally, handle the error
|
alert("Name not changed");
|
||||||
setErrorMessage("Failed to change username");
|
console.error("An error occurred during change:", error);
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleButtonClick = (): void => {
|
|
||||||
handleSubmit().catch((error) => {
|
|
||||||
console.error("Error in handleSubmit:", error);
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<InputField
|
|
||||||
label="New Username"
|
|
||||||
type="text"
|
|
||||||
value={newUsername}
|
|
||||||
onChange={handleChange}
|
|
||||||
/>
|
|
||||||
{errorMessage && <div>{errorMessage}</div>}
|
|
||||||
<button onClick={handleButtonClick}>Update Username</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ChangeUsername;
|
export default ChangeUsername;
|
||||||
|
|
33
frontend/src/Components/DeleteProject.tsx
Normal file
33
frontend/src/Components/DeleteProject.tsx
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import { api, APIResponse } from "../API/API";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use to delete a project from the system
|
||||||
|
* @param {string} props.projectToDelete - The projectname of project to delete
|
||||||
|
* @returns {void} Nothing
|
||||||
|
* @example
|
||||||
|
* const exampleProjectName = "project";
|
||||||
|
* DeleteProject({ projectToDelete: exampleProjectName });
|
||||||
|
*/
|
||||||
|
|
||||||
|
function DeleteProject(props: { projectToDelete: string }): void {
|
||||||
|
api
|
||||||
|
.removeProject(
|
||||||
|
props.projectToDelete,
|
||||||
|
localStorage.getItem("accessToken") ?? "",
|
||||||
|
)
|
||||||
|
.then((response: APIResponse<string>) => {
|
||||||
|
if (response.success) {
|
||||||
|
alert("Project has been deleted!");
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert("Project has not been deleted");
|
||||||
|
console.error(response.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
alert("project has not been deleted");
|
||||||
|
console.error("An error occurred during deletion:", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DeleteProject;
|
|
@ -3,7 +3,7 @@ import { api, APIResponse } from "../API/API";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use to remove a user from the system
|
* Use to remove a user from the system
|
||||||
* @param props - The username of user to remove
|
* @param {string} props.usernameToDelete - The username of user to remove
|
||||||
* @returns {boolean} True if removed, false if not
|
* @returns {boolean} True if removed, false if not
|
||||||
* @example
|
* @example
|
||||||
* const exampleUsername = "user";
|
* const exampleUsername = "user";
|
||||||
|
@ -29,7 +29,7 @@ function DeleteUser(props: { usernameToDelete: string }): boolean {
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
alert("User has not been deleted");
|
alert("User has not been deleted");
|
||||||
console.error("An error occurred during creation:", error);
|
console.error("An error occurred during deletion:", error);
|
||||||
});
|
});
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Link, useParams } from "react-router-dom";
|
import { Link, useParams } from "react-router-dom";
|
||||||
|
import { api } from "../API/API";
|
||||||
interface UnsignedReports {
|
import { WeeklyReport } from "../Types/goTypes";
|
||||||
projectName: string;
|
|
||||||
username: string;
|
|
||||||
week: number;
|
|
||||||
signed: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a component that displays the projects a user is a part of and links to the projects start-page.
|
* Renders a component that displays the projects a user is a part of and links to the projects start-page.
|
||||||
|
@ -14,80 +9,25 @@ interface UnsignedReports {
|
||||||
*/
|
*/
|
||||||
function DisplayUserProject(): JSX.Element {
|
function DisplayUserProject(): JSX.Element {
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
const [unsignedReports, setUnsignedReports] = useState<UnsignedReports[]>([]);
|
const [unsignedReports, setUnsignedReports] = useState<WeeklyReport[]>([]);
|
||||||
//const navigate = useNavigate();
|
//const navigate = useNavigate();
|
||||||
|
useEffect(() => {
|
||||||
// const getUnsignedReports = async (): Promise<void> => {
|
|
||||||
// const token = localStorage.getItem("accessToken") ?? "";
|
|
||||||
// const response = await api.getUserProjects(token);
|
|
||||||
// console.log(response);
|
|
||||||
// if (response.success) {
|
|
||||||
// setUnsignedReports(response.data ?? []);
|
|
||||||
// } else {
|
|
||||||
// console.error(response.message);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// const handleReportClick = async (projectName: string): Promise<void> => {
|
|
||||||
// const username = localStorage.getItem("username") ?? "";
|
|
||||||
// const token = localStorage.getItem("accessToken") ?? "";
|
|
||||||
// const response = await api.checkIfProjectManager(
|
|
||||||
// username,
|
|
||||||
// projectName,
|
|
||||||
// token,
|
|
||||||
// );
|
|
||||||
// if (response.success) {
|
|
||||||
// if (response.data) {
|
|
||||||
// navigate(`/PMProjectPage/${projectName}`);
|
|
||||||
// } else {
|
|
||||||
// navigate(`/project/${projectName}`);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// // handle error
|
|
||||||
// console.error(response.message);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
const getUnsignedReports = async (): Promise<void> => {
|
const getUnsignedReports = async (): Promise<void> => {
|
||||||
// Simulate a delay
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
await Promise.resolve();
|
const response = await api.getUnsignedReportsInProject(
|
||||||
|
projectName ?? "",
|
||||||
// Use mock data
|
token,
|
||||||
const reports: UnsignedReports[] = [
|
);
|
||||||
{
|
console.log(response);
|
||||||
projectName: "projecttest",
|
if (response.success) {
|
||||||
username: "user1",
|
setUnsignedReports(response.data ?? []);
|
||||||
week: 2,
|
} else {
|
||||||
signed: false,
|
console.error(response.message);
|
||||||
},
|
}
|
||||||
{
|
|
||||||
projectName: "projecttest",
|
|
||||||
username: "user2",
|
|
||||||
week: 2,
|
|
||||||
signed: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
projectName: "projecttest",
|
|
||||||
username: "user3",
|
|
||||||
week: 2,
|
|
||||||
signed: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
projectName: "projecttest",
|
|
||||||
username: "user4",
|
|
||||||
week: 2,
|
|
||||||
signed: false,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// Set the state with the mock data
|
|
||||||
setUnsignedReports(reports);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call getProjects when the component mounts
|
|
||||||
useEffect(() => {
|
|
||||||
void getUnsignedReports();
|
void getUnsignedReports();
|
||||||
}, []);
|
}, [projectName]); // Include 'projectName' in the dependency array
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -95,21 +35,30 @@ function DisplayUserProject(): JSX.Element {
|
||||||
All Unsigned Reports In: {projectName}{" "}
|
All Unsigned Reports In: {projectName}{" "}
|
||||||
</h1>
|
</h1>
|
||||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[70vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px] text-[20px]">
|
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[70vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px] text-[20px]">
|
||||||
{unsignedReports.map(
|
{unsignedReports.map((unsignedReport: WeeklyReport, index: number) => (
|
||||||
(unsignedReport: UnsignedReports, index: number) => (
|
|
||||||
<h1 key={index} className="border-b-2 border-black w-full">
|
<h1 key={index} className="border-b-2 border-black w-full">
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
<h1>{unsignedReport.username}</h1>
|
<span className="ml-6 mr-2 font-bold">UserID:</span>
|
||||||
|
<h1>{unsignedReport.userId}</h1>
|
||||||
<span className="ml-6 mr-2 font-bold">Week:</span>
|
<span className="ml-6 mr-2 font-bold">Week:</span>
|
||||||
<h1>{unsignedReport.week}</h1>
|
<h1>{unsignedReport.week}</h1>
|
||||||
|
<span className="ml-6 mr-2 font-bold">Total Time:</span>
|
||||||
|
<h1>
|
||||||
|
{unsignedReport.developmentTime +
|
||||||
|
unsignedReport.meetingTime +
|
||||||
|
unsignedReport.adminTime +
|
||||||
|
unsignedReport.ownWorkTime +
|
||||||
|
unsignedReport.studyTime +
|
||||||
|
unsignedReport.testingTime}
|
||||||
|
</h1>
|
||||||
<span className="ml-6 mr-2 font-bold">Signed:</span>
|
<span className="ml-6 mr-2 font-bold">Signed:</span>
|
||||||
<h1>NO</h1>
|
<h1>NO</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
<div className="ml-auto flex space-x-4">
|
<div className="ml-auto flex space-x-4">
|
||||||
<Link
|
<Link
|
||||||
to={`/PMViewUnsignedReport/${projectName}/${unsignedReport.username}/${unsignedReport.week}`}
|
to={`/PMViewUnsignedReport/${projectName}/${unsignedReport.userId}/${unsignedReport.week}`}
|
||||||
>
|
>
|
||||||
<h1 className="underline cursor-pointer font-bold">
|
<h1 className="underline cursor-pointer font-bold">
|
||||||
View Report
|
View Report
|
||||||
|
@ -119,8 +68,7 @@ function DisplayUserProject(): JSX.Element {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</h1>
|
</h1>
|
||||||
),
|
))}
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState } from "react";
|
||||||
import { Project } from "../Types/goTypes";
|
import { Project } from "../Types/goTypes";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import GetProjects from "./GetProjects";
|
||||||
import { api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,23 +12,20 @@ function DisplayUserProject(): JSX.Element {
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const getProjects = async (): Promise<void> => {
|
GetProjects({
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
setProjectsProp: setProjects,
|
||||||
const response = await api.getUserProjects(token);
|
username: localStorage.getItem("username") ?? "",
|
||||||
console.log(response);
|
});
|
||||||
if (response.success) {
|
|
||||||
setProjects(response.data ?? []);
|
|
||||||
} else {
|
|
||||||
console.error(response.message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleProjectClick = async (projectName: string): Promise<void> => {
|
const handleProjectClick = async (projectName: string): Promise<void> => {
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
const response = await api.checkIfProjectManager(projectName, token);
|
const response = await api.checkIfProjectManager(projectName, token);
|
||||||
console.log(response.data);
|
console.log(response.data);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
if (response.data === true) {
|
if (
|
||||||
|
(response.data as unknown as { isProjectManager: boolean })
|
||||||
|
.isProjectManager
|
||||||
|
) {
|
||||||
navigate(`/PMProjectPage/${projectName}`);
|
navigate(`/PMProjectPage/${projectName}`);
|
||||||
} else {
|
} else {
|
||||||
navigate(`/project/${projectName}`);
|
navigate(`/project/${projectName}`);
|
||||||
|
@ -38,11 +36,6 @@ function DisplayUserProject(): JSX.Element {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call getProjects when the component mounts
|
|
||||||
useEffect(() => {
|
|
||||||
void getProjects();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className="font-bold text-[30px] mb-[20px]">Your Projects</h1>
|
<h1 className="font-bold text-[30px] mb-[20px]">Your Projects</h1>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { WeeklyReport, NewWeeklyReport } from "../Types/goTypes";
|
import { WeeklyReport, UpdateWeeklyReport } from "../Types/goTypes";
|
||||||
import { api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
|
@ -22,6 +22,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
fetchedWeek: string;
|
fetchedWeek: string;
|
||||||
}>();
|
}>();
|
||||||
|
const username = localStorage.getItem("userName") ?? "";
|
||||||
console.log(projectName, fetchedWeek);
|
console.log(projectName, fetchedWeek);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -60,8 +61,9 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
void fetchWeeklyReport();
|
void fetchWeeklyReport();
|
||||||
}, [projectName, fetchedWeek, token]);
|
}, [projectName, fetchedWeek, token]);
|
||||||
|
|
||||||
const handleNewWeeklyReport = async (): Promise<void> => {
|
const handleUpdateWeeklyReport = async (): Promise<void> => {
|
||||||
const newWeeklyReport: NewWeeklyReport = {
|
const updateWeeklyReport: UpdateWeeklyReport = {
|
||||||
|
userName: username,
|
||||||
projectName: projectName ?? "",
|
projectName: projectName ?? "",
|
||||||
week,
|
week,
|
||||||
developmentTime,
|
developmentTime,
|
||||||
|
@ -72,7 +74,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
testingTime,
|
testingTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
await api.submitWeeklyReport(newWeeklyReport, token);
|
await api.updateWeeklyReport(updateWeeklyReport, token);
|
||||||
};
|
};
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
@ -89,7 +91,8 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void handleNewWeeklyReport();
|
void handleUpdateWeeklyReport();
|
||||||
|
alert("Changes submitted");
|
||||||
navigate(-1);
|
navigate(-1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -128,7 +131,12 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -152,7 +160,12 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -176,7 +189,12 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -200,7 +218,12 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -224,7 +247,12 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -248,7 +276,12 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
59
frontend/src/Components/GetProjectTimes.tsx
Normal file
59
frontend/src/Components/GetProjectTimes.tsx
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
import { Dispatch, SetStateAction, useEffect } from "react";
|
||||||
|
import { api } from "../API/API";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for reported time per category + total time reported
|
||||||
|
*/
|
||||||
|
export interface projectTimes {
|
||||||
|
admin: number;
|
||||||
|
development: number;
|
||||||
|
meeting: number;
|
||||||
|
own_work: number;
|
||||||
|
study: number;
|
||||||
|
testing: number;
|
||||||
|
totalTime?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all reported times for this project
|
||||||
|
* @param {Dispatch} props.setTimesProp - A setStateAction for the map you want to put times in
|
||||||
|
* @param {string} props.projectName - Username
|
||||||
|
* @returns {void} Nothing
|
||||||
|
* @example
|
||||||
|
* const projectName = "Example";
|
||||||
|
* const [times, setTimes] = useState<Times>();
|
||||||
|
* GetProjectTimes({ setTimesProp: setTimes, projectName: projectName });
|
||||||
|
*/
|
||||||
|
function GetProjectTimes(props: {
|
||||||
|
setTimesProp: Dispatch<SetStateAction<projectTimes | undefined>>;
|
||||||
|
projectName: string;
|
||||||
|
}): void {
|
||||||
|
const setTimes: Dispatch<SetStateAction<projectTimes | undefined>> =
|
||||||
|
props.setTimesProp;
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchUsers = async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
|
const response = await api.getProjectTimes(props.projectName, token);
|
||||||
|
if (response.success && response.data) {
|
||||||
|
// Calculates total time reported
|
||||||
|
response.data.totalTime = response.data.admin;
|
||||||
|
response.data.totalTime += response.data.development;
|
||||||
|
response.data.totalTime += response.data.meeting;
|
||||||
|
response.data.totalTime += response.data.own_work;
|
||||||
|
response.data.totalTime += response.data.study;
|
||||||
|
response.data.totalTime += response.data.testing;
|
||||||
|
setTimes(response.data);
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch project times:", response.message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching times:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void fetchUsers();
|
||||||
|
}, [props.projectName, setTimes]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default GetProjectTimes;
|
|
@ -4,14 +4,17 @@ import { api } from "../API/API";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all projects that user is a member of
|
* Gets all projects that user is a member of
|
||||||
* @param props - A setStateAction for the array you want to put projects in
|
* @param {Dispatch} props.setProjectsProp - A setStateAction for the array you want to put projects in
|
||||||
|
* @param {string} props.username - Username
|
||||||
* @returns {void} Nothing
|
* @returns {void} Nothing
|
||||||
* @example
|
* @example
|
||||||
|
* const username = "Example";
|
||||||
* const [projects, setProjects] = useState<Project[]>([]);
|
* const [projects, setProjects] = useState<Project[]>([]);
|
||||||
* GetAllUsers({ setProjectsProp: setProjects });
|
* GetProjects({ setProjectsProp: setProjects, username: username });
|
||||||
*/
|
*/
|
||||||
function GetProjects(props: {
|
function GetProjects(props: {
|
||||||
setProjectsProp: Dispatch<React.SetStateAction<Project[]>>;
|
setProjectsProp: Dispatch<React.SetStateAction<Project[]>>;
|
||||||
|
username: string;
|
||||||
}): void {
|
}): void {
|
||||||
const setProjects: Dispatch<React.SetStateAction<Project[]>> =
|
const setProjects: Dispatch<React.SetStateAction<Project[]>> =
|
||||||
props.setProjectsProp;
|
props.setProjectsProp;
|
||||||
|
@ -19,7 +22,7 @@ function GetProjects(props: {
|
||||||
const fetchUsers = async (): Promise<void> => {
|
const fetchUsers = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
const response = await api.getUserProjects(token);
|
const response = await api.getUserProjects(props.username, token);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setProjects(response.data ?? []);
|
setProjects(response.data ?? []);
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,7 +34,7 @@ function GetProjects(props: {
|
||||||
};
|
};
|
||||||
|
|
||||||
void fetchUsers();
|
void fetchUsers();
|
||||||
}, [setProjects]);
|
}, [props.username, setProjects]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GetProjects;
|
export default GetProjects;
|
||||||
|
|
|
@ -1,20 +1,25 @@
|
||||||
import { Dispatch, useEffect } from "react";
|
import { Dispatch, useEffect } from "react";
|
||||||
import { UserProjectMember } from "../Types/goTypes";
|
|
||||||
import { api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
|
|
||||||
|
export interface ProjectMember {
|
||||||
|
Username: string;
|
||||||
|
UserRole: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all projects that user is a member of
|
* Gets all members of a project
|
||||||
* @param props - A setStateAction for the array you want to put projects in
|
* @param string - The project's name
|
||||||
|
* @param Dispatch - A setStateAction for the array you want to put members in
|
||||||
* @returns {void} Nothing
|
* @returns {void} Nothing
|
||||||
* @example
|
* @example
|
||||||
* const [projects, setProjects] = useState<Project[]>([]);
|
* const [users, setUsers] = useState<User[]>([]);
|
||||||
* GetAllUsers({ setProjectsProp: setProjects });
|
* GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers });
|
||||||
*/
|
*/
|
||||||
function GetUsersInProject(props: {
|
function GetUsersInProject(props: {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
setUsersProp: Dispatch<React.SetStateAction<UserProjectMember[]>>;
|
setUsersProp: Dispatch<React.SetStateAction<ProjectMember[]>>;
|
||||||
}): void {
|
}): void {
|
||||||
const setUsers: Dispatch<React.SetStateAction<UserProjectMember[]>> =
|
const setUsers: Dispatch<React.SetStateAction<ProjectMember[]>> =
|
||||||
props.setUsersProp;
|
props.setUsersProp;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUsers = async (): Promise<void> => {
|
const fetchUsers = async (): Promise<void> => {
|
||||||
|
@ -24,10 +29,10 @@ function GetUsersInProject(props: {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setUsers(response.data ?? []);
|
setUsers(response.data ?? []);
|
||||||
} else {
|
} else {
|
||||||
console.error("Failed to fetch projects:", response.message);
|
console.error("Failed to fetch members:", response.message);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching projects:", error);
|
console.error("Error fetching members:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
void fetchUsers();
|
void fetchUsers();
|
||||||
|
|
|
@ -19,7 +19,7 @@ function InputField(props: {
|
||||||
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div className="mb-4">
|
<div className="">
|
||||||
<label
|
<label
|
||||||
className="block text-gray-700 text-sm font-sans font-bold mb-2"
|
className="block text-gray-700 text-sm font-sans font-bold mb-2"
|
||||||
htmlFor={props.label}
|
htmlFor={props.label}
|
||||||
|
|
|
@ -25,6 +25,7 @@ function Login(props: {
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<form className="flex flex-col items-center" onSubmit={props.handleSubmit}>
|
<form className="flex flex-col items-center" onSubmit={props.handleSubmit}>
|
||||||
|
<div className="space-y-3">
|
||||||
<InputField
|
<InputField
|
||||||
type="text"
|
type="text"
|
||||||
label="Username"
|
label="Username"
|
||||||
|
@ -41,6 +42,7 @@ function Login(props: {
|
||||||
}}
|
}}
|
||||||
value={props.password}
|
value={props.password}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
<Button
|
<Button
|
||||||
text="Login"
|
text="Login"
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
|
|
72
frontend/src/Components/MemberInfoModal.tsx
Normal file
72
frontend/src/Components/MemberInfoModal.tsx
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
import Button from "./Button";
|
||||||
|
import DeleteUser from "./DeleteUser";
|
||||||
|
import UserProjectListAdmin from "./UserProjectListAdmin";
|
||||||
|
import { useState } from "react";
|
||||||
|
import ChangeRoleView from "./ChangeRoleView";
|
||||||
|
|
||||||
|
function MemberInfoModal(props: {
|
||||||
|
projectName: string;
|
||||||
|
username: string;
|
||||||
|
onClose: () => void;
|
||||||
|
}): JSX.Element {
|
||||||
|
const [showRoles, setShowRoles] = useState(false);
|
||||||
|
|
||||||
|
const handleChangeRole = (): void => {
|
||||||
|
if (showRoles) {
|
||||||
|
setShowRoles(false);
|
||||||
|
} else {
|
||||||
|
setShowRoles(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
||||||
|
flex justify-center items-center"
|
||||||
|
>
|
||||||
|
<div className="border-4 border-black bg-white rounded-lg text-center flex flex-col">
|
||||||
|
<div className="mx-10">
|
||||||
|
<p className="font-bold text-[30px]">{props.username}</p>
|
||||||
|
<p
|
||||||
|
className="hover:font-bold hover:cursor-pointer underline"
|
||||||
|
onClick={handleChangeRole}
|
||||||
|
>
|
||||||
|
(Change Role)
|
||||||
|
</p>
|
||||||
|
{showRoles && (
|
||||||
|
<ChangeRoleView
|
||||||
|
projectName={props.projectName}
|
||||||
|
username={props.username}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<h2 className="font-bold text-[20px]">Member of these projects:</h2>
|
||||||
|
<UserProjectListAdmin username={props.username} />
|
||||||
|
<div className="items-center space-x-6">
|
||||||
|
<Button
|
||||||
|
text={"Delete"}
|
||||||
|
onClick={function (): void {
|
||||||
|
if (
|
||||||
|
window.confirm("Are you sure you want to delete this user?")
|
||||||
|
) {
|
||||||
|
DeleteUser({
|
||||||
|
usernameToDelete: props.username,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
text={"Close"}
|
||||||
|
onClick={function (): void {
|
||||||
|
setShowRoles(false);
|
||||||
|
props.onClose();
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MemberInfoModal;
|
|
@ -139,7 +139,12 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -163,7 +168,12 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -187,7 +197,12 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -211,7 +226,12 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -235,7 +255,12 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -259,7 +284,12 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
if (
|
||||||
|
!/\d/.test(keyValue) &&
|
||||||
|
keyValue !== "Backspace" &&
|
||||||
|
keyValue !== "ArrowLeft" &&
|
||||||
|
keyValue !== "ArrowRight"
|
||||||
|
)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,31 +1,49 @@
|
||||||
import { useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import { UserProjectMember } from "../Types/goTypes";
|
import GetUsersInProject, { ProjectMember } from "./GetUsersInProject";
|
||||||
import GetUsersInProject from "./GetUsersInProject";
|
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
import GetProjectTimes, { projectTimes } from "./GetProjectTimes";
|
||||||
|
import DeleteProject from "./DeleteProject";
|
||||||
|
|
||||||
function ProjectInfoModal(props: {
|
function ProjectInfoModal(props: {
|
||||||
isVisible: boolean;
|
|
||||||
projectname: string;
|
projectname: string;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onClick: (username: string) => void;
|
onClick: (username: string) => void;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const [users, setUsers] = useState<UserProjectMember[]>([]);
|
const [users, setUsers] = useState<ProjectMember[]>([]);
|
||||||
|
const [times, setTimes] = useState<projectTimes>();
|
||||||
|
const totalTime = useRef(0);
|
||||||
GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers });
|
GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers });
|
||||||
if (!props.isVisible) return <></>;
|
|
||||||
|
GetProjectTimes({ setTimesProp: setTimes, projectName: props.projectname });
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (times?.totalTime !== undefined) {
|
||||||
|
totalTime.current = times.totalTime;
|
||||||
|
}
|
||||||
|
}, [times]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
||||||
flex justify-center items-center"
|
flex justify-center items-center"
|
||||||
>
|
>
|
||||||
<div className="border-4 border-black bg-white p-2 rounded-2xl text-center h-[47vh] w-[40] flex flex-col">
|
<div className="border-4 border-black bg-white p-2 rounded-2xl text-center h-[61vh] w-[40] overflow-auto">
|
||||||
<div className="pl-20 pr-20">
|
<div className="pl-10 pr-10">
|
||||||
<h1 className="font-bold text-[32px] mb-[20px]">
|
<h1 className="font-bold text-[32px] mb-[20px]">
|
||||||
{localStorage.getItem("projectName") ?? ""}
|
{props.projectname}
|
||||||
</h1>
|
</h1>
|
||||||
<h2 className="font-bold text-[24px] mb-[20px]">Project members:</h2>
|
<div className="p-1 text-center">
|
||||||
<div className="border-2 border-black p-2 rounded-lg text-center overflow-scroll h-[26vh]">
|
<h2 className="text-[20px] font-bold">Statistics:</h2>
|
||||||
|
</div>
|
||||||
|
<div className="border-2 border-black rounded-lg h-[8vh] text-left divide-y-2 flex flex-col overflow-auto mx-10">
|
||||||
|
<p className="p-2">Number of members: {users.length}</p>
|
||||||
|
<p className="p-2">Total time reported: {totalTime.current}</p>
|
||||||
|
</div>
|
||||||
|
<div className="h-[6vh] p-7 text-center">
|
||||||
|
<h2 className="text-[20px] font-bold">Project members:</h2>
|
||||||
|
</div>
|
||||||
|
<div className="border-2 border-black p-2 rounded-lg text-center overflow-auto h-[24vh] mx-10">
|
||||||
<ul className="text-left font-medium space-y-2">
|
<ul className="text-left font-medium space-y-2">
|
||||||
<div></div>
|
<div></div>
|
||||||
{users.map((user) => (
|
{users.map((user) => (
|
||||||
|
@ -45,16 +63,28 @@ function ProjectInfoModal(props: {
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div className="space-x-5 my-2">
|
||||||
<div className="space-x-16">
|
|
||||||
<Button
|
<Button
|
||||||
text={"Delete"}
|
text={"Delete"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
//DELETE PROJECT
|
if (
|
||||||
|
window.confirm(
|
||||||
|
"Are you sure you want to delete this project?",
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
DeleteProject({
|
||||||
|
projectToDelete: props.projectname,
|
||||||
|
});
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
/>
|
/>
|
||||||
<Link to={"/adminProjectAddMember"}>
|
<Link
|
||||||
|
to={{
|
||||||
|
pathname: "/adminProjectAddMember",
|
||||||
|
search: props.projectname,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
text={"Add Member"}
|
text={"Add Member"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
|
@ -73,6 +103,7 @@ function ProjectInfoModal(props: {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { NewProject } from "../Types/goTypes";
|
import { NewProject } from "../Types/goTypes";
|
||||||
import ProjectInfoModal from "./ProjectInfoModal";
|
import ProjectInfoModal from "./ProjectInfoModal";
|
||||||
import UserInfoModal from "./UserInfoModal";
|
import MemberInfoModal from "./MemberInfoModal";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of projects for admin manage projects page, that sets an onClick
|
* A list of projects for admin manage projects page, that sets an onClick
|
||||||
|
@ -18,7 +18,7 @@ export function ProjectListAdmin(props: {
|
||||||
projects: NewProject[];
|
projects: NewProject[];
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const [projectModalVisible, setProjectModalVisible] = useState(false);
|
const [projectModalVisible, setProjectModalVisible] = useState(false);
|
||||||
const [projectname, setProjectname] = useState("");
|
const [projectName, setProjectName] = useState("");
|
||||||
const [userModalVisible, setUserModalVisible] = useState(false);
|
const [userModalVisible, setUserModalVisible] = useState(false);
|
||||||
const [username, setUsername] = useState("");
|
const [username, setUsername] = useState("");
|
||||||
|
|
||||||
|
@ -28,39 +28,36 @@ export function ProjectListAdmin(props: {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickProject = (projectname: string): void => {
|
const handleClickProject = (projectname: string): void => {
|
||||||
setProjectname(projectname);
|
setProjectName(projectname);
|
||||||
localStorage.setItem("projectName", projectname);
|
|
||||||
setProjectModalVisible(true);
|
setProjectModalVisible(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCloseProject = (): void => {
|
const handleCloseProject = (): void => {
|
||||||
setProjectname("");
|
setProjectName("");
|
||||||
setProjectModalVisible(false);
|
setProjectModalVisible(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCloseUser = (): void => {
|
const handleCloseUser = (): void => {
|
||||||
setProjectname("");
|
setUsername("");
|
||||||
setUserModalVisible(false);
|
setUserModalVisible(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{projectModalVisible && (
|
||||||
<ProjectInfoModal
|
<ProjectInfoModal
|
||||||
onClose={handleCloseProject}
|
onClose={handleCloseProject}
|
||||||
onClick={handleClickUser}
|
onClick={handleClickUser}
|
||||||
isVisible={projectModalVisible}
|
projectname={projectName}
|
||||||
projectname={projectname}
|
|
||||||
/>
|
/>
|
||||||
<UserInfoModal
|
)}
|
||||||
manageMember={true}
|
{userModalVisible && (
|
||||||
|
<MemberInfoModal
|
||||||
onClose={handleCloseUser}
|
onClose={handleCloseUser}
|
||||||
//TODO: CHANGE TO REMOVE USER FROM PROJECT
|
|
||||||
onDelete={() => {
|
|
||||||
return;
|
|
||||||
}}
|
|
||||||
isVisible={userModalVisible}
|
|
||||||
username={username}
|
username={username}
|
||||||
|
projectName={projectName}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<div>
|
<div>
|
||||||
<ul className="font-bold underline text-[30px] cursor-pointer padding">
|
<ul className="font-bold underline text-[30px] cursor-pointer padding">
|
||||||
{props.projects.map((project) => (
|
{props.projects.map((project) => (
|
||||||
|
|
|
@ -1,31 +1,15 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { Link, useParams } from "react-router-dom";
|
import { Link, useParams } from "react-router-dom";
|
||||||
import { api } from "../API/API";
|
import GetUsersInProject, { ProjectMember } from "./GetUsersInProject";
|
||||||
import { UserProjectMember } from "../Types/goTypes";
|
|
||||||
|
|
||||||
function ProjectMembers(): JSX.Element {
|
function ProjectMembers(): JSX.Element {
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
const [projectMembers, setProjectMembers] = useState<UserProjectMember[]>([]);
|
const [projectMembers, setProjectMembers] = useState<ProjectMember[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
GetUsersInProject({
|
||||||
const getProjectMembers = async (): Promise<void> => {
|
projectName: projectName ?? "",
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
setUsersProp: setProjectMembers,
|
||||||
const response = await api.getAllUsersProject(projectName ?? "", token);
|
});
|
||||||
console.log(response);
|
|
||||||
if (response.success) {
|
|
||||||
setProjectMembers(response.data ?? []);
|
|
||||||
} else {
|
|
||||||
console.error(response.message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void getProjectMembers();
|
|
||||||
}, [projectName]);
|
|
||||||
|
|
||||||
interface ProjectMember {
|
|
||||||
Username: string;
|
|
||||||
UserRole: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -22,6 +22,8 @@ export default function Register(): JSX.Element {
|
||||||
const response = await api.registerUser(newUser);
|
const response = await api.registerUser(newUser);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
alert("User added!");
|
alert("User added!");
|
||||||
|
setPassword("");
|
||||||
|
setUsername("");
|
||||||
} else {
|
} else {
|
||||||
alert("User not added");
|
alert("User not added");
|
||||||
setErrMessage(response.message ?? "Unknown error");
|
setErrMessage(response.message ?? "Unknown error");
|
||||||
|
@ -47,6 +49,7 @@ 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>
|
||||||
|
<div className="space-y-3">
|
||||||
<InputField
|
<InputField
|
||||||
label="Username"
|
label="Username"
|
||||||
type="text"
|
type="text"
|
||||||
|
@ -63,6 +66,7 @@ export default function Register(): JSX.Element {
|
||||||
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,70 +1,45 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
import { api } from "../API/API";
|
||||||
|
import { projectTimes } from "./GetProjectTimes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the component for showing total time per role in a project.
|
* Renders the component for showing total time per role in a project.
|
||||||
* @returns JSX.Element
|
* @returns JSX.Element
|
||||||
*/
|
*/
|
||||||
export default function TimePerRole(): JSX.Element {
|
export default function TimePerRole(): JSX.Element {
|
||||||
const [developmentTime, setDevelopmentTime] = useState<number>();
|
const [development, setDevelopment] = useState<number>();
|
||||||
const [meetingTime, setMeetingTime] = useState<number>();
|
const [meeting, setMeeting] = useState<number>();
|
||||||
const [adminTime, setAdminTime] = useState<number>();
|
const [admin, setAdmin] = useState<number>();
|
||||||
const [ownWorkTime, setOwnWorkTime] = useState<number>();
|
const [own_work, setOwnWork] = useState<number>();
|
||||||
const [studyTime, setStudyTime] = useState<number>();
|
const [study, setStudy] = useState<number>();
|
||||||
const [testingTime, setTestingTime] = useState<number>();
|
const [testing, setTesting] = useState<number>();
|
||||||
|
|
||||||
// const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
// const username = localStorage.getItem("username") ?? "";
|
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
|
|
||||||
// const fetchTimePerRole = async (): Promise<void> => {
|
|
||||||
// const response = await api.getTimePerRole(
|
|
||||||
// username,
|
|
||||||
// projectName ?? "",
|
|
||||||
// token,
|
|
||||||
// );
|
|
||||||
// {
|
|
||||||
// if (response.success) {
|
|
||||||
// const report: TimePerRole = response.data ?? {
|
|
||||||
// PManagerTime: 0,
|
|
||||||
// SManagerTime: 0,
|
|
||||||
// DeveloperTime: 0,
|
|
||||||
// TesterTime: 0,
|
|
||||||
// };
|
|
||||||
// } else {
|
|
||||||
// console.error("Failed to fetch weekly report:", response.message);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
interface TimePerActivity {
|
|
||||||
developmentTime: number;
|
|
||||||
meetingTime: number;
|
|
||||||
adminTime: number;
|
|
||||||
ownWorkTime: number;
|
|
||||||
studyTime: number;
|
|
||||||
testingTime: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchTimePerActivity = async (): Promise<void> => {
|
const fetchTimePerActivity = async (): Promise<void> => {
|
||||||
// Use mock data
|
const response = await api.getProjectTimes(projectName ?? "", token);
|
||||||
const report: TimePerActivity = {
|
{
|
||||||
developmentTime: 100,
|
if (response.success) {
|
||||||
meetingTime: 200,
|
const report: projectTimes = response.data ?? {
|
||||||
adminTime: 300,
|
development: 0,
|
||||||
ownWorkTime: 50,
|
meeting: 0,
|
||||||
studyTime: 75,
|
admin: 0,
|
||||||
testingTime: 110,
|
own_work: 0,
|
||||||
|
study: 0,
|
||||||
|
testing: 0,
|
||||||
};
|
};
|
||||||
|
setDevelopment(report.development);
|
||||||
// Set the state with the mock data
|
setMeeting(report.meeting);
|
||||||
setDevelopmentTime(report.developmentTime);
|
setAdmin(report.admin);
|
||||||
setMeetingTime(report.meetingTime);
|
setOwnWork(report.own_work);
|
||||||
setAdminTime(report.adminTime);
|
setStudy(report.study);
|
||||||
setOwnWorkTime(report.ownWorkTime);
|
setTesting(report.testing);
|
||||||
setStudyTime(report.studyTime);
|
} else {
|
||||||
setTestingTime(report.testingTime);
|
console.error("Failed to fetch weekly report:", response.message);
|
||||||
|
}
|
||||||
await Promise.resolve();
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -94,10 +69,8 @@ export default function TimePerRole(): JSX.Element {
|
||||||
<input
|
<input
|
||||||
type="string"
|
type="string"
|
||||||
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={developmentTime}
|
value={development}
|
||||||
onKeyDown={(event) => {
|
readOnly
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -107,10 +80,8 @@ export default function TimePerRole(): JSX.Element {
|
||||||
<input
|
<input
|
||||||
type="string"
|
type="string"
|
||||||
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={meetingTime}
|
value={meeting}
|
||||||
onKeyDown={(event) => {
|
readOnly
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -120,10 +91,8 @@ export default function TimePerRole(): JSX.Element {
|
||||||
<input
|
<input
|
||||||
type="string"
|
type="string"
|
||||||
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={adminTime}
|
value={admin}
|
||||||
onKeyDown={(event) => {
|
readOnly
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -133,10 +102,8 @@ export default function TimePerRole(): JSX.Element {
|
||||||
<input
|
<input
|
||||||
type="string"
|
type="string"
|
||||||
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={ownWorkTime}
|
value={own_work}
|
||||||
onKeyDown={(event) => {
|
readOnly
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -146,10 +113,8 @@ export default function TimePerRole(): JSX.Element {
|
||||||
<input
|
<input
|
||||||
type="string"
|
type="string"
|
||||||
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={studyTime}
|
value={study}
|
||||||
onKeyDown={(event) => {
|
readOnly
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -159,10 +124,8 @@ export default function TimePerRole(): JSX.Element {
|
||||||
<input
|
<input
|
||||||
type="string"
|
type="string"
|
||||||
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={testingTime}
|
value={testing}
|
||||||
onKeyDown={(event) => {
|
readOnly
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -1,51 +1,75 @@
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import DeleteUser from "./DeleteUser";
|
import DeleteUser from "./DeleteUser";
|
||||||
import UserProjectListAdmin from "./UserProjectListAdmin";
|
import UserProjectListAdmin from "./UserProjectListAdmin";
|
||||||
|
import { useState } from "react";
|
||||||
|
import InputField from "./InputField";
|
||||||
|
import ChangeUsername from "./ChangeUsername";
|
||||||
|
import { StrNameChange } from "../Types/goTypes";
|
||||||
|
|
||||||
function UserInfoModal(props: {
|
function UserInfoModal(props: {
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
manageMember: boolean;
|
|
||||||
username: string;
|
username: string;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onDelete: (username: string) => void;
|
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
if (!props.isVisible) return <></>;
|
const [showInput, setShowInput] = useState(false);
|
||||||
const ManageUserOrMember = (check: boolean): JSX.Element => {
|
const [newUsername, setNewUsername] = useState("");
|
||||||
if (check) {
|
if (!props.isVisible) {
|
||||||
return (
|
return <></>;
|
||||||
<Link to="/AdminChangeRole">
|
}
|
||||||
<p className="mb-[20px] hover:font-bold hover:cursor-pointer underline">
|
|
||||||
(Change Role)
|
const handleChangeNameView = (): void => {
|
||||||
</p>
|
if (showInput) {
|
||||||
</Link>
|
setShowInput(false);
|
||||||
);
|
} else {
|
||||||
|
setShowInput(true);
|
||||||
}
|
}
|
||||||
return (
|
|
||||||
<Link to="/AdminChangeUserName">
|
|
||||||
<p className="mb-[20px] hover:font-bold hover:cursor-pointer underline">
|
|
||||||
(Change Username)
|
|
||||||
</p>
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleClickChangeName = (): void => {
|
||||||
|
const nameChange: StrNameChange = {
|
||||||
|
prevName: props.username,
|
||||||
|
newName: newUsername,
|
||||||
|
};
|
||||||
|
ChangeUsername({ nameChange: nameChange });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
||||||
flex justify-center items-center"
|
flex justify-center items-center"
|
||||||
>
|
>
|
||||||
<div className="border-4 border-black bg-white p-2 rounded-lg text-center flex flex-col">
|
<div className="border-4 border-black bg-white rounded-lg text-center flex flex-col">
|
||||||
|
<div className="mx-10">
|
||||||
<p className="font-bold text-[30px]">{props.username}</p>
|
<p className="font-bold text-[30px]">{props.username}</p>
|
||||||
{ManageUserOrMember(props.manageMember)}
|
<p
|
||||||
|
className="mb-[10px] hover:font-bold hover:cursor-pointer underline"
|
||||||
|
onClick={handleChangeNameView}
|
||||||
|
>
|
||||||
|
(Change Username)
|
||||||
|
</p>
|
||||||
|
{showInput && (
|
||||||
<div>
|
<div>
|
||||||
<h2 className="font-bold text-[22px] mb-[20px]">
|
<InputField
|
||||||
Member of these projects:
|
label={"New username"}
|
||||||
</h2>
|
type={"text"}
|
||||||
<div className="pr-6 pl-6">
|
value={newUsername}
|
||||||
<UserProjectListAdmin />
|
onChange={function (e): void {
|
||||||
|
e.defaultPrevented;
|
||||||
|
setNewUsername(e.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
text={"Change"}
|
||||||
|
onClick={function (): void {
|
||||||
|
handleClickChangeName();
|
||||||
|
}}
|
||||||
|
type={"submit"}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
<div className="items-center space-x-6 pr-6 pl-6">
|
<h2 className="font-bold text-[20px]">Member of these projects:</h2>
|
||||||
|
<UserProjectListAdmin username={props.username} />
|
||||||
|
<div className="items-center space-x-6">
|
||||||
<Button
|
<Button
|
||||||
text={"Delete"}
|
text={"Delete"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
|
@ -62,6 +86,8 @@ function UserInfoModal(props: {
|
||||||
<Button
|
<Button
|
||||||
text={"Close"}
|
text={"Close"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
|
setNewUsername("");
|
||||||
|
setShowInput(false);
|
||||||
props.onClose();
|
props.onClose();
|
||||||
}}
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -69,6 +95,7 @@ function UserInfoModal(props: {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import UserInfoModal from "./UserInfoModal";
|
import UserInfoModal from "./UserInfoModal";
|
||||||
import DeleteUser from "./DeleteUser";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of users for admin manage users page, that sets an onClick
|
* A list of users for admin manage users page, that sets an onClick
|
||||||
|
@ -30,9 +29,7 @@ export function UserListAdmin(props: { users: string[] }): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<UserInfoModal
|
<UserInfoModal
|
||||||
manageMember={false}
|
|
||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
onDelete={() => DeleteUser}
|
|
||||||
isVisible={modalVisible}
|
isVisible={modalVisible}
|
||||||
username={username}
|
username={username}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,35 +1,17 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { api } from "../API/API";
|
|
||||||
import { Project } from "../Types/goTypes";
|
import { Project } from "../Types/goTypes";
|
||||||
|
import GetProjects from "./GetProjects";
|
||||||
|
|
||||||
function UserProjectListAdmin(): JSX.Element {
|
function UserProjectListAdmin(props: { username: string }): JSX.Element {
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
GetProjects({ setProjectsProp: setProjects, username: props.username });
|
||||||
const fetchProjects = async (): Promise<void> => {
|
|
||||||
try {
|
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
|
||||||
// const username = props.username;
|
|
||||||
|
|
||||||
const response = await api.getUserProjects(token);
|
|
||||||
if (response.success) {
|
|
||||||
setProjects(response.data ?? []);
|
|
||||||
} else {
|
|
||||||
console.error("Failed to fetch projects:", response.message);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching projects:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void fetchProjects();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border-2 border-black bg-white p-2 rounded-lg text-center">
|
<div className="border-2 border-black bg-white rounded-lg text-left overflow-auto h-[15vh] font-medium">
|
||||||
<ul>
|
<ul className="divide-y-2">
|
||||||
{projects.map((project) => (
|
{projects.map((project) => (
|
||||||
<li key={project.id}>
|
<li className="mx-2 my-1" key={project.id}>
|
||||||
<span>{project.name}</span>
|
<span>{project.name}</span>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { WeeklyReport, NewWeeklyReport } from "../Types/goTypes";
|
import { WeeklyReport } from "../Types/goTypes";
|
||||||
import { api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
|
@ -18,6 +18,7 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
const [ownWorkTime, setOwnWorkTime] = useState(0);
|
const [ownWorkTime, setOwnWorkTime] = useState(0);
|
||||||
const [studyTime, setStudyTime] = useState(0);
|
const [studyTime, setStudyTime] = useState(0);
|
||||||
const [testingTime, setTestingTime] = useState(0);
|
const [testingTime, setTestingTime] = useState(0);
|
||||||
|
const [reportId, setReportId] = useState(0);
|
||||||
|
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
|
@ -45,6 +46,7 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
studyTime: 0,
|
studyTime: 0,
|
||||||
testingTime: 0,
|
testingTime: 0,
|
||||||
};
|
};
|
||||||
|
setReportId(report.reportId);
|
||||||
setWeek(report.week);
|
setWeek(report.week);
|
||||||
setDevelopmentTime(report.developmentTime);
|
setDevelopmentTime(report.developmentTime);
|
||||||
setMeetingTime(report.meetingTime);
|
setMeetingTime(report.meetingTime);
|
||||||
|
@ -61,30 +63,23 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSignWeeklyReport = async (): Promise<void> => {
|
const handleSignWeeklyReport = async (): Promise<void> => {
|
||||||
const newWeeklyReport: NewWeeklyReport = {
|
await api.signReport(reportId, token);
|
||||||
projectName: projectName ?? "",
|
|
||||||
week,
|
|
||||||
developmentTime,
|
|
||||||
meetingTime,
|
|
||||||
adminTime,
|
|
||||||
ownWorkTime,
|
|
||||||
studyTime,
|
|
||||||
testingTime,
|
|
||||||
};
|
|
||||||
|
|
||||||
await api.submitWeeklyReport(newWeeklyReport, token);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className="text-[30px] font-bold">{username}'s Report</h1>
|
<h1 className="text-[30px] font-bold">
|
||||||
|
{" "}
|
||||||
|
UserId: {username}'s Report
|
||||||
|
</h1>
|
||||||
<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
|
<form
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void handleSignWeeklyReport();
|
void handleSignWeeklyReport();
|
||||||
|
alert("Report successfully signed!");
|
||||||
navigate(-1);
|
navigate(-1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -112,7 +107,10 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
type="text"
|
type="text"
|
||||||
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={developmentTime === 0 ? "" : developmentTime}
|
defaultValue={
|
||||||
|
developmentTime === 0 ? "" : developmentTime
|
||||||
|
}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -123,7 +121,8 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
type="text"
|
type="text"
|
||||||
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={meetingTime === 0 ? "" : meetingTime}
|
defaultValue={meetingTime === 0 ? "" : meetingTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -134,7 +133,8 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
type="text"
|
type="text"
|
||||||
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={adminTime === 0 ? "" : adminTime}
|
defaultValue={adminTime === 0 ? "" : adminTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -145,7 +145,8 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
type="text"
|
type="text"
|
||||||
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={ownWorkTime === 0 ? "" : ownWorkTime}
|
defaultValue={ownWorkTime === 0 ? "" : ownWorkTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -156,7 +157,8 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
type="text"
|
type="text"
|
||||||
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={studyTime === 0 ? "" : studyTime}
|
defaultValue={studyTime === 0 ? "" : studyTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -167,7 +169,8 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
type="text"
|
type="text"
|
||||||
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={testingTime === 0 ? "" : testingTime}
|
defaultValue={testingTime === 0 ? "" : testingTime}
|
||||||
|
readOnly
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
23
frontend/src/Containers/GenApiDemo.tsx
Normal file
23
frontend/src/Containers/GenApiDemo.tsx
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { GenApi } from "../API/GenApi";
|
||||||
|
|
||||||
|
// Instantiation of the API
|
||||||
|
const api = new GenApi();
|
||||||
|
|
||||||
|
export function GenApiDemo(): JSX.Element {
|
||||||
|
// Sync wrapper around the loginCreate method
|
||||||
|
const register = async (): Promise<void> => {
|
||||||
|
const response = await api.login.loginCreate({
|
||||||
|
username: "admin",
|
||||||
|
password: "admin",
|
||||||
|
});
|
||||||
|
console.log(response.data); // This should be the inner type of the response
|
||||||
|
};
|
||||||
|
|
||||||
|
// Call the wrapper
|
||||||
|
useEffect(() => {
|
||||||
|
void register();
|
||||||
|
});
|
||||||
|
|
||||||
|
return <></>;
|
||||||
|
}
|
|
@ -1,28 +0,0 @@
|
||||||
import BackButton from "../../Components/BackButton";
|
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
|
||||||
import Button from "../../Components/Button";
|
|
||||||
import ChangeUsername from "../../Components/ChangeUsername";
|
|
||||||
|
|
||||||
function AdminChangeUsername(): JSX.Element {
|
|
||||||
const content = (
|
|
||||||
<>
|
|
||||||
<ChangeUsername />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
const buttons = (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
text="Finish"
|
|
||||||
onClick={(): void => {
|
|
||||||
return;
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
/>
|
|
||||||
<BackButton />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
return <BasicWindow content={content} buttons={buttons} />;
|
|
||||||
}
|
|
||||||
export default AdminChangeUsername;
|
|
|
@ -9,7 +9,10 @@ import { useState } from "react";
|
||||||
|
|
||||||
function AdminManageProjects(): JSX.Element {
|
function AdminManageProjects(): JSX.Element {
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
GetProjects({ setProjectsProp: setProjects });
|
GetProjects({
|
||||||
|
setProjectsProp: setProjects,
|
||||||
|
username: localStorage.getItem("username") ?? "",
|
||||||
|
});
|
||||||
const content = (
|
const content = (
|
||||||
<>
|
<>
|
||||||
<h1 className="font-bold text-[30px] mb-[20px]">Manage Projects</h1>
|
<h1 className="font-bold text-[30px] mb-[20px]">Manage Projects</h1>
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
import AddUserToProject from "../../Components/AddUserToProject";
|
import AddUserToProject from "../../Components/AddUserToProject";
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
import BasicWindow from "../../Components/BasicWindow";
|
||||||
|
|
||||||
function AdminProjectAddMember(): JSX.Element {
|
function AdminProjectAddMember(): JSX.Element {
|
||||||
const content = <AddUserToProject />;
|
const projectName = useLocation().search.slice(1);
|
||||||
|
const content = <AddUserToProject projectName={projectName} />;
|
||||||
const buttons = <></>;
|
const buttons = <></>;
|
||||||
|
|
||||||
return <BasicWindow content={content} buttons={buttons} />;
|
return <BasicWindow content={content} buttons={buttons} />;
|
||||||
}
|
}
|
||||||
export default AdminProjectAddMember;
|
export default AdminProjectAddMember;
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
import BackButton from "../../Components/BackButton";
|
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
|
||||||
import Button from "../../Components/Button";
|
|
||||||
|
|
||||||
function AdminProjectChangeUserRole(): JSX.Element {
|
|
||||||
const content = <></>;
|
|
||||||
|
|
||||||
const buttons = (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
text="Change"
|
|
||||||
onClick={(): void => {
|
|
||||||
return;
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
/>
|
|
||||||
<BackButton />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
return <BasicWindow content={content} buttons={buttons} />;
|
|
||||||
}
|
|
||||||
export default AdminProjectChangeUserRole;
|
|
|
@ -1,23 +0,0 @@
|
||||||
import BackButton from "../../Components/BackButton";
|
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
|
||||||
import Button from "../../Components/Button";
|
|
||||||
|
|
||||||
function AdminProjectManageMembers(): JSX.Element {
|
|
||||||
const content = <></>;
|
|
||||||
|
|
||||||
const buttons = (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
text="Add Member"
|
|
||||||
onClick={(): void => {
|
|
||||||
return;
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
/>
|
|
||||||
<BackButton />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
return <BasicWindow content={content} buttons={buttons} />;
|
|
||||||
}
|
|
||||||
export default AdminProjectManageMembers;
|
|
|
@ -1,33 +0,0 @@
|
||||||
import { useParams } from "react-router-dom";
|
|
||||||
import { api } from "../../API/API";
|
|
||||||
import BackButton from "../../Components/BackButton";
|
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
|
||||||
import Button from "../../Components/Button";
|
|
||||||
|
|
||||||
async function handleDeleteProject(
|
|
||||||
projectName: string,
|
|
||||||
token: string,
|
|
||||||
): Promise<void> {
|
|
||||||
await api.removeProject(projectName, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
function AdminProjectPage(): JSX.Element {
|
|
||||||
const content = <></>;
|
|
||||||
const { projectName } = useParams();
|
|
||||||
const token = localStorage.getItem("accessToken");
|
|
||||||
|
|
||||||
const buttons = (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
text="Delete"
|
|
||||||
onClick={() => handleDeleteProject(projectName, token)}
|
|
||||||
type="button"
|
|
||||||
/>
|
|
||||||
<BackButton />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
return <BasicWindow content={content} buttons={buttons} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default AdminProjectPage;
|
|
|
@ -1,23 +0,0 @@
|
||||||
import BackButton from "../../Components/BackButton";
|
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
|
||||||
import Button from "../../Components/Button";
|
|
||||||
|
|
||||||
function AdminProjectViewMemberInfo(): JSX.Element {
|
|
||||||
const content = <></>;
|
|
||||||
|
|
||||||
const buttons = (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
text="Remove"
|
|
||||||
onClick={(): void => {
|
|
||||||
return;
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
/>
|
|
||||||
<BackButton />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
return <BasicWindow content={content} buttons={buttons} />;
|
|
||||||
}
|
|
||||||
export default AdminProjectViewMemberInfo;
|
|
|
@ -1,28 +0,0 @@
|
||||||
import BasicWindow from "../../Components/BasicWindow";
|
|
||||||
import Button from "../../Components/Button";
|
|
||||||
import BackButton from "../../Components/BackButton";
|
|
||||||
import UserProjectListAdmin from "../../Components/UserProjectListAdmin";
|
|
||||||
|
|
||||||
function AdminViewUserInfo(): JSX.Element {
|
|
||||||
const content = (
|
|
||||||
<>
|
|
||||||
<UserProjectListAdmin />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
const buttons = (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
text="Delete"
|
|
||||||
onClick={(): void => {
|
|
||||||
return;
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
/>
|
|
||||||
<BackButton />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
return <BasicWindow content={content} buttons={buttons} />;
|
|
||||||
}
|
|
||||||
export default AdminViewUserInfo;
|
|
|
@ -124,6 +124,44 @@ export interface WeeklyReport {
|
||||||
*/
|
*/
|
||||||
signedBy?: number /* int */;
|
signedBy?: number /* int */;
|
||||||
}
|
}
|
||||||
|
export interface UpdateWeeklyReport {
|
||||||
|
/**
|
||||||
|
* The name of the project, as it appears in the database
|
||||||
|
*/
|
||||||
|
projectName: string;
|
||||||
|
/**
|
||||||
|
* The name of the user
|
||||||
|
*/
|
||||||
|
userName: string;
|
||||||
|
/**
|
||||||
|
* The week number
|
||||||
|
*/
|
||||||
|
week: number /* int */;
|
||||||
|
/**
|
||||||
|
* Total time spent on development
|
||||||
|
*/
|
||||||
|
developmentTime: number /* int */;
|
||||||
|
/**
|
||||||
|
* Total time spent in meetings
|
||||||
|
*/
|
||||||
|
meetingTime: number /* int */;
|
||||||
|
/**
|
||||||
|
* Total time spent on administrative tasks
|
||||||
|
*/
|
||||||
|
adminTime: number /* int */;
|
||||||
|
/**
|
||||||
|
* Total time spent on personal projects
|
||||||
|
*/
|
||||||
|
ownWorkTime: number /* int */;
|
||||||
|
/**
|
||||||
|
* Total time spent on studying
|
||||||
|
*/
|
||||||
|
studyTime: number /* int */;
|
||||||
|
/**
|
||||||
|
* Total time spent on testing
|
||||||
|
*/
|
||||||
|
testingTime: number /* int */;
|
||||||
|
}
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// source: project.go
|
// source: project.go
|
||||||
|
@ -151,16 +189,9 @@ export interface NewProject {
|
||||||
*/
|
*/
|
||||||
export interface RoleChange {
|
export interface RoleChange {
|
||||||
username: string;
|
username: string;
|
||||||
role: "project_manager" | "user";
|
role: 'project_manager' | 'user';
|
||||||
projectname: string;
|
projectname: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NewProjMember {
|
|
||||||
username: string;
|
|
||||||
projectname: string;
|
|
||||||
role: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NameChange {
|
export interface NameChange {
|
||||||
id: number /* int */;
|
id: number /* int */;
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -191,11 +222,6 @@ export interface PublicUser {
|
||||||
userId: string;
|
userId: string;
|
||||||
username: string;
|
username: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserProjectMember {
|
|
||||||
Username: string;
|
|
||||||
UserRole: string;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* wrapper type for token
|
* wrapper type for token
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,17 +18,11 @@ import PMTotalTimeRole from "./Pages/ProjectManagerPages/PMTotalTimeRole.tsx";
|
||||||
import PMUnsignedReports from "./Pages/ProjectManagerPages/PMUnsignedReports.tsx";
|
import PMUnsignedReports from "./Pages/ProjectManagerPages/PMUnsignedReports.tsx";
|
||||||
import PMViewUnsignedReport from "./Pages/ProjectManagerPages/PMViewUnsignedReport.tsx";
|
import PMViewUnsignedReport from "./Pages/ProjectManagerPages/PMViewUnsignedReport.tsx";
|
||||||
import AdminManageUsers from "./Pages/AdminPages/AdminManageUsers.tsx";
|
import AdminManageUsers from "./Pages/AdminPages/AdminManageUsers.tsx";
|
||||||
import AdminViewUserInfo from "./Pages/AdminPages/AdminViewUserInfo.tsx";
|
|
||||||
import AdminManageProjects from "./Pages/AdminPages/AdminManageProjects.tsx";
|
import AdminManageProjects from "./Pages/AdminPages/AdminManageProjects.tsx";
|
||||||
import AdminAddProject from "./Pages/AdminPages/AdminAddProject.tsx";
|
import AdminAddProject from "./Pages/AdminPages/AdminAddProject.tsx";
|
||||||
import AdminAddUser from "./Pages/AdminPages/AdminAddUser.tsx";
|
import AdminAddUser from "./Pages/AdminPages/AdminAddUser.tsx";
|
||||||
import AdminChangeUsername from "./Pages/AdminPages/AdminChangeUsername.tsx";
|
|
||||||
import AdminProjectAddMember from "./Pages/AdminPages/AdminProjectAddMember.tsx";
|
import AdminProjectAddMember from "./Pages/AdminPages/AdminProjectAddMember.tsx";
|
||||||
import AdminProjectChangeUserRole from "./Pages/AdminPages/AdminProjectChangeUserRole.tsx";
|
|
||||||
import AdminProjectManageMembers from "./Pages/AdminPages/AdminProjectManageMembers.tsx";
|
|
||||||
import AdminProjectStatistics from "./Pages/AdminPages/AdminProjectStatistics.tsx";
|
import AdminProjectStatistics from "./Pages/AdminPages/AdminProjectStatistics.tsx";
|
||||||
import AdminProjectViewMemberInfo from "./Pages/AdminPages/AdminProjectViewMemberInfo.tsx";
|
|
||||||
import AdminProjectPage from "./Pages/AdminPages/AdminProjectPage.tsx";
|
|
||||||
import NotFoundPage from "./Pages/NotFoundPage.tsx";
|
import NotFoundPage from "./Pages/NotFoundPage.tsx";
|
||||||
import UnauthorizedPage from "./Pages/UnauthorizedPage.tsx";
|
import UnauthorizedPage from "./Pages/UnauthorizedPage.tsx";
|
||||||
import PMViewOtherUsersTR from "./Pages/ProjectManagerPages/PMViewOtherUsersTR.tsx";
|
import PMViewOtherUsersTR from "./Pages/ProjectManagerPages/PMViewOtherUsersTR.tsx";
|
||||||
|
@ -100,34 +94,14 @@ const router = createBrowserRouter([
|
||||||
path: "/PMViewUnsignedReport/:projectName/:username/:fetchedWeek",
|
path: "/PMViewUnsignedReport/:projectName/:username/:fetchedWeek",
|
||||||
element: <PMViewUnsignedReport />,
|
element: <PMViewUnsignedReport />,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/adminChangeUsername",
|
|
||||||
element: <AdminChangeUsername />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/adminProjectAddMember",
|
path: "/adminProjectAddMember",
|
||||||
element: <AdminProjectAddMember />,
|
element: <AdminProjectAddMember />,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/adminProjectChangeUserRole",
|
|
||||||
element: <AdminProjectChangeUserRole />,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/adminProjectManageMembers",
|
|
||||||
element: <AdminProjectManageMembers />,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/adminProjectPage",
|
|
||||||
element: <AdminProjectPage />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/adminProjectStatistics",
|
path: "/adminProjectStatistics",
|
||||||
element: <AdminProjectStatistics />,
|
element: <AdminProjectStatistics />,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/adminProjectViewMembers",
|
|
||||||
element: <AdminProjectViewMemberInfo />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/addProject",
|
path: "/addProject",
|
||||||
element: <AdminAddProject />,
|
element: <AdminAddProject />,
|
||||||
|
@ -136,10 +110,6 @@ const router = createBrowserRouter([
|
||||||
path: "/adminAddUser",
|
path: "/adminAddUser",
|
||||||
element: <AdminAddUser />,
|
element: <AdminAddUser />,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/adminUserInfo",
|
|
||||||
element: <AdminViewUserInfo />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/adminManageProject",
|
path: "/adminManageProject",
|
||||||
element: <AdminManageProjects />,
|
element: <AdminManageProjects />,
|
||||||
|
|
Loading…
Reference in a new issue