Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 21 additions & 3 deletions src/api/gatherings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,34 @@ export const getApplicationStatus = async (gatheringId: number): Promise<GetAppl
}
};

/** GET /v1/gatherings/main — 메인 페이지 모임 목록 (서버/클라이언트 공용) */
/** GET /v1/gatherings/main — 메인 페이지 모임 목록 (클라이언트 전용) */
export const getMainGatherings = async (params?: GetMainGatheringsParams): Promise<GetMainGatheringsResponse> => {
const { data } = await axiosClient.get<ApiResponse<GetMainGatheringsResponse>>('/v1/gatherings/main', {
params,
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate',
Pragma: 'no-cache',
},
Comment thread
kwonjin2 marked this conversation as resolved.
Outdated
});

const result = unwrapResponse(data);
return {
popular: normalizeGatheringList(result.popular),
deadline: normalizeGatheringList(result.deadline),
latest: normalizeGatheringList(result.latest),
};
};
Comment thread
kwonjin2 marked this conversation as resolved.

/** GET /v1/gatherings/main — 메인 페이지 모임 목록 (서버 전용) */
export const fetchMainGatherings = async (params?: GetMainGatheringsParams): Promise<GetMainGatheringsResponse> => {
const searchParams = new URLSearchParams();
if (params?.limit !== undefined) searchParams.set('limit', String(params.limit));
const qs = searchParams.toString();

const isServer = typeof window === 'undefined';
const res = await fetch(`${getBaseUrl()}/v1/gatherings/main${qs ? `?${qs}` : ''}`, {
...(isServer && { next: { tags: [GATHERING_TAGS.all, GATHERING_TAGS.main] } }),
next: { tags: [GATHERING_TAGS.all, GATHERING_TAGS.main] },
});

if (!res.ok) throw new Error(`gatherings/main fetch failed: ${res.status}`);
const json: ApiResponse<GetMainGatheringsResponse> = await res.json();
const data = unwrapResponse(json);
Expand Down
30 changes: 20 additions & 10 deletions src/api/gatherings/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
updateGathering,
deleteGathering,
GATHERING_TAGS,
getMainGatherings,
} from './index';

import type { UseMutationOptions } from '@tanstack/react-query';
Expand Down Expand Up @@ -46,7 +47,7 @@ export const gatheringQueries = {
main: (params?: GetMainGatheringsParams) =>
queryOptions({
queryKey: gatheringKeys.main(params),
queryFn: () => fetchMainGatherings(params),
queryFn: () => (isServer ? fetchMainGatherings(params) : getMainGatherings(params)),
}),

/** GET /gatherings/:gatheringId — 모임 상세 */
Expand Down Expand Up @@ -80,9 +81,12 @@ export const useCreateGathering = (
return useMutation({
mutationFn: (body: CreateGatheringRequest) => createGathering(body),
...options,
onSuccess: (data, variables, onMutateResult, context) => {
queryClient.invalidateQueries({ queryKey: gatheringKeys.all });
invalidateServerCache(GATHERING_TAGS.all);
onSuccess: async (data, variables, onMutateResult, context) => {
await invalidateServerCache(GATHERING_TAGS.all);
await Promise.all([
queryClient.invalidateQueries({ queryKey: gatheringKeys.all }),
queryClient.invalidateQueries({ queryKey: ['memberships'] }),
]);
Comment thread
kwonjin2 marked this conversation as resolved.
options?.onSuccess?.(data, variables, onMutateResult, context);
},
});
Expand All @@ -101,9 +105,12 @@ export const useUpdateGathering = (
return updateGathering(gatheringId, body);
},
...options,
onSuccess: (data, variables, onMutateResult, context) => {
queryClient.invalidateQueries({ queryKey: gatheringKeys.all });
invalidateServerCache(GATHERING_TAGS.all);
onSuccess: async (data, variables, onMutateResult, context) => {
await invalidateServerCache(GATHERING_TAGS.all);
await Promise.all([
queryClient.invalidateQueries({ queryKey: gatheringKeys.all }),
queryClient.invalidateQueries({ queryKey: ['memberships'] }),
]);
options?.onSuccess?.(data, variables, onMutateResult, context);
},
});
Expand All @@ -116,9 +123,12 @@ export const useDeleteGathering = (gatheringId: number, options?: UseMutationOpt
return useMutation({
mutationFn: () => deleteGathering(gatheringId),
...options,
onSuccess: (data, variables, onMutateResult, context) => {
queryClient.invalidateQueries({ queryKey: gatheringKeys.all });
invalidateServerCache(GATHERING_TAGS.all);
onSuccess: async (data, variables, onMutateResult, context) => {
await invalidateServerCache(GATHERING_TAGS.all);
await Promise.all([
queryClient.invalidateQueries({ queryKey: gatheringKeys.all }),
queryClient.invalidateQueries({ queryKey: ['memberships'] }),
]);
options?.onSuccess?.(data, variables, onMutateResult, context);
},
});
Expand Down
4 changes: 4 additions & 0 deletions src/api/memberships/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const normalizeMembershipGathering = (item: MembershipGathering): MembershipGath
export const getMyGatherings = async (params?: MyGatheringsParams): Promise<MyGatheringList> => {
const { data } = await axiosClient.get<ApiResponse<MyGatheringList>>('/v1/users/me/gatherings', {
params,
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate',
Pragma: 'no-cache',
},
Comment thread
kwonjin2 marked this conversation as resolved.
Outdated
});
const result = unwrapResponse(data);
return { ...result, gatherings: result.gatherings.map(normalizeMembershipGathering) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function LeaderActionDropdown({ gatheringId }: LeaderActionDropdownProps)
deleteGathering(undefined, {
onSuccess: () => {
showToast({ variant: 'success', title: '모임이 삭제되었습니다' });
router.refresh();
Comment thread
kwonjin2 marked this conversation as resolved.
Outdated
router.push('/main');
},
onError: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const useMemberList = (gatheringId: number) => {

const getHasReviewed = (index: number): boolean => {
const userReviews = memberReviewResults[index]?.data?.reviews || [];
return userReviews.some((r) => r.reviewer.id === user?.id);
return userReviews.some((r) => r.reviewer?.id === user?.id);
Comment thread
kwonjin2 marked this conversation as resolved.
};

const handlePageChange = (page: number) => {
Expand Down
1 change: 1 addition & 0 deletions src/app/gatherings/new/CreateGatheringForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export function CreateGatheringForm({ mode = 'create', gatheringId, initialValue
mutate(data, {
onSuccess: () => {
showToast({ variant: 'success', title: isEditMode ? '모임이 수정되었습니다.' : '모임이 생성되었습니다.' });
router.refresh();
Comment thread
kwonjin2 marked this conversation as resolved.
Outdated
if (isEditMode && gatheringId) {
router.push(`/gatherings/${gatheringId}`);
} else {
Expand Down
File renamed without changes.
Loading