chore: set max characters for title&display_name

This commit is contained in:
haitao(lj) 2022-09-29 18:24:34 +08:00
parent 23b797c1f9
commit 8668f09ae1
6 changed files with 48 additions and 17 deletions

View File

@ -232,10 +232,12 @@ const Image: FC<IEditorContext> = ({ editor }) => {
</Modal.Header> </Modal.Header>
<Modal.Body> <Modal.Body>
<Tabs onSelect={handleSelect}> <Tabs onSelect={handleSelect}>
<Tab eventKey="localImage" title={t('image.tab_1')}> <Tab eventKey="localImage" title={t('image.tab_image')}>
<Form className="mt-3" onSubmit={handleClick}> <Form className="mt-3" onSubmit={handleClick}>
<Form.Group controlId="editor.imgLink" className="mb-3"> <Form.Group controlId="editor.imgLink" className="mb-3">
<Form.Label>{t('image.form1.fields.file.label')}</Form.Label> <Form.Label>
{t('image.form_image.fields.file.label')}
</Form.Label>
<Form.Control <Form.Control
type="file" type="file"
onChange={onUpload} onChange={onUpload}
@ -243,13 +245,13 @@ const Image: FC<IEditorContext> = ({ editor }) => {
/> />
<Form.Control.Feedback type="invalid"> <Form.Control.Feedback type="invalid">
{t('image.form1.fields.file.msg.empty')} {t('image.form_image.fields.file.msg.empty')}
</Form.Control.Feedback> </Form.Control.Feedback>
</Form.Group> </Form.Group>
<Form.Group controlId="editor.imgDescription" className="mb-3"> <Form.Group controlId="editor.imgDescription" className="mb-3">
<Form.Label> <Form.Label>
{t('image.form1.fields.description.label')} {t('image.form_image.fields.description.label')}
</Form.Label> </Form.Label>
<Form.Control <Form.Control
type="text" type="text"
@ -262,10 +264,12 @@ const Image: FC<IEditorContext> = ({ editor }) => {
</Form.Group> </Form.Group>
</Form> </Form>
</Tab> </Tab>
<Tab eventKey="remoteImage" title={t('image.tab_2')}> <Tab eventKey="remoteImage" title={t('image.tab_url')}>
<Form className="mt-3" onSubmit={handleClick}> <Form className="mt-3" onSubmit={handleClick}>
<Form.Group controlId="editor.imgUrl" className="mb-3"> <Form.Group controlId="editor.imgUrl" className="mb-3">
<Form.Label>{t('image.form2.fields.url.label')}</Form.Label> <Form.Label>
{t('image.form_url.fields.url.label')}
</Form.Label>
<Form.Control <Form.Control
type="text" type="text"
value={link.value} value={link.value}
@ -275,12 +279,14 @@ const Image: FC<IEditorContext> = ({ editor }) => {
isInvalid={currentTab === 'remoteImage' && link.isInvalid} isInvalid={currentTab === 'remoteImage' && link.isInvalid}
/> />
<Form.Control.Feedback type="invalid"> <Form.Control.Feedback type="invalid">
{t('image.form2.fields.url.msg.empty')} {t('image.form_url.fields.url.msg.empty')}
</Form.Control.Feedback> </Form.Control.Feedback>
</Form.Group> </Form.Group>
<Form.Group controlId="editor.imgName" className="mb-3"> <Form.Group controlId="editor.imgName" className="mb-3">
<Form.Label>{t('image.form2.fields.name.label')}</Form.Label> <Form.Label>
{t('image.form_url.fields.name.label')}
</Form.Label>
<Form.Control <Form.Control
type="text" type="text"
value={imageName.value} value={imageName.value}

View File

@ -100,8 +100,8 @@
"image": { "image": {
"text": "Image", "text": "Image",
"add_image": "Add image", "add_image": "Add image",
"tab_1": "Upload image", "tab_image": "Upload image",
"form1": { "form_image": {
"fields": { "fields": {
"file": { "file": {
"label": "Image file", "label": "Image file",
@ -117,8 +117,8 @@
} }
} }
}, },
"tab_2": "Image URL", "tab_url": "Image URL",
"form2": { "form_url": {
"fields": { "fields": {
"url": { "url": {
"label": "Image URL", "label": "Image URL",
@ -361,7 +361,8 @@
"label": "Title", "label": "Title",
"placeholder": "Be specific and imagine youre asking a question to another person", "placeholder": "Be specific and imagine youre asking a question to another person",
"msg": { "msg": {
"empty": "Title cannot be empty." "empty": "Title cannot be empty.",
"range": "Title up to 150 characters"
} }
}, },
"body": { "body": {
@ -454,7 +455,8 @@
"name": { "name": {
"label": "Name", "label": "Name",
"msg": { "msg": {
"empty": "Name cannot be empty." "empty": "Name cannot be empty.",
"range": "Name up to 30 characters"
} }
}, },
"email": { "email": {
@ -512,7 +514,8 @@
"btn_name": "Update profile", "btn_name": "Update profile",
"display_name": { "display_name": {
"label": "Display name", "label": "Display name",
"msg": "Display name cannot be empty." "msg": "Display name cannot be empty.",
"msg_range": "Display name up to 30 characters"
}, },
"avatar": { "avatar": {
"label": "Profile image", "label": "Profile image",
@ -864,4 +867,4 @@
} }
} }
} }
} }

View File

@ -124,6 +124,13 @@ const Ask = () => {
isInvalid: true, isInvalid: true,
errorMsg: t('form.fields.title.msg.empty'), errorMsg: t('form.fields.title.msg.empty'),
}; };
} else if ([...title.value].length > 150) {
bol = false;
formData.title = {
value: title.value,
isInvalid: true,
errorMsg: t('form.fields.title.msg.range'),
};
} else { } else {
formData.title = { formData.title = {
value: title.value, value: title.value,

View File

@ -52,6 +52,13 @@ const Index: React.FC<Props> = ({ callback }) => {
isInvalid: true, isInvalid: true,
errorMsg: t('name.msg.empty'), errorMsg: t('name.msg.empty'),
}; };
} else if ([...name.value].length > 30) {
bol = false;
formData.name = {
value: name.value,
isInvalid: true,
errorMsg: t('name.msg.range'),
};
} }
if (!e_mail.value) { if (!e_mail.value) {
@ -182,7 +189,7 @@ const Index: React.FC<Props> = ({ callback }) => {
<div className="text-center"> <div className="text-center">
<Trans i18nKey="login.info_login" ns="translation"> <Trans i18nKey="login.info_login" ns="translation">
DAlready have an account? <Link to="/users/login">Log in</Link> Already have an account? <Link to="/users/login">Log in</Link>
</Trans> </Trans>
</div> </div>
</Col> </Col>

View File

@ -74,6 +74,13 @@ const Index: React.FC = () => {
isInvalid: true, isInvalid: true,
errorMsg: t('display_name.msg'), errorMsg: t('display_name.msg'),
}; };
} else if ([...display_name.value].length > 30) {
bol = false;
formData.display_name = {
value: display_name.value,
isInvalid: true,
errorMsg: t('display_name.msg_range'),
};
} }
const reg = /^(http|https):\/\//g; const reg = /^(http|https):\/\//g;

View File

@ -7,6 +7,7 @@
"esModuleInterop": true, "esModuleInterop": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"strict": true, "strict": true,
"downlevelIteration": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"module": "esnext", "module": "esnext",