add: share modal

This commit is contained in:
Mahyar Khanbolooki
2025-07-29 22:39:53 +03:30
parent 25a6f3e729
commit 8bf8da5df7
4 changed files with 98 additions and 4 deletions
+61 -2
View File
@@ -21,6 +21,8 @@ import { useAuthStore } from '@/zustand/authStore';
import { useParams, usePathname, useRouter } from 'next/navigation';
import clsx from 'clsx';
import { useTranslation } from 'react-i18next';
import { DocumentCopy, Instagram, Share, Whatsapp } from 'iconsax-react';
import TelegramIcon from '../icons/TelegramIcon';
type MenuItemType = {
href: string | undefined;
@@ -37,7 +39,7 @@ const menuItems: Array<Array<MenuItemType>> = [
{ href: 'orders', title: 'Orders', icon: <CalendarSearchIcon width={20} height={20} /> },
{ href: 'transactions', title: 'Transactions', icon: <ReceiptIcon width={20} height={20} /> },
{ href: '/', title: 'Games', icon: <GameControllerIcon width={20} height={20} /> },
{ href: 'my-services', title: 'ShareWithFriends', icon: <ThumbsUpIcon width={20} height={20} /> },
{ href: '?share', title: 'ShareWithFriends', icon: <ThumbsUpIcon width={20} height={20} /> },
{ href: 'services', title: 'ReportProblem', icon: <NoteBoardIcon width={20} height={20} /> },
{ href: 'invoices', title: 'InstallApp', icon: <DirectboxReceiveIcon width={20} height={20} /> }
],
@@ -58,6 +60,7 @@ type Props = {
function SideMenu({ menuState, toggleMenuState, nightModeState, togglenightModeState }: Props) {
const menuStateMemo = useMemo(() => menuState, [menuState]);
const [logoutModalVisible, setLogoutModalVisible] = useState(false);
const [shareModalVisible, setShareModalVisible] = useState(false);
const closeRef = useRef<HTMLDivElement>(null);
const userIsAuthenticated = true; // useAuthStore((state) => state.isAuthenticated);
const authLogout = useAuthStore((state) => state.logout);
@@ -71,6 +74,9 @@ function SideMenu({ menuState, toggleMenuState, nightModeState, togglenightModeS
const { t: tLogoutModal } = useTranslation('common', {
keyPrefix: 'LogoutModal'
});
const { t: tShareModal } = useTranslation('common', {
keyPrefix: 'ShareModal'
});
const variants: Variants = {
hidden: { x: '100%', transition: { duration: 0.1, ease: 'easeInOut' } },
@@ -89,6 +95,12 @@ function SideMenu({ menuState, toggleMenuState, nightModeState, togglenightModeS
setLogoutModalVisible((state) => !state);
};
const toggleShareModalVisiblity = (e?: React.MouseEvent) => {
e?.preventDefault();
e?.stopPropagation();
setShareModalVisible((state) => !state);
};
const onLogout = (e: React.MouseEvent<HTMLButtonElement> | null) => {
if (!e) return;
if (userIsAuthenticated) {
@@ -97,7 +109,10 @@ function SideMenu({ menuState, toggleMenuState, nightModeState, togglenightModeS
}
};
const hrefOnClicks = [{ href: '?logout', handler: toggleLogoutModalVisiblity }];
const hrefOnClicks = [
{ href: '?logout', handler: toggleLogoutModalVisiblity },
{ href: '?share', handler: toggleShareModalVisiblity }
];
return (
<>
@@ -137,6 +152,11 @@ function SideMenu({ menuState, toggleMenuState, nightModeState, togglenightModeS
className={clsx(isActive && 'text-foreground!')}
href={item.href ?? ''}
title={tMenu(item.title)}
onClick={
typeof item.href === 'string'
? hrefOnClicks.find((i) => i.href === item.href)?.handler
: undefined
}
icon={
<span className={clsx(isActive ? 'text-foreground!' : 'text-icon-deactive')}>
{item.icon}
@@ -203,6 +223,45 @@ function SideMenu({ menuState, toggleMenuState, nightModeState, togglenightModeS
</motion.div>
</div>
</BlurredOverlayContainer>
{/* Share modal */}
<BlurredOverlayContainer visible={shareModalVisible} onClick={toggleShareModalVisiblity} inDuration={100} outDuration={100} outDelay={75}>
<div className="absolute top-1/2 left-0 w-full px-6">
<motion.div
animate={{ y: shareModalVisible ? [10, 0] : [0, 10] }}
transition={{ duration: 0.1, ease: 'easeInOut' }}
className="top-1/2 absolute left-1/2 min-w-xs w-full max-w-sm text-center -translate-1/2 px-6 pt-8 pb-9 drop-shadow-container bg-white/63 rounded-4xl"
>
<h2 className="text-base font-medium">
<Share className="inline-block ml-2 mb-1.5 stroke-primary" size={24} />
{tShareModal('Heading')}
</h2>
<p className="text-xs font-medium mt-6">
{tShareModal('Description')}
</p>
<Button onClick={onLogout} className="text-sm mt-8">
<DocumentCopy className="inline-block ml-2 mb-0.5 stroke-white" size={20} />
<span className="font-light">{tShareModal('ButtonCopy')}</span>
</Button>
<div className="grid grid-cols-3 gap-5.5 mt-6 px-12">
<div className="place-items-center">
<TelegramIcon width={24} height={24} className="mb-1.5 stroke-primary" />
<span className='text-xs2 font-medium'>Telegram</span>
</div>
<div className="place-items-center">
<Whatsapp size={24} className="mb-1.5 stroke-primary" />
<span className='text-xs2 font-medium'>WhatsApp</span>
</div>
<div className="place-items-center">
<Instagram size={24} className="mb-1.5 stroke-primary" />
<span className='text-xs2 font-medium'>Instagram</span>
</div>
</div>
</motion.div>
</div>
</BlurredOverlayContainer>
</>
);
}