mirror of https://gitee.com/answerdev/answer.git
fix(Signup): Display the registration form by configuration.
This commit is contained in:
parent
3880eab449
commit
38ad85978a
|
@ -1,98 +0,0 @@
|
|||
import { useEffect } from 'react';
|
||||
import { Modal, Form, Button, InputGroup } from 'react-bootstrap';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Icon } from '@/components';
|
||||
import type { FormValue, FormDataType, ImgCodeRes } from '@/common/interface';
|
||||
import { CAPTCHA_CODE_STORAGE_KEY } from '@/common/constants';
|
||||
import Storage from '@/utils/storage';
|
||||
|
||||
interface IProps {
|
||||
/** control visible */
|
||||
visible: boolean;
|
||||
data: {
|
||||
captcha: FormValue;
|
||||
imgCode: ImgCodeRes;
|
||||
};
|
||||
handleCaptcha: (parma: FormDataType) => void;
|
||||
clickSubmit: (e: any) => void;
|
||||
refreshImgCode: () => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const Index: React.FC<IProps> = ({
|
||||
visible,
|
||||
data,
|
||||
handleCaptcha,
|
||||
clickSubmit,
|
||||
refreshImgCode,
|
||||
onClose,
|
||||
}) => {
|
||||
const { t } = useTranslation('translation', { keyPrefix: 'pic_auth_code' });
|
||||
const { captcha, imgCode } = data;
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
refreshImgCode();
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
return (
|
||||
<Modal size="sm" title="Captcha" show={visible} onHide={onClose} centered>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title as="h5">{t('title')}</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
<Form noValidate onSubmit={clickSubmit}>
|
||||
<Form.Group controlId="code" className="mb-3">
|
||||
<div className="mb-3 p-2 d-flex align-items-center justify-content-center bg-light rounded-2">
|
||||
<img
|
||||
src={imgCode?.captcha_img}
|
||||
alt="code"
|
||||
width="auto"
|
||||
height="40px"
|
||||
/>
|
||||
</div>
|
||||
<InputGroup>
|
||||
<Form.Control
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
placeholder={t('placeholder')}
|
||||
isInvalid={captcha?.isInvalid}
|
||||
onChange={(e) => {
|
||||
Storage.set(CAPTCHA_CODE_STORAGE_KEY, e.target.value);
|
||||
handleCaptcha({
|
||||
captcha_code: {
|
||||
value: e.target.value,
|
||||
isInvalid: false,
|
||||
errorMsg: '',
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
onClick={refreshImgCode}
|
||||
variant="outline-secondary"
|
||||
title={t('refresh', { keyPrefix: 'btns' })}
|
||||
style={{
|
||||
borderTopRightRadius: '0.375rem',
|
||||
borderBottomRightRadius: '0.375rem',
|
||||
}}>
|
||||
<Icon name="arrow-repeat" />
|
||||
</Button>
|
||||
|
||||
<Form.Control.Feedback type="invalid">
|
||||
{captcha?.errorMsg}
|
||||
</Form.Control.Feedback>
|
||||
</InputGroup>
|
||||
</Form.Group>
|
||||
|
||||
<div className="d-grid">
|
||||
<Button type="submit">{t('verify', { keyPrefix: 'btns' })}</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
export default Index;
|
|
@ -1,6 +1,5 @@
|
|||
import DefaultModal from './Modal';
|
||||
import confirm, { Config } from './Confirm';
|
||||
import PicAuthCodeModal from './PicAuthCodeModal';
|
||||
import LoginToContinueModal from './LoginToContinueModal';
|
||||
|
||||
type ModalType = typeof DefaultModal & {
|
||||
|
@ -14,5 +13,4 @@ Modal.confirm = function (props: Config) {
|
|||
|
||||
export default Modal;
|
||||
|
||||
export { PicAuthCodeModal };
|
||||
export { LoginToContinueModal };
|
||||
|
|
|
@ -14,7 +14,6 @@ import Operate from './Operate';
|
|||
import UserCard from './UserCard';
|
||||
import Pagination from './Pagination';
|
||||
import Comment from './Comment';
|
||||
import PicAuthCodeModal from './Modal/PicAuthCodeModal';
|
||||
import TextArea from './TextArea';
|
||||
import Mentions from './Mentions';
|
||||
import FormatTime from './FormatTime';
|
||||
|
@ -59,7 +58,6 @@ export {
|
|||
UserCard,
|
||||
Pagination,
|
||||
Comment,
|
||||
PicAuthCodeModal,
|
||||
TextArea,
|
||||
Mentions,
|
||||
FormatTime,
|
||||
|
|
|
@ -189,7 +189,7 @@ const Index = (captchaKey: CaptchaKey) => {
|
|||
src={captcha?.captcha_img}
|
||||
alt="captcha img"
|
||||
width="auto"
|
||||
height="40px"
|
||||
height="60px"
|
||||
/>
|
||||
</div>
|
||||
<InputGroup>
|
||||
|
|
|
@ -231,11 +231,6 @@ const Index: React.FC<Props> = ({ callback }) => {
|
|||
.
|
||||
</Trans>
|
||||
</div>
|
||||
<div className="text-center mt-5">
|
||||
<Trans i18nKey="login.info_login" ns="translation">
|
||||
Already have an account? <Link to="/users/login">Log in</Link>
|
||||
</Trans>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,25 +1,34 @@
|
|||
import React, { useState } from 'react';
|
||||
import { Container, Col } from 'react-bootstrap';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Trans, useTranslation } from 'react-i18next';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { usePageTags } from '@/hooks';
|
||||
import { Unactivate, WelcomeTitle, PluginRender } from '@/components';
|
||||
import { guard } from '@/utils';
|
||||
import { loginSettingStore } from '@/stores';
|
||||
|
||||
import SignUpForm from './components/SignUpForm';
|
||||
|
||||
const Index: React.FC = () => {
|
||||
const [showForm, setShowForm] = useState(true);
|
||||
const { t } = useTranslation('translation', { keyPrefix: 'login' });
|
||||
const loginSetting = loginSettingStore((state) => state.login);
|
||||
const onStep = () => {
|
||||
setShowForm((bol) => !bol);
|
||||
};
|
||||
usePageTags({
|
||||
title: t('sign_up', { keyPrefix: 'page_title' }),
|
||||
});
|
||||
|
||||
if (!guard.singUpAgent().ok) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const showSignupForm =
|
||||
loginSetting?.allow_new_registrations &&
|
||||
loginSetting.allow_email_registrations;
|
||||
|
||||
return (
|
||||
<Container style={{ paddingTop: '4rem', paddingBottom: '5rem' }}>
|
||||
<WelcomeTitle />
|
||||
|
@ -27,7 +36,12 @@ const Index: React.FC = () => {
|
|||
{showForm ? (
|
||||
<Col className="mx-auto" md={6} lg={4} xl={3}>
|
||||
<PluginRender type="Connector" className="mb-5" />
|
||||
<SignUpForm callback={onStep} />
|
||||
{showSignupForm ? <SignUpForm callback={onStep} /> : null}
|
||||
<div className="text-center mt-5">
|
||||
<Trans i18nKey="login.info_login" ns="translation">
|
||||
Already have an account? <Link to="/users/login">Log in</Link>
|
||||
</Trans>
|
||||
</div>
|
||||
</Col>
|
||||
) : (
|
||||
<Unactivate visible={!showForm} />
|
||||
|
|
Loading…
Reference in New Issue