feat: email conflict tip in widget login
This commit is contained in:
@@ -6,6 +6,7 @@ import './assets/index.css';
|
|||||||
import store from "./app/store";
|
import store from "./app/store";
|
||||||
import './i18n';
|
import './i18n';
|
||||||
import { isDarkMode } from "./common/utils";
|
import { isDarkMode } from "./common/utils";
|
||||||
|
import { Toaster } from "react-hot-toast";
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
|
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
|
||||||
const hostId = new URLSearchParams(location.search).get("host") || 1;
|
const hostId = new URLSearchParams(location.search).get("host") || 1;
|
||||||
@@ -18,6 +19,9 @@ if (isDarkMode()) {
|
|||||||
root.render(
|
root.render(
|
||||||
hostId ? <Provider store={store}>
|
hostId ? <Provider store={store}>
|
||||||
<WidgetProvider>
|
<WidgetProvider>
|
||||||
|
<Toaster toastOptions={{
|
||||||
|
className: "dark:!bg-gray-800 dark:!text-gray-50"
|
||||||
|
}} />
|
||||||
<Widget hostId={Number(hostId)} />
|
<Widget hostId={Number(hostId)} />
|
||||||
</WidgetProvider>
|
</WidgetProvider>
|
||||||
</Provider> : null
|
</Provider> : null
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// import React from 'react'
|
// import React from 'react'
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { FormEvent, useEffect } from 'react';
|
import { FormEvent, useEffect } from 'react';
|
||||||
|
import { toast } from 'react-hot-toast';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { useRegisterMutation } from '../../../app/services/auth';
|
import { useRegisterMutation } from '../../../app/services/auth';
|
||||||
import { useGetLoginConfigQuery } from '../../../app/services/server';
|
import { useGetLoginConfigQuery } from '../../../app/services/server';
|
||||||
@@ -21,7 +22,7 @@ const Login = () => {
|
|||||||
const { color, fgColor, from } = useWidget();
|
const { color, fgColor, from } = useWidget();
|
||||||
const { clientId } = useGoogleAuthConfig();
|
const { clientId } = useGoogleAuthConfig();
|
||||||
const { config: githubAuthConfig } = useGithubAuthConfig();
|
const { config: githubAuthConfig } = useGithubAuthConfig();
|
||||||
const [register, { isLoading, isSuccess, data }] = useRegisterMutation();
|
const [register, { isLoading, isSuccess, data, error }] = useRegisterMutation();
|
||||||
const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery();
|
const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery();
|
||||||
const handleSubmit = (evt: FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (evt: FormEvent<HTMLFormElement>) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
@@ -47,6 +48,20 @@ const Login = () => {
|
|||||||
dispatch(setAuthData(data));
|
dispatch(setAuthData(data));
|
||||||
}
|
}
|
||||||
}, [isSuccess, data]);
|
}, [isSuccess, data]);
|
||||||
|
// 报错处理
|
||||||
|
useEffect(() => {
|
||||||
|
if (error) {
|
||||||
|
switch (error.status) {
|
||||||
|
case 409:
|
||||||
|
toast.error("Email existed already!");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
toast.error("Something error!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [error]);
|
||||||
|
|
||||||
|
|
||||||
if (!loginConfigSuccess) return null;
|
if (!loginConfigSuccess) return null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user