mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-21 11:30:27 -05:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 75f05f85e9 |
@@ -83,6 +83,7 @@ export const SurveyEditor = ({
|
|||||||
const [activeView, setActiveView] = useState<TSurveyEditorTabs>("questions");
|
const [activeView, setActiveView] = useState<TSurveyEditorTabs>("questions");
|
||||||
const [activeQuestionId, setActiveQuestionId] = useState<string | null>(null);
|
const [activeQuestionId, setActiveQuestionId] = useState<string | null>(null);
|
||||||
const [localSurvey, setLocalSurvey] = useState<TSurvey | null>(() => structuredClone(survey));
|
const [localSurvey, setLocalSurvey] = useState<TSurvey | null>(() => structuredClone(survey));
|
||||||
|
const [savedSurvey, setSavedSurvey] = useState<TSurvey>(survey);
|
||||||
const [invalidQuestions, setInvalidQuestions] = useState<string[] | null>(null);
|
const [invalidQuestions, setInvalidQuestions] = useState<string[] | null>(null);
|
||||||
const [selectedLanguageCode, setSelectedLanguageCode] = useState<string>("default");
|
const [selectedLanguageCode, setSelectedLanguageCode] = useState<string>("default");
|
||||||
const surveyEditorRef = useRef(null);
|
const surveyEditorRef = useRef(null);
|
||||||
@@ -108,6 +109,7 @@ export const SurveyEditor = ({
|
|||||||
|
|
||||||
const surveyClone = structuredClone(survey);
|
const surveyClone = structuredClone(survey);
|
||||||
setLocalSurvey(surveyClone);
|
setLocalSurvey(surveyClone);
|
||||||
|
setSavedSurvey(surveyClone);
|
||||||
|
|
||||||
if (survey.questions.length > 0) {
|
if (survey.questions.length > 0) {
|
||||||
setActiveQuestionId(survey.questions[0].id);
|
setActiveQuestionId(survey.questions[0].id);
|
||||||
@@ -160,8 +162,9 @@ export const SurveyEditor = ({
|
|||||||
<SurveyMenuBar
|
<SurveyMenuBar
|
||||||
setLocalSurvey={setLocalSurvey}
|
setLocalSurvey={setLocalSurvey}
|
||||||
localSurvey={localSurvey}
|
localSurvey={localSurvey}
|
||||||
survey={survey}
|
survey={savedSurvey}
|
||||||
environmentId={environment.id}
|
environmentId={environment.id}
|
||||||
|
setSavedSurvey={setSavedSurvey}
|
||||||
activeId={activeView}
|
activeId={activeView}
|
||||||
setActiveId={setActiveView}
|
setActiveId={setActiveView}
|
||||||
setInvalidQuestions={setInvalidQuestions}
|
setInvalidQuestions={setInvalidQuestions}
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { getFormattedErrorMessage } from "@/lib/utils/helper";
|
|
||||||
import { createSegmentAction } from "@/modules/ee/contacts/segments/actions";
|
|
||||||
import { Alert, AlertButton, AlertTitle } from "@/modules/ui/components/alert";
|
|
||||||
import { AlertDialog } from "@/modules/ui/components/alert-dialog";
|
|
||||||
import { Button } from "@/modules/ui/components/button";
|
|
||||||
import { Input } from "@/modules/ui/components/input";
|
|
||||||
import { Project } from "@prisma/client";
|
import { Project } from "@prisma/client";
|
||||||
import { useTranslate } from "@tolgee/react";
|
import { useTranslate } from "@tolgee/react";
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
import { ArrowLeftIcon, SettingsIcon } from "lucide-react";
|
import { ArrowLeftIcon, SettingsIcon } from "lucide-react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
import { flushSync } from "react-dom";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { getLanguageLabel } from "@formbricks/i18n-utils/src/utils";
|
import { getLanguageLabel } from "@formbricks/i18n-utils/src/utils";
|
||||||
import { TSegment } from "@formbricks/types/segment";
|
import { TSegment } from "@formbricks/types/segment";
|
||||||
@@ -23,11 +18,18 @@ import {
|
|||||||
ZSurveyEndScreenCard,
|
ZSurveyEndScreenCard,
|
||||||
ZSurveyRedirectUrlCard,
|
ZSurveyRedirectUrlCard,
|
||||||
} from "@formbricks/types/surveys/types";
|
} from "@formbricks/types/surveys/types";
|
||||||
|
import { getFormattedErrorMessage } from "@/lib/utils/helper";
|
||||||
|
import { createSegmentAction } from "@/modules/ee/contacts/segments/actions";
|
||||||
|
import { Alert, AlertButton, AlertTitle } from "@/modules/ui/components/alert";
|
||||||
|
import { AlertDialog } from "@/modules/ui/components/alert-dialog";
|
||||||
|
import { Button } from "@/modules/ui/components/button";
|
||||||
|
import { Input } from "@/modules/ui/components/input";
|
||||||
import { updateSurveyAction } from "../actions";
|
import { updateSurveyAction } from "../actions";
|
||||||
import { isSurveyValid } from "../lib/validation";
|
import { isSurveyValid } from "../lib/validation";
|
||||||
|
|
||||||
interface SurveyMenuBarProps {
|
interface SurveyMenuBarProps {
|
||||||
localSurvey: TSurvey;
|
localSurvey: TSurvey;
|
||||||
|
setSavedSurvey: (survey: TSurvey) => void;
|
||||||
survey: TSurvey;
|
survey: TSurvey;
|
||||||
setLocalSurvey: (survey: TSurvey) => void;
|
setLocalSurvey: (survey: TSurvey) => void;
|
||||||
environmentId: string;
|
environmentId: string;
|
||||||
@@ -47,6 +49,7 @@ interface SurveyMenuBarProps {
|
|||||||
export const SurveyMenuBar = ({
|
export const SurveyMenuBar = ({
|
||||||
localSurvey,
|
localSurvey,
|
||||||
survey,
|
survey,
|
||||||
|
setSavedSurvey,
|
||||||
environmentId,
|
environmentId,
|
||||||
setLocalSurvey,
|
setLocalSurvey,
|
||||||
activeId,
|
activeId,
|
||||||
@@ -247,9 +250,12 @@ export const SurveyMenuBar = ({
|
|||||||
|
|
||||||
setIsSurveySaving(false);
|
setIsSurveySaving(false);
|
||||||
if (updatedSurveyResponse?.data) {
|
if (updatedSurveyResponse?.data) {
|
||||||
setLocalSurvey(updatedSurveyResponse.data);
|
const updatedSurvey = updatedSurveyResponse.data;
|
||||||
|
flushSync(() => {
|
||||||
|
setLocalSurvey(updatedSurvey);
|
||||||
|
setSavedSurvey(updatedSurvey);
|
||||||
|
});
|
||||||
toast.success(t("environments.surveys.edit.changes_saved"));
|
toast.success(t("environments.surveys.edit.changes_saved"));
|
||||||
router.refresh();
|
|
||||||
} else {
|
} else {
|
||||||
const errorMessage = getFormattedErrorMessage(updatedSurveyResponse);
|
const errorMessage = getFormattedErrorMessage(updatedSurveyResponse);
|
||||||
toast.error(errorMessage);
|
toast.error(errorMessage);
|
||||||
@@ -292,12 +298,18 @@ export const SurveyMenuBar = ({
|
|||||||
const segment = await handleSegmentUpdate();
|
const segment = await handleSegmentUpdate();
|
||||||
clearSurveyLocalStorage();
|
clearSurveyLocalStorage();
|
||||||
|
|
||||||
await updateSurveyAction({
|
const publishedSurveyResponse = await updateSurveyAction({
|
||||||
...localSurvey,
|
...localSurvey,
|
||||||
status,
|
status,
|
||||||
segment,
|
segment,
|
||||||
});
|
});
|
||||||
setIsSurveyPublishing(false);
|
setIsSurveyPublishing(false);
|
||||||
|
if (publishedSurveyResponse?.data) {
|
||||||
|
const publishedSurvey = publishedSurveyResponse.data;
|
||||||
|
flushSync(() => {
|
||||||
|
setSavedSurvey(publishedSurvey);
|
||||||
|
});
|
||||||
|
}
|
||||||
router.push(`/environments/${environmentId}/surveys/${localSurvey.id}/summary?success=true`);
|
router.push(`/environments/${environmentId}/surveys/${localSurvey.id}/summary?success=true`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user