Merge branch 'dev' of https://github.com/spicecat/qOverflow into dev
This commit is contained in:
commit
f4228ad22e
5 changed files with 17 additions and 14 deletions
|
|
@ -5,7 +5,7 @@ import { AnswerForm } from 'controllers/FormControllers';
|
|||
|
||||
export default function CreateAnswer({ canAnswer, show, toggleShow }) {
|
||||
return (
|
||||
<div>
|
||||
<div style = {{display : 'inline'}}>
|
||||
<Tooltip
|
||||
title={
|
||||
canAnswer
|
||||
|
|
|
|||
|
|
@ -14,15 +14,16 @@ export default function Suggest(){
|
|||
useEffect(()=>{
|
||||
setCanSuggest(userData.level >= 7)
|
||||
|
||||
if(ongoingEdit.users.length > 0)setCanSuggest((userData.username !== ongoingEdit.users[0]))
|
||||
|
||||
if(!questionData.loading) setOngoingEdit({users : questionData.edit, new : questionData.editText})
|
||||
},[userData, questionData, setCanSuggest])
|
||||
|
||||
async function toggleShow(){
|
||||
if(questionData.edit.length === 0){
|
||||
if(questionData.edit.length === 0 || userData.username !== ongoingEdit.users[0]){
|
||||
setShow(!show)
|
||||
}else{
|
||||
const { status } = await editQuestion(questionData.question_id);
|
||||
window.location.reload(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -30,7 +31,7 @@ export default function Suggest(){
|
|||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style = {{display : 'inline', marginLeft : '10px'}}>
|
||||
<Tooltip
|
||||
title= {
|
||||
canSuggest
|
||||
|
|
@ -53,10 +54,10 @@ export default function Suggest(){
|
|||
{ongoingEdit.users.length > 0 &&
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Markdown {...{content: ongoingEdit.new[0]}}/>
|
||||
<Markdown {...{content: ongoingEdit.new[1]}}/>
|
||||
New Title: <Markdown {...{content: ongoingEdit.new[1]}}/>
|
||||
New Text: <Markdown {...{content: ongoingEdit.new[0]}}/>
|
||||
</CardContent>
|
||||
<Typography> {ongoingEdit.users} have voted to edit the question </Typography>
|
||||
<Typography> {ongoingEdit.users} has voted to edit the question </Typography>
|
||||
</Card>
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import { Form } from 'controllers/FormControllers';
|
||||
import { generateEditFields } from 'services/fields';
|
||||
import { editQuestion } from 'services/questionsServices';
|
||||
import { questionSchema } from 'services/schemas';
|
||||
import { editSchema } from 'services/schemas';
|
||||
import { useQuestion } from 'contexts';
|
||||
|
||||
export default function EditFormController() {
|
||||
|
|
@ -22,7 +22,7 @@ export default function EditFormController() {
|
|||
return !questionData.loading && Form({
|
||||
fields: field,
|
||||
onSubmit: editTheQuestion,
|
||||
validationSchema: questionSchema,
|
||||
validationSchema: editSchema,
|
||||
initialValues: {etext : text, etitle : title}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,4 +119,5 @@ export {
|
|||
registerSchema,
|
||||
resetSchema,
|
||||
searchSchema,
|
||||
editSchema
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ async function EditQuestionStatusClosed(req, res) {
|
|||
const { user } = req;
|
||||
const { question_id } = req.params;
|
||||
const { etext, etitle } = req.body;
|
||||
|
||||
let eObj = [etext, etitle]
|
||||
// Verify user has required level
|
||||
if (getUserLevel(user.points) < 7) {
|
||||
return res.status(403).send(config.errorForbidden);
|
||||
|
|
@ -25,7 +25,7 @@ async function EditQuestionStatusClosed(req, res) {
|
|||
}
|
||||
|
||||
await Question.findByIdAndUpdate(question_id, {
|
||||
editText: etext,
|
||||
editText: eObj,
|
||||
$push: { edit: user.username },
|
||||
});
|
||||
|
||||
|
|
@ -48,13 +48,14 @@ async function EditQuestionStatusClosed(req, res) {
|
|||
if (question.edit.length === 2) {
|
||||
const question = await Question.findByIdAndUpdate(question_id, {
|
||||
edit: [],
|
||||
etext,
|
||||
etitle
|
||||
eObj,
|
||||
|
||||
});
|
||||
|
||||
const { success } = await createRequest('patch', `/questions/${question_id}`, {
|
||||
etext,
|
||||
etitle
|
||||
eObj
|
||||
|
||||
});
|
||||
|
||||
return success
|
||||
|
|
|
|||
Reference in a new issue