Skip to content

Commit 5841582

Browse files
committed
refactor: 코드리뷰 반영
1 parent 770b7d7 commit 5841582

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

app/(sub)/create-capsule/page.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ const CreateCapsule = () => {
3838
const [capsuleInfo, setCapsuleInfo] = useState<CapsuleInfo | null>(null);
3939
const [showLoading, setShowLoading] = useState(false);
4040
const { open } = useOverlay();
41-
const { mutate: createCapsuleMutate, isPending } = useMutation(
42-
capsuleMutationOptions.create,
43-
);
41+
const {
42+
mutate: createCapsuleMutate,
43+
isPending,
44+
isSuccess,
45+
isError,
46+
} = useMutation(capsuleMutationOptions.create);
4447

4548
const defaultOpenDate = getDate(14);
4649
const defaultClosedAt = getDate(10);
@@ -85,15 +88,19 @@ const CreateCapsule = () => {
8588
useEffect(() => {
8689
if (isPending) {
8790
setShowLoading(true);
88-
} else if (showLoading && !isPending) {
91+
return;
92+
}
93+
if (isSuccess && showLoading) {
8994
const timer = setTimeout(() => {
9095
setShowLoading(false);
9196
setStep("complete");
9297
}, 2000);
93-
9498
return () => clearTimeout(timer);
9599
}
96-
}, [isPending, showLoading]);
100+
if (isError) {
101+
setShowLoading(false);
102+
}
103+
}, [isPending, isSuccess, isError, showLoading]);
97104

98105
if (showLoading) {
99106
return <CreateCapsuleLoading />;

0 commit comments

Comments
 (0)