Skip to content

Commit

Permalink
Fix: Change toastAlertStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonghun authored and Yonghun committed Feb 21, 2024
1 parent 0fe82a1 commit 8056d06
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const App = () => {
const modalState = useModalStore();
const toastState = useToastStore();

const notify = () => toast("회원가입 완료");
const notify = () => toast(toastState.toastText);

useEffect(() => {
if (toastState.isToast) {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/MarkerInfoModal/MarkerInfoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const MarkerInfoModal = ({

useEffect(() => {
toastState.close();
toastState.setToastText("");

if (currentMarkerInfo.photos) {
console.log(currentMarkerInfo.photos[0].photoUrl);
Expand All @@ -37,6 +38,7 @@ const MarkerInfoModal = ({
const handleDelete = () => {
DeleteMarker(currentMarkerInfo.markerId).then((res) => {
console.log(res);
toastState.setToastText("삭제 완료");
toastState.open();
markers[currentMarkerInfo.index].setMap(null);
setMarkerInfoModal(false);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/SignupForm/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const SignupForm = () => {

useEffect(() => {
toastState.close();
toastState.setToastText("");
}, []);

const handleSubmit = () => {
Expand Down Expand Up @@ -80,6 +81,7 @@ const SignupForm = () => {
} else if (res.error && res.error.code === 500) {
setSigninError("서버 에러");
} else {
toastState.setToastText("회원 가입 완료");
toastState.open();
modalState.close();
modalState.openLogin();
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/store/useToastStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { create } from "zustand";

interface ToastState {
isToast: boolean;
toastText: string;
setToastText: (text: string) => void;
close: VoidFunction;
open: VoidFunction;
}

const useToastStore = create<ToastState>()((set) => ({
isToast: false,
toastText: "",
setToastText: (text: string) => set({ toastText: text }),
close: () => set({ isToast: false }),
open: () => set({ isToast: true }),
}));
Expand Down

0 comments on commit 8056d06

Please sign in to comment.