refactor: modals
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import Prompt, { PromptProps } from '@/components/utils/Prompt'
|
||||
import { useAuthStore } from '@/zustand/authStore';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
|
||||
function LogoutPrompt({ ...rest }: Omit<PromptProps, 'onConfirm' | 'onCancel' | 'children'>) {
|
||||
const { t } = useTranslation('common', {
|
||||
keyPrefix: 'LogoutModal'
|
||||
});
|
||||
const authLogout = useAuthStore((state) => state.logout);
|
||||
const router = useRouter();
|
||||
const userIsAuthenticated = useAuthStore((state) => state.isAuthenticated);
|
||||
|
||||
const onConfirmLogout = (e: React.MouseEvent) => {
|
||||
if (!e) return;
|
||||
if (userIsAuthenticated) {
|
||||
authLogout();
|
||||
}
|
||||
router.replace('/');
|
||||
};
|
||||
|
||||
const toggleShareModalVisiblity = (e: React.MouseEvent) => {
|
||||
e?.preventDefault();
|
||||
e?.stopPropagation();
|
||||
console.log(e);
|
||||
rest.onClick?.(e);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<Prompt
|
||||
title={t("Heading")}
|
||||
description={t("Description")}
|
||||
textConfirm={t("ButtonOk")}
|
||||
textCancel={t("ButtonCancel")}
|
||||
onConfirm={onConfirmLogout}
|
||||
onCancel={toggleShareModalVisiblity}
|
||||
{...rest}>
|
||||
<></>
|
||||
</Prompt>
|
||||
)
|
||||
}
|
||||
|
||||
export default LogoutPrompt
|
||||
Reference in New Issue
Block a user