client: fix email ui with systemConfig.enableEmailVerify

This commit is contained in:
fantasticit 2022-08-17 18:35:18 +08:00
parent c6a720887b
commit 536915753b
2 changed files with 11 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import { Button, Col, Form, Row, Toast, Typography } from '@douyinfe/semi-ui'; import { Button, Col, Form, Row, Toast } from '@douyinfe/semi-ui';
import { useResetPassword, useSystemPublicConfig, useVerifyCode } from 'data/user'; import { useResetPassword, useSystemPublicConfig, useUser, useVerifyCode } from 'data/user';
import { useInterval } from 'hooks/use-interval'; import { useInterval } from 'hooks/use-interval';
import { useToggle } from 'hooks/use-toggle'; import { useToggle } from 'hooks/use-toggle';
import React, { useCallback, useState } from 'react'; import React, { useCallback, useState } from 'react';
@ -8,6 +8,7 @@ export const ResetPassword = ({ onSuccess }) => {
const [email, setEmail] = useState(''); const [email, setEmail] = useState('');
const [hasSendVerifyCode, toggleHasSendVerifyCode] = useToggle(false); const [hasSendVerifyCode, toggleHasSendVerifyCode] = useToggle(false);
const [countDown, setCountDown] = useState(0); const [countDown, setCountDown] = useState(0);
const { user } = useUser();
const { reset, loading } = useResetPassword(); const { reset, loading } = useResetPassword();
const { data: systemConfig } = useSystemPublicConfig(); const { data: systemConfig } = useSystemPublicConfig();
const { sendVerifyCode, loading: sendVerifyCodeLoading } = useVerifyCode(); const { sendVerifyCode, loading: sendVerifyCodeLoading } = useVerifyCode();
@ -51,7 +52,11 @@ export const ResetPassword = ({ onSuccess }) => {
}, [email, toggleHasSendVerifyCode, sendVerifyCode, start, stop]); }, [email, toggleHasSendVerifyCode, sendVerifyCode, start, stop]);
return ( return (
<Form initValues={{ name: '', password: '' }} onChange={onFormChange} onSubmit={onFinish}> <Form
initValues={{ email: user.email, password: '', confirmPassword: '' }}
onChange={onFormChange}
onSubmit={onFinish}
>
<Form.Input <Form.Input
noLabel noLabel
field="email" field="email"

View File

@ -1,7 +1,7 @@
import { Avatar, Button, Col, Form, Modal, Row, Space, Toast } from '@douyinfe/semi-ui'; import { Avatar, Button, Col, Form, Modal, Row, Space, Toast } from '@douyinfe/semi-ui';
import { FormApi } from '@douyinfe/semi-ui/lib/es/form'; import { FormApi } from '@douyinfe/semi-ui/lib/es/form';
import { Upload } from 'components/upload'; import { Upload } from 'components/upload';
import { useUser, useVerifyCode } from 'data/user'; import { useSystemPublicConfig, useUser, useVerifyCode } from 'data/user';
import { useInterval } from 'hooks/use-interval'; import { useInterval } from 'hooks/use-interval';
import { useToggle } from 'hooks/use-toggle'; import { useToggle } from 'hooks/use-toggle';
import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react'; import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react';
@ -16,6 +16,7 @@ export const UserSetting: React.FC<IProps> = ({ visible, toggleVisible }) => {
const { user, loading, updateUser } = useUser(); const { user, loading, updateUser } = useUser();
const [currentAvatar, setCurrentAvatar] = useState(''); const [currentAvatar, setCurrentAvatar] = useState('');
const [email, setEmail] = useState(''); const [email, setEmail] = useState('');
const { data: systemConfig } = useSystemPublicConfig();
const { sendVerifyCode, loading: sendVerifyCodeLoading } = useVerifyCode(); const { sendVerifyCode, loading: sendVerifyCodeLoading } = useVerifyCode();
const [hasSendVerifyCode, toggleHasSendVerifyCode] = useToggle(false); const [hasSendVerifyCode, toggleHasSendVerifyCode] = useToggle(false);
const [countDown, setCountDown] = useState(0); const [countDown, setCountDown] = useState(0);
@ -108,7 +109,7 @@ export const UserSetting: React.FC<IProps> = ({ visible, toggleVisible }) => {
<Form.Input label="邮箱" field="email" style={{ width: '100%' }} placeholder="请输入账户邮箱"></Form.Input> <Form.Input label="邮箱" field="email" style={{ width: '100%' }} placeholder="请输入账户邮箱"></Form.Input>
{email && email !== user.email ? ( {systemConfig && systemConfig.enableEmailVerify && email && email !== user.email ? (
<Form.Slot label="验证码"> <Form.Slot label="验证码">
<Row gutter={8}> <Row gutter={8}>
<Col span={16}> <Col span={16}>