Skip to content

Commit

Permalink
Refactor : callback 구조 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jobkaeHenry committed Dec 4, 2023
1 parent 9772f5a commit f5f9f0d
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions client/src/app/(protectedRoute)/new-post/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,35 @@ export default function NewpostPage() {
const { mutateAsync: attachFileHandler } = useNewAttachMutation();
const { mutateAsync: deletePostHandler } = useDeletePostMutation();

const submitHandler = useCallback(async () => {
setLoading(true);
let postNo;
try {
const { postNo: res } = await newPostHandler({
...formValue,
alcoholNo,
});
postNo = res;
if (file) {
try {
await attachFileHandler({
file,
url: { pk: postNo, type: "POST" },
});
} catch {
deletePostHandler(postNo);
return;
const submitHandler = useCallback(
async (formValue: NewPostRequestInterface, file?: File) => {
setLoading(true);
let postNo;
try {
const { postNo: res } = await newPostHandler(formValue);
postNo = res;
if (file) {
try {
await attachFileHandler({
file,
url: { pk: postNo, type: "POST" },
});
} catch {
deletePostHandler(postNo);
return;
}
}
invalidatePreviousPost();
SetIsSuccess(true);
router.push(HOME);
} catch {
return;
} finally {
setLoading(false);
}
invalidatePreviousPost();
SetIsSuccess(true);
router.push(HOME);
} catch {
return;
} finally {
setLoading(false);
}
}, [formValue, alcoholNo, router, file]);
},
[router]
);

return (
<Paper>
Expand All @@ -85,7 +85,7 @@ export default function NewpostPage() {
title="포스팅"
appendButton="공유"
disableAppend={isSuccess}
onClickAppend={submitHandler}
onClickAppend={()=>submitHandler({...formValue,alcoholNo},file)}
/>

<Container sx={{ p: { xs: 0, sm: 4 } }} maxWidth={"lg"}>
Expand Down

0 comments on commit f5f9f0d

Please sign in to comment.