From a52c686fbf7e4bdea6dadb7e136f5bb50327dde8 Mon Sep 17 00:00:00 2001 From: Stefan Pejcic Date: Sun, 11 Feb 2024 20:04:27 +0100 Subject: [PATCH] Update doc-survey-widget.tsx --- documentation/src/refine-theme/doc-survey-widget.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/documentation/src/refine-theme/doc-survey-widget.tsx b/documentation/src/refine-theme/doc-survey-widget.tsx index 240f54f1..63836547 100644 --- a/documentation/src/refine-theme/doc-survey-widget.tsx +++ b/documentation/src/refine-theme/doc-survey-widget.tsx @@ -59,8 +59,10 @@ export const DocSurveyWidget = ({ className }: Props) => { return; } + const currentSurveyId = survey?.id || generateRandomSurveyId(); + const data = await updateSurvey({ - surveyId: survey?.id, + surveyId: currentSurveyId, body: { response: selectedOption, responseText: text }, }); if (!data) return; @@ -304,7 +306,8 @@ const generateRandomSurveyId = () => { }; const createSurvey = async ({ body }: { body: DocSurveyCreateDto }) => { - const response = await fetch(`${DOC_SURVEY_URL}?surveyId=${generateRandomSurveyId()}`, { + const surveyId = generateRandomSurveyId(); + const response = await fetch(`${DOC_SURVEY_URL}?surveyId=${surveyId}`, { method: "POST", headers: { "Content-Type": "application/json", @@ -321,6 +324,7 @@ const createSurvey = async ({ body }: { body: DocSurveyCreateDto }) => { }; + const updateSurvey = async ({ surveyId, body, @@ -328,7 +332,7 @@ const updateSurvey = async ({ surveyId?: string; body: DocSurveyUpdateDto; }) => { - const response = await fetch(`${DOC_SURVEY_URL}?surveyId=${generateRandomSurveyId()}`, { + const response = await fetch(`${DOC_SURVEY_URL}?surveyId=${surveyId}`, { method: "PATCH", headers: { "Content-Type": "application/json", @@ -344,6 +348,7 @@ const updateSurvey = async ({ return data; }; + const surveyOptions: { value: SurveyOption; img: string;