Commit e07fd2aa authored by tom's avatar tom

close user profile dropdown after click on buttons/link inside it

parent c39a3908
...@@ -55,10 +55,16 @@ export const PopoverCloseTriggerWrapper = React.forwardRef< ...@@ -55,10 +55,16 @@ export const PopoverCloseTriggerWrapper = React.forwardRef<
HTMLButtonElement, HTMLButtonElement,
ChakraPopover.CloseTriggerProps ChakraPopover.CloseTriggerProps
>(function PopoverCloseTriggerWrapper(props, ref) { >(function PopoverCloseTriggerWrapper(props, ref) {
const { disabled, ...rest } = props;
if (disabled) {
return props.children;
}
return ( return (
<ChakraPopover.CloseTrigger <ChakraPopover.CloseTrigger
ref={ ref } ref={ ref }
{ ...props } { ...rest }
asChild asChild
/> />
); );
......
...@@ -19,7 +19,6 @@ import AuthModalScreenSelectMethod from './screens/AuthModalScreenSelectMethod'; ...@@ -19,7 +19,6 @@ import AuthModalScreenSelectMethod from './screens/AuthModalScreenSelectMethod';
import AuthModalScreenSuccessEmail from './screens/AuthModalScreenSuccessEmail'; import AuthModalScreenSuccessEmail from './screens/AuthModalScreenSuccessEmail';
import AuthModalScreenSuccessWallet from './screens/AuthModalScreenSuccessWallet'; import AuthModalScreenSuccessWallet from './screens/AuthModalScreenSuccessWallet';
// TODO @tom2drum: check login flow
const feature = config.features.account; const feature = config.features.account;
interface Props { interface Props {
......
...@@ -64,6 +64,11 @@ const UserProfileContent = ({ data, onClose, onLogin, onAddEmail, onAddAddress } ...@@ -64,6 +64,11 @@ const UserProfileContent = ({ data, onClose, onLogin, onAddEmail, onAddAddress }
const { isAutoConnectDisabled } = useMarketplaceContext(); const { isAutoConnectDisabled } = useMarketplaceContext();
const logout = useLogout(); const logout = useLogout();
const handleLogoutClick = React.useCallback(() => {
logout();
onClose();
}, [ logout, onClose ]);
if (!data) { if (!data) {
return ( return (
<Box> <Box>
...@@ -96,17 +101,13 @@ const UserProfileContent = ({ data, onClose, onLogin, onAddEmail, onAddAddress } ...@@ -96,17 +101,13 @@ const UserProfileContent = ({ data, onClose, onLogin, onAddEmail, onAddAddress }
ml={ 1 } ml={ 1 }
/> />
{ data?.address_hash ? { data?.address_hash ?
<Box ml="auto">{ shortenString(data?.address_hash) }</Box> : <Box ml="auto">{ shortenString(data?.address_hash) }</Box> : <Link ml="auto" onClick={ onAddAddress }>Add address</Link> }
<Link ml="auto" onClick={ onAddAddress }>Add address</Link>
}
</Flex> </Flex>
) } ) }
<Flex p={ 2 } columnGap={ 4 }> <Flex p={ 2 } columnGap={ 4 }>
<Box mr="auto">Email</Box> <Box mr="auto">Email</Box>
{ data?.email ? { data?.email ?
<TruncatedValue value={ data.email }/> : <TruncatedValue value={ data.email }/> : <Link onClick={ onAddEmail }>Add email</Link> }
<Link onClick={ onAddEmail }>Add email</Link>
}
</Flex> </Flex>
</Box> </Box>
...@@ -127,7 +128,7 @@ const UserProfileContent = ({ data, onClose, onLogin, onAddEmail, onAddAddress } ...@@ -127,7 +128,7 @@ const UserProfileContent = ({ data, onClose, onLogin, onAddEmail, onAddAddress }
<UserProfileContentNavLink <UserProfileContentNavLink
text="Sign out" text="Sign out"
icon="sign_out" icon="sign_out"
onClick={ logout } onClick={ handleLogoutClick }
/> />
</Box> </Box>
); );
......
...@@ -32,6 +32,10 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => { ...@@ -32,6 +32,10 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
onClose?.(); onClose?.();
}, [ web3Wallet, onClose ]); }, [ web3Wallet, onClose ]);
const handleAddressClick = React.useCallback(() => {
onClose?.();
}, [ onClose ]);
const content = (() => { const content = (() => {
if (web3Wallet.isConnected && web3AccountWithDomain.address) { if (web3Wallet.isConnected && web3AccountWithDomain.address) {
return ( return (
...@@ -52,6 +56,7 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => { ...@@ -52,6 +56,7 @@ const UserProfileContentWallet = ({ onClose, className }: Props) => {
fontSize="sm" fontSize="sm"
fontWeight={ 500 } fontWeight={ 500 }
noAltHash noAltHash
onClick={ handleAddressClick }
/> />
{ web3Wallet.isReconnecting ? <Spinner size="sm" m="2px" flexShrink={ 0 }/> : ( { web3Wallet.isReconnecting ? <Spinner size="sm" m="2px" flexShrink={ 0 }/> : (
<IconButton <IconButton
......
...@@ -51,29 +51,28 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) => ...@@ -51,29 +51,28 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) =>
const handleAddEmailClick = React.useCallback(() => { const handleAddEmailClick = React.useCallback(() => {
setAuthInitialScreen({ type: 'email', isAuth: true }); setAuthInitialScreen({ type: 'email', isAuth: true });
authModal.onOpen(); authModal.onOpen();
}, [ authModal ]); profileMenu.onClose();
}, [ authModal, profileMenu ]);
const handleAddAddressClick = React.useCallback(() => { const handleAddAddressClick = React.useCallback(() => {
setAuthInitialScreen({ type: 'connect_wallet', isAuth: true, loginToRewards: true }); setAuthInitialScreen({ type: 'connect_wallet', isAuth: true, loginToRewards: true });
authModal.onOpen(); authModal.onOpen();
}, [ authModal ]); profileMenu.onClose();
}, [ authModal, profileMenu ]);
const handleAuthModalClose = React.useCallback(() => { const handleAuthModalClose = React.useCallback(() => {
setAuthInitialScreen(initialScreen); setAuthInitialScreen(initialScreen);
authModal.onClose(); authModal.onClose();
}, [ authModal ]); }, [ authModal ]);
const handleOpenChange = React.useCallback(({ open }: { open: boolean }) => { const handleLoginClick = React.useCallback(() => {
if (open) { authModal.onOpen();
profileMenu.onOpen(); profileMenu.onClose();
} else { }, [ authModal, profileMenu ]);
profileMenu.onClose();
}
}, [ profileMenu ]);
return ( return (
<> <>
<PopoverRoot positioning={{ placement: 'bottom-end' }} open={ profileMenu.open } onOpenChange={ handleOpenChange }> <PopoverRoot positioning={{ placement: 'bottom-end' }} open={ profileMenu.open } onOpenChange={ profileMenu.onOpenChange }>
<PopoverTrigger> <PopoverTrigger>
<UserProfileButton <UserProfileButton
profileQuery={ profileQuery } profileQuery={ profileQuery }
...@@ -88,7 +87,7 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) => ...@@ -88,7 +87,7 @@ const UserProfileDesktop = ({ buttonSize, buttonVariant = 'header' }: Props) =>
<UserProfileContent <UserProfileContent
data={ profileQuery.data } data={ profileQuery.data }
onClose={ profileMenu.onClose } onClose={ profileMenu.onClose }
onLogin={ authModal.onOpen } onLogin={ handleLoginClick }
onAddEmail={ handleAddEmailClick } onAddEmail={ handleAddEmailClick }
onAddAddress={ handleAddAddressClick } onAddAddress={ handleAddAddressClick }
/> />
......
...@@ -45,31 +45,30 @@ const UserProfileMobile = () => { ...@@ -45,31 +45,30 @@ const UserProfileMobile = () => {
const handleAddEmailClick = React.useCallback(() => { const handleAddEmailClick = React.useCallback(() => {
setAuthInitialScreen({ type: 'email', isAuth: true }); setAuthInitialScreen({ type: 'email', isAuth: true });
authModal.onOpen(); authModal.onOpen();
}, [ authModal ]); profileMenu.onClose();
}, [ authModal, profileMenu ]);
const handleAddAddressClick = React.useCallback(() => { const handleAddAddressClick = React.useCallback(() => {
setAuthInitialScreen({ type: 'connect_wallet', isAuth: true, loginToRewards: true }); setAuthInitialScreen({ type: 'connect_wallet', isAuth: true, loginToRewards: true });
authModal.onOpen(); authModal.onOpen();
}, [ authModal ]); profileMenu.onClose();
}, [ authModal, profileMenu ]);
const handleAuthModalClose = React.useCallback(() => { const handleAuthModalClose = React.useCallback(() => {
setAuthInitialScreen(initialScreen); setAuthInitialScreen(initialScreen);
authModal.onClose(); authModal.onClose();
}, [ authModal ]); }, [ authModal ]);
const handleDrawerOpenChange = React.useCallback(({ open }: { open: boolean }) => { const handleLoginClick = React.useCallback(() => {
if (profileQuery.data || web3Address) { authModal.onOpen();
open ? profileMenu.onOpen() : profileMenu.onClose(); profileMenu.onClose();
} else { }, [ authModal, profileMenu ]);
authModal.onOpen();
}
}, [ profileQuery.data, web3Address, authModal, profileMenu ]);
return ( return (
<> <>
<DrawerRoot <DrawerRoot
open={ profileMenu.open } open={ profileMenu.open }
onOpenChange={ handleDrawerOpenChange } onOpenChange={ profileMenu.onOpenChange }
> >
<DrawerBackdrop/> <DrawerBackdrop/>
<DrawerTrigger> <DrawerTrigger>
...@@ -84,7 +83,7 @@ const UserProfileMobile = () => { ...@@ -84,7 +83,7 @@ const UserProfileMobile = () => {
<UserProfileContent <UserProfileContent
data={ profileQuery.data } data={ profileQuery.data }
onClose={ profileMenu.onClose } onClose={ profileMenu.onClose }
onLogin={ authModal.onOpen } onLogin={ handleLoginClick }
onAddEmail={ handleAddEmailClick } onAddEmail={ handleAddEmailClick }
onAddAddress={ handleAddAddressClick } onAddAddress={ handleAddAddressClick }
/> />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment