mirror of https://gitee.com/answerdev/answer.git
fix(question): add field summary for question edit
This commit is contained in:
parent
d9d4e6a204
commit
f3b00e8f0f
|
@ -497,6 +497,11 @@ ui:
|
||||||
label: Answer
|
label: Answer
|
||||||
msg:
|
msg:
|
||||||
empty: Answer cannot be empty.
|
empty: Answer cannot be empty.
|
||||||
|
edit_summary:
|
||||||
|
label: Edit Summary
|
||||||
|
placeholder: >-
|
||||||
|
Briefly explain your changes (corrected spelling, fixed grammar,
|
||||||
|
improved formatting)
|
||||||
btn_post_question: Post your question
|
btn_post_question: Post your question
|
||||||
btn_save_edits: Save edits
|
btn_save_edits: Save edits
|
||||||
answer_question: Answer your own question
|
answer_question: Answer your own question
|
||||||
|
|
|
@ -25,6 +25,7 @@ interface FormDataItem {
|
||||||
tags: Type.FormValue<Type.Tag[]>;
|
tags: Type.FormValue<Type.Tag[]>;
|
||||||
content: Type.FormValue<string>;
|
content: Type.FormValue<string>;
|
||||||
answer: Type.FormValue<string>;
|
answer: Type.FormValue<string>;
|
||||||
|
edit_summary: Type.FormValue<string>;
|
||||||
}
|
}
|
||||||
const initFormData = {
|
const initFormData = {
|
||||||
title: {
|
title: {
|
||||||
|
@ -47,9 +48,15 @@ const initFormData = {
|
||||||
isInvalid: false,
|
isInvalid: false,
|
||||||
errorMsg: '',
|
errorMsg: '',
|
||||||
},
|
},
|
||||||
|
edit_summary: {
|
||||||
|
value: '',
|
||||||
|
isInvalid: false,
|
||||||
|
errorMsg: '',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const Ask = () => {
|
const Ask = () => {
|
||||||
|
const { t } = useTranslation('translation', { keyPrefix: 'ask' });
|
||||||
const [formData, setFormData] = useState<FormDataItem>(initFormData);
|
const [formData, setFormData] = useState<FormDataItem>(initFormData);
|
||||||
const [checked, setCheckState] = useState(false);
|
const [checked, setCheckState] = useState(false);
|
||||||
const [focusType, setForceType] = useState('');
|
const [focusType, setForceType] = useState('');
|
||||||
|
@ -63,7 +70,6 @@ const Ask = () => {
|
||||||
|
|
||||||
const { qid } = useParams();
|
const { qid } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { t } = useTranslation('translation', { keyPrefix: 'ask' });
|
|
||||||
|
|
||||||
const isEdit = qid !== undefined;
|
const isEdit = qid !== undefined;
|
||||||
const { data: similarQuestions = { list: [] } } = useQueryQuestionByTitle(
|
const { data: similarQuestions = { list: [] } } = useQueryQuestionByTitle(
|
||||||
|
@ -114,6 +120,15 @@ const Ask = () => {
|
||||||
answer: { ...formData.answer, value },
|
answer: { ...formData.answer, value },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleSummaryChange = (evt: React.ChangeEvent<HTMLInputElement>) =>
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
edit_summary: {
|
||||||
|
...formData.edit_summary,
|
||||||
|
value: evt.currentTarget.value,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const checkValidated = (): boolean => {
|
const checkValidated = (): boolean => {
|
||||||
let bol = true;
|
let bol = true;
|
||||||
const { title, content, tags, answer } = formData;
|
const { title, content, tags, answer } = formData;
|
||||||
|
@ -205,7 +220,11 @@ const Ask = () => {
|
||||||
tags: formData.tags.value,
|
tags: formData.tags.value,
|
||||||
};
|
};
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
modifyQuestion({ ...params, id: qid })
|
modifyQuestion({
|
||||||
|
...params,
|
||||||
|
id: qid,
|
||||||
|
edit_summary: formData.edit_summary.value,
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
navigate(`/questions/${qid}`);
|
navigate(`/questions/${qid}`);
|
||||||
})
|
})
|
||||||
|
@ -354,6 +373,21 @@ const Ask = () => {
|
||||||
{formData.tags.errorMsg}
|
{formData.tags.errorMsg}
|
||||||
</Form.Control.Feedback>
|
</Form.Control.Feedback>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
{isEdit && (
|
||||||
|
<Form.Group controlId="edit_summary" className="my-3">
|
||||||
|
<Form.Label>{t('form.fields.edit_summary.label')}</Form.Label>
|
||||||
|
<Form.Control
|
||||||
|
type="text"
|
||||||
|
defaultValue={formData.edit_summary.value}
|
||||||
|
isInvalid={formData.edit_summary.isInvalid}
|
||||||
|
placeholder={t('form.fields.edit_summary.placeholder')}
|
||||||
|
onChange={handleSummaryChange}
|
||||||
|
/>
|
||||||
|
<Form.Control.Feedback type="invalid">
|
||||||
|
{formData.edit_summary.errorMsg}
|
||||||
|
</Form.Control.Feedback>
|
||||||
|
</Form.Group>
|
||||||
|
)}
|
||||||
{!checked && (
|
{!checked && (
|
||||||
<div className="mt-3">
|
<div className="mt-3">
|
||||||
<Button type="submit" className="me-2">
|
<Button type="submit" className="me-2">
|
||||||
|
|
|
@ -73,7 +73,7 @@ export const useQueryAnswerInfo = (id: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const modifyQuestion = (
|
export const modifyQuestion = (
|
||||||
params: Type.QuestionParams & { id: string },
|
params: Type.QuestionParams & { id: string; edit_summary: string },
|
||||||
) => {
|
) => {
|
||||||
return request.put(`/answer/api/v1/question`, params);
|
return request.put(`/answer/api/v1/question`, params);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue