System inform (#2263)

* feat: Bind Notification Pipe (#2229)

* chore: account page add bind notification modal

* feat: timerlock schema and type

* feat(fe): bind notification method modal

* chore: fe adjust

* feat: clean useless code

* fix: cron lock

* chore: adjust the code

* chore: rename api

* chore: remove unused code

* chore: fe adjust

* perf: bind inform ux

* fix: time ts

* chore: notification (#2251)

* perf: send message code

* perf: sub schema index

* fix: timezone plugin

* fix: format

---------

Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com>
This commit is contained in:
Archer
2024-08-05 00:29:14 +08:00
committed by GitHub
parent 998e7833e8
commit 56f6e69bc7
31 changed files with 344 additions and 171 deletions

View File

@@ -63,6 +63,9 @@ export const updatePasswordByOld = ({ oldPsw, newPsw }: { oldPsw: string; newPsw
newPsw: hashStr(newPsw)
});
export const updateNotificationAccount = (data: { account: string; verifyCode: string }) =>
PUT('/proApi/support/user/team/updateNotificationAccount', data);
export const postLogin = ({ password, ...props }: PostLoginProps) =>
POST<ResLogin>('/support/user/account/loginByPassword', {
...props,

View File

@@ -1,19 +1,40 @@
import { useState, useMemo, useCallback } from 'react';
import { useState, useMemo } from 'react';
import { sendAuthCode } from '@/web/support/user/api';
import { UserAuthTypeEnum } from '@fastgpt/global/support/user/auth/constants';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { getErrText } from '@fastgpt/global/common/error/utils';
import { useTranslation } from 'next-i18next';
import { useSystemStore } from '@/web/common/system/useSystemStore';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
let timer: any;
let timer: NodeJS.Timeout;
export const useSendCode = () => {
const { t } = useTranslation();
const { toast } = useToast();
const { feConfigs } = useSystemStore();
const [codeSending, setCodeSending] = useState(false);
const [codeCountDown, setCodeCountDown] = useState(0);
const { runAsync: sendCode, loading: codeSending } = useRequest2(
async ({ username, type }: { username: string; type: `${UserAuthTypeEnum}` }) => {
if (codeCountDown > 0) return;
const googleToken = await getClientToken(feConfigs.googleClientVerKey);
await sendAuthCode({ username, type, googleToken });
setCodeCountDown(60);
timer = setInterval(() => {
setCodeCountDown((val) => {
if (val <= 0) {
clearInterval(timer);
}
return val - 1;
});
}, 1000);
},
{
successToast: '验证码已发送',
errorToast: '验证码发送异常',
refreshDeps: [codeCountDown, feConfigs?.googleClientVerKey]
}
);
const sendCodeText = useMemo(() => {
if (codeSending) return t('common:support.user.auth.Sending Code');
if (codeCountDown >= 10) {
@@ -25,41 +46,6 @@ export const useSendCode = () => {
return '获取验证码';
}, [codeCountDown, codeSending, t]);
const sendCode = useCallback(
async ({ username, type }: { username: string; type: `${UserAuthTypeEnum}` }) => {
if (codeCountDown > 0) return;
setCodeSending(true);
try {
await sendAuthCode({
username,
type,
googleToken: await getClientToken(feConfigs.googleClientVerKey)
});
setCodeCountDown(60);
timer = setInterval(() => {
setCodeCountDown((val) => {
if (val <= 0) {
clearInterval(timer);
}
return val - 1;
});
}, 1000);
toast({
title: '验证码已发送',
status: 'success',
position: 'top'
});
} catch (error: any) {
toast({
title: getErrText(error, '验证码发送异常'),
status: 'error'
});
}
setCodeSending(false);
},
[codeCountDown, feConfigs?.googleClientVerKey, toast]
);
return {
codeSending,
sendCode,