@@ -15,32 +15,36 @@ const ColoredIconButton = styled(IconButton)(({ theme }) => ({
1515 transition : "color 0.4s ease, background-color 0.4s ease" ,
1616} ) ) ;
1717
18- type InnerUserMenuButtonPropType = {
18+ type UserMenuButtonProps = { onClose ?: ( ) => void } ;
19+
20+ type InnerUserMenuButtonPropType = UserMenuButtonProps & {
1921 loading ?: boolean ;
2022 user ?: UserSignedInStatus [ "data" ] [ "user" ] ;
2123 onSignOut ?: ( ) => void ;
2224} ;
2325
24- const InnerUserMenuButton : FC < InnerUserMenuButtonPropType > = ( { loading, user, onSignOut } ) => {
26+ const InnerUserMenuButton : FC < InnerUserMenuButtonPropType > = ( { loading, user, onSignOut, onClose } ) => {
2527 const navigate = useNavigate ( ) ;
2628 const { language } = useAppContext ( ) ;
2729 const [ anchorEl , setAnchorEl ] = useState < HTMLElement | null > ( null ) ;
2830 const open = Boolean ( anchorEl ) ;
2931
3032 const handleOpen = ( event : MouseEvent < HTMLElement > ) => setAnchorEl ( event . currentTarget ) ;
31- const handleClose = ( ) => setAnchorEl ( null ) ;
33+ const handleMenuClose = ( ) => setAnchorEl ( null ) ;
3234
3335 const signInLabel = language === "ko" ? "로그인" : "Sign In" ;
3436 const orderHistoryLabel = language === "ko" ? "결제 내역" : "Order History" ;
3537 const signOutLabel = language === "ko" ? "로그아웃" : "Sign Out" ;
3638
3739 const goTo = ( path : string ) => {
38- handleClose ( ) ;
40+ handleMenuClose ( ) ;
41+ onClose ?.( ) ;
3942 navigate ( path ) ;
4043 } ;
4144
4245 const handleSignOut = ( ) => {
43- handleClose ( ) ;
46+ handleMenuClose ( ) ;
47+ onClose ?.( ) ;
4448 onSignOut ?.( ) ;
4549 } ;
4650
@@ -59,7 +63,7 @@ const InnerUserMenuButton: FC<InnerUserMenuButtonPropType> = ({ loading, user, o
5963 id = "user-menu"
6064 anchorEl = { anchorEl }
6165 open = { open }
62- onClose = { handleClose }
66+ onClose = { handleMenuClose }
6367 anchorOrigin = { { vertical : "bottom" , horizontal : "right" } }
6468 transformOrigin = { { vertical : "top" , horizontal : "right" } }
6569 slotProps = { { paper : { sx : { minWidth : 180 , mt : 0.5 } } } }
@@ -98,18 +102,18 @@ const InnerUserMenuButton: FC<InnerUserMenuButtonPropType> = ({ loading, user, o
98102 ) ;
99103} ;
100104
101- const UserMenuButtonContent : FC = ( ) => {
105+ const UserMenuButtonContent : FC < UserMenuButtonProps > = ( { onClose } ) => {
102106 const shopAPIClient = useShopClient ( ) ;
103107 const signOutMutation = useSignOutMutation ( shopAPIClient ) ;
104108 const { data } = useUserStatus ( shopAPIClient ) ;
105109
106- return < InnerUserMenuButton user = { data ?. data . user } onSignOut = { signOutMutation . mutate } /> ;
110+ return < InnerUserMenuButton user = { data ?. data . user } onSignOut = { signOutMutation . mutate } onClose = { onClose } /> ;
107111} ;
108112
109- export const UserMenuButton : FC = ( ) => (
110- < ErrorBoundary fallback = { < InnerUserMenuButton /> } >
111- < Suspense fallback = { < InnerUserMenuButton loading /> } >
112- < UserMenuButtonContent />
113+ export const UserMenuButton : FC < UserMenuButtonProps > = ( { onClose } ) => (
114+ < ErrorBoundary fallback = { < InnerUserMenuButton onClose = { onClose } /> } >
115+ < Suspense fallback = { < InnerUserMenuButton loading onClose = { onClose } /> } >
116+ < UserMenuButtonContent onClose = { onClose } />
113117 </ Suspense >
114118 </ ErrorBoundary >
115119) ;
0 commit comments