From 967c2f94f27d0cd7f6733c5293d2f201eacad090 Mon Sep 17 00:00:00 2001 From: xion Date: Sun, 6 Apr 2025 01:44:35 +0800 Subject: [PATCH] add toast login --- src/toast/ToastLogin.tsx | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/toast/ToastLogin.tsx diff --git a/src/toast/ToastLogin.tsx b/src/toast/ToastLogin.tsx new file mode 100644 index 0000000..1277716 --- /dev/null +++ b/src/toast/ToastLogin.tsx @@ -0,0 +1,42 @@ +import { toast } from 'react-toastify'; +import { useTranslation } from 'react-i18next'; +// Custom message component +const LoginMessage = (props: ToastLoginProps) => { + const { t } = useTranslation(); + const handleClick = () => { + const currentUrl = window.location.href; + const redirect = encodeURIComponent(props?.redirectUrl || currentUrl); + const loginUrl = props?.loginUrl || '/user/login/'; + const newUrl = location.origin + loginUrl + '?redirect=' + redirect; + window.open(newUrl, '_self'); + }; + + return ( +
+

{t('Please login')}

+

{t('Click here to go to the login page.')}

+
+ ); +}; +type ToastLoginProps = { + /** + * 登录页面地址, /user/login + */ + loginUrl?: string; + /** + * 登录成功后跳转的地址, 默认是当前页面 + */ + redirectUrl?: string; +}; +/** + * 登录提示 + * @param props + * @example + * toastLogin({ + * loginUrl: '/user/login/', + * redirectUrl: window.location.href, + * }); + */ +export const toastLogin = (props: ToastLoginProps = {}) => { + toast.info(); +};