mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-07 01:02:55 +08:00
perf: login page (#5571)
This commit is contained in:
@@ -4,7 +4,7 @@ import { useForm } from 'react-hook-form';
|
||||
import { LoginPageTypeEnum } from '@/web/support/user/login/constants';
|
||||
import { postFindPassword } from '@/web/support/user/api';
|
||||
import { useSendCode } from '@/web/support/user/hooks/useSendCode';
|
||||
import type { ResLogin } from '@/global/support/api/userRes.d';
|
||||
import type { LoginSuccessResponse } from '@/global/support/api/userRes.d';
|
||||
import { useToast } from '@fastgpt/web/hooks/useToast';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
@@ -13,7 +13,7 @@ import { checkPasswordRule } from '@fastgpt/global/common/string/password';
|
||||
|
||||
interface Props {
|
||||
setPageType: Dispatch<`${LoginPageTypeEnum}`>;
|
||||
loginSuccess: (e: ResLogin) => void;
|
||||
loginSuccess: (e: LoginSuccessResponse) => void;
|
||||
}
|
||||
|
||||
interface RegisterType {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { FormControl, Flex, Input, Button, Box } from '@chakra-ui/react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { LoginPageTypeEnum } from '@/web/support/user/login/constants';
|
||||
import { postLogin, getPreLogin } from '@/web/support/user/api';
|
||||
import type { ResLogin } from '@/global/support/api/userRes';
|
||||
import type { LoginSuccessResponse } from '@/global/support/api/userRes';
|
||||
import { useToast } from '@fastgpt/web/hooks/useToast';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
@@ -13,7 +13,7 @@ import PolicyTip from './PolicyTip';
|
||||
|
||||
interface Props {
|
||||
setPageType: Dispatch<`${LoginPageTypeEnum}`>;
|
||||
loginSuccess: (e: ResLogin) => void;
|
||||
loginSuccess: (e: LoginSuccessResponse) => void;
|
||||
}
|
||||
|
||||
interface LoginFormType {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { type Dispatch } from 'react';
|
||||
import { LoginPageTypeEnum } from '@/web/support/user/login/constants';
|
||||
import type { ResLogin } from '@/global/support/api/userRes';
|
||||
import type { LoginSuccessResponse } from '@/global/support/api/userRes';
|
||||
import { Box, Center, Flex, Link } from '@chakra-ui/react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { getWXLoginQR, getWXLoginResult } from '@/web/support/user/api';
|
||||
@@ -23,7 +23,7 @@ import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import PolicyTip from './PolicyTip';
|
||||
|
||||
interface Props {
|
||||
loginSuccess: (e: ResLogin) => void;
|
||||
loginSuccess: (e: LoginSuccessResponse) => void;
|
||||
setPageType: Dispatch<`${LoginPageTypeEnum}`>;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ const WechatForm = ({ setPageType, loginSuccess }: Props) => {
|
||||
{
|
||||
refetchInterval: 3 * 1000,
|
||||
enabled: !!wechatInfo?.code,
|
||||
onSuccess(data: ResLogin | undefined) {
|
||||
onSuccess(data: LoginSuccessResponse | undefined) {
|
||||
if (data) {
|
||||
removeFastGPTSem();
|
||||
loginSuccess(data);
|
||||
|
||||
@@ -4,10 +4,10 @@ import { LoginContainer } from '@/pageComponents/login';
|
||||
import I18nLngSelector from '@/components/Select/I18nLngSelector';
|
||||
import { useSystem } from '@fastgpt/web/hooks/useSystem';
|
||||
import { getWebReqUrl } from '@fastgpt/web/common/system/utils';
|
||||
import type { ResLogin } from '@/global/support/api/userRes';
|
||||
import type { LoginSuccessResponse } from '@/global/support/api/userRes';
|
||||
|
||||
type LoginModalProps = {
|
||||
onSuccess?: (res: ResLogin) => void;
|
||||
onSuccess: (e: LoginSuccessResponse) => any;
|
||||
};
|
||||
|
||||
const LoginModal = ({ onSuccess }: LoginModalProps) => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useForm } from 'react-hook-form';
|
||||
import { LoginPageTypeEnum } from '@/web/support/user/login/constants';
|
||||
import { postRegister } from '@/web/support/user/api';
|
||||
import { useSendCode } from '@/web/support/user/hooks/useSendCode';
|
||||
import type { ResLogin } from '@/global/support/api/userRes';
|
||||
import type { LoginSuccessResponse } from '@/global/support/api/userRes';
|
||||
import { useToast } from '@fastgpt/web/hooks/useToast';
|
||||
import { postCreateApp } from '@/web/core/app/api';
|
||||
import { emptyTemplates } from '@/web/core/app/templates';
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
import { checkPasswordRule } from '@fastgpt/global/common/string/password';
|
||||
|
||||
interface Props {
|
||||
loginSuccess: (e: ResLogin) => void;
|
||||
loginSuccess: (e: LoginSuccessResponse) => void;
|
||||
setPageType: Dispatch<`${LoginPageTypeEnum}`>;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '@chakra-ui/react';
|
||||
import { LoginPageTypeEnum } from '@/web/support/user/login/constants';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import type { ResLogin } from '@/global/support/api/userRes.d';
|
||||
import type { LoginSuccessResponse } from '@/global/support/api/userRes.d';
|
||||
import { useUserStore } from '@/web/support/user/useUserStore';
|
||||
import { useChatStore } from '@/web/core/chat/context/useChatStore';
|
||||
import dynamic from 'next/dynamic';
|
||||
@@ -21,8 +21,6 @@ import { useTranslation } from 'next-i18next';
|
||||
import LoginForm from '@/pageComponents/login/LoginForm/LoginForm';
|
||||
import { GET } from '@/web/common/api/request';
|
||||
import { getDocPath } from '@/web/common/system/doc';
|
||||
import { postAcceptInvitationLink } from '@/web/support/user/team/api';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
const RegisterForm = dynamic(() => import('@/pageComponents/login/RegisterForm'));
|
||||
const ForgetPasswordForm = dynamic(() => import('@/pageComponents/login/ForgetPasswordForm'));
|
||||
@@ -187,25 +185,21 @@ export const LoginContainer = ({
|
||||
onSuccess
|
||||
}: {
|
||||
children?: React.ReactNode;
|
||||
onSuccess?: (res: ResLogin) => void;
|
||||
onSuccess: (res: LoginSuccessResponse) => void;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { feConfigs } = useSystemStore();
|
||||
const { setUserInfo } = useUserStore();
|
||||
const { setLastChatAppId } = useChatStore();
|
||||
|
||||
const [pageType, setPageType] = useState<`${LoginPageTypeEnum}` | null>(null);
|
||||
const [showCommunityModal, setShowCommunityModal] = useState(false);
|
||||
const router = useRouter();
|
||||
const { lastRoute = '' } = router.query as { lastRoute: string };
|
||||
|
||||
// login success handler
|
||||
const loginSuccess = useCallback(
|
||||
async (res: ResLogin) => {
|
||||
setUserInfo(res.user);
|
||||
(res: LoginSuccessResponse) => {
|
||||
onSuccess?.(res);
|
||||
},
|
||||
[setUserInfo, onSuccess]
|
||||
[onSuccess]
|
||||
);
|
||||
|
||||
// initialization logic
|
||||
|
||||
Reference in New Issue
Block a user