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 ? ( - - - + + - {!isEditor && ( -

- {session?.user.username} -

- )} - -
- - {!isUser && ( - + > + + {!isEditor && ( +

+ {session?.user.username} +

+ )} + +
+ + {!isUser && ( + + + Management + + + )} + - Management + Settings - )} - { + signOut() + }} > - Settings + LogOut - - { - signOut() - }} + +
+ + - LogOut - - - + + + + ) : ( diff --git a/apps/frontend/components/auth/UpdateInformation.tsx b/apps/frontend/components/auth/UpdateInformation.tsx new file mode 100644 index 0000000000..30310fb603 --- /dev/null +++ b/apps/frontend/components/auth/UpdateInformation.tsx @@ -0,0 +1,47 @@ +'use client' + +import { Button } from '@/components/ui/button' +import CodedangLogo from '@/public/codedang.svg' +import Image from 'next/image' +import { useRouter } from 'next/navigation' +import { IoWarningOutline } from 'react-icons/io5' + +export default function UpdateInformation() { + const router = useRouter() + return ( +
+
+ codedang +
+
+ +

Update Information

+
+
+

To continue using the service,

+

you must update your information.

+
+
+

Your account will be DELETED if you do not

+

update your information by August 31.

+
+
+

We need the information

+
    +
  • Your Student ID
  • +
  • Your First Major
  • +
+ +
+ ) +} diff --git a/apps/frontend/components/ui/dialog.tsx b/apps/frontend/components/ui/dialog.tsx index bec6e4ca5a..1139448c1f 100644 --- a/apps/frontend/components/ui/dialog.tsx +++ b/apps/frontend/components/ui/dialog.tsx @@ -15,6 +15,7 @@ type DialogOverlayProps = React.ComponentPropsWithoutRef< interface ExtendedDialogContentProps extends React.ComponentPropsWithoutRef { showDarkOverlay?: boolean + hideCloseButton?: boolean } const Dialog = DialogPrimitive.Root @@ -47,28 +48,35 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName const DialogContent = React.forwardRef< React.ElementRef, ExtendedDialogContentProps ->(({ className, children, showDarkOverlay, ...props }, ref) => ( - - - - {children} - ( + ( + { className, children, showDarkOverlay, hideCloseButton = false, ...props }, + ref + ) => ( + + + - - Close - - - -)) + {children} + {!hideCloseButton && ( + + + Close + + )} + + + ) +) DialogContent.displayName = DialogPrimitive.Content.displayName const DialogHeader = ({