From 2abe6ef765a844f96c385a23308687d3c968d8f8 Mon Sep 17 00:00:00 2001 From: kuwsh1n Date: Fri, 26 Apr 2024 11:23:46 +0300 Subject: [PATCH] fix ticket 12 --- src/pages/NewForm.jsx | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/pages/NewForm.jsx b/src/pages/NewForm.jsx index fde4e55..ed9f6c9 100644 --- a/src/pages/NewForm.jsx +++ b/src/pages/NewForm.jsx @@ -36,7 +36,8 @@ const NewForm = () => { const [currentOptionAnswer, setCurrentOptionAnswer] = useState(""); const [datetime, setDatetime] = useState(""); - const [titleForm, setTitleForm] = useState(""); + const [newTitleForm, setNewTitleForm] = useState(""); + const [oldTitleFrom, setOldTitleForm] = useState(""); const [listBlock, setListBlock] = useState([]); @@ -64,12 +65,15 @@ const NewForm = () => { const responseBlock = await listFormBlockApi(cookies.token, formId); if (responseBlock.status === 200 && responseBlock.data && responseForms.status === 200) { - setListBlock(responseDataToListBlock(responseBlock.data)); - setTitleForm(responseForms.data.find(item => item.id === formId).title); + setListBlock(responseDataToListBlock(responseBlock.data)); + const title = responseForms.data.find(item => item.id === formId).title + setNewTitleForm(title); + setOldTitleForm(title); } else { setListBlock([]) - setTitleForm("Новыя форма") + setNewTitleForm("Новыя форма"); + setOldTitleForm("Новыя форма"); } }; @@ -136,8 +140,6 @@ const NewForm = () => { video: video } - console.log(parseVKlinkVideo(video)) - const response = await addFormBlockApi(cookies.token, formId, newBlock) if (response.status === 200) { @@ -150,7 +152,7 @@ const NewForm = () => { }; async function updateTitleForm() { - const response = await updateTitleFormApi(cookies.token, formId, titleForm); + const response = await updateTitleFormApi(cookies.token, formId, newTitleForm); if (response.status === 200) { console.log(response) @@ -201,22 +203,13 @@ const NewForm = () => { }) }; - function saveForm() { - // saveFormApi("Новая форма", listBlock) - // .then((resolve, reject) => { - // console.log(resolve); - // setForms( - // [...forms, { - // id: nextID(forms), - // title: "Новая форма", - // questions: listBlock, - // answers: [] - // }] - // ); + async function saveForm() { + if (oldTitleFrom !== newTitleForm) { + await updateTitleForm() + } + cleanStates(); navigate("/forms"); - // }) - // .catch(error => console.log(error)); }; return ( @@ -230,14 +223,14 @@ const NewForm = () => {
Название формы - setTitleForm(event.target.value)}/> + setNewTitleForm(event.target.value)}/>
- } click={() => updateTitleForm()} class={"main__green"} otherStyle={{paddingLeft: "0.9rem", paddingRight: "0.9rem"}}> - + */}