fix: Unsaved Changes Confirm even though changes were saved (#2372)

Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com>
This commit is contained in:
Piyush Gupta
2024-04-09 14:54:59 +05:30
committed by GitHub
parent 015d4c7663
commit 496d1b3c2e
2 changed files with 4 additions and 1 deletions

View File

@@ -53,7 +53,7 @@ export default function SurveyEditor({
}: SurveyEditorProps): JSX.Element {
const [activeView, setActiveView] = useState<TSurveyEditorTabs>("questions");
const [activeQuestionId, setActiveQuestionId] = useState<string | null>(null);
const [localSurvey, setLocalSurvey] = useState<TSurvey | null>(survey);
const [localSurvey, setLocalSurvey] = useState<TSurvey | null>(() => structuredClone(survey));
const [invalidQuestions, setInvalidQuestions] = useState<string[] | null>(null);
const [selectedLanguageCode, setSelectedLanguageCode] = useState<string>("default");
const surveyEditorRef = useRef(null);

View File

@@ -118,6 +118,7 @@ export default function SurveyMenuBar({
const handleBack = () => {
const { updatedAt, ...localSurveyRest } = localSurvey;
const { updatedAt: _, ...surveyRest } = survey;
localSurveyRest.triggers = localSurveyRest.triggers.filter((trigger) => Boolean(trigger));
if (!isEqual(localSurveyRest, surveyRest)) {
setConfirmDialogOpen(true);
@@ -347,10 +348,12 @@ export default function SurveyMenuBar({
return;
}
strippedSurvey.triggers = strippedSurvey.triggers.filter((trigger) => Boolean(trigger));
try {
await updateSurveyAction({ ...strippedSurvey });
setIsSurveySaving(false);
setLocalSurvey(strippedSurvey);
toast.success("Changes saved.");
if (shouldNavigateBack) {
router.back();