From 50e22da113999912aa941ef4db1f78cd275ffe2b Mon Sep 17 00:00:00 2001 From: harish Date: Fri, 20 Dec 2024 18:43:43 -0500 Subject: [PATCH 1/5] #2816 progress --- .../src/pages/HomePage/OnboardingHomePage.tsx | 28 +++++++++++++--- .../ConfirmOnboardingChecklistModal.tsx | 32 +++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx diff --git a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx index b294cb178e..9c18ea882f 100644 --- a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx +++ b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx @@ -1,16 +1,19 @@ -import { Box, Grid, Typography } from '@mui/material'; +import { Box, Grid, Typography, Button } from '@mui/material'; import PageLayout from '../../components/PageLayout'; import { useCurrentOrganization } from '../../hooks/organizations.hooks'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import LoadingIndicator from '../../components/LoadingIndicator'; import ErrorPage from '../ErrorPage'; import { useHomePageContext } from '../../app/HomePageContext'; import ChecklistSection from './components/ChecklistSection'; import OnboardingInfoSection from './components/OnboardingInfoSection'; +import ConfirmOnboardingChecklistModal from './components/ConfirmOnboardingChecklistModal'; // Import the modal +import { NERButton } from '../../components/NERButton'; const OnboardingHomePage = () => { const { data: organization, isError, error, isLoading } = useCurrentOrganization(); const { setCurrentHomePage } = useHomePageContext(); + const [isModalOpen, setModalOpen] = useState(false); // State to manage modal visibility useEffect(() => { setCurrentHomePage('onboarding'); @@ -19,15 +22,25 @@ const OnboardingHomePage = () => { if (!organization || isLoading) return ; if (isError) return ; + const handleOpenModal = () => { + setModalOpen(true); + }; + + const handleCloseModal = () => { + setModalOpen(false); + }; + return ( Welcome to the {organization.name} Team - {/* This will be replaced with the 'Finished' button*/} - Finished + {/* Replace with the 'Finished' button */} + + Finished + { }} > - {/* This will be replaced with the 'Progress Bar' component*/} + {/* Replace with the 'Progress Bar' component */} Progress Bar @@ -64,7 +77,12 @@ const OnboardingHomePage = () => { + {/* Render modal conditionally */} + {isModalOpen && } ); }; + export default OnboardingHomePage; diff --git a/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx b/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx new file mode 100644 index 0000000000..847d511718 --- /dev/null +++ b/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx @@ -0,0 +1,32 @@ +import React from 'react'; +import { FieldValues, useForm } from 'react-hook-form'; +import { Typography } from '@mui/material'; +import NERFormModal from '../../../components/NERFormModal'; +import { NERModalProps } from '../../../components/NERModal'; + +interface ConfirmOnboardingChecklistModalProps extends Omit { + onFormSubmit: (data: T) => void; +} + +const ConfirmOnboardingChecklistModal = ({ open, onHide, onFormSubmit }: ConfirmOnboardingCHecklistModalProps) => { + const { handleSubmit, reset } = useForm({ + mode: 'onChange' + }); + + return ( + + Looks like you completed everything on the onboarding checklist! {dataType}? + You sure you want to submit? + + ); +}; + +export default ConfirmOnboardingChecklistModal; From a85ec326b316df3b7d1d55798da958ecc0160367 Mon Sep 17 00:00:00 2001 From: harish Date: Fri, 20 Dec 2024 19:37:48 -0500 Subject: [PATCH 2/5] #2816 modal done --- .../src/pages/HomePage/OnboardingHomePage.tsx | 29 ++++++--- .../ConfirmOnboardingChecklistModal.tsx | 59 +++++++++++-------- 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx index 9c18ea882f..c16fcd9123 100644 --- a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx +++ b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx @@ -1,19 +1,22 @@ -import { Box, Grid, Typography, Button } from '@mui/material'; +import { Box, Grid, Typography } from '@mui/material'; import PageLayout from '../../components/PageLayout'; import { useCurrentOrganization } from '../../hooks/organizations.hooks'; -import { useEffect, useState } from 'react'; +import React, { useEffect, useState } from 'react'; import LoadingIndicator from '../../components/LoadingIndicator'; import ErrorPage from '../ErrorPage'; import { useHomePageContext } from '../../app/HomePageContext'; import ChecklistSection from './components/ChecklistSection'; import OnboardingInfoSection from './components/OnboardingInfoSection'; -import ConfirmOnboardingChecklistModal from './components/ConfirmOnboardingChecklistModal'; // Import the modal +import ConfirmOnboardingChecklistModal from './components/ConfirmOnboardingChecklistModal'; import { NERButton } from '../../components/NERButton'; +import { useCurrentUser } from '../../hooks/users.hooks'; const OnboardingHomePage = () => { const { data: organization, isError, error, isLoading } = useCurrentOrganization(); const { setCurrentHomePage } = useHomePageContext(); - const [isModalOpen, setModalOpen] = useState(false); // State to manage modal visibility + const [isModalOpen, setModalOpen] = useState(false); + + const user = useCurrentUser(); useEffect(() => { setCurrentHomePage('onboarding'); @@ -30,6 +33,11 @@ const OnboardingHomePage = () => { setModalOpen(false); }; + const handleConfirmModal = () => { + user.role = 'MEMBER'; + setModalOpen(false); + }; + return ( @@ -37,7 +45,6 @@ const OnboardingHomePage = () => { Welcome to the {organization.name} Team - {/* Replace with the 'Finished' button */} Finished @@ -52,7 +59,6 @@ const OnboardingHomePage = () => { }} > - {/* Replace with the 'Progress Bar' component */} Progress Bar @@ -78,9 +84,14 @@ const OnboardingHomePage = () => { {/* Render modal conditionally */} - {isModalOpen && } + {isModalOpen && ( + + )} ); }; diff --git a/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx b/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx index 847d511718..e15624295f 100644 --- a/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx +++ b/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx @@ -1,31 +1,44 @@ import React from 'react'; -import { FieldValues, useForm } from 'react-hook-form'; -import { Typography } from '@mui/material'; -import NERFormModal from '../../../components/NERFormModal'; -import { NERModalProps } from '../../../components/NERModal'; +import { Typography, Box } from '@mui/material'; +import NERModal from '../../../components/NERModal'; -interface ConfirmOnboardingChecklistModalProps extends Omit { - onFormSubmit: (data: T) => void; +interface ConfirmOnboardingChecklistModalProps { + open: boolean; + onHide: () => void; + onConfirm: () => void; + title?: string; + message?: string; } -const ConfirmOnboardingChecklistModal = ({ open, onHide, onFormSubmit }: ConfirmOnboardingCHecklistModalProps) => { - const { handleSubmit, reset } = useForm({ - mode: 'onChange' - }); - +const ConfirmOnboardingChecklistModal: React.FC = ({ + open, + onHide, + title = 'Confirm Action' +}) => { return ( - - Looks like you completed everything on the onboarding checklist! {dataType}? - You sure you want to submit? - + + + + Looks like you completed everything on the onboarding checklist! + + + + You sure you want to submit? + + + + (After you submit, you will be officially onboarded into NER!) + + + ); }; From 62efe19ff373ff03dd4c3780b7d7101ae6e21116 Mon Sep 17 00:00:00 2001 From: harish Date: Fri, 20 Dec 2024 19:46:49 -0500 Subject: [PATCH 3/5] #2816 modal handles user promotion --- .../src/pages/HomePage/OnboardingHomePage.tsx | 37 ++----------------- .../ConfirmOnboardingChecklistModal.tsx | 14 +++++-- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx index c16fcd9123..b294cb178e 100644 --- a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx +++ b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx @@ -1,22 +1,16 @@ import { Box, Grid, Typography } from '@mui/material'; import PageLayout from '../../components/PageLayout'; import { useCurrentOrganization } from '../../hooks/organizations.hooks'; -import React, { useEffect, useState } from 'react'; +import { useEffect } from 'react'; import LoadingIndicator from '../../components/LoadingIndicator'; import ErrorPage from '../ErrorPage'; import { useHomePageContext } from '../../app/HomePageContext'; import ChecklistSection from './components/ChecklistSection'; import OnboardingInfoSection from './components/OnboardingInfoSection'; -import ConfirmOnboardingChecklistModal from './components/ConfirmOnboardingChecklistModal'; -import { NERButton } from '../../components/NERButton'; -import { useCurrentUser } from '../../hooks/users.hooks'; const OnboardingHomePage = () => { const { data: organization, isError, error, isLoading } = useCurrentOrganization(); const { setCurrentHomePage } = useHomePageContext(); - const [isModalOpen, setModalOpen] = useState(false); - - const user = useCurrentUser(); useEffect(() => { setCurrentHomePage('onboarding'); @@ -25,29 +19,15 @@ const OnboardingHomePage = () => { if (!organization || isLoading) return ; if (isError) return ; - const handleOpenModal = () => { - setModalOpen(true); - }; - - const handleCloseModal = () => { - setModalOpen(false); - }; - - const handleConfirmModal = () => { - user.role = 'MEMBER'; - setModalOpen(false); - }; - return ( Welcome to the {organization.name} Team + {/* This will be replaced with the 'Finished' button*/} - - Finished - + Finished { }} > + {/* This will be replaced with the 'Progress Bar' component*/} Progress Bar @@ -83,17 +64,7 @@ const OnboardingHomePage = () => { - {/* Render modal conditionally */} - {isModalOpen && ( - - )} ); }; - export default OnboardingHomePage; diff --git a/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx b/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx index e15624295f..dd2d2adcee 100644 --- a/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx +++ b/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx @@ -1,13 +1,12 @@ import React from 'react'; import { Typography, Box } from '@mui/material'; import NERModal from '../../../components/NERModal'; +import { useCurrentUser } from '../../../hooks/users.hooks'; interface ConfirmOnboardingChecklistModalProps { open: boolean; onHide: () => void; - onConfirm: () => void; title?: string; - message?: string; } const ConfirmOnboardingChecklistModal: React.FC = ({ @@ -15,8 +14,17 @@ const ConfirmOnboardingChecklistModal: React.FC { + const user = useCurrentUser(); + + const handleConfirm = () => { + if (user) { + user.role = 'MEMBER'; + } + onHide(); + }; + return ( - + Date: Wed, 25 Dec 2024 17:24:27 -0500 Subject: [PATCH 4/5] #2816 user promotion --- src/backend/src/prisma/schema.prisma | 2 +- src/backend/src/services/users.services.ts | 18 ++++- src/frontend/src/apis/users.api.ts | 4 + src/frontend/src/hooks/users.hooks.ts | 25 ++++++- .../src/pages/HomePage/OnboardingHomePage.tsx | 73 ++++++++++++------- .../ConfirmOnboardingChecklistModal.tsx | 16 +--- src/frontend/src/utils/urls.ts | 4 +- src/shared/src/types/user-types.ts | 4 + 8 files changed, 101 insertions(+), 45 deletions(-) diff --git a/src/backend/src/prisma/schema.prisma b/src/backend/src/prisma/schema.prisma index d693609748..8f4a185042 100644 --- a/src/backend/src/prisma/schema.prisma +++ b/src/backend/src/prisma/schema.prisma @@ -116,7 +116,7 @@ model User { googleAuthId String @unique email String @unique emailId String? @unique - completedOnboarding Boolean @default(true) + completedOnboarding Boolean @default(false) roles Role[] userSettings User_Settings? userSecureSettings User_Secure_Settings? diff --git a/src/backend/src/services/users.services.ts b/src/backend/src/services/users.services.ts index a03c231000..e69e88d10a 100644 --- a/src/backend/src/services/users.services.ts +++ b/src/backend/src/services/users.services.ts @@ -395,7 +395,7 @@ export default class UsersService { } /** - * Toggles the completed onboarding status of a user + * Toggles the completed onboarding status of a user and elevates role to member if user completed onboarding * @param user the user who's onboarding status is being toggled * @returns the updated user */ @@ -409,8 +409,24 @@ export default class UsersService { ...getUserQueryArgs(organization.organizationId) }); + if (updatedUser.completedOnboarding) { + const currentRole = updatedUser.roles.find((role) => role.organizationId === organization.organizationId); + + if (currentRole && currentRole.roleType !== RoleEnum.MEMBER) { + await prisma.role.update({ + where: { + uniqueRole: { userId, organizationId: organization.organizationId } + }, + data: { + roleType: RoleEnum.MEMBER + } + }); + } + } + return userTransformer(updatedUser); } + /** * Gets a user's secure settings * @param userId the id of user who's secure settings are being returned diff --git a/src/frontend/src/apis/users.api.ts b/src/frontend/src/apis/users.api.ts index 44d7a40d70..36770460fc 100644 --- a/src/frontend/src/apis/users.api.ts +++ b/src/frontend/src/apis/users.api.ts @@ -141,3 +141,7 @@ export const updateUserScheduleSettings = (settings: SetUserScheduleSettingsPayl export const updateUserRole = (id: string, role: string) => { return axios.post<{ message: string }>(apiUrls.userRoleByUserId(id), { role }); }; + +export const toggleCompletedOnboarding = (id: string) => { + return axios.post<{ message: string }>(apiUrls.toggleCompletedOnboarding(id)); +}; diff --git a/src/frontend/src/hooks/users.hooks.ts b/src/frontend/src/hooks/users.hooks.ts index b0c76b09b9..835141f47d 100644 --- a/src/frontend/src/hooks/users.hooks.ts +++ b/src/frontend/src/hooks/users.hooks.ts @@ -17,7 +17,8 @@ import { getCurrentUserSecureSettings, getUserSecureSettings, getUserScheduleSettings, - updateUserScheduleSettings + updateUserScheduleSettings, + toggleCompletedOnboarding } from '../apis/users.api'; import { User, @@ -28,7 +29,8 @@ import { UserSecureSettings, UserScheduleSettings, UserWithScheduleSettings, - SetUserScheduleSettingsPayload + SetUserScheduleSettingsPayload, + ToggleCompletedOnboardingPayload } from 'shared'; import { useAuth } from './auth.hooks'; import { useContext } from 'react'; @@ -233,3 +235,22 @@ export const useUpdateUserRole = () => { } ); }; + +/** + * Custom React Hook to update a user's role. + */ +export const useToggleCompletedOnboarding = () => { + const queryClient = useQueryClient(); + return useMutation<{ message: string }, Error, ToggleCompletedOnboardingPayload>( + ['users', 'toggle-onboarding'], + async (toggleCompletedOnboardingPayload: ToggleCompletedOnboardingPayload) => { + const { data } = await toggleCompletedOnboarding(toggleCompletedOnboardingPayload.userId); + return data; + }, + { + onSuccess: () => { + queryClient.invalidateQueries(['users']); + } + } + ); +}; diff --git a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx index a9e8dd006d..fa2ceda074 100644 --- a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx +++ b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx @@ -1,19 +1,29 @@ -import React, { useEffect } from 'react'; -import { Box, Grid, Typography, useTheme } from '@mui/material'; +import { Box, Grid, Typography } from '@mui/material'; import PageLayout from '../../components/PageLayout'; import { useCurrentOrganization } from '../../hooks/organizations.hooks'; +import React, { useEffect, useState } from 'react'; import LoadingIndicator from '../../components/LoadingIndicator'; import ErrorPage from '../ErrorPage'; import { useHomePageContext } from '../../app/HomePageContext'; import ChecklistSection from './components/ChecklistSection'; import OnboardingInfoSection from './components/OnboardingInfoSection'; -import OnboardingProgressBar from '../../components/OnboardingProgressBar'; +import ConfirmOnboardingChecklistModal from './components/ConfirmOnboardingChecklistModal'; import { NERButton } from '../../components/NERButton'; +import { useCurrentUser, useToggleCompletedOnboarding } from '../../hooks/users.hooks'; +import { useToast } from '../../hooks/toasts.hooks'; const OnboardingHomePage = () => { const { data: organization, isError, error, isLoading } = useCurrentOrganization(); const { setCurrentHomePage } = useHomePageContext(); - const theme = useTheme(); + const [isModalOpen, setModalOpen] = useState(false); + + const user = useCurrentUser(); + + console.log(user); + + const toast = useToast(); + + const toggleCompletedOnboarding = useToggleCompletedOnboarding(); useEffect(() => { setCurrentHomePage('onboarding'); @@ -22,13 +32,31 @@ const OnboardingHomePage = () => { if (!organization || isLoading) return ; if (isError) return ; + const handleOpenModal = () => { + setModalOpen(true); + }; + + const handleCloseModal = () => { + setModalOpen(false); + }; + + const handleConfirmModal = async () => { + await toggleCompletedOnboarding.mutateAsync({ userId: user.userId }); + toast.success('Role updated successfully!'); + setModalOpen(false); + }; + return ( - + Welcome to the {organization.name} Team - Finished? + + + Finished? + + { flexDirection: 'column' }} > - - - - + + Progress Bar - + { + {isModalOpen && ( + + )} ); }; diff --git a/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx b/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx index dd2d2adcee..9394797ee3 100644 --- a/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx +++ b/src/frontend/src/pages/HomePage/components/ConfirmOnboardingChecklistModal.tsx @@ -1,34 +1,26 @@ import React from 'react'; import { Typography, Box } from '@mui/material'; import NERModal from '../../../components/NERModal'; -import { useCurrentUser } from '../../../hooks/users.hooks'; interface ConfirmOnboardingChecklistModalProps { open: boolean; onHide: () => void; + onConfirm: () => void; title?: string; + message?: string; } const ConfirmOnboardingChecklistModal: React.FC = ({ open, onHide, + onConfirm, title = 'Confirm Action' }) => { - const user = useCurrentUser(); - - const handleConfirm = () => { - if (user) { - user.role = 'MEMBER'; - } - onHide(); - }; - return ( - + `${users()}/secure-settings/current-user const userSecureSettingsSet = () => `${users()}/secure-settings/set`; const userRoleByUserId = (id: string) => `${usersById(id)}/change-role`; const userFavoriteProjects = (id: string) => `${usersById(id)}/favorite-projects`; -const userSecureSettings = (id: string) => `${usersById(id)}/secure-settings`; +const userSecureSettings = (id: string) => `${usersById(id)}/secure-psettings`; const userScheduleSettings = (id: string) => `${usersById(id)}/schedule-settings`; const userScheduleSettingsSet = () => `${users()}/schedule-settings/set`; +const toggleCompletedOnboarding = (id: string) => `${usersById(id)}/toggle-completed-onboarding`; /**************** Projects Endpoints ****************/ const projects = () => `${API_URL}/projects`; @@ -217,6 +218,7 @@ export const apiUrls = { userSecureSettings, userScheduleSettings, userScheduleSettingsSet, + toggleCompletedOnboarding, projects, allProjects, diff --git a/src/shared/src/types/user-types.ts b/src/shared/src/types/user-types.ts index 4cb0626f96..6ae35fb093 100644 --- a/src/shared/src/types/user-types.ts +++ b/src/shared/src/types/user-types.ts @@ -91,6 +91,10 @@ export interface UpdateUserRolePayload { role: string; } +export interface ToggleCompletedOnboardingPayload { + userId: string; +} + export interface UserScheduleSettings { drScheduleSettingsId: string; personalGmail: string; From ecc8c8c77fef51688fe04fb807ce30cc3a29b044 Mon Sep 17 00:00:00 2001 From: harish Date: Thu, 2 Jan 2025 17:15:22 -0500 Subject: [PATCH 5/5] #2816 optimizing hook --- src/backend/src/controllers/users.controllers.ts | 2 +- src/backend/src/prisma/schema.prisma | 2 +- src/backend/src/routes/users.routes.ts | 2 +- src/frontend/src/apis/users.api.ts | 4 ++-- src/frontend/src/hooks/users.hooks.ts | 11 +++++------ .../src/pages/HomePage/OnboardingHomePage.tsx | 8 ++------ src/frontend/src/utils/urls.ts | 4 ++-- src/shared/src/types/user-types.ts | 4 ---- 8 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/backend/src/controllers/users.controllers.ts b/src/backend/src/controllers/users.controllers.ts index 458c19b8e4..4e6c9a9b8c 100644 --- a/src/backend/src/controllers/users.controllers.ts +++ b/src/backend/src/controllers/users.controllers.ts @@ -117,7 +117,7 @@ export default class UsersController { static async toggleCompletedOnboarding(req: Request, res: Response, next: NextFunction) { try { - const { userId } = req.params; + const { userId } = req.currentUser; await UsersService.toggleCompletedOnboarding(userId, req.organization); diff --git a/src/backend/src/prisma/schema.prisma b/src/backend/src/prisma/schema.prisma index 8f4a185042..d693609748 100644 --- a/src/backend/src/prisma/schema.prisma +++ b/src/backend/src/prisma/schema.prisma @@ -116,7 +116,7 @@ model User { googleAuthId String @unique email String @unique emailId String? @unique - completedOnboarding Boolean @default(false) + completedOnboarding Boolean @default(true) roles Role[] userSettings User_Settings? userSecureSettings User_Secure_Settings? diff --git a/src/backend/src/routes/users.routes.ts b/src/backend/src/routes/users.routes.ts index 3a580231e5..c80e2d5ed3 100644 --- a/src/backend/src/routes/users.routes.ts +++ b/src/backend/src/routes/users.routes.ts @@ -19,7 +19,7 @@ userRouter.post( UsersController.updateUserSettings ); userRouter.post('/:userId/change-role', isRole(body('role')), validateInputs, UsersController.updateUserRole); -userRouter.post('/:userId/toggle-completed-onboarding', UsersController.toggleCompletedOnboarding); +userRouter.post('/toggle-completed-onboarding', UsersController.toggleCompletedOnboarding); userRouter.post('/auth/login', UsersController.logUserIn); userRouter.post('/auth/login/dev', UsersController.logUserInDev); userRouter.post( diff --git a/src/frontend/src/apis/users.api.ts b/src/frontend/src/apis/users.api.ts index 36770460fc..1ae1171efb 100644 --- a/src/frontend/src/apis/users.api.ts +++ b/src/frontend/src/apis/users.api.ts @@ -142,6 +142,6 @@ export const updateUserRole = (id: string, role: string) => { return axios.post<{ message: string }>(apiUrls.userRoleByUserId(id), { role }); }; -export const toggleCompletedOnboarding = (id: string) => { - return axios.post<{ message: string }>(apiUrls.toggleCompletedOnboarding(id)); +export const toggleCompletedOnboarding = () => { + return axios.post<{ message: string }>(apiUrls.toggleCompletedOnboarding()); }; diff --git a/src/frontend/src/hooks/users.hooks.ts b/src/frontend/src/hooks/users.hooks.ts index 835141f47d..d8f2a20137 100644 --- a/src/frontend/src/hooks/users.hooks.ts +++ b/src/frontend/src/hooks/users.hooks.ts @@ -29,8 +29,7 @@ import { UserSecureSettings, UserScheduleSettings, UserWithScheduleSettings, - SetUserScheduleSettingsPayload, - ToggleCompletedOnboardingPayload + SetUserScheduleSettingsPayload } from 'shared'; import { useAuth } from './auth.hooks'; import { useContext } from 'react'; @@ -237,14 +236,14 @@ export const useUpdateUserRole = () => { }; /** - * Custom React Hook to update a user's role. + * Custom React Hook to toggle the current user's completed onboarding status. */ export const useToggleCompletedOnboarding = () => { const queryClient = useQueryClient(); - return useMutation<{ message: string }, Error, ToggleCompletedOnboardingPayload>( + return useMutation<{ message: string }, Error>( ['users', 'toggle-onboarding'], - async (toggleCompletedOnboardingPayload: ToggleCompletedOnboardingPayload) => { - const { data } = await toggleCompletedOnboarding(toggleCompletedOnboardingPayload.userId); + async () => { + const { data } = await toggleCompletedOnboarding(); return data; }, { diff --git a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx index fa2ceda074..a410a91fb8 100644 --- a/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx +++ b/src/frontend/src/pages/HomePage/OnboardingHomePage.tsx @@ -9,7 +9,7 @@ import ChecklistSection from './components/ChecklistSection'; import OnboardingInfoSection from './components/OnboardingInfoSection'; import ConfirmOnboardingChecklistModal from './components/ConfirmOnboardingChecklistModal'; import { NERButton } from '../../components/NERButton'; -import { useCurrentUser, useToggleCompletedOnboarding } from '../../hooks/users.hooks'; +import { useToggleCompletedOnboarding } from '../../hooks/users.hooks'; import { useToast } from '../../hooks/toasts.hooks'; const OnboardingHomePage = () => { @@ -17,10 +17,6 @@ const OnboardingHomePage = () => { const { setCurrentHomePage } = useHomePageContext(); const [isModalOpen, setModalOpen] = useState(false); - const user = useCurrentUser(); - - console.log(user); - const toast = useToast(); const toggleCompletedOnboarding = useToggleCompletedOnboarding(); @@ -41,7 +37,7 @@ const OnboardingHomePage = () => { }; const handleConfirmModal = async () => { - await toggleCompletedOnboarding.mutateAsync({ userId: user.userId }); + await toggleCompletedOnboarding.mutateAsync(); toast.success('Role updated successfully!'); setModalOpen(false); }; diff --git a/src/frontend/src/utils/urls.ts b/src/frontend/src/utils/urls.ts index db124dcd61..ca34310953 100644 --- a/src/frontend/src/utils/urls.ts +++ b/src/frontend/src/utils/urls.ts @@ -21,10 +21,10 @@ const currentUserSecureSettings = () => `${users()}/secure-settings/current-user const userSecureSettingsSet = () => `${users()}/secure-settings/set`; const userRoleByUserId = (id: string) => `${usersById(id)}/change-role`; const userFavoriteProjects = (id: string) => `${usersById(id)}/favorite-projects`; -const userSecureSettings = (id: string) => `${usersById(id)}/secure-psettings`; +const userSecureSettings = (id: string) => `${usersById(id)}/secure-settings`; const userScheduleSettings = (id: string) => `${usersById(id)}/schedule-settings`; const userScheduleSettingsSet = () => `${users()}/schedule-settings/set`; -const toggleCompletedOnboarding = (id: string) => `${usersById(id)}/toggle-completed-onboarding`; +const toggleCompletedOnboarding = () => `${users()}/toggle-completed-onboarding`; /**************** Projects Endpoints ****************/ const projects = () => `${API_URL}/projects`; diff --git a/src/shared/src/types/user-types.ts b/src/shared/src/types/user-types.ts index 6ae35fb093..4cb0626f96 100644 --- a/src/shared/src/types/user-types.ts +++ b/src/shared/src/types/user-types.ts @@ -91,10 +91,6 @@ export interface UpdateUserRolePayload { role: string; } -export interface ToggleCompletedOnboardingPayload { - userId: string; -} - export interface UserScheduleSettings { drScheduleSettingsId: string; personalGmail: string;