This commit is contained in:
Stefan Pejcic 2024-02-11 19:23:21 +01:00
parent 51c18709cc
commit e91e495668

View File

@ -54,29 +54,30 @@ export const DocSurveyWidget = ({ className }: Props) => {
} }
}; };
const handleSurveyTextSubmit = async (text: string) => { const handleSurveyTextSubmit = async (text: string) => {
if (text.trim() === "") { if (text.trim() === "") {
return; return;
} }
const data = await updateSurvey({ const surveyIdToUpdate = survey?.id; // Use the existing survey ID if available
surveyId: survey.id,
body: { response: selectedOption, responseText: text },
});
if (!data) return;
setSurvey(data); const data = await updateSurvey({
// when the user submits text feedback, we show a thank you message surveyId: surveyIdToUpdate,
setIsFinished(true); body: { response: selectedOption, responseText: text },
});
// reset the survey after N seconds so that the user can submit another survey if (!data) return;
setTimeout(() => {
setSelectedOption(null); setSurvey(data);
setSurvey(null); setIsFinished(true);
setIsFinished(false);
setIsSurveyTextVisible(false); setTimeout(() => {
}, 3000); setSelectedOption(null);
}; setSurvey(null);
setIsFinished(false);
setIsSurveyTextVisible(false);
}, 3000);
};
return ( return (
<div <div