mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/ui-0.5.0' into 'test'
Feat/ui 0.5.0 See merge request opensource/answer!295
This commit is contained in:
commit
0e41f807ac
|
@ -53,6 +53,7 @@ const General: FC = () => {
|
||||||
const uiSchema: UISchema = {
|
const uiSchema: UISchema = {
|
||||||
site_url: {
|
site_url: {
|
||||||
'ui:options': {
|
'ui:options': {
|
||||||
|
type: 'url',
|
||||||
validator: (value) => {
|
validator: (value) => {
|
||||||
let url: URL | undefined;
|
let url: URL | undefined;
|
||||||
try {
|
try {
|
||||||
|
@ -76,6 +77,7 @@ const General: FC = () => {
|
||||||
},
|
},
|
||||||
contact_email: {
|
contact_email: {
|
||||||
'ui:options': {
|
'ui:options': {
|
||||||
|
type: 'email',
|
||||||
validator: (value) => {
|
validator: (value) => {
|
||||||
if (!Pattern.email.test(value)) {
|
if (!Pattern.email.test(value)) {
|
||||||
return t('contact_email.validate');
|
return t('contact_email.validate');
|
||||||
|
@ -85,7 +87,9 @@ const General: FC = () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const [formData, setFormData] = useState(initFormData(schema));
|
const [formData, setFormData] = useState<Type.FormDataType>(
|
||||||
|
initFormData(schema),
|
||||||
|
);
|
||||||
|
|
||||||
const onSubmit = (evt) => {
|
const onSubmit = (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
|
@ -67,6 +67,11 @@ const Smtp: FC = () => {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const uiSchema: UISchema = {
|
const uiSchema: UISchema = {
|
||||||
|
from_email: {
|
||||||
|
'ui:options': {
|
||||||
|
type: 'email',
|
||||||
|
},
|
||||||
|
},
|
||||||
encryption: {
|
encryption: {
|
||||||
'ui:widget': 'select',
|
'ui:widget': 'select',
|
||||||
},
|
},
|
||||||
|
@ -100,6 +105,7 @@ const Smtp: FC = () => {
|
||||||
},
|
},
|
||||||
smtp_port: {
|
smtp_port: {
|
||||||
'ui:options': {
|
'ui:options': {
|
||||||
|
type: 'number',
|
||||||
validator: (value) => {
|
validator: (value) => {
|
||||||
if (!/^[1-9][0-9]*$/.test(value) || Number(value) > 65535) {
|
if (!/^[1-9][0-9]*$/.test(value) || Number(value) > 65535) {
|
||||||
return t('smtp_port.msg');
|
return t('smtp_port.msg');
|
||||||
|
@ -110,6 +116,7 @@ const Smtp: FC = () => {
|
||||||
},
|
},
|
||||||
test_email_recipient: {
|
test_email_recipient: {
|
||||||
'ui:options': {
|
'ui:options': {
|
||||||
|
type: 'email',
|
||||||
validator: (value) => {
|
validator: (value) => {
|
||||||
if (value && !pattern.email.test(value)) {
|
if (value && !pattern.email.test(value)) {
|
||||||
return t('test_email_recipient.msg');
|
return t('test_email_recipient.msg');
|
||||||
|
@ -162,18 +169,17 @@ const Smtp: FC = () => {
|
||||||
if (!setting) {
|
if (!setting) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const formState = {};
|
const formMeta = {};
|
||||||
Object.keys(formData).forEach((k) => {
|
Object.keys(setting).forEach((k) => {
|
||||||
let v = setting[k];
|
formMeta[k] = { ...formData[k], value: setting[k] };
|
||||||
if (v === null || v === undefined) {
|
|
||||||
v = '';
|
|
||||||
}
|
|
||||||
formState[k] = { ...formData[k], value: v };
|
|
||||||
});
|
});
|
||||||
setFormData(formState);
|
setFormData({ ...formData, ...formMeta });
|
||||||
}, [setting]);
|
}, [setting]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (formData.smtp_authentication.value === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (formData.smtp_authentication.value) {
|
if (formData.smtp_authentication.value) {
|
||||||
setFormData({
|
setFormData({
|
||||||
...formData,
|
...formData,
|
||||||
|
@ -187,7 +193,7 @@ const Smtp: FC = () => {
|
||||||
smtp_password: { ...formData.smtp_password, hidden: true },
|
smtp_password: { ...formData.smtp_password, hidden: true },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [formData.smtp_authentication]);
|
}, [formData.smtp_authentication.value]);
|
||||||
|
|
||||||
const handleOnChange = (data) => {
|
const handleOnChange = (data) => {
|
||||||
setFormData(data);
|
setFormData(data);
|
||||||
|
|
|
@ -223,7 +223,7 @@ const Ask = () => {
|
||||||
{t('title', { keyPrefix: 'how_to_format' })}
|
{t('title', { keyPrefix: 'how_to_format' })}
|
||||||
</Card.Header>
|
</Card.Header>
|
||||||
<Card.Body
|
<Card.Body
|
||||||
className="fmt"
|
className="fmt small"
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: t('description', { keyPrefix: 'how_to_format' }),
|
__html: t('description', { keyPrefix: 'how_to_format' }),
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -255,7 +255,7 @@ const Ask = () => {
|
||||||
{t('title', { keyPrefix: 'how_to_format' })}
|
{t('title', { keyPrefix: 'how_to_format' })}
|
||||||
</Card.Header>
|
</Card.Header>
|
||||||
<Card.Body
|
<Card.Body
|
||||||
className="fmt"
|
className="fmt small"
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: t('description', { keyPrefix: 'how_to_format' }),
|
__html: t('description', { keyPrefix: 'how_to_format' }),
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in New Issue