Skip to content

Commit 041055a

Browse files
authored
Merge pull request #315 from SCBJ-7/feature/##275-toast
[#275] path가 바뀔 때마다 토스트 상태 리셋
2 parents 7ac5baa + 9868403 commit 041055a

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

src/App.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ import IsLogin from "@components/isLogin/IsLogin";
22
import ScrollToTop from "@components/scrollToTop/ScrollToTop";
33
import Toast from "@components/toast/Toast";
44
import { AnimatePresence } from "framer-motion";
5-
import { Outlet } from "react-router-dom";
5+
import { useEffect } from "react";
6+
import { Outlet, useLocation } from "react-router-dom";
67

78
import "./firebase.ts";
89

910
import { useToastStore } from "./store/store";
1011

1112
const App = () => {
13+
const location = useLocation();
1214
const toastConfig = useToastStore((state) => state.config);
15+
const resetToast = useToastStore((state) => state.resetToast);
16+
17+
useEffect(() => {
18+
resetToast();
19+
}, [location, resetToast]);
1320

1421
return (
1522
<IsLogin>

src/components/toast/Toast.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Toast = () => {
1414
duration: 0.3,
1515
type: "spring",
1616
stiffness: 60,
17-
delay: 0.5,
17+
delay: 0,
1818
},
1919
},
2020
hidden: {

src/pages/paymentPage/Payment.tsx

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import Caption from "@components/caption/Caption";
2+
import Modal from "@components/modal/Modal";
3+
import { paymentCaptions } from "@constants/caption";
4+
import { isAxiosError } from "axios";
5+
import { useEffect, useState } from "react";
6+
import { FormProvider, useForm } from "react-hook-form";
7+
import { useLocation, useNavigate, useParams } from "react-router-dom";
8+
9+
import PaymentButton from "./components/paymentButton/PaymentButton";
10+
import * as S from "./Payment.style";
11+
112
import { ERROR_CODE } from "@/constants/api";
213
import { PATH } from "@/constants/path";
314
import {
@@ -9,16 +20,6 @@ import PaymentInfoSection from "@/pages/paymentPage/components/paymentInfoSectio
920
import PaymentMethodSection from "@/pages/paymentPage/components/paymentMethodSection/PaymentMethodSection";
1021
import TermsAgreementSection from "@/pages/paymentPage/components/termsAgreementSection/TermsAgreementSection";
1122
import UserInfoSection from "@/pages/paymentPage/components/userInfoSection/UserInfoSection";
12-
import Caption from "@components/caption/Caption";
13-
import Modal from "@components/modal/Modal";
14-
import { paymentCaptions } from "@constants/caption";
15-
import { isAxiosError } from "axios";
16-
import { useEffect, useState } from "react";
17-
import { FormProvider, useForm } from "react-hook-form";
18-
import { useLocation, useNavigate, useParams } from "react-router-dom";
19-
20-
import PaymentButton from "./components/paymentButton/PaymentButton";
21-
import * as S from "./Payment.style";
2223

2324
interface PaymentProps {
2425
action: "default" | "cancel" | "ready";

src/store/store.ts

+9
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export type configType = {
7070
interface ToastStates {
7171
config: configType;
7272
setToastConfig: (updatedConfig: configType) => void;
73+
resetToast: () => void;
7374
}
7475

7576
export const useToastStore = create<ToastStates>((set) => ({
@@ -85,6 +86,14 @@ export const useToastStore = create<ToastStates>((set) => ({
8586
...updated,
8687
},
8788
})),
89+
resetToast: () =>
90+
set(() => ({
91+
config: {
92+
isShow: false,
93+
isError: false,
94+
strings: [],
95+
},
96+
})),
8897
}));
8998

9099
interface SearchState {

0 commit comments

Comments
 (0)