Compare commits
No commits in common. "4d7b3e0d5736628fa420cb12ec3ac1f282d9168f" and "c1f49915baff3271ded8d5b33bf8f57b52715db7" have entirely different histories.
4d7b3e0d57
...
c1f49915ba
54 changed files with 884 additions and 1544 deletions
|
@ -34,7 +34,6 @@ 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
|
||||||
|
@ -106,7 +105,6 @@ 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 in a user and returns a JWT token",
|
"description": "logs the user in and returns a jwt token",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"text/plain"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Auth"
|
"User"
|
||||||
],
|
],
|
||||||
"summary": "Login",
|
"summary": "login",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "User credentials",
|
"description": "login info",
|
||||||
"name": "body",
|
"name": "NewUser",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
|
@ -45,9 +45,9 @@ const docTemplate = `{
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "JWT token",
|
"description": "Successfully signed token for user",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/types.Token"
|
"type": "Token"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
|
@ -71,26 +71,29 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/loginrenew": {
|
"/loginerenew": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"JWT": []
|
"bererToken": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Renews the users token.",
|
"description": "renews the users token",
|
||||||
"produces": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
"produces": [
|
||||||
|
"text/plain"
|
||||||
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Auth"
|
"User"
|
||||||
],
|
],
|
||||||
"summary": "LoginRenews",
|
"summary": "LoginRenews",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Successfully signed token for user",
|
"description": "Successfully signed token for user",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/types.Token"
|
"type": "Token"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
|
@ -110,12 +113,7 @@ const docTemplate = `{
|
||||||
},
|
},
|
||||||
"/promoteToAdmin": {
|
"/promoteToAdmin": {
|
||||||
"post": {
|
"post": {
|
||||||
"security": [
|
"description": "promote chosen user to admin",
|
||||||
{
|
|
||||||
"JWT": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Promote chosen user to site admin",
|
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
@ -141,7 +139,7 @@ const docTemplate = `{
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Successfully promoted user",
|
"description": "Successfully promoted user",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/types.Token"
|
"type": "json"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
|
@ -175,7 +173,7 @@ const docTemplate = `{
|
||||||
"text/plain"
|
"text/plain"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Auth"
|
"User"
|
||||||
],
|
],
|
||||||
"summary": "Register",
|
"summary": "Register",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
@ -213,11 +211,6 @@ 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"
|
||||||
|
@ -259,27 +252,22 @@ const docTemplate = `{
|
||||||
},
|
},
|
||||||
"/users/all": {
|
"/users/all": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"JWT": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "lists all users",
|
"description": "lists all users",
|
||||||
"produces": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
"produces": [
|
||||||
|
"text/plain"
|
||||||
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"User"
|
"User"
|
||||||
],
|
],
|
||||||
"summary": "ListsAllUsers",
|
"summary": "ListsAllUsers",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Successfully returned all users",
|
"description": "Successfully signed token for user",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "array",
|
"type": "json"
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
|
@ -303,27 +291,16 @@ 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": {
|
||||||
"JWT": {
|
"bererToken": {
|
||||||
"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,16 +4,15 @@ import (
|
||||||
db "ttime/internal/database"
|
db "ttime/internal/database"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/log"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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 {
|
||||||
username := c.Params("username")
|
// First we get the username from the token
|
||||||
if username == "" {
|
user := c.Locals("user").(*jwt.Token)
|
||||||
log.Info("No username provided")
|
claims := user.Claims.(jwt.MapClaims)
|
||||||
return c.Status(400).SendString("No username provided")
|
username := claims["name"].(string)
|
||||||
}
|
|
||||||
|
|
||||||
// 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,13 +24,7 @@ func ProjectRoleChange(c *fiber.Ctx) error {
|
||||||
return c.Status(400).SendString(err.Error())
|
return c.Status(400).SendString(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is trying to change its own role
|
log.Info("Changing role for user: ", username, " in project: ", data.Projectname, " to: ", data.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 {
|
||||||
|
@ -42,7 +36,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(data.UserName, data.Projectname, data.Role); err != nil {
|
if err := db.GetDb(c).ChangeUserRole(username, data.Projectname, data.Role); err != nil {
|
||||||
return c.Status(500).SendString(err.Error())
|
return c.Status(500).SendString(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,17 +7,16 @@ 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
|
||||||
// @Produce json
|
// @Accept json
|
||||||
// @Security JWT
|
// @Produce plain
|
||||||
// @Success 200 {array} string "Successfully returned all users"
|
// @Success 200 {json} json "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 /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,19 +10,18 @@ import (
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @Summary Login
|
// Login is a simple login handler that returns a JWT token
|
||||||
// @Description Logs in a user and returns a JWT token
|
// @Summary login
|
||||||
// @Tags Auth
|
// @Description logs the user in and returns a jwt token
|
||||||
|
// @Tags User
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Param NewUser body types.NewUser true "login info"
|
||||||
// @Param body body types.NewUser true "User credentials"
|
// @Produce plain
|
||||||
// @Success 200 {object} types.Token "JWT token"
|
// @Success 200 Token types.Token "Successfully signed token for 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 /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,40 +9,34 @@ 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
|
||||||
// @Tags Auth
|
// @Security bererToken
|
||||||
// @Produce json
|
// @Tags User
|
||||||
// @Security JWT
|
// @Accept json
|
||||||
// @Success 200 {object} types.Token "Successfully signed token for user"
|
// @Produce plain
|
||||||
|
// @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 /loginrenew [post]
|
// @Router /loginerenew [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) // 500
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
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,19 +9,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// @Summary PromoteToAdmin
|
// @Summary PromoteToAdmin
|
||||||
// @Description Promote chosen user to site admin
|
// @Description promote chosen user to 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 {object} types.Token "Successfully promoted user"
|
// @Success 200 {json} json "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,9 +8,11 @@ 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 Auth
|
// @Tags User
|
||||||
// @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"
|
||||||
|
@ -18,8 +20,6 @@ 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" example:"username123"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password" example:"password123"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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,10 +25,9 @@ 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 JWT
|
//@securityDefinitions.apikey bererToken
|
||||||
//@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
|
||||||
|
@ -112,8 +111,7 @@ 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("/getProjectTimes/:projectName", projects.GetProjectTimesHandler)
|
api.Get("/getUserProjects", projects.GetUserProjects)
|
||||||
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)
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
goTypes.ts
|
|
||||||
GenApi.ts
|
|
|
@ -1,16 +1,13 @@
|
||||||
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";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +73,10 @@ 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(project: NewProject, token: string): Promise<APIResponse<void>>;
|
createProject(
|
||||||
|
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,17 +88,6 @@ 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.
|
||||||
|
@ -124,14 +113,10 @@ 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(
|
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
|
||||||
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.
|
||||||
|
@ -139,16 +124,6 @@ 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.
|
||||||
|
@ -158,18 +133,7 @@ interface API {
|
||||||
getAllUsersProject(
|
getAllUsersProject(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<ProjectMember[]>>;
|
): Promise<APIResponse<UserProjectMember[]>>;
|
||||||
|
|
||||||
/** 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.
|
||||||
|
@ -180,21 +144,10 @@ 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<void>>;
|
): Promise<APIResponse<NewProjMember>>;
|
||||||
|
|
||||||
removeProject(
|
removeProject(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
|
@ -296,7 +249,7 @@ export const api: API = {
|
||||||
async createProject(
|
async createProject(
|
||||||
project: NewProject,
|
project: NewProject,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<void>> {
|
): Promise<APIResponse<Project>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/project", {
|
const response = await fetch("/api/project", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -310,17 +263,18 @@ 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 {
|
||||||
return { success: true };
|
const data = (await response.json()) as Project;
|
||||||
|
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<void>> {
|
): Promise<APIResponse<NewProjMember>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/addUserToProject", {
|
const response = await fetch("/api/addUserToProject", {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
@ -362,39 +316,9 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async changeUserRole(
|
async getUserProjects(token: string): Promise<APIResponse<Project[]>> {
|
||||||
roleInfo: ProjectRoleChange,
|
|
||||||
token: string,
|
|
||||||
): Promise<APIResponse<void>> {
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/ProjectRoleChange", {
|
const response = await fetch("/api/getUserProjects", {
|
||||||
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",
|
||||||
|
@ -419,37 +343,6 @@ 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,
|
||||||
|
@ -481,37 +374,6 @@ 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,
|
||||||
|
@ -648,7 +510,7 @@ export const api: API = {
|
||||||
async getAllUsersProject(
|
async getAllUsersProject(
|
||||||
projectName: string,
|
projectName: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<ProjectMember[]>> {
|
): Promise<APIResponse<UserProjectMember[]>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/getUsersProject/${projectName}`, {
|
const response = await fetch(`/api/getUsersProject/${projectName}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
@ -664,7 +526,7 @@ export const api: API = {
|
||||||
message: "Failed to get users",
|
message: "Failed to get users",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const data = (await response.json()) as ProjectMember[];
|
const data = (await response.json()) as UserProjectMember[];
|
||||||
return Promise.resolve({ success: true, data });
|
return Promise.resolve({ success: true, data });
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -675,38 +537,6 @@ 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,
|
||||||
|
@ -736,7 +566,7 @@ export const api: API = {
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<string>> {
|
): Promise<APIResponse<string>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/removeProject/${projectName}`, {
|
const response = await fetch(`/api/projectdelete/${projectName}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
|
@ -1,358 +0,0 @@
|
||||||
/* 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,10 +1,5 @@
|
||||||
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
|
||||||
|
@ -26,7 +21,7 @@ function AddMember(props: { memberToAdd: NewProjMember }): boolean {
|
||||||
props.memberToAdd,
|
props.memberToAdd,
|
||||||
localStorage.getItem("accessToken") ?? "",
|
localStorage.getItem("accessToken") ?? "",
|
||||||
)
|
)
|
||||||
.then((response: APIResponse<void>) => {
|
.then((response: APIResponse<NewProjMember>) => {
|
||||||
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 } from "../Types/goTypes";
|
import { NewProject, Project } 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,26 +10,27 @@ 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 }): void {
|
function CreateProject(props: { name: string; description: string }): boolean {
|
||||||
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<void>) => {
|
.then((response: APIResponse<Project>) => {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
alert("Project added!");
|
created = true;
|
||||||
} 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,10 +48,7 @@ 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({
|
CreateProject({ name: name, description: description });
|
||||||
name: name,
|
|
||||||
description: description,
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
|
@ -61,13 +59,11 @@ 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);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -76,11 +72,9 @@ 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,14 +1,15 @@
|
||||||
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, { NewProjMember } from "./AddMember";
|
import AddMember 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(props: { projectName: string }): JSX.Element {
|
function AddUserToProject(): 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("");
|
||||||
|
@ -17,7 +18,7 @@ function AddUserToProject(props: { projectName: string }): JSX.Element {
|
||||||
const handleClick = (): boolean => {
|
const handleClick = (): boolean => {
|
||||||
const newMember: NewProjMember = {
|
const newMember: NewProjMember = {
|
||||||
username: name,
|
username: name,
|
||||||
projectname: props.projectName,
|
projectname: localStorage.getItem("projectName") ?? "",
|
||||||
role: role,
|
role: role,
|
||||||
};
|
};
|
||||||
return AddMember({ memberToAdd: newMember });
|
return AddMember({ memberToAdd: newMember });
|
||||||
|
@ -32,13 +33,13 @@ function AddUserToProject(props: { projectName: string }): 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: [{props.projectName}]
|
Project chosen: [{localStorage.getItem("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-[16] overflow-auto">
|
<div className="border-2 border-black p-2 rounded-xl text-center h-[10h] w-[16vh]">
|
||||||
<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-[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"
|
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"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setRole("member");
|
setRole("member");
|
||||||
}}
|
}}
|
||||||
|
@ -46,7 +47,7 @@ function AddUserToProject(props: { projectName: string }): JSX.Element {
|
||||||
{"Member"}
|
{"Member"}
|
||||||
</li>
|
</li>
|
||||||
<li
|
<li
|
||||||
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"
|
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"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setRole("project_manager");
|
setRole("project_manager");
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
//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 { WeeklyReport } from "../Types/goTypes";
|
import { NewWeeklyReport } 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.
|
||||||
|
@ -12,14 +11,14 @@ import { api } from "../API/API";
|
||||||
function AllTimeReportsInProject(): JSX.Element {
|
function AllTimeReportsInProject(): JSX.Element {
|
||||||
const { username } = useParams();
|
const { username } = useParams();
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
const [weeklyReports, setWeeklyReports] = useState<WeeklyReport[]>([]);
|
const [weeklyReports, setWeeklyReports] = useState<NewWeeklyReport[]>([]);
|
||||||
|
|
||||||
|
/* // 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.getWeeklyReportsForDifferentUser(
|
const response = await api.getWeeklyReportsForUser(
|
||||||
projectName ?? "",
|
projectName ?? "",
|
||||||
username ?? "",
|
|
||||||
token,
|
token,
|
||||||
);
|
);
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
@ -28,8 +27,39 @@ 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();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
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,26 +1,61 @@
|
||||||
import { APIResponse, api } from "../API/API";
|
import React, { useState } from "react";
|
||||||
import { StrNameChange } from "../Types/goTypes";
|
import InputField from "./InputField";
|
||||||
|
import { api } from "../API/API";
|
||||||
|
|
||||||
function ChangeUsername(props: { nameChange: StrNameChange }): void {
|
function ChangeUsername(): JSX.Element {
|
||||||
if (props.nameChange.newName === "") {
|
const [newUsername, setNewUsername] = useState("");
|
||||||
alert("You have to select a new name");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
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
|
|
||||||
.changeUserName(props.nameChange, localStorage.getItem("accessToken") ?? "")
|
const response = await api.changeUserName(
|
||||||
.then((response: APIResponse<void>) => {
|
{ prevName: "currentName", newName: newUsername },
|
||||||
|
token,
|
||||||
|
);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
alert("Name changed successfully");
|
// Optionally, add a success message or redirect the user
|
||||||
location.reload();
|
console.log("Username changed successfully");
|
||||||
} else {
|
} else {
|
||||||
alert("Name not changed");
|
// Handle the error message
|
||||||
console.error(response.message);
|
console.error("Failed to change username:", response.message);
|
||||||
|
setErrorMessage(response.message ?? "Failed to change username");
|
||||||
}
|
}
|
||||||
})
|
} catch (error) {
|
||||||
.catch((error) => {
|
console.error("Error changing username:", error);
|
||||||
alert("Name not changed");
|
// Optionally, handle the error
|
||||||
console.error("An error occurred during change:", error);
|
setErrorMessage("Failed to change username");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
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 {string} props.usernameToDelete - The username of user to remove
|
* @param props - 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 deletion:", error);
|
console.error("An error occurred during creation:", error);
|
||||||
});
|
});
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
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";
|
|
||||||
import { WeeklyReport } from "../Types/goTypes";
|
interface UnsignedReports {
|
||||||
|
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.
|
||||||
|
@ -9,25 +14,80 @@ import { WeeklyReport } from "../Types/goTypes";
|
||||||
*/
|
*/
|
||||||
function DisplayUserProject(): JSX.Element {
|
function DisplayUserProject(): JSX.Element {
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
const [unsignedReports, setUnsignedReports] = useState<WeeklyReport[]>([]);
|
const [unsignedReports, setUnsignedReports] = useState<UnsignedReports[]>([]);
|
||||||
//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> => {
|
||||||
const token = localStorage.getItem("accessToken") ?? "";
|
// Simulate a delay
|
||||||
const response = await api.getUnsignedReportsInProject(
|
await Promise.resolve();
|
||||||
projectName ?? "",
|
|
||||||
token,
|
// Use mock data
|
||||||
);
|
const reports: UnsignedReports[] = [
|
||||||
console.log(response);
|
{
|
||||||
if (response.success) {
|
projectName: "projecttest",
|
||||||
setUnsignedReports(response.data ?? []);
|
username: "user1",
|
||||||
} else {
|
week: 2,
|
||||||
console.error(response.message);
|
signed: false,
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
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 (
|
||||||
<>
|
<>
|
||||||
|
@ -35,30 +95,21 @@ 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((unsignedReport: WeeklyReport, index: number) => (
|
{unsignedReports.map(
|
||||||
|
(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">
|
||||||
<span className="ml-6 mr-2 font-bold">UserID:</span>
|
<h1>{unsignedReport.username}</h1>
|
||||||
<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.userId}/${unsignedReport.week}`}
|
to={`/PMViewUnsignedReport/${projectName}/${unsignedReport.username}/${unsignedReport.week}`}
|
||||||
>
|
>
|
||||||
<h1 className="underline cursor-pointer font-bold">
|
<h1 className="underline cursor-pointer font-bold">
|
||||||
View Report
|
View Report
|
||||||
|
@ -68,7 +119,8 @@ function DisplayUserProject(): JSX.Element {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</h1>
|
</h1>
|
||||||
))}
|
),
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState, useEffect } 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";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,20 +11,23 @@ function DisplayUserProject(): JSX.Element {
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
GetProjects({
|
const getProjects = async (): Promise<void> => {
|
||||||
setProjectsProp: setProjects,
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
username: localStorage.getItem("username") ?? "",
|
const response = await api.getUserProjects(token);
|
||||||
});
|
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 (
|
if (response.data === true) {
|
||||||
(response.data as unknown as { isProjectManager: boolean })
|
|
||||||
.isProjectManager
|
|
||||||
) {
|
|
||||||
navigate(`/PMProjectPage/${projectName}`);
|
navigate(`/PMProjectPage/${projectName}`);
|
||||||
} else {
|
} else {
|
||||||
navigate(`/project/${projectName}`);
|
navigate(`/project/${projectName}`);
|
||||||
|
@ -36,6 +38,11 @@ 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, UpdateWeeklyReport } from "../Types/goTypes";
|
import { WeeklyReport, NewWeeklyReport } 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,7 +22,6 @@ 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(() => {
|
||||||
|
@ -61,9 +60,8 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
void fetchWeeklyReport();
|
void fetchWeeklyReport();
|
||||||
}, [projectName, fetchedWeek, token]);
|
}, [projectName, fetchedWeek, token]);
|
||||||
|
|
||||||
const handleUpdateWeeklyReport = async (): Promise<void> => {
|
const handleNewWeeklyReport = async (): Promise<void> => {
|
||||||
const updateWeeklyReport: UpdateWeeklyReport = {
|
const newWeeklyReport: NewWeeklyReport = {
|
||||||
userName: username,
|
|
||||||
projectName: projectName ?? "",
|
projectName: projectName ?? "",
|
||||||
week,
|
week,
|
||||||
developmentTime,
|
developmentTime,
|
||||||
|
@ -74,7 +72,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
testingTime,
|
testingTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
await api.updateWeeklyReport(updateWeeklyReport, token);
|
await api.submitWeeklyReport(newWeeklyReport, token);
|
||||||
};
|
};
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
@ -91,8 +89,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void handleUpdateWeeklyReport();
|
void handleNewWeeklyReport();
|
||||||
alert("Changes submitted");
|
|
||||||
navigate(-1);
|
navigate(-1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -131,12 +128,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -160,12 +152,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -189,12 +176,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -218,12 +200,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -247,12 +224,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -276,12 +248,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
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,17 +4,14 @@ import { api } from "../API/API";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all projects that user is a member of
|
* Gets all projects that user is a member of
|
||||||
* @param {Dispatch} props.setProjectsProp - A setStateAction for the array you want to put projects in
|
* @param props - 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[]>([]);
|
||||||
* GetProjects({ setProjectsProp: setProjects, username: username });
|
* GetAllUsers({ setProjectsProp: setProjects });
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
|
@ -22,7 +19,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(props.username, token);
|
const response = await api.getUserProjects(token);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setProjects(response.data ?? []);
|
setProjects(response.data ?? []);
|
||||||
} else {
|
} else {
|
||||||
|
@ -34,7 +31,7 @@ function GetProjects(props: {
|
||||||
};
|
};
|
||||||
|
|
||||||
void fetchUsers();
|
void fetchUsers();
|
||||||
}, [props.username, setProjects]);
|
}, [setProjects]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GetProjects;
|
export default GetProjects;
|
||||||
|
|
|
@ -1,25 +1,20 @@
|
||||||
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 members of a project
|
* Gets all projects that user is a member of
|
||||||
* @param string - The project's name
|
* @param props - A setStateAction for the array you want to put projects in
|
||||||
* @param Dispatch - A setStateAction for the array you want to put members in
|
|
||||||
* @returns {void} Nothing
|
* @returns {void} Nothing
|
||||||
* @example
|
* @example
|
||||||
* const [users, setUsers] = useState<User[]>([]);
|
* const [projects, setProjects] = useState<Project[]>([]);
|
||||||
* GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers });
|
* GetAllUsers({ setProjectsProp: setProjects });
|
||||||
*/
|
*/
|
||||||
function GetUsersInProject(props: {
|
function GetUsersInProject(props: {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
setUsersProp: Dispatch<React.SetStateAction<ProjectMember[]>>;
|
setUsersProp: Dispatch<React.SetStateAction<UserProjectMember[]>>;
|
||||||
}): void {
|
}): void {
|
||||||
const setUsers: Dispatch<React.SetStateAction<ProjectMember[]>> =
|
const setUsers: Dispatch<React.SetStateAction<UserProjectMember[]>> =
|
||||||
props.setUsersProp;
|
props.setUsersProp;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUsers = async (): Promise<void> => {
|
const fetchUsers = async (): Promise<void> => {
|
||||||
|
@ -29,10 +24,10 @@ function GetUsersInProject(props: {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setUsers(response.data ?? []);
|
setUsers(response.data ?? []);
|
||||||
} else {
|
} else {
|
||||||
console.error("Failed to fetch members:", response.message);
|
console.error("Failed to fetch projects:", response.message);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching members:", error);
|
console.error("Error fetching projects:", 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="">
|
<div className="mb-4">
|
||||||
<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,7 +25,6 @@ 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"
|
||||||
|
@ -42,7 +41,6 @@ function Login(props: {
|
||||||
}}
|
}}
|
||||||
value={props.password}
|
value={props.password}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<Button
|
<Button
|
||||||
text="Login"
|
text="Login"
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
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,12 +139,7 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -168,12 +163,7 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -197,12 +187,7 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -226,12 +211,7 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -255,12 +235,7 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -284,12 +259,7 @@ export default function NewWeeklyReport(): JSX.Element {
|
||||||
}}
|
}}
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
const keyValue = event.key;
|
const keyValue = event.key;
|
||||||
if (
|
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||||
!/\d/.test(keyValue) &&
|
|
||||||
keyValue !== "Backspace" &&
|
|
||||||
keyValue !== "ArrowLeft" &&
|
|
||||||
keyValue !== "ArrowRight"
|
|
||||||
)
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,49 +1,31 @@
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useState } from "react";
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import GetUsersInProject, { ProjectMember } from "./GetUsersInProject";
|
import { UserProjectMember } from "../Types/goTypes";
|
||||||
|
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<ProjectMember[]>([]);
|
const [users, setUsers] = useState<UserProjectMember[]>([]);
|
||||||
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-[61vh] w-[40] overflow-auto">
|
<div className="border-4 border-black bg-white p-2 rounded-2xl text-center h-[47vh] w-[40] flex flex-col">
|
||||||
<div className="pl-10 pr-10">
|
<div className="pl-20 pr-20">
|
||||||
<h1 className="font-bold text-[32px] mb-[20px]">
|
<h1 className="font-bold text-[32px] mb-[20px]">
|
||||||
{props.projectname}
|
{localStorage.getItem("projectName") ?? ""}
|
||||||
</h1>
|
</h1>
|
||||||
<div className="p-1 text-center">
|
<h2 className="font-bold text-[24px] mb-[20px]">Project members:</h2>
|
||||||
<h2 className="text-[20px] font-bold">Statistics:</h2>
|
<div className="border-2 border-black p-2 rounded-lg text-center overflow-scroll h-[26vh]">
|
||||||
</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) => (
|
||||||
|
@ -63,28 +45,16 @@ function ProjectInfoModal(props: {
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-x-5 my-2">
|
</div>
|
||||||
|
<div className="space-x-16">
|
||||||
<Button
|
<Button
|
||||||
text={"Delete"}
|
text={"Delete"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
if (
|
//DELETE PROJECT
|
||||||
window.confirm(
|
|
||||||
"Are you sure you want to delete this project?",
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
DeleteProject({
|
|
||||||
projectToDelete: props.projectname,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
/>
|
/>
|
||||||
<Link
|
<Link to={"/adminProjectAddMember"}>
|
||||||
to={{
|
|
||||||
pathname: "/adminProjectAddMember",
|
|
||||||
search: props.projectname,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button
|
<Button
|
||||||
text={"Add Member"}
|
text={"Add Member"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
|
@ -103,7 +73,6 @@ 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 MemberInfoModal from "./MemberInfoModal";
|
import UserInfoModal from "./UserInfoModal";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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,36 +28,39 @@ 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 => {
|
||||||
setUsername("");
|
setProjectname("");
|
||||||
setUserModalVisible(false);
|
setUserModalVisible(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{projectModalVisible && (
|
|
||||||
<ProjectInfoModal
|
<ProjectInfoModal
|
||||||
onClose={handleCloseProject}
|
onClose={handleCloseProject}
|
||||||
onClick={handleClickUser}
|
onClick={handleClickUser}
|
||||||
projectname={projectName}
|
isVisible={projectModalVisible}
|
||||||
|
projectname={projectname}
|
||||||
/>
|
/>
|
||||||
)}
|
<UserInfoModal
|
||||||
{userModalVisible && (
|
manageMember={true}
|
||||||
<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,15 +1,31 @@
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Link, useParams } from "react-router-dom";
|
import { Link, useParams } from "react-router-dom";
|
||||||
import GetUsersInProject, { ProjectMember } from "./GetUsersInProject";
|
import { api } from "../API/API";
|
||||||
|
import { UserProjectMember } from "../Types/goTypes";
|
||||||
|
|
||||||
function ProjectMembers(): JSX.Element {
|
function ProjectMembers(): JSX.Element {
|
||||||
const { projectName } = useParams();
|
const { projectName } = useParams();
|
||||||
const [projectMembers, setProjectMembers] = useState<ProjectMember[]>([]);
|
const [projectMembers, setProjectMembers] = useState<UserProjectMember[]>([]);
|
||||||
|
|
||||||
GetUsersInProject({
|
useEffect(() => {
|
||||||
projectName: projectName ?? "",
|
const getProjectMembers = async (): Promise<void> => {
|
||||||
setUsersProp: setProjectMembers,
|
const token = localStorage.getItem("accessToken") ?? "";
|
||||||
});
|
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,8 +22,6 @@ 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");
|
||||||
|
@ -49,7 +47,6 @@ 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"
|
||||||
|
@ -66,7 +63,6 @@ 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,45 +1,70 @@
|
||||||
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 [development, setDevelopment] = useState<number>();
|
const [developmentTime, setDevelopmentTime] = useState<number>();
|
||||||
const [meeting, setMeeting] = useState<number>();
|
const [meetingTime, setMeetingTime] = useState<number>();
|
||||||
const [admin, setAdmin] = useState<number>();
|
const [adminTime, setAdminTime] = useState<number>();
|
||||||
const [own_work, setOwnWork] = useState<number>();
|
const [ownWorkTime, setOwnWorkTime] = useState<number>();
|
||||||
const [study, setStudy] = useState<number>();
|
const [studyTime, setStudyTime] = useState<number>();
|
||||||
const [testing, setTesting] = useState<number>();
|
const [testingTime, setTestingTime] = 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> => {
|
||||||
const response = await api.getProjectTimes(projectName ?? "", token);
|
// Use mock data
|
||||||
{
|
const report: TimePerActivity = {
|
||||||
if (response.success) {
|
developmentTime: 100,
|
||||||
const report: projectTimes = response.data ?? {
|
meetingTime: 200,
|
||||||
development: 0,
|
adminTime: 300,
|
||||||
meeting: 0,
|
ownWorkTime: 50,
|
||||||
admin: 0,
|
studyTime: 75,
|
||||||
own_work: 0,
|
testingTime: 110,
|
||||||
study: 0,
|
|
||||||
testing: 0,
|
|
||||||
};
|
};
|
||||||
setDevelopment(report.development);
|
|
||||||
setMeeting(report.meeting);
|
// Set the state with the mock data
|
||||||
setAdmin(report.admin);
|
setDevelopmentTime(report.developmentTime);
|
||||||
setOwnWork(report.own_work);
|
setMeetingTime(report.meetingTime);
|
||||||
setStudy(report.study);
|
setAdminTime(report.adminTime);
|
||||||
setTesting(report.testing);
|
setOwnWorkTime(report.ownWorkTime);
|
||||||
} else {
|
setStudyTime(report.studyTime);
|
||||||
console.error("Failed to fetch weekly report:", response.message);
|
setTestingTime(report.testingTime);
|
||||||
}
|
|
||||||
}
|
await Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -69,8 +94,10 @@ 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={development}
|
value={developmentTime}
|
||||||
readOnly
|
onKeyDown={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -80,8 +107,10 @@ 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={meeting}
|
value={meetingTime}
|
||||||
readOnly
|
onKeyDown={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -91,8 +120,10 @@ 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={admin}
|
value={adminTime}
|
||||||
readOnly
|
onKeyDown={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -102,8 +133,10 @@ 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={own_work}
|
value={ownWorkTime}
|
||||||
readOnly
|
onKeyDown={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -113,8 +146,10 @@ 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={study}
|
value={studyTime}
|
||||||
readOnly
|
onKeyDown={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -124,8 +159,10 @@ 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={testing}
|
value={testingTime}
|
||||||
readOnly
|
onKeyDown={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -1,75 +1,51 @@
|
||||||
|
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 {
|
||||||
const [showInput, setShowInput] = useState(false);
|
if (!props.isVisible) return <></>;
|
||||||
const [newUsername, setNewUsername] = useState("");
|
const ManageUserOrMember = (check: boolean): JSX.Element => {
|
||||||
if (!props.isVisible) {
|
if (check) {
|
||||||
return <></>;
|
return (
|
||||||
}
|
<Link to="/AdminChangeRole">
|
||||||
|
<p className="mb-[20px] hover:font-bold hover:cursor-pointer underline">
|
||||||
const handleChangeNameView = (): void => {
|
(Change Role)
|
||||||
if (showInput) {
|
</p>
|
||||||
setShowInput(false);
|
</Link>
|
||||||
} 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 rounded-lg text-center flex flex-col">
|
<div className="border-4 border-black bg-white p-2 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>
|
||||||
<p
|
{ManageUserOrMember(props.manageMember)}
|
||||||
className="mb-[10px] hover:font-bold hover:cursor-pointer underline"
|
|
||||||
onClick={handleChangeNameView}
|
|
||||||
>
|
|
||||||
(Change Username)
|
|
||||||
</p>
|
|
||||||
{showInput && (
|
|
||||||
<div>
|
<div>
|
||||||
<InputField
|
<h2 className="font-bold text-[22px] mb-[20px]">
|
||||||
label={"New username"}
|
Member of these projects:
|
||||||
type={"text"}
|
</h2>
|
||||||
value={newUsername}
|
<div className="pr-6 pl-6">
|
||||||
onChange={function (e): void {
|
<UserProjectListAdmin />
|
||||||
e.defaultPrevented;
|
|
||||||
setNewUsername(e.target.value);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
text={"Change"}
|
|
||||||
onClick={function (): void {
|
|
||||||
handleClickChangeName();
|
|
||||||
}}
|
|
||||||
type={"submit"}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
<h2 className="font-bold text-[20px]">Member of these projects:</h2>
|
<div className="items-center space-x-6 pr-6 pl-6">
|
||||||
<UserProjectListAdmin username={props.username} />
|
|
||||||
<div className="items-center space-x-6">
|
|
||||||
<Button
|
<Button
|
||||||
text={"Delete"}
|
text={"Delete"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
|
@ -86,8 +62,6 @@ 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"
|
||||||
|
@ -95,7 +69,6 @@ function UserInfoModal(props: {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
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
|
||||||
|
@ -29,7 +30,9 @@ 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,17 +1,35 @@
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { api } from "../API/API";
|
||||||
import { Project } from "../Types/goTypes";
|
import { Project } from "../Types/goTypes";
|
||||||
import GetProjects from "./GetProjects";
|
|
||||||
|
|
||||||
function UserProjectListAdmin(props: { username: string }): JSX.Element {
|
function UserProjectListAdmin(): JSX.Element {
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
|
|
||||||
GetProjects({ setProjectsProp: setProjects, username: props.username });
|
useEffect(() => {
|
||||||
|
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 rounded-lg text-left overflow-auto h-[15vh] font-medium">
|
<div className="border-2 border-black bg-white p-2 rounded-lg text-center">
|
||||||
<ul className="divide-y-2">
|
<ul>
|
||||||
{projects.map((project) => (
|
{projects.map((project) => (
|
||||||
<li className="mx-2 my-1" key={project.id}>
|
<li 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 } from "../Types/goTypes";
|
import { WeeklyReport, NewWeeklyReport } 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,7 +18,6 @@ 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();
|
||||||
|
@ -46,7 +45,6 @@ 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);
|
||||||
|
@ -63,23 +61,30 @@ export default function GetOtherUsersReport(): JSX.Element {
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSignWeeklyReport = async (): Promise<void> => {
|
const handleSignWeeklyReport = async (): Promise<void> => {
|
||||||
await api.signReport(reportId, token);
|
const newWeeklyReport: NewWeeklyReport = {
|
||||||
|
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">
|
<h1 className="text-[30px] font-bold">{username}'s Report</h1>
|
||||||
{" "}
|
|
||||||
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);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -107,10 +112,7 @@ 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"
|
||||||
defaultValue={
|
value={developmentTime === 0 ? "" : developmentTime}
|
||||||
developmentTime === 0 ? "" : developmentTime
|
|
||||||
}
|
|
||||||
readOnly
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -121,8 +123,7 @@ 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"
|
||||||
defaultValue={meetingTime === 0 ? "" : meetingTime}
|
value={meetingTime === 0 ? "" : meetingTime}
|
||||||
readOnly
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -133,8 +134,7 @@ 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"
|
||||||
defaultValue={adminTime === 0 ? "" : adminTime}
|
value={adminTime === 0 ? "" : adminTime}
|
||||||
readOnly
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -145,8 +145,7 @@ 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"
|
||||||
defaultValue={ownWorkTime === 0 ? "" : ownWorkTime}
|
value={ownWorkTime === 0 ? "" : ownWorkTime}
|
||||||
readOnly
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -157,8 +156,7 @@ 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"
|
||||||
defaultValue={studyTime === 0 ? "" : studyTime}
|
value={studyTime === 0 ? "" : studyTime}
|
||||||
readOnly
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -169,8 +167,7 @@ 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"
|
||||||
defaultValue={testingTime === 0 ? "" : testingTime}
|
value={testingTime === 0 ? "" : testingTime}
|
||||||
readOnly
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
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 <></>;
|
|
||||||
}
|
|
28
frontend/src/Pages/AdminPages/AdminChangeUsername.tsx
Normal file
28
frontend/src/Pages/AdminPages/AdminChangeUsername.tsx
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
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,10 +9,7 @@ import { useState } from "react";
|
||||||
|
|
||||||
function AdminManageProjects(): JSX.Element {
|
function AdminManageProjects(): JSX.Element {
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
GetProjects({
|
GetProjects({ setProjectsProp: setProjects });
|
||||||
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 projectName = useLocation().search.slice(1);
|
const content = <AddUserToProject />;
|
||||||
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;
|
||||||
|
|
23
frontend/src/Pages/AdminPages/AdminProjectChangeUserRole.tsx
Normal file
23
frontend/src/Pages/AdminPages/AdminProjectChangeUserRole.tsx
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
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;
|
23
frontend/src/Pages/AdminPages/AdminProjectManageMembers.tsx
Normal file
23
frontend/src/Pages/AdminPages/AdminProjectManageMembers.tsx
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
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;
|
33
frontend/src/Pages/AdminPages/AdminProjectPage.tsx
Normal file
33
frontend/src/Pages/AdminPages/AdminProjectPage.tsx
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
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;
|
23
frontend/src/Pages/AdminPages/AdminProjectViewMemberInfo.tsx
Normal file
23
frontend/src/Pages/AdminPages/AdminProjectViewMemberInfo.tsx
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
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;
|
28
frontend/src/Pages/AdminPages/AdminViewUserInfo.tsx
Normal file
28
frontend/src/Pages/AdminPages/AdminViewUserInfo.tsx
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
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,44 +124,6 @@ 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
|
||||||
|
@ -189,9 +151,16 @@ 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;
|
||||||
|
@ -222,6 +191,11 @@ 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,11 +18,17 @@ 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";
|
||||||
|
@ -94,14 +100,34 @@ 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 />,
|
||||||
|
@ -110,6 +136,10 @@ 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