From aa8e9a3a7c25cebca4bd4357198fed307b76b683 Mon Sep 17 00:00:00 2001 From: Hrishav Date: Thu, 10 Aug 2023 17:32:38 +0530 Subject: [PATCH] feat: Added account setting screens (#4119) * feat: Done with new routing setup for account screens and started with account screen implementations Signed-off-by: Hrishav * feat: Added support for React-Query and automatic API generation using swagger file Signed-off-by: Hrishav * chore: Updated createAt swagger issue Signed-off-by: Hrishav * chore: Updated invitation_state Signed-off-by: Hrishav * chore: Updated invitation_state again Signed-off-by: Hrishav * feat: Added swagger API generation and several account setting screens Signed-off-by: Hrishav * feat: Added user interaction modals in settings overview Signed-off-by: Hrishav * feat: Added new automatic API generations and account setting screens Signed-off-by: Hrishav * chore: updated testUtils Signed-off-by: Hrishav * chore: updated testUtils and fixed errors Signed-off-by: Hrishav * chore: Fixed review comments Signed-off-by: Hrishav * chore: updated user search function Signed-off-by: Hrishav * chore: fixed request comments Signed-off-by: Hrishav --------- Signed-off-by: Hrishav --- .../api/handlers/rest/project_handler.go | 2 +- .../api/routes/project_router.go | 2 +- .../authentication/pkg/project/repository.go | 52 +- .../server/pkg/authorization/user_jwt.go | 4 +- chaoscenter/web/config/oats.config.ts | 33 + chaoscenter/web/package.json | 9 +- chaoscenter/web/scripts/services.mjs | 27 + chaoscenter/web/src/api/LitmusAPIProvider.tsx | 92 +- .../auth/hooks/useAcceptInvitationMutation.ts | 49 + .../auth/hooks/useCreateProjectMutation.ts | 48 + .../api/auth/hooks/useCreateUserMutation.ts | 51 + .../hooks/useDeclineInvitationMutation.ts | 47 + .../auth/hooks/useGetOwnerProjectsQuery.ts | 38 + .../auth/hooks/useGetProjectMembersQuery.ts | 44 + .../src/api/auth/hooks/useGetProjectQuery.ts | 41 + .../api/auth/hooks/useGetProjectRoleQuery.ts | 43 + .../api/auth/hooks/useGetProjectStatsQuery.ts | 34 + .../web/src/api/auth/hooks/useGetUserQuery.ts | 39 + .../auth/hooks/useGetUserWithProjectQuery.ts | 44 + .../hooks/useGetUsersForInvitationQuery.ts | 46 + .../api/auth/hooks/useLeaveProjectMutation.ts | 49 + .../api/auth/hooks/useListInvitationsQuery.ts | 44 + .../api/auth/hooks/useListProjectsQuery.ts | 38 + .../src/api/auth/hooks/useLoginMutation.ts | 47 + .../auth/hooks/useRemoveInvitationMutation.ts | 47 + .../auth/hooks/useResetPasswordMutation.ts | 49 + .../auth/hooks/useSendInvitationMutation.ts | 51 + .../web/src/api/auth/hooks/useStatusQuery.ts | 36 + .../auth/hooks/useUpdateDetailsMutation.ts | 48 + .../auth/hooks/useUpdatePasswordMutation.ts | 50 + .../hooks/useUpdateProjectNameMutation.ts | 49 + .../api/auth/hooks/useUpdateStateMutation.ts | 48 + .../web/src/api/auth/hooks/useUsersQuery.ts | 31 + chaoscenter/web/src/api/auth/index.ts | 185 ++ .../DeclineInvitationBodyRequestBody.ts | 12 + .../web/src/api/auth/schemas/ActionBy.ts | 9 + .../web/src/api/auth/schemas/ErrorModel.ts | 12 + .../api/auth/schemas/GetInvitationResponse.ts | 11 + .../api/auth/schemas/GetUserWithProject.ts | 9 + .../web/src/api/auth/schemas/LoginResponse.ts | 11 + .../web/src/api/auth/schemas/Project.ts | 17 + .../web/src/api/auth/schemas/ProjectMember.ts | 13 + chaoscenter/web/src/api/auth/schemas/User.ts | 17 + chaoscenter/web/src/api/auth/schemas/Users.ts | 6 + chaoscenter/web/src/app/App.tsx | 28 +- chaoscenter/web/src/bootstrap.tsx | 2 +- .../DefaultLayout/DefaultLayout.tsx | 6 +- .../components/MainNav/MainNav.module.scss | 12 + .../MainNav/MainNav.module.scss.d.ts | 2 + .../web/src/components/MainNav/MainNav.tsx | 77 +- .../components/ProjectCard/ProjectCard.tsx | 39 +- .../RBACSplitButton/RBACSplitButton.tsx | 6 +- .../RBACSplitButton/RBACSplitButtonOption.tsx | 6 +- .../src/components/RbacButton/RbacButton.tsx | 6 +- .../components/RbacMenuItem/RbacMenuItem.tsx | 6 +- .../SettingsWrapper.module.scss | 18 + .../SettingsWrapper.module.scss.d.ts | 11 + .../SettingsWrapper/SettingsWrapper.tsx | 138 + .../src/components/SettingsWrapper/index.ts | 3 + .../web/src/components/SideNav/SideNav.tsx | 2 +- .../StatusBadgeV2/StatusBadgeV2.tsx | 15 +- chaoscenter/web/src/config/index.ts | 14 +- .../web/src/context/AppStoreContext.tsx | 38 +- .../AccountDetailsChange.tsx | 37 + .../controllers/AccountDetailsChange/index.ts | 3 + .../AccountPasswordChange.tsx | 37 + .../AccountPasswordChange/index.ts | 3 + .../AccountSettings/AccountSettings.tsx | 26 + .../src/controllers/AccountSettings/index.ts | 3 + .../AccountSettingsOverview.tsx | 41 + .../AccountSettingsOverview/index.ts | 3 + .../AccountSettingsOverviewProjects.tsx | 72 + .../AccountSettingsOverviewProjects/index.ts | 3 + .../AccountSettingsUserManagement.tsx | 59 + .../AccountSettingsUserManagement/index.ts | 3 + .../CreateNewUser/CreateNewUser.tsx | 37 + .../src/controllers/CreateNewUser/index.ts | 3 + .../DeleteProjectInvitation.tsx | 30 + .../DeleteProjectInvitation/index.ts | 3 + .../EnableDisableUser/EnableDisableUser.tsx | 31 + .../controllers/EnableDisableUser/index.ts | 3 + .../controllers/LeaveProject/LeaveProject.tsx | 33 + .../web/src/controllers/LeaveProject/index.ts | 3 + .../web/src/controllers/Login/LoginPage.tsx | 60 +- .../ProjectSelector/ProjectSelector.tsx | 21 +- .../src/controllers/ProjectSelector/index.ts | 3 + .../ProjectSelectorList.tsx | 22 +- .../ResetPassword/ResetPassword.tsx | 24 + .../src/controllers/ResetPassword/index.ts | 3 + .../UpdateProjectName/UpdateProjectName.tsx | 40 + .../controllers/UpdateProjectName/index.ts | 3 + chaoscenter/web/src/global.d.ts | 1 + chaoscenter/web/src/hooks/useLogout.ts | 5 +- .../web/src/hooks/useRouteDefinitionsMatch.ts | 17 +- .../web/src/hooks/useRouteWithBaseUrl.ts | 19 +- chaoscenter/web/src/models/index.ts | 2 + chaoscenter/web/src/models/projects.ts | 6 + chaoscenter/web/src/models/token.ts | 6 + chaoscenter/web/src/models/user.ts | 36 +- .../web/src/routes/RouteDefinitions.ts | 22 +- .../web/src/routes/RouteDestinations.tsx | 64 +- chaoscenter/web/src/services/fetcher.ts | 51 + chaoscenter/web/src/strings/strings.en.yaml | 66 +- chaoscenter/web/src/strings/types.ts | 66 +- chaoscenter/web/src/utils/auth.ts | 14 +- .../web/src/utils/getPropsBasedOnStatus.tsx | 27 +- chaoscenter/web/src/utils/index.ts | 2 +- chaoscenter/web/src/utils/isUserAllowed.ts | 21 - chaoscenter/web/src/utils/testUtils.tsx | 38 +- chaoscenter/web/src/utils/usePermissions.ts | 26 + chaoscenter/web/src/utils/userDetails.ts | 33 +- .../AccountDetailsChange.tsx | 115 + .../AccountNameChange.module.scss | 0 .../src/views/AccountDetailsChange/index.ts | 3 + .../AccountPasswordChange.tsx | 132 + .../src/views/AccountPasswordChange/index.ts | 3 + .../AccountSettings.module.scss | 27 + .../AccountSettings.module.scss.d.ts | 10 + .../views/AccountSettings/AccountSettings.tsx | 101 + .../web/src/views/AccountSettings/index.ts | 3 + .../AccountSettingsOverview.module.scss | 4 + .../AccountSettingsOverview.module.scss.d.ts | 9 + .../AccountSettingsOverview.tsx | 73 + .../views/AccountSettingsOverview/index.ts | 3 + .../AccountSettingsUserManagement.module.scss | 53 + ...untSettingsUserManagement.module.scss.d.ts | 14 + .../AccountSettingsUserManagement.tsx | 247 ++ .../AccountSettingsUserManagement/index.ts | 3 + .../ChaosHubs/__tests__/ChaosHubs.test.tsx | 204 -- .../src/views/CreateNewUser/CreateNewUser.tsx | 137 + .../web/src/views/CreateNewUser/index.ts | 3 + .../DeleteProjectInvitation.tsx | 52 + .../views/DeleteProjectInvitation/index.ts | 3 + .../EnableDisableUser/EnableDisableUser.tsx | 55 + .../web/src/views/EnableDisableUser/index.ts | 3 + .../src/views/LeaveProject/LeaveProject.tsx | 47 + .../web/src/views/LeaveProject/index.ts | 3 + .../web/src/views/Login/LoginPage.test.tsx | 20 - chaoscenter/web/src/views/Login/LoginPage.tsx | 12 +- .../web/src/views/Overview/Overview.tsx | 2 +- .../ProjectInvitations/ProjectInvitations.tsx | 200 ++ .../ProjectsInvitation.module.scss | 28 + .../ProjectsInvitation.module.scss.d.ts | 10 + .../web/src/views/ProjectInvitations/index.ts | 3 + .../views/ProjectSelector/ProjectSelector.tsx | 10 +- .../ProjectSelectorList.tsx | 6 +- .../ProjectsJoined/ProjectsJoined.module.scss | 28 + .../ProjectsJoined.module.scss.d.ts | 10 + .../views/ProjectsJoined/ProjectsJoined.tsx | 152 + .../web/src/views/ProjectsJoined/index.ts | 3 + .../src/views/ResetPassword/ResetPassword.tsx | 124 + .../web/src/views/ResetPassword/index.ts | 3 + .../UpdateProjectName/UpdateProjectName.tsx | 103 + .../web/src/views/UpdateProjectName/index.ts | 3 + .../UserCreatedProjects.module.scss | 28 + .../UserCreatedProjects.module.scss.d.ts | 10 + .../UserCreatedProjects.tsx | 147 + .../src/views/UserCreatedProjects/index.ts | 3 + chaoscenter/web/yarn.lock | 2539 +++++------------ mkdocs/docs/auth/v3.0.0/auth-api.json | 4 +- 160 files changed, 5436 insertions(+), 2513 deletions(-) create mode 100644 chaoscenter/web/config/oats.config.ts create mode 100644 chaoscenter/web/scripts/services.mjs create mode 100644 chaoscenter/web/src/api/auth/hooks/useAcceptInvitationMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useCreateProjectMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useCreateUserMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useDeclineInvitationMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useGetOwnerProjectsQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useGetProjectMembersQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useGetProjectQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useGetProjectRoleQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useGetProjectStatsQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useGetUserQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useGetUserWithProjectQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useGetUsersForInvitationQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useLeaveProjectMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useListInvitationsQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useListProjectsQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useLoginMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useRemoveInvitationMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useResetPasswordMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useSendInvitationMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useStatusQuery.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useUpdateDetailsMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useUpdatePasswordMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useUpdateProjectNameMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useUpdateStateMutation.ts create mode 100644 chaoscenter/web/src/api/auth/hooks/useUsersQuery.ts create mode 100644 chaoscenter/web/src/api/auth/index.ts create mode 100644 chaoscenter/web/src/api/auth/requestBodies/DeclineInvitationBodyRequestBody.ts create mode 100644 chaoscenter/web/src/api/auth/schemas/ActionBy.ts create mode 100644 chaoscenter/web/src/api/auth/schemas/ErrorModel.ts create mode 100644 chaoscenter/web/src/api/auth/schemas/GetInvitationResponse.ts create mode 100644 chaoscenter/web/src/api/auth/schemas/GetUserWithProject.ts create mode 100644 chaoscenter/web/src/api/auth/schemas/LoginResponse.ts create mode 100644 chaoscenter/web/src/api/auth/schemas/Project.ts create mode 100644 chaoscenter/web/src/api/auth/schemas/ProjectMember.ts create mode 100644 chaoscenter/web/src/api/auth/schemas/User.ts create mode 100644 chaoscenter/web/src/api/auth/schemas/Users.ts create mode 100644 chaoscenter/web/src/components/SettingsWrapper/SettingsWrapper.module.scss create mode 100644 chaoscenter/web/src/components/SettingsWrapper/SettingsWrapper.module.scss.d.ts create mode 100644 chaoscenter/web/src/components/SettingsWrapper/SettingsWrapper.tsx create mode 100644 chaoscenter/web/src/components/SettingsWrapper/index.ts create mode 100644 chaoscenter/web/src/controllers/AccountDetailsChange/AccountDetailsChange.tsx create mode 100644 chaoscenter/web/src/controllers/AccountDetailsChange/index.ts create mode 100644 chaoscenter/web/src/controllers/AccountPasswordChange/AccountPasswordChange.tsx create mode 100644 chaoscenter/web/src/controllers/AccountPasswordChange/index.ts create mode 100644 chaoscenter/web/src/controllers/AccountSettings/AccountSettings.tsx create mode 100644 chaoscenter/web/src/controllers/AccountSettings/index.ts create mode 100644 chaoscenter/web/src/controllers/AccountSettingsOverview/AccountSettingsOverview.tsx create mode 100644 chaoscenter/web/src/controllers/AccountSettingsOverview/index.ts create mode 100644 chaoscenter/web/src/controllers/AccountSettingsOverviewProjects/AccountSettingsOverviewProjects.tsx create mode 100644 chaoscenter/web/src/controllers/AccountSettingsOverviewProjects/index.ts create mode 100644 chaoscenter/web/src/controllers/AccountSettingsUserManagement/AccountSettingsUserManagement.tsx create mode 100644 chaoscenter/web/src/controllers/AccountSettingsUserManagement/index.ts create mode 100644 chaoscenter/web/src/controllers/CreateNewUser/CreateNewUser.tsx create mode 100644 chaoscenter/web/src/controllers/CreateNewUser/index.ts create mode 100644 chaoscenter/web/src/controllers/DeleteProjectInvitation/DeleteProjectInvitation.tsx create mode 100644 chaoscenter/web/src/controllers/DeleteProjectInvitation/index.ts create mode 100644 chaoscenter/web/src/controllers/EnableDisableUser/EnableDisableUser.tsx create mode 100644 chaoscenter/web/src/controllers/EnableDisableUser/index.ts create mode 100644 chaoscenter/web/src/controllers/LeaveProject/LeaveProject.tsx create mode 100644 chaoscenter/web/src/controllers/LeaveProject/index.ts create mode 100644 chaoscenter/web/src/controllers/ProjectSelector/index.ts create mode 100644 chaoscenter/web/src/controllers/ResetPassword/ResetPassword.tsx create mode 100644 chaoscenter/web/src/controllers/ResetPassword/index.ts create mode 100644 chaoscenter/web/src/controllers/UpdateProjectName/UpdateProjectName.tsx create mode 100644 chaoscenter/web/src/controllers/UpdateProjectName/index.ts create mode 100644 chaoscenter/web/src/models/projects.ts create mode 100644 chaoscenter/web/src/models/token.ts create mode 100644 chaoscenter/web/src/services/fetcher.ts delete mode 100644 chaoscenter/web/src/utils/isUserAllowed.ts create mode 100644 chaoscenter/web/src/utils/usePermissions.ts create mode 100644 chaoscenter/web/src/views/AccountDetailsChange/AccountDetailsChange.tsx create mode 100644 chaoscenter/web/src/views/AccountDetailsChange/AccountNameChange.module.scss create mode 100644 chaoscenter/web/src/views/AccountDetailsChange/index.ts create mode 100644 chaoscenter/web/src/views/AccountPasswordChange/AccountPasswordChange.tsx create mode 100644 chaoscenter/web/src/views/AccountPasswordChange/index.ts create mode 100644 chaoscenter/web/src/views/AccountSettings/AccountSettings.module.scss create mode 100644 chaoscenter/web/src/views/AccountSettings/AccountSettings.module.scss.d.ts create mode 100644 chaoscenter/web/src/views/AccountSettings/AccountSettings.tsx create mode 100644 chaoscenter/web/src/views/AccountSettings/index.ts create mode 100644 chaoscenter/web/src/views/AccountSettingsOverview/AccountSettingsOverview.module.scss create mode 100644 chaoscenter/web/src/views/AccountSettingsOverview/AccountSettingsOverview.module.scss.d.ts create mode 100644 chaoscenter/web/src/views/AccountSettingsOverview/AccountSettingsOverview.tsx create mode 100644 chaoscenter/web/src/views/AccountSettingsOverview/index.ts create mode 100644 chaoscenter/web/src/views/AccountSettingsUserManagement/AccountSettingsUserManagement.module.scss create mode 100644 chaoscenter/web/src/views/AccountSettingsUserManagement/AccountSettingsUserManagement.module.scss.d.ts create mode 100644 chaoscenter/web/src/views/AccountSettingsUserManagement/AccountSettingsUserManagement.tsx create mode 100644 chaoscenter/web/src/views/AccountSettingsUserManagement/index.ts delete mode 100644 chaoscenter/web/src/views/ChaosHubs/__tests__/ChaosHubs.test.tsx create mode 100644 chaoscenter/web/src/views/CreateNewUser/CreateNewUser.tsx create mode 100644 chaoscenter/web/src/views/CreateNewUser/index.ts create mode 100644 chaoscenter/web/src/views/DeleteProjectInvitation/DeleteProjectInvitation.tsx create mode 100644 chaoscenter/web/src/views/DeleteProjectInvitation/index.ts create mode 100644 chaoscenter/web/src/views/EnableDisableUser/EnableDisableUser.tsx create mode 100644 chaoscenter/web/src/views/EnableDisableUser/index.ts create mode 100644 chaoscenter/web/src/views/LeaveProject/LeaveProject.tsx create mode 100644 chaoscenter/web/src/views/LeaveProject/index.ts delete mode 100644 chaoscenter/web/src/views/Login/LoginPage.test.tsx create mode 100644 chaoscenter/web/src/views/ProjectInvitations/ProjectInvitations.tsx create mode 100644 chaoscenter/web/src/views/ProjectInvitations/ProjectsInvitation.module.scss create mode 100644 chaoscenter/web/src/views/ProjectInvitations/ProjectsInvitation.module.scss.d.ts create mode 100644 chaoscenter/web/src/views/ProjectInvitations/index.ts create mode 100644 chaoscenter/web/src/views/ProjectsJoined/ProjectsJoined.module.scss create mode 100644 chaoscenter/web/src/views/ProjectsJoined/ProjectsJoined.module.scss.d.ts create mode 100644 chaoscenter/web/src/views/ProjectsJoined/ProjectsJoined.tsx create mode 100644 chaoscenter/web/src/views/ProjectsJoined/index.ts create mode 100644 chaoscenter/web/src/views/ResetPassword/ResetPassword.tsx create mode 100644 chaoscenter/web/src/views/ResetPassword/index.ts create mode 100644 chaoscenter/web/src/views/UpdateProjectName/UpdateProjectName.tsx create mode 100644 chaoscenter/web/src/views/UpdateProjectName/index.ts create mode 100644 chaoscenter/web/src/views/UserCreatedProjects/UserCreatedProjects.module.scss create mode 100644 chaoscenter/web/src/views/UserCreatedProjects/UserCreatedProjects.module.scss.d.ts create mode 100644 chaoscenter/web/src/views/UserCreatedProjects/UserCreatedProjects.tsx create mode 100644 chaoscenter/web/src/views/UserCreatedProjects/index.ts diff --git a/chaoscenter/authentication/api/handlers/rest/project_handler.go b/chaoscenter/authentication/api/handlers/rest/project_handler.go index 248717ab0b7..31d5478a277 100644 --- a/chaoscenter/authentication/api/handlers/rest/project_handler.go +++ b/chaoscenter/authentication/api/handlers/rest/project_handler.go @@ -153,7 +153,7 @@ func getInvitation(service services.ApplicationService, member entities.MemberIn func ListInvitations(service services.ApplicationService) gin.HandlerFunc { return func(c *gin.Context) { uID := c.MustGet("uid").(string) - invitationState := c.Param("invitation-state") + invitationState := c.Param("invitation_state") var response []entities.ListInvitationResponse projects, err := service.ListInvitations(uID, entities.Invitation(invitationState)) if err != nil { diff --git a/chaoscenter/authentication/api/routes/project_router.go b/chaoscenter/authentication/api/routes/project_router.go index 65e14c0bf48..669eaa7079b 100644 --- a/chaoscenter/authentication/api/routes/project_router.go +++ b/chaoscenter/authentication/api/routes/project_router.go @@ -18,7 +18,7 @@ func ProjectRouter(router *gin.Engine, service services.ApplicationService) { router.GET("/get_project_role/:project_id", rest.GetProjectRole(service)) router.GET("/list_projects", rest.GetProjectsByUserID(service)) router.GET("/get_projects_stats", rest.GetProjectStats(service)) - router.GET("/list_invitations_with_filters/:invitation-state", rest.ListInvitations(service)) + router.GET("/list_invitations_with_filters/:invitation_state", rest.ListInvitations(service)) router.POST("/create_project", rest.CreateProject(service)) router.POST("/send_invitation", rest.SendInvitation(service)) router.POST("/accept_invitation", rest.AcceptInvitation(service)) diff --git a/chaoscenter/authentication/pkg/project/repository.go b/chaoscenter/authentication/pkg/project/repository.go index 9ca3d1b03b1..4c34e918186 100644 --- a/chaoscenter/authentication/pkg/project/repository.go +++ b/chaoscenter/authentication/pkg/project/repository.go @@ -4,7 +4,6 @@ import ( "context" "errors" "log" - "strconv" "time" "github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/entities" @@ -88,6 +87,9 @@ func (r repository) GetProjectsByUserID(userID string, isOwner bool) ([]*entitie {"$elemMatch", bson.D{ {"user_id", userID}, {"$and", bson.A{ + bson.D{{"invitation", bson.D{ + {"$ne", entities.PendingInvitation}, + }}}, bson.D{{"invitation", bson.D{ {"$ne", entities.DeclinedInvitation}, }}}, @@ -241,7 +243,7 @@ func (r repository) UpdateInvite(projectID string, userID string, invitation ent update = bson.D{ {"$set", bson.D{ {"members.$[elem].invitation", invitation}, - {"members.$[elem].joined_at", strconv.FormatInt(time.Now().Unix(), 10)}, + {"members.$[elem].joined_at", time.Now().Unix()}, }}} case entities.ExitedProject: update = bson.D{ @@ -345,6 +347,13 @@ func (r repository) GetOwnerProjects(ctx context.Context, userID string) ([]*ent pipeline := mongo.Pipeline{ bson.D{{"$match", filter}}, bson.D{{"$project", bson.D{ + {"name", 1}, + {"state", 1}, + {"created_at", 1}, + {"updated_at", 1}, + {"created_by", 1}, + {"updated_by", 1}, + {"is_removed", 1}, {"members", bson.D{ {"$filter", bson.D{ {"input", "$members"}, @@ -471,17 +480,36 @@ func (r repository) GetProjectMembers(projectID string, state string) ([]*entiti func (r repository) ListInvitations(userID string, invitationState entities.Invitation) ([]*entities.Project, error) { var pipeline mongo.Pipeline - filter := bson.D{ - {"$match", bson.D{ - {"members", bson.D{ - {"$elemMatch", bson.D{ - {"user_id", userID}, - {"invitation", bson.D{ - {"$eq", invitationState}, + var filter bson.D + if invitationState == entities.PendingInvitation { + filter = bson.D{ + {"$match", bson.D{ + {"members", bson.D{ + {"$elemMatch", bson.D{ + {"user_id", userID}, + {"invitation", bson.D{ + {"$eq", invitationState}, + }}, }}, - }}, - }}}, - }, + }}}, + }, + } + } else if invitationState == entities.AcceptedInvitation { + filter = bson.D{ + {"$match", bson.D{ + {"members", bson.D{ + {"$elemMatch", bson.D{ + {"user_id", userID}, + {"role", bson.D{ + {"$ne", entities.RoleOwner}, + }}, + {"invitation", bson.D{ + {"$eq", invitationState}, + }}, + }}, + }}}, + }, + } } pipeline = append(pipeline, filter) diff --git a/chaoscenter/graphql/server/pkg/authorization/user_jwt.go b/chaoscenter/graphql/server/pkg/authorization/user_jwt.go index 81ea769a82a..e34f4a28ec6 100644 --- a/chaoscenter/graphql/server/pkg/authorization/user_jwt.go +++ b/chaoscenter/graphql/server/pkg/authorization/user_jwt.go @@ -13,8 +13,8 @@ import ( // UserValidateJWT validates the cluster jwt func UserValidateJWT(token string) (jwt.MapClaims, error) { tkn, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) { - if ok := token.Method.Alg() == jwt.SigningMethodHS512.Alg(); !ok { - return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) + if _, isValid := token.Method.(*jwt.SigningMethodHMAC); !isValid { + return nil, fmt.Errorf("invalid token %s", token.Header["alg"]) } return []byte(utils.Config.JwtSecret), nil }) diff --git a/chaoscenter/web/config/oats.config.ts b/chaoscenter/web/config/oats.config.ts new file mode 100644 index 00000000000..85c1e5eeaf5 --- /dev/null +++ b/chaoscenter/web/config/oats.config.ts @@ -0,0 +1,33 @@ +import { defineConfig } from '@harnessio/oats-cli'; +import reactQueryPlugin from '@harnessio/oats-plugin-react-query'; +import { mapKeys, omit } from 'lodash-es'; + +function normalizePath(url: string): string { + return url.replace(/\/{2,}/g, '/'); +} + +export default defineConfig({ + services: { + auth: { + url: 'https://raw.githubusercontent.com/litmuschaos/litmus/master/mkdocs/docs/auth/v3.0.0/auth-api.json', + output: 'src/api/auth', + transformer(spec) { + return { + ...spec, + components: { + ...spec.components, + schemas: omit(spec.components?.schemas, ['OauthSettings']) + }, + paths: mapKeys(spec.paths, (_val, key) => normalizePath(`/auth/${key}`)) + }; + }, + genOnlyUsed: true, + plugins: [ + reactQueryPlugin({ + customFetcher: 'services/fetcher', + overrides: {} + }) + ] + } + } +}); diff --git a/chaoscenter/web/package.json b/chaoscenter/web/package.json index d973595f9e4..59f4f6a108c 100644 --- a/chaoscenter/web/package.json +++ b/chaoscenter/web/package.json @@ -16,6 +16,7 @@ "test:watch": "yarn test --watch", "test:coverage": "jest --coverage --colors --maxWorkers=2", "prepare": "cd ../../ && husky install chaoscenter/web/.husky", + "services": "node scripts/services.mjs", "strings:check": "node scripts/strings/yamlStringsCheck.js", "strings:sort": "yaml-sort -i src/strings/strings.en.yaml", "typecheck": "tsc", @@ -59,8 +60,11 @@ "@blueprintjs/select": "3.12.3", "@harnessio/design-system": "^1.6.0-beta.1", "@harnessio/icons": "^2.0.0-beta.2", + "@harnessio/oats-cli": "^2.1.0", + "@harnessio/oats-plugin-react-query": "^2.1.0", "@harnessio/uicore": "^4.0.0-beta.1", "@popperjs/core": "^2.11.5", + "@tanstack/react-query": "4.20.4", "@types/d3-array": "^3.0.3", "@types/react-timeago": "^4.1.3", "@visx/axis": "^2.10.0", @@ -94,6 +98,7 @@ "masonry-layout": "^4.2.2", "moment": "^2.25.3", "normalize.css": "^8.0.1", + "prompts": "^2.4.2", "qs": "^6.9.4", "react": "^17.0.2", "react-dom": "^17.0.2", @@ -106,13 +111,13 @@ "react-table": "^7.1.0", "react-timeago": "^7.1.0", "react-to-print": "^2.14.12", - "restful-react": "15.6.0", "subscriptions-transport-ws": "^0.11.0", "swr": "^1.3.0", "uuid": "^8.3.2", "yaml": "^2.1.0", "yaml-sort": "^1.2.1", - "yup": "^0.32.11" + "yup": "^0.32.11", + "zx": "^5.3.0" }, "devDependencies": { "@apollo/react-testing": "^4.0.0", diff --git a/chaoscenter/web/scripts/services.mjs b/chaoscenter/web/scripts/services.mjs new file mode 100644 index 00000000000..4d13ee1e68c --- /dev/null +++ b/chaoscenter/web/scripts/services.mjs @@ -0,0 +1,27 @@ +import prompts from 'prompts'; +import { $ } from 'zx'; + +(async () => { + const services = ['auth']; + + services.sort(); + + const response = await prompts({ + type: 'multiselect', + name: 'services', + message: 'Please select the services you want to generate', + choices: services.map(title => ({ title })) + }); + + if (!response.services || response.services.length === 0) { + console.log('No services selected. Exiting...'); + process.exit(0); + } + + for (const index of response.services) { + const service = services[index]; + await $`npx oats import --config config/oats.config.ts --service ${service} --clean`; + } + + await $`npx prettier --write \"src/services/**/*.{ts,tsx,json,scss}\"`; +})(); diff --git a/chaoscenter/web/src/api/LitmusAPIProvider.tsx b/chaoscenter/web/src/api/LitmusAPIProvider.tsx index 37d423e1c1d..fc55e8abb4b 100644 --- a/chaoscenter/web/src/api/LitmusAPIProvider.tsx +++ b/chaoscenter/web/src/api/LitmusAPIProvider.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import axios from 'axios'; import { ApolloClient, ApolloLink, @@ -8,17 +7,14 @@ import { HttpLink, InMemoryCache, NormalizedCacheObject, - Operation, - RequestHandler, - split + RequestHandler } from '@apollo/client'; -import { WebSocketLink } from '@apollo/client/link/ws'; -import { getMainDefinition } from '@apollo/client/utilities'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { getUserDetails } from '@utils'; export interface APIConfig { gqlEndpoints: { chaosManagerUri: string; - sockURL: string; }; restEndpoints: { authUri: string; @@ -28,44 +24,27 @@ export interface APIConfig { interface LitmusAPIProviderProps { config: APIConfig; - token: string; } -function createApolloClient({ - config, - token -}: LitmusAPIProviderProps): ApolloClient | undefined { +function createApolloClient({ config }: LitmusAPIProviderProps): ApolloClient | undefined { + const { accessToken } = getUserDetails(); if (!config.gqlEndpoints) return undefined; const httpLinkUri = config.gqlEndpoints.chaosManagerUri; - const wsLinkUri = config.gqlEndpoints.sockURL; - if (!httpLinkUri && !wsLinkUri) return undefined; + if (!httpLinkUri) return undefined; let httpLink: HttpLink | null = null; - if (httpLinkUri) { - httpLink = new HttpLink({ - uri: httpLinkUri - }); - } - - let wsLink: WebSocketLink | null = null; - if (wsLinkUri) { - wsLink = new WebSocketLink({ - uri: wsLinkUri, - options: { - reconnect: true, - timeout: 30000 - } - }); - } + httpLink = new HttpLink({ + uri: httpLinkUri + }); const authLink = new ApolloLink((operation, forward) => { // add the authorization to the headers operation.setContext(({ headers = {} }) => ({ headers: { ...headers, - authorization: token + authorization: `${accessToken}` } })); @@ -73,26 +52,7 @@ function createApolloClient({ }); const links: (ApolloLink | RequestHandler)[] = [authLink]; - - // The split function takes three parameters: - // - // * A function that's called for each operation to execute - // * The Link to use for an operation if the function returns a "truthy" value - // * The Link to use for an operation if the function returns a "falsy" value - const splitOperation = ({ query }: Operation): boolean => { - const definition = getMainDefinition(query); - return definition.kind === 'OperationDefinition' && definition.operation === 'subscription'; - }; - - if (httpLink && !wsLink) { - links.push(httpLink); - } else if (!httpLink && wsLink) { - const splitLink = split(splitOperation, wsLink); - links.push(splitLink); - } else if (httpLink && wsLink) { - const splitLink = split(splitOperation, wsLink, httpLink); - links.push(splitLink); - } + links.push(httpLink); const client = new ApolloClient({ link: from(links), @@ -102,18 +62,22 @@ function createApolloClient({ return client; } -export const LitmusAPIProvider: React.FC = ({ - config, - token, - children -}): React.ReactElement => { - if (config.restEndpoints) { - axios.defaults.baseURL = config.restEndpoints.authUri; - axios.defaults.headers.common['Authorization'] = `Bearer ${token}`; - } - - // const scope = getScope(); - const apolloClient = createApolloClient({ config, token }); +export const LitmusAPIProvider: React.FC = ({ config, children }): React.ReactElement => { + const apolloClient = createApolloClient({ config }); + const reactQueryClient = new QueryClient({ + defaultOptions: { + queries: { + refetchOnWindowFocus: false + }, + mutations: { + retry: false + } + } + }); - return apolloClient ? {children} : <>; + return ( + + {apolloClient ? {children} : children} + + ); }; diff --git a/chaoscenter/web/src/api/auth/hooks/useAcceptInvitationMutation.ts b/chaoscenter/web/src/api/auth/hooks/useAcceptInvitationMutation.ts new file mode 100644 index 00000000000..d7cac267265 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useAcceptInvitationMutation.ts @@ -0,0 +1,49 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type AcceptInvitationRequestBody = { + projectID: string; + userID: string; +}; + +export type AcceptInvitationOkResponse = { + message?: string; +}; + +export type AcceptInvitationErrorResponse = unknown; + +export interface AcceptInvitationProps extends Omit, 'url'> { + body: AcceptInvitationRequestBody; +} + +export function acceptInvitation(props: AcceptInvitationProps): Promise { + return fetcher({ + url: `/auth/accept_invitation`, + method: 'POST', + ...props + }); +} + +export type AcceptInvitationMutationProps = Omit & + Partial>; + +/** + * This API is used to accept a project invite + */ +export function useAcceptInvitationMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: AcceptInvitationMutationProps) => + acceptInvitation({ ...props, ...mutateProps } as AcceptInvitationProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useCreateProjectMutation.ts b/chaoscenter/web/src/api/auth/hooks/useCreateProjectMutation.ts new file mode 100644 index 00000000000..16cc061509b --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useCreateProjectMutation.ts @@ -0,0 +1,48 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import type { Project } from '../schemas/Project'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type CreateProjectRequestBody = { + projectName: string; +}; + +export type CreateProjectOkResponse = { + data?: Project; +}; + +export type CreateProjectErrorResponse = unknown; + +export interface CreateProjectProps extends Omit, 'url'> { + body: CreateProjectRequestBody; +} + +export function createProject(props: CreateProjectProps): Promise { + return fetcher({ + url: `/auth/create_project`, + method: 'POST', + ...props + }); +} + +export type CreateProjectMutationProps = Omit & + Partial>; + +/** + * This API is used to create a project + */ +export function useCreateProjectMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: CreateProjectMutationProps) => createProject({ ...props, ...mutateProps } as CreateProjectProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useCreateUserMutation.ts b/chaoscenter/web/src/api/auth/hooks/useCreateUserMutation.ts new file mode 100644 index 00000000000..697af9e2426 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useCreateUserMutation.ts @@ -0,0 +1,51 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import type { User } from '../schemas/User'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type CreateUserRequestBody = { + email?: string; + name?: string; + password?: string; + required?: {}; + role?: string; + username?: string; +}; + +export type CreateUserOkResponse = User; + +export type CreateUserErrorResponse = unknown; + +export interface CreateUserProps extends Omit, 'url'> { + body: CreateUserRequestBody; +} + +export function createUser(props: CreateUserProps): Promise { + return fetcher({ + url: `/auth/create_user`, + method: 'POST', + ...props + }); +} + +export type CreateUserMutationProps = Omit & + Partial>; + +/** + * This API is used to create a new user. + */ +export function useCreateUserMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: CreateUserMutationProps) => createUser({ ...props, ...mutateProps } as CreateUserProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useDeclineInvitationMutation.ts b/chaoscenter/web/src/api/auth/hooks/useDeclineInvitationMutation.ts new file mode 100644 index 00000000000..b58b96c7fda --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useDeclineInvitationMutation.ts @@ -0,0 +1,47 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import type { DeclineInvitationBodyRequestBody } from '../requestBodies/DeclineInvitationBodyRequestBody'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type DeclineInvitationRequestBody = DeclineInvitationBodyRequestBody; + +export type DeclineInvitationOkResponse = { + message?: string; +}; + +export type DeclineInvitationErrorResponse = unknown; + +export interface DeclineInvitationProps extends Omit, 'url'> { + body: DeclineInvitationRequestBody; +} + +export function declineInvitation(props: DeclineInvitationProps): Promise { + return fetcher({ + url: `/auth/decline_invitation`, + method: 'POST', + ...props + }); +} + +export type DeclineInvitationMutationProps = Omit & + Partial>; + +/** + * This API is used to decline a project invite + */ +export function useDeclineInvitationMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: DeclineInvitationMutationProps) => + declineInvitation({ ...props, ...mutateProps } as DeclineInvitationProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useGetOwnerProjectsQuery.ts b/chaoscenter/web/src/api/auth/hooks/useGetOwnerProjectsQuery.ts new file mode 100644 index 00000000000..0e1015ab4c3 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useGetOwnerProjectsQuery.ts @@ -0,0 +1,38 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import type { Project } from '../schemas/Project'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type GetOwnerProjectsOkResponse = { + data?: Project[]; +}; + +export type GetOwnerProjectsErrorResponse = unknown; + +export interface GetOwnerProjectsProps extends Omit, 'url'> {} + +export function getOwnerProjects(props: GetOwnerProjectsProps): Promise { + return fetcher({ + url: `/auth/get_owner_projects`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to list all the project IDs in which the user is the owner + * + */ +export function useGetOwnerProjectsQuery( + props: GetOwnerProjectsProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['getOwnerProjects'], + ({ signal }) => getOwnerProjects({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useGetProjectMembersQuery.ts b/chaoscenter/web/src/api/auth/hooks/useGetProjectMembersQuery.ts new file mode 100644 index 00000000000..9dd364b7cc0 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useGetProjectMembersQuery.ts @@ -0,0 +1,44 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import type { ProjectMember } from '../schemas/ProjectMember'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export interface GetProjectMembersQueryPathParams { + project_id: string; + state: 'accepted' | 'all' | 'not_accepted'; +} + +export type GetProjectMembersOkResponse = { + data?: ProjectMember[]; +}; + +export type GetProjectMembersErrorResponse = unknown; + +export interface GetProjectMembersProps + extends GetProjectMembersQueryPathParams, + Omit, 'url'> {} + +export function getProjectMembers(props: GetProjectMembersProps): Promise { + return fetcher({ + url: `/auth/get_project_members/${props.project_id}/${props.state}`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to fetch members of the project based on the invitation state + */ +export function useGetProjectMembersQuery( + props: GetProjectMembersProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['getProjectMembers', props.project_id, props.state], + ({ signal }) => getProjectMembers({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useGetProjectQuery.ts b/chaoscenter/web/src/api/auth/hooks/useGetProjectQuery.ts new file mode 100644 index 00000000000..e4e213535e8 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useGetProjectQuery.ts @@ -0,0 +1,41 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import type { Project } from '../schemas/Project'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export interface GetProjectQueryPathParams { + project_id: string; +} + +export type GetProjectOkResponse = { + data?: Project; +}; + +export type GetProjectErrorResponse = unknown; + +export interface GetProjectProps extends GetProjectQueryPathParams, Omit, 'url'> {} + +export function getProject(props: GetProjectProps): Promise { + return fetcher({ + url: `/auth/get_project/${props.project_id}`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to get details of a project with given project ID + */ +export function useGetProjectQuery( + props: GetProjectProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['getProject', props.project_id], + ({ signal }) => getProject({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useGetProjectRoleQuery.ts b/chaoscenter/web/src/api/auth/hooks/useGetProjectRoleQuery.ts new file mode 100644 index 00000000000..38c8b190ced --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useGetProjectRoleQuery.ts @@ -0,0 +1,43 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export interface GetProjectRoleQueryPathParams { + project_id: string; +} + +export type GetProjectRoleOkResponse = { + role?: string; +}; + +export type GetProjectRoleErrorResponse = unknown; + +export interface GetProjectRoleProps + extends GetProjectRoleQueryPathParams, + Omit, 'url'> {} + +export function getProjectRole(props: GetProjectRoleProps): Promise { + return fetcher({ + url: `/auth/get_project_role/${props.project_id}`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to fetch the role of the user in the given project + * + */ +export function useGetProjectRoleQuery( + props: GetProjectRoleProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['getProjectRole', props.project_id], + ({ signal }) => getProjectRole({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useGetProjectStatsQuery.ts b/chaoscenter/web/src/api/auth/hooks/useGetProjectStatsQuery.ts new file mode 100644 index 00000000000..150dbb5c2ce --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useGetProjectStatsQuery.ts @@ -0,0 +1,34 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type GetProjectStatsOkResponse = { [key: string]: any }; + +export type GetProjectStatsErrorResponse = unknown; + +export interface GetProjectStatsProps extends Omit, 'url'> {} + +export function getProjectStats(props: GetProjectStatsProps): Promise { + return fetcher({ + url: `/auth/get_projects_stats`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to get overall stats for all the projects(accessible only to admin). + */ +export function useGetProjectStatsQuery( + props: GetProjectStatsProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['getProjectStats'], + ({ signal }) => getProjectStats({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useGetUserQuery.ts b/chaoscenter/web/src/api/auth/hooks/useGetUserQuery.ts new file mode 100644 index 00000000000..754e397979f --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useGetUserQuery.ts @@ -0,0 +1,39 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import type { User } from '../schemas/User'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export interface GetUserQueryPathParams { + user_id: string; +} + +export type GetUserOkResponse = User; + +export type GetUserErrorResponse = unknown; + +export interface GetUserProps extends GetUserQueryPathParams, Omit, 'url'> {} + +export function getUser(props: GetUserProps): Promise { + return fetcher({ + url: `/auth/get_user/${props.user_id}`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to get the details of an user by passing uid in the URL + */ +export function useGetUserQuery( + props: GetUserProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['getUser', props.user_id], + ({ signal }) => getUser({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useGetUserWithProjectQuery.ts b/chaoscenter/web/src/api/auth/hooks/useGetUserWithProjectQuery.ts new file mode 100644 index 00000000000..5c2458d13e8 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useGetUserWithProjectQuery.ts @@ -0,0 +1,44 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import type { GetUserWithProject } from '../schemas/GetUserWithProject'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export interface GetUserWithProjectQueryPathParams { + username: string; +} + +export type GetUserWithProjectOkResponse = { + data?: GetUserWithProject; +}; + +export type GetUserWithProjectErrorResponse = unknown; + +export interface GetUserWithProjectProps + extends GetUserWithProjectQueryPathParams, + Omit, 'url'> {} + +export function getUserWithProject(props: GetUserWithProjectProps): Promise { + return fetcher({ + url: `/auth/get_user_with_project/${props.username}`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to get details of a project for a user + * + */ +export function useGetUserWithProjectQuery( + props: GetUserWithProjectProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['getUserWithProject', props.username], + ({ signal }) => getUserWithProject({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useGetUsersForInvitationQuery.ts b/chaoscenter/web/src/api/auth/hooks/useGetUsersForInvitationQuery.ts new file mode 100644 index 00000000000..3d8124d3f46 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useGetUsersForInvitationQuery.ts @@ -0,0 +1,46 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import type { User } from '../schemas/User'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export interface GetUsersForInvitationQueryPathParams { + project_id: string; +} + +export type GetUsersForInvitationOkResponse = { + data?: User[]; +}; + +export type GetUsersForInvitationErrorResponse = unknown; + +export interface GetUsersForInvitationProps + extends GetUsersForInvitationQueryPathParams, + Omit, 'url'> {} + +export function getUsersForInvitation(props: GetUsersForInvitationProps): Promise { + return fetcher({ + url: `/auth/invite_users/${props.project_id}`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to fetch users who can be invited + */ +export function useGetUsersForInvitationQuery( + props: GetUsersForInvitationProps, + options?: Omit< + UseQueryOptions, + 'queryKey' | 'queryFn' + > +) { + return useQuery( + ['getUsersForInvitation', props.project_id], + ({ signal }) => getUsersForInvitation({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useLeaveProjectMutation.ts b/chaoscenter/web/src/api/auth/hooks/useLeaveProjectMutation.ts new file mode 100644 index 00000000000..03b8973fc23 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useLeaveProjectMutation.ts @@ -0,0 +1,49 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type LeaveProjectRequestBody = { + projectID?: string; + required?: {}; + userID?: string; +}; + +export type LeaveProjectOkResponse = { + message?: string; +}; + +export type LeaveProjectErrorResponse = unknown; + +export interface LeaveProjectProps extends Omit, 'url'> { + body: LeaveProjectRequestBody; +} + +export function leaveProject(props: LeaveProjectProps): Promise { + return fetcher({ + url: `/auth/leave_project`, + method: 'POST', + ...props + }); +} + +export type LeaveProjectMutationProps = Omit & + Partial>; + +/** + * This API is used to leave a project + */ +export function useLeaveProjectMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: LeaveProjectMutationProps) => leaveProject({ ...props, ...mutateProps } as LeaveProjectProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useListInvitationsQuery.ts b/chaoscenter/web/src/api/auth/hooks/useListInvitationsQuery.ts new file mode 100644 index 00000000000..6794b30dd63 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useListInvitationsQuery.ts @@ -0,0 +1,44 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import type { GetInvitationResponse } from '../schemas/GetInvitationResponse'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export interface ListInvitationsQueryPathParams { + invitation_state: 'Accepted' | 'Declined' | 'Exited' | 'Pending'; +} + +export type ListInvitationsOkResponse = { + data?: GetInvitationResponse[]; +}; + +export type ListInvitationsErrorResponse = unknown; + +export interface ListInvitationsProps + extends ListInvitationsQueryPathParams, + Omit, 'url'> {} + +export function listInvitations(props: ListInvitationsProps): Promise { + return fetcher({ + url: `/auth/list_invitations_with_filters/${props.invitation_state}`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to list all the pending invitations of the user + * + */ +export function useListInvitationsQuery( + props: ListInvitationsProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['listInvitations', props.invitation_state], + ({ signal }) => listInvitations({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useListProjectsQuery.ts b/chaoscenter/web/src/api/auth/hooks/useListProjectsQuery.ts new file mode 100644 index 00000000000..ab93f23e48e --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useListProjectsQuery.ts @@ -0,0 +1,38 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import type { Project } from '../schemas/Project'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type ListProjectsOkResponse = { + data?: Project[]; +}; + +export type ListProjectsErrorResponse = unknown; + +export interface ListProjectsProps extends Omit, 'url'> {} + +export function listProjects(props: ListProjectsProps): Promise { + return fetcher({ + url: `/auth/list_projects`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to get project details of logged in user + * + */ +export function useListProjectsQuery( + props: ListProjectsProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['listProjects'], + ({ signal }) => listProjects({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useLoginMutation.ts b/chaoscenter/web/src/api/auth/hooks/useLoginMutation.ts new file mode 100644 index 00000000000..406ab7b495c --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useLoginMutation.ts @@ -0,0 +1,47 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import type { LoginResponse } from '../schemas/LoginResponse'; +import type { ErrorModel } from '../schemas/ErrorModel'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type LoginRequestBody = { + password: string; + username: string; +}; + +export type LoginOkResponse = LoginResponse; + +export type LoginErrorResponse = ErrorModel; + +export interface LoginProps extends Omit, 'url'> { + body: LoginRequestBody; +} + +export function login(props: LoginProps): Promise { + return fetcher({ + url: `/auth/login`, + method: 'POST', + ...props + }); +} + +export type LoginMutationProps = Omit & Partial>; + +/** + * This API is used to login into auth server. + */ +export function useLoginMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: LoginMutationProps) => login({ ...props, ...mutateProps } as LoginProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useRemoveInvitationMutation.ts b/chaoscenter/web/src/api/auth/hooks/useRemoveInvitationMutation.ts new file mode 100644 index 00000000000..80bcb77b72b --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useRemoveInvitationMutation.ts @@ -0,0 +1,47 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import type { DeclineInvitationBodyRequestBody } from '../requestBodies/DeclineInvitationBodyRequestBody'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type RemoveInvitationRequestBody = DeclineInvitationBodyRequestBody; + +export type RemoveInvitationOkResponse = { + message?: string; +}; + +export type RemoveInvitationErrorResponse = unknown; + +export interface RemoveInvitationProps extends Omit, 'url'> { + body: RemoveInvitationRequestBody; +} + +export function removeInvitation(props: RemoveInvitationProps): Promise { + return fetcher({ + url: `/auth/remove_invitation`, + method: 'POST', + ...props + }); +} + +export type RemoveInvitationMutationProps = Omit & + Partial>; + +/** + * This API is used to revoke a project invite or remove a project member + */ +export function useRemoveInvitationMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: RemoveInvitationMutationProps) => + removeInvitation({ ...props, ...mutateProps } as RemoveInvitationProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useResetPasswordMutation.ts b/chaoscenter/web/src/api/auth/hooks/useResetPasswordMutation.ts new file mode 100644 index 00000000000..6c16ec8a7a7 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useResetPasswordMutation.ts @@ -0,0 +1,49 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type ResetPasswordRequestBody = { + newPassword: string; + oldPassword: string; + username: string; +}; + +export type ResetPasswordOkResponse = { + message?: string; +}; + +export type ResetPasswordErrorResponse = unknown; + +export interface ResetPasswordProps extends Omit, 'url'> { + body: ResetPasswordRequestBody; +} + +export function resetPassword(props: ResetPasswordProps): Promise { + return fetcher({ + url: `/auth/reset/password`, + method: 'POST', + ...props + }); +} + +export type ResetPasswordMutationProps = Omit & + Partial>; + +/** + * This API is used to reset the password of a user. + */ +export function useResetPasswordMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: ResetPasswordMutationProps) => resetPassword({ ...props, ...mutateProps } as ResetPasswordProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useSendInvitationMutation.ts b/chaoscenter/web/src/api/auth/hooks/useSendInvitationMutation.ts new file mode 100644 index 00000000000..6957bf81f51 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useSendInvitationMutation.ts @@ -0,0 +1,51 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import type { ProjectMember } from '../schemas/ProjectMember'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type SendInvitationRequestBody = { + projectID: string; + role: 'Editor' | 'Owner' | 'Viewer'; + userID: string; +}; + +export type SendInvitationOkResponse = { + data?: ProjectMember; +}; + +export type SendInvitationErrorResponse = unknown; + +export interface SendInvitationProps extends Omit, 'url'> { + body: SendInvitationRequestBody; +} + +export function sendInvitation(props: SendInvitationProps): Promise { + return fetcher({ + url: `/auth/send_invitation`, + method: 'POST', + ...props + }); +} + +export type SendInvitationMutationProps = Omit & + Partial>; + +/** + * This API is used to send project invite to an user + */ +export function useSendInvitationMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: SendInvitationMutationProps) => + sendInvitation({ ...props, ...mutateProps } as SendInvitationProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useStatusQuery.ts b/chaoscenter/web/src/api/auth/hooks/useStatusQuery.ts new file mode 100644 index 00000000000..ad8c8c736a6 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useStatusQuery.ts @@ -0,0 +1,36 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type StatusOkResponse = { + status?: string; +}; + +export type StatusErrorResponse = unknown; + +export interface StatusProps extends Omit, 'url'> {} + +export function status(props: StatusProps): Promise { + return fetcher({ + url: `/auth/status`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to check the status of the server. + */ +export function useStatusQuery( + props: StatusProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery( + ['status'], + ({ signal }) => status({ ...props, signal }), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useUpdateDetailsMutation.ts b/chaoscenter/web/src/api/auth/hooks/useUpdateDetailsMutation.ts new file mode 100644 index 00000000000..3d7f356be29 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useUpdateDetailsMutation.ts @@ -0,0 +1,48 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type UpdateDetailsRequestBody = { + email?: string; + name?: string; +}; + +export type UpdateDetailsOkResponse = { + message?: string; +}; + +export type UpdateDetailsErrorResponse = unknown; + +export interface UpdateDetailsProps extends Omit, 'url'> { + body: UpdateDetailsRequestBody; +} + +export function updateDetails(props: UpdateDetailsProps): Promise { + return fetcher({ + url: `/auth/update/details`, + method: 'POST', + ...props + }); +} + +export type UpdateDetailsMutationProps = Omit & + Partial>; + +/** + * This API is used to update the details of a user. + */ +export function useUpdateDetailsMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: UpdateDetailsMutationProps) => updateDetails({ ...props, ...mutateProps } as UpdateDetailsProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useUpdatePasswordMutation.ts b/chaoscenter/web/src/api/auth/hooks/useUpdatePasswordMutation.ts new file mode 100644 index 00000000000..78581a4a069 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useUpdatePasswordMutation.ts @@ -0,0 +1,50 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type UpdatePasswordRequestBody = { + newPassword: string; + oldPassword: string; + username: string; +}; + +export type UpdatePasswordOkResponse = { + message?: string; +}; + +export type UpdatePasswordErrorResponse = unknown; + +export interface UpdatePasswordProps extends Omit, 'url'> { + body: UpdatePasswordRequestBody; +} + +export function updatePassword(props: UpdatePasswordProps): Promise { + return fetcher({ + url: `/auth/update/password`, + method: 'POST', + ...props + }); +} + +export type UpdatePasswordMutationProps = Omit & + Partial>; + +/** + * This API is used to update the password + */ +export function useUpdatePasswordMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: UpdatePasswordMutationProps) => + updatePassword({ ...props, ...mutateProps } as UpdatePasswordProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useUpdateProjectNameMutation.ts b/chaoscenter/web/src/api/auth/hooks/useUpdateProjectNameMutation.ts new file mode 100644 index 00000000000..a6296aad535 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useUpdateProjectNameMutation.ts @@ -0,0 +1,49 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type UpdateProjectNameRequestBody = { + projectID: string; + projectName: string; +}; + +export type UpdateProjectNameOkResponse = { + message?: string; +}; + +export type UpdateProjectNameErrorResponse = unknown; + +export interface UpdateProjectNameProps extends Omit, 'url'> { + body: UpdateProjectNameRequestBody; +} + +export function updateProjectName(props: UpdateProjectNameProps): Promise { + return fetcher({ + url: `/auth/update_project_name`, + method: 'POST', + ...props + }); +} + +export type UpdateProjectNameMutationProps = Omit & + Partial>; + +/** + * This API is used to update a project name + */ +export function useUpdateProjectNameMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: UpdateProjectNameMutationProps) => + updateProjectName({ ...props, ...mutateProps } as UpdateProjectNameProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useUpdateStateMutation.ts b/chaoscenter/web/src/api/auth/hooks/useUpdateStateMutation.ts new file mode 100644 index 00000000000..6f7303394f7 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useUpdateStateMutation.ts @@ -0,0 +1,48 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useMutation, UseMutationOptions } from '@tanstack/react-query'; + +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type UpdateStateRequestBody = { + isDeactivate: boolean; + username: string; +}; + +export type UpdateStateOkResponse = { + message?: string; +}; + +export type UpdateStateErrorResponse = unknown; + +export interface UpdateStateProps extends Omit, 'url'> { + body: UpdateStateRequestBody; +} + +export function updateState(props: UpdateStateProps): Promise { + return fetcher({ + url: `/auth/update/state`, + method: 'POST', + ...props + }); +} + +export type UpdateStateMutationProps = Omit & + Partial>; + +/** + * This API is used to update the state of a user. + */ +export function useUpdateStateMutation( + props: Pick, T>, + options?: Omit< + UseMutationOptions>, + 'mutationKey' | 'mutationFn' + > +) { + return useMutation>( + (mutateProps: UpdateStateMutationProps) => updateState({ ...props, ...mutateProps } as UpdateStateProps), + options + ); +} diff --git a/chaoscenter/web/src/api/auth/hooks/useUsersQuery.ts b/chaoscenter/web/src/api/auth/hooks/useUsersQuery.ts new file mode 100644 index 00000000000..73e0ee003f1 --- /dev/null +++ b/chaoscenter/web/src/api/auth/hooks/useUsersQuery.ts @@ -0,0 +1,31 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; + +import type { Users } from '../schemas/Users'; +import { fetcher, FetcherOptions } from 'services/fetcher'; + +export type UsersOkResponse = Users; + +export type UsersErrorResponse = unknown; + +export interface UsersProps extends Omit, 'url'> {} + +export function users(props: UsersProps): Promise { + return fetcher({ + url: `/auth/users`, + method: 'GET', + ...props + }); +} + +/** + * This API is used to get the list of users + */ +export function useUsersQuery( + props: UsersProps, + options?: Omit, 'queryKey' | 'queryFn'> +) { + return useQuery(['users'], ({ signal }) => users({ ...props, signal }), options); +} diff --git a/chaoscenter/web/src/api/auth/index.ts b/chaoscenter/web/src/api/auth/index.ts new file mode 100644 index 00000000000..b49633b77c4 --- /dev/null +++ b/chaoscenter/web/src/api/auth/index.ts @@ -0,0 +1,185 @@ +export type { + AcceptInvitationErrorResponse, + AcceptInvitationMutationProps, + AcceptInvitationOkResponse, + AcceptInvitationProps, + AcceptInvitationRequestBody +} from './hooks/useAcceptInvitationMutation'; +export { acceptInvitation, useAcceptInvitationMutation } from './hooks/useAcceptInvitationMutation'; +export type { + CreateProjectErrorResponse, + CreateProjectMutationProps, + CreateProjectOkResponse, + CreateProjectProps, + CreateProjectRequestBody +} from './hooks/useCreateProjectMutation'; +export { createProject, useCreateProjectMutation } from './hooks/useCreateProjectMutation'; +export type { + CreateUserErrorResponse, + CreateUserMutationProps, + CreateUserOkResponse, + CreateUserProps, + CreateUserRequestBody +} from './hooks/useCreateUserMutation'; +export { createUser, useCreateUserMutation } from './hooks/useCreateUserMutation'; +export type { + DeclineInvitationErrorResponse, + DeclineInvitationMutationProps, + DeclineInvitationOkResponse, + DeclineInvitationProps, + DeclineInvitationRequestBody +} from './hooks/useDeclineInvitationMutation'; +export { declineInvitation, useDeclineInvitationMutation } from './hooks/useDeclineInvitationMutation'; +export type { + GetOwnerProjectsErrorResponse, + GetOwnerProjectsOkResponse, + GetOwnerProjectsProps +} from './hooks/useGetOwnerProjectsQuery'; +export { getOwnerProjects, useGetOwnerProjectsQuery } from './hooks/useGetOwnerProjectsQuery'; +export type { + GetProjectMembersErrorResponse, + GetProjectMembersOkResponse, + GetProjectMembersProps, + GetProjectMembersQueryPathParams +} from './hooks/useGetProjectMembersQuery'; +export { getProjectMembers, useGetProjectMembersQuery } from './hooks/useGetProjectMembersQuery'; +export type { + GetProjectErrorResponse, + GetProjectOkResponse, + GetProjectProps, + GetProjectQueryPathParams +} from './hooks/useGetProjectQuery'; +export { getProject, useGetProjectQuery } from './hooks/useGetProjectQuery'; +export type { + GetProjectRoleErrorResponse, + GetProjectRoleOkResponse, + GetProjectRoleProps, + GetProjectRoleQueryPathParams +} from './hooks/useGetProjectRoleQuery'; +export { getProjectRole, useGetProjectRoleQuery } from './hooks/useGetProjectRoleQuery'; +export type { + GetProjectStatsErrorResponse, + GetProjectStatsOkResponse, + GetProjectStatsProps +} from './hooks/useGetProjectStatsQuery'; +export { getProjectStats, useGetProjectStatsQuery } from './hooks/useGetProjectStatsQuery'; +export type { + GetUserErrorResponse, + GetUserOkResponse, + GetUserProps, + GetUserQueryPathParams +} from './hooks/useGetUserQuery'; +export { getUser, useGetUserQuery } from './hooks/useGetUserQuery'; +export type { + GetUserWithProjectErrorResponse, + GetUserWithProjectOkResponse, + GetUserWithProjectProps, + GetUserWithProjectQueryPathParams +} from './hooks/useGetUserWithProjectQuery'; +export { getUserWithProject, useGetUserWithProjectQuery } from './hooks/useGetUserWithProjectQuery'; +export type { + GetUsersForInvitationErrorResponse, + GetUsersForInvitationOkResponse, + GetUsersForInvitationProps, + GetUsersForInvitationQueryPathParams +} from './hooks/useGetUsersForInvitationQuery'; +export { getUsersForInvitation, useGetUsersForInvitationQuery } from './hooks/useGetUsersForInvitationQuery'; +export type { + LeaveProjectErrorResponse, + LeaveProjectMutationProps, + LeaveProjectOkResponse, + LeaveProjectProps, + LeaveProjectRequestBody +} from './hooks/useLeaveProjectMutation'; +export { leaveProject, useLeaveProjectMutation } from './hooks/useLeaveProjectMutation'; +export type { + ListInvitationsErrorResponse, + ListInvitationsOkResponse, + ListInvitationsProps, + ListInvitationsQueryPathParams +} from './hooks/useListInvitationsQuery'; +export { listInvitations, useListInvitationsQuery } from './hooks/useListInvitationsQuery'; +export type { + ListProjectsErrorResponse, + ListProjectsOkResponse, + ListProjectsProps +} from './hooks/useListProjectsQuery'; +export { listProjects, useListProjectsQuery } from './hooks/useListProjectsQuery'; +export type { + LoginErrorResponse, + LoginMutationProps, + LoginOkResponse, + LoginProps, + LoginRequestBody +} from './hooks/useLoginMutation'; +export { login, useLoginMutation } from './hooks/useLoginMutation'; +export type { + RemoveInvitationErrorResponse, + RemoveInvitationMutationProps, + RemoveInvitationOkResponse, + RemoveInvitationProps, + RemoveInvitationRequestBody +} from './hooks/useRemoveInvitationMutation'; +export { removeInvitation, useRemoveInvitationMutation } from './hooks/useRemoveInvitationMutation'; +export type { + ResetPasswordErrorResponse, + ResetPasswordMutationProps, + ResetPasswordOkResponse, + ResetPasswordProps, + ResetPasswordRequestBody +} from './hooks/useResetPasswordMutation'; +export { resetPassword, useResetPasswordMutation } from './hooks/useResetPasswordMutation'; +export type { + SendInvitationErrorResponse, + SendInvitationMutationProps, + SendInvitationOkResponse, + SendInvitationProps, + SendInvitationRequestBody +} from './hooks/useSendInvitationMutation'; +export { sendInvitation, useSendInvitationMutation } from './hooks/useSendInvitationMutation'; +export type { StatusErrorResponse, StatusOkResponse, StatusProps } from './hooks/useStatusQuery'; +export { status, useStatusQuery } from './hooks/useStatusQuery'; +export type { + UpdateDetailsErrorResponse, + UpdateDetailsMutationProps, + UpdateDetailsOkResponse, + UpdateDetailsProps, + UpdateDetailsRequestBody +} from './hooks/useUpdateDetailsMutation'; +export { updateDetails, useUpdateDetailsMutation } from './hooks/useUpdateDetailsMutation'; +export type { + UpdatePasswordErrorResponse, + UpdatePasswordMutationProps, + UpdatePasswordOkResponse, + UpdatePasswordProps, + UpdatePasswordRequestBody +} from './hooks/useUpdatePasswordMutation'; +export { updatePassword, useUpdatePasswordMutation } from './hooks/useUpdatePasswordMutation'; +export type { + UpdateProjectNameErrorResponse, + UpdateProjectNameMutationProps, + UpdateProjectNameOkResponse, + UpdateProjectNameProps, + UpdateProjectNameRequestBody +} from './hooks/useUpdateProjectNameMutation'; +export { updateProjectName, useUpdateProjectNameMutation } from './hooks/useUpdateProjectNameMutation'; +export type { + UpdateStateErrorResponse, + UpdateStateMutationProps, + UpdateStateOkResponse, + UpdateStateProps, + UpdateStateRequestBody +} from './hooks/useUpdateStateMutation'; +export { updateState, useUpdateStateMutation } from './hooks/useUpdateStateMutation'; +export type { UsersErrorResponse, UsersOkResponse, UsersProps } from './hooks/useUsersQuery'; +export { useUsersQuery, users } from './hooks/useUsersQuery'; +export type { DeclineInvitationBodyRequestBody } from './requestBodies/DeclineInvitationBodyRequestBody'; +export type { ActionBy } from './schemas/ActionBy'; +export type { ErrorModel } from './schemas/ErrorModel'; +export type { GetInvitationResponse } from './schemas/GetInvitationResponse'; +export type { GetUserWithProject } from './schemas/GetUserWithProject'; +export type { LoginResponse } from './schemas/LoginResponse'; +export type { Project } from './schemas/Project'; +export type { ProjectMember } from './schemas/ProjectMember'; +export type { User } from './schemas/User'; +export type { Users } from './schemas/Users'; diff --git a/chaoscenter/web/src/api/auth/requestBodies/DeclineInvitationBodyRequestBody.ts b/chaoscenter/web/src/api/auth/requestBodies/DeclineInvitationBodyRequestBody.ts new file mode 100644 index 00000000000..13fc54013f0 --- /dev/null +++ b/chaoscenter/web/src/api/auth/requestBodies/DeclineInvitationBodyRequestBody.ts @@ -0,0 +1,12 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. + +/** + * @example {"projectID":"384f6666-3b7d-4381-b5b5-bfc4c3dedbc8","userID":"3bdc0bd9-fc46-433b-ac21-05d555566c46"} + */ + +export interface DeclineInvitationBodyRequestBody { + projectID: string; + userID: string; +} diff --git a/chaoscenter/web/src/api/auth/schemas/ActionBy.ts b/chaoscenter/web/src/api/auth/schemas/ActionBy.ts new file mode 100644 index 00000000000..07223b4137f --- /dev/null +++ b/chaoscenter/web/src/api/auth/schemas/ActionBy.ts @@ -0,0 +1,9 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. + +export interface ActionBy { + email?: string; + userID?: string; + username?: string; +} diff --git a/chaoscenter/web/src/api/auth/schemas/ErrorModel.ts b/chaoscenter/web/src/api/auth/schemas/ErrorModel.ts new file mode 100644 index 00000000000..deadf886d22 --- /dev/null +++ b/chaoscenter/web/src/api/auth/schemas/ErrorModel.ts @@ -0,0 +1,12 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. + +export interface ErrorModel { + /** + * @format int32 + */ + code?: number; + error?: string; + errorDescription?: string; +} diff --git a/chaoscenter/web/src/api/auth/schemas/GetInvitationResponse.ts b/chaoscenter/web/src/api/auth/schemas/GetInvitationResponse.ts new file mode 100644 index 00000000000..47d86c0515b --- /dev/null +++ b/chaoscenter/web/src/api/auth/schemas/GetInvitationResponse.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import type { ProjectMember } from '../schemas/ProjectMember'; + +export interface GetInvitationResponse { + invitationRole: 'Editor' | 'Owner' | 'Viewer'; + projectID: string; + projectName: string; + projectOwner: ProjectMember; +} diff --git a/chaoscenter/web/src/api/auth/schemas/GetUserWithProject.ts b/chaoscenter/web/src/api/auth/schemas/GetUserWithProject.ts new file mode 100644 index 00000000000..42b32467d03 --- /dev/null +++ b/chaoscenter/web/src/api/auth/schemas/GetUserWithProject.ts @@ -0,0 +1,9 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import type { Project } from '../schemas/Project'; +import type { User } from '../schemas/User'; + +export interface GetUserWithProject extends User { + projects?: Project[]; +} diff --git a/chaoscenter/web/src/api/auth/schemas/LoginResponse.ts b/chaoscenter/web/src/api/auth/schemas/LoginResponse.ts new file mode 100644 index 00000000000..d5f7bb05548 --- /dev/null +++ b/chaoscenter/web/src/api/auth/schemas/LoginResponse.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. + +export interface LoginResponse { + accessToken: string; + expiresIn: number; + projectID: string; + projectRole: string; + type: string; +} diff --git a/chaoscenter/web/src/api/auth/schemas/Project.ts b/chaoscenter/web/src/api/auth/schemas/Project.ts new file mode 100644 index 00000000000..22b97f0a748 --- /dev/null +++ b/chaoscenter/web/src/api/auth/schemas/Project.ts @@ -0,0 +1,17 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import type { ActionBy } from '../schemas/ActionBy'; +import type { ProjectMember } from '../schemas/ProjectMember'; + +export interface Project { + createAt?: number; + createdBy?: ActionBy; + isRemoved?: boolean; + members: ProjectMember[]; + name: string; + projectID: string; + state?: string; + updatedAt?: number; + updatedBy?: ActionBy; +} diff --git a/chaoscenter/web/src/api/auth/schemas/ProjectMember.ts b/chaoscenter/web/src/api/auth/schemas/ProjectMember.ts new file mode 100644 index 00000000000..25d32ff5069 --- /dev/null +++ b/chaoscenter/web/src/api/auth/schemas/ProjectMember.ts @@ -0,0 +1,13 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. + +export interface ProjectMember { + email?: string; + invitation: 'Accepted' | 'Declined' | 'Exited' | 'Pending'; + joinedAt?: string; + name?: string; + role: 'Editor' | 'Owner' | 'Viewer'; + userID: string; + username: string; +} diff --git a/chaoscenter/web/src/api/auth/schemas/User.ts b/chaoscenter/web/src/api/auth/schemas/User.ts new file mode 100644 index 00000000000..30d22696c7d --- /dev/null +++ b/chaoscenter/web/src/api/auth/schemas/User.ts @@ -0,0 +1,17 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import type { ActionBy } from '../schemas/ActionBy'; + +export interface User { + createdAt?: number; + createdBy?: ActionBy; + email?: string; + isRemoved: boolean; + name?: string; + role: string; + updatedAt?: number; + updatedBy?: ActionBy; + userID: string; + username: string; +} diff --git a/chaoscenter/web/src/api/auth/schemas/Users.ts b/chaoscenter/web/src/api/auth/schemas/Users.ts new file mode 100644 index 00000000000..6fbb8057765 --- /dev/null +++ b/chaoscenter/web/src/api/auth/schemas/Users.ts @@ -0,0 +1,6 @@ +/* eslint-disable */ +// This code is autogenerated using @harnessio/oats-cli. +// Please do not modify this code directly. +import type { User } from '../schemas/User'; + +export type Users = User[]; diff --git a/chaoscenter/web/src/app/App.tsx b/chaoscenter/web/src/app/App.tsx index f94053e4c04..029b2b0fab4 100644 --- a/chaoscenter/web/src/app/App.tsx +++ b/chaoscenter/web/src/app/App.tsx @@ -1,41 +1,20 @@ import React from 'react'; -import jwtDecode from 'jwt-decode'; import { StringsContext } from 'strings'; import { LitmusAPIProvider } from '@api/LitmusAPIProvider'; import { RoutesWithAuthentication, RoutesWithoutAuthentication } from '@routes/RouteDestinations'; import strings from 'strings/strings.en.yaml'; import APIEndpoints from '@config'; -import { getUserDetails } from '@utils'; import type { StringsMap } from 'strings/types'; import { useLogout } from '@hooks'; import { AppStoreProvider } from '@context'; -interface DecodedTokenType { - exp: number; - role: string; - uid: string; - username: string; -} export function AppWithAuthentication(): React.ReactElement { - const userDetails = getUserDetails(); const { forceLogout } = useLogout(); try { - const tokenDecode: DecodedTokenType = jwtDecode(userDetails.token); return ( - void 0} - > + - + @@ -48,10 +27,9 @@ export function AppWithAuthentication(): React.ReactElement { } export function AppWithoutAuthentication(): React.ReactElement { - const userDetails = getUserDetails(); return ( - + diff --git a/chaoscenter/web/src/bootstrap.tsx b/chaoscenter/web/src/bootstrap.tsx index 8c2daa8ad73..808645d3a0f 100644 --- a/chaoscenter/web/src/bootstrap.tsx +++ b/chaoscenter/web/src/bootstrap.tsx @@ -7,7 +7,7 @@ import './bootstrap.scss'; ReactDOM.render( - + diff --git a/chaoscenter/web/src/components/DefaultLayout/DefaultLayout.tsx b/chaoscenter/web/src/components/DefaultLayout/DefaultLayout.tsx index d37e131b0a8..45f6bd9649e 100644 --- a/chaoscenter/web/src/components/DefaultLayout/DefaultLayout.tsx +++ b/chaoscenter/web/src/components/DefaultLayout/DefaultLayout.tsx @@ -21,6 +21,7 @@ export interface DefaultLayoutTemplateProps { message: React.ReactNode; }; loading?: boolean; + hideSideNav?: boolean; } export default function DefaultLayoutTemplate({ @@ -33,7 +34,8 @@ export default function DefaultLayoutTemplate({ rightSideBar, levelUpBanner, loading, - children + children, + hideSideNav }: React.PropsWithChildren): React.ReactElement { const breadCrumb = ; return ( @@ -41,7 +43,7 @@ export default function DefaultLayoutTemplate({ - + {!hideSideNav && } { +export const LitmusNavItem = (): React.ReactElement => { + const projectScopedPaths = useRouteWithBaseUrl(); const { getString } = useStrings(); + return ( - - - + !location.pathname.includes('/settings/')} + activeClassName={css.active} + to={projectScopedPaths.toDashboard} > - {getString('litmus')} - - + + + + {getString('litmus')} + + + + ); }; export default function MainNav(): React.ReactElement { + const accountScopedPaths = useRouteWithBaseUrl('account'); const { getString } = useStrings(); - const userData = useContext(AppStoreContext); + const { currentUserInfo } = useAppStore(); const { forceLogout } = useLogout(); + return (