From 98137aa53cff91be372b0bef037c006dbf10a05d Mon Sep 17 00:00:00 2001 From: LSJ Date: Mon, 9 Sep 2024 12:26:30 +0900 Subject: [PATCH] fix error --- pageTemplates/vote/VoteDrawer.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pageTemplates/vote/VoteDrawer.tsx b/pageTemplates/vote/VoteDrawer.tsx index 1599cb88d..a8ff74315 100644 --- a/pageTemplates/vote/VoteDrawer.tsx +++ b/pageTemplates/vote/VoteDrawer.tsx @@ -4,7 +4,7 @@ import { useEffect, useState } from "react"; import BottomDrawerLg from "../../components/organisms/drawer/BottomDrawerLg"; import { STUDY_PREFERENCE_LOCAL } from "../../constants/keys/queryKeys"; import { useStudyPreferenceQuery } from "../../hooks/study/queries"; -import { StudyVoteMapActionType } from "../../pages/vote"; +import { PreferStorageProps, StudyVoteMapActionType } from "../../pages/vote"; import { DispatchType } from "../../types/hooks/reactTypes"; import { IParticipation, IPlace } from "../../types/models/studyTypes/studyDetails"; import { @@ -33,16 +33,16 @@ function VoteDrawer({ studyVoteData, myVote, setMyVote, setActionType }: VoteDra const preferenceStorage = localStorage.getItem(STUDY_PREFERENCE_LOCAL); const { data: studyPreference } = useStudyPreferenceQuery({ - enabled: !preferenceStorage, - onSuccess(data) { - localStorage.setItem(STUDY_PREFERENCE_LOCAL, JSON.stringify(data)); + enabled: !preferenceStorage || preferenceStorage === "undefined", + onSuccess() { setMyVote(null); }, }); - - const savedPrefer = preferenceStorage - ? (JSON.parse(preferenceStorage) as IStudyVotePlaces) - : studyPreference; + console.log(preferenceStorage); + const savedPrefer = + preferenceStorage && preferenceStorage !== "undefined" + ? (JSON.parse(preferenceStorage) as PreferStorageProps)?.prefer + : studyPreference; const savedPreferPlace: { place: IPlace; subPlace: IPlace[] } = savedPrefer && { place: studyVoteData.find((par) => par.place._id === savedPrefer.place)?.place,