From 1988ba9f612c3448811ba0336edcf83d999de118 Mon Sep 17 00:00:00 2001 From: Woojin Jung <44637040+jwoojin9@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:02:36 +0900 Subject: [PATCH] feat(fe): show update information modal for existing users (#2006) --- .../components/auth/HeaderAuthPanel.tsx | 126 +++++++++++------- .../components/auth/UpdateInformation.tsx | 47 +++++++ apps/frontend/components/ui/dialog.tsx | 50 ++++--- 3 files changed, 156 insertions(+), 67 deletions(-) create mode 100644 apps/frontend/components/auth/UpdateInformation.tsx diff --git a/apps/frontend/components/auth/HeaderAuthPanel.tsx b/apps/frontend/components/auth/HeaderAuthPanel.tsx index 3efe1bc4a7..7cd06db45f 100644 --- a/apps/frontend/components/auth/HeaderAuthPanel.tsx +++ b/apps/frontend/components/auth/HeaderAuthPanel.tsx @@ -9,15 +9,18 @@ import { DropdownMenuItem, DropdownMenuSeparator } from '@/components/ui/dropdown-menu' -import { cn } from '@/lib/utils' +import { cn, fetcherWithAuth } from '@/lib/utils' import useAuthModalStore from '@/stores/authModal' import { LogOut, UserRoundCog, ChevronDown } from 'lucide-react' import type { Session } from 'next-auth' import { signOut } from 'next-auth/react' import Link from 'next/link' +import { usePathname } from 'next/navigation' +import { useEffect, useState } from 'react' import { BiSolidUser } from 'react-icons/bi' import { RxHamburgerMenu } from 'react-icons/rx' import AuthModal from './AuthModal' +import UpdateInformation from './UpdateInformation' interface HeaderAuthPanelProps { session: Session | null @@ -38,38 +41,73 @@ export default function HeaderAuthPanel({ ) const isUser = session?.user.role === 'User' const isEditor = group === 'editor' + const [needsUpdate, setNeedsUpdate] = useState(false) + const pathname = usePathname() + + useEffect(() => { + const checkIfNeedsUpdate = async () => { + const userResponse = await fetcherWithAuth.get('user') + const user: { studentId: string; major: string } = + await userResponse.json() + const updateNeeded = + user.studentId === '0000000000' || + user.major === 'Department Information Unavailable / 학과 정보 없음' + + setNeedsUpdate(updateNeeded) + } + if (session) { + checkIfNeedsUpdate() + } + }, [session]) + + const shouldShowDialog = + needsUpdate && pathname.split('/').pop() !== 'settings' return (
- {session?.user.username} -
- )} -+ {session?.user.username} +
+ )} +