Skip to content

Commit

Permalink
Remove calling add user in a useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
jadmsaadaot committed Jan 21, 2025
1 parent a9eccc1 commit 65114b6
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions submit-web/src/routes/staff/_staffLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import EaoSideNavBar from "@/components/Shared/layout/SideNav/EaoSideNavBar";
import NoRoles from "@/components/Shared/NoRoles";
import { PageLoader } from "@/components/Shared/PageLoader";
import { useGetUserByGuid } from "@/hooks/api/useAccounts";
import { useStaffAddUser } from "@/hooks/api/useStaffUser";
import { useIsMobile } from "@/hooks/common";
import { EPIC_SUBMIT_ROLE } from "@/models/Role";
import { USER_TYPE } from "@/models/User";
Expand All @@ -29,9 +28,6 @@ function Staff() {
isLoading: isAuthLoading,
} = useAuth();

const { mutate: addStaffUser, isPending: isCreatingStaffUserPending } =
useStaffAddUser();

const {
data: userData,
error: getUserError,
Expand Down Expand Up @@ -81,21 +77,6 @@ function Staff() {
}
}, [handleUser, isAuthLoading]);

useEffect(() => {
if (userData && kcUser && !isCreatingStaffUserPending) {
if (!userData.staff_user) {
console.log(userData);
const staffUser = {
auth_guid: kcUser.profile.sub,
first_name: kcUser.profile.given_name,
last_name: kcUser.profile.family_name,
work_email_address: kcUser.profile.email ?? "",
};
addStaffUser(staffUser);
}
}
}, [userData, kcUser, addStaffUser, isCreatingStaffUserPending]);

if (isLoading) {
return <PageLoader />;
}
Expand All @@ -104,7 +85,7 @@ function Staff() {
return <Navigate to="/error" />;
}

if (userData?.type !== USER_TYPE.STAFF) {
if (userData?.type !== USER_TYPE.STAFF || !userData.staff_user) {
return <Navigate to="/not-found" />;
}

Expand Down

0 comments on commit 65114b6

Please sign in to comment.