Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix/#415] 등록 완료 페이지로 이동되지 않는 오류 수정 #416

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/apis/domains/performances/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,10 @@ export const getScheduleAvailable = async (
export type PerformanceResponse = components["schemas"]["PerformanceResponse"];

// 공연 등록 API (POST)
export const postPerformance = async (formData): Promise<PerformanceResponse | number> => {
try {
const response = await post("/performances", formData);
export const postPerformance = async (formData): Promise<PerformanceResponse> => {
const response = await post("/performances", formData);

return response.data;
} catch (error) {
console.error("error", error);

return null;
}
return response.data;
};

export type PerformanceModifyResponse = components["schemas"]["PerformanceModifyResponse"];
Expand Down
38 changes: 12 additions & 26 deletions src/apis/domains/performances/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
postPerformance,
updatePerformance,
} from "./api";
import { useModal } from "@hooks";

export const PERFORMANCE_QUERY_KEY = {
DETAIL: "detail",
Expand Down Expand Up @@ -144,10 +145,11 @@ const isPerformanceResponse = (res: any): res is PerformanceResponse => {
export const usePostPerformance = () => {
const queryClient = useQueryClient();
const navigate = useNavigate();
const { openAlert } = useModal();

return useMutation({
mutationFn: (formData: PerformanceFormData) => postPerformance(formData),
onSuccess: async (res) => {
onSuccess: (res) => {
queryClient.invalidateQueries({
queryKey: [HOME_QUERY_KEY.LIST, PERFORMANCE_QUERY_KEY.DETAIL],
});
Expand All @@ -157,31 +159,15 @@ export const usePostPerformance = () => {
exact: true,
});

// if (isPerformanceResponse(res) && res.status === 201) {
// // 프리렌더 작업 수행
// const prerenderResponse = await fetch(`${import.meta.env.VITE_CLIENT_URL}/api/prerender`, {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// },
// body: JSON.stringify({ performanceId: res.data.performanceId }),
// });

// console.log("prerenderResponse is: ", prerenderResponse);

// if (prerenderResponse.ok) {
// console.log("Prerender successful");
// } else {
// console.error("Prerender failed");
// }

// // 등록 완료 페이지로 이동
// navigate("/register-complete", {
// state: { performanceId: res.data.performanceId },
// });
// } else {
// console.error("Performance creation failed:", res);
// }
// 등록 완료 페이지로 이동
navigate("/register-complete", {
state: { performanceId: res.performanceId },
});
},
onError: () => {
openAlert({
title: "공연 등록이 실패했습니다.\n 다시 시도해주세요.",
});
},
});
};
Expand Down