Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/api/service/group-service/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { api } from '@/api/core';
import {
CreateGroupPayload,
CreateGroupResponse,
GetGroupsPayload,
GetGroupsResponse,
GetMyGroupsPayload,
Expand Down Expand Up @@ -31,4 +33,8 @@ export const groupServiceRemote = () => ({

return api.get<GetMyGroupsResponse>(`/groups/me?${params.toString()}`);
},

createGroup: (payload: CreateGroupPayload) => {
return api.post<CreateGroupResponse>('/groups/create', payload);
},
});
16 changes: 12 additions & 4 deletions src/app/post-meetup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,28 @@ import {
MeetupTagsField,
MeetupTitleField,
} from '@/components/pages/post-meetup';
import { useCreateGroup } from '@/hooks/use-group/use-group-create';
import { CreateGroupPayload } from '@/types/service/group';

const PostMeetupPage = () => {
const { mutate } = useCreateGroup();

const form = useForm({
defaultValues: {
title: '',
location: '',
locationDetail: '',
startTime: '',
maxParticipants: 0,
images: {},
description: '',
endTime: '',
tags: [] as string[],
},
description: '',
maxParticipants: 0,
images: [],
} as CreateGroupPayload,
onSubmit: ({ value }) => {
console.log(value);
const res = mutate(value);
console.log(res);
},
});

Expand Down
17 changes: 17 additions & 0 deletions src/hooks/use-group/use-group-create/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useMutation } from '@tanstack/react-query';

import { API } from '@/api';
import { CreateGroupPayload } from '@/types/service/group';

export const useCreateGroup = () => {
const query = useMutation({
mutationFn: (payload: CreateGroupPayload) => API.groupService.createGroup(payload),
onSuccess: () => {
// 상세 페이지 이동할거라 목록 캐시를 갱신할 이유가 없음 (GPT 피셜)
},
onError: () => {
console.log('모임 생성 실패.');
},
});
return query;
};
47 changes: 47 additions & 0 deletions src/types/service/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,50 @@ export interface Group {
updatedAt: string;
joinedCount: number;
}

export interface PreUploadGroupImagePayload {
images: File[];
}

export interface PreUploadGroupImageResponse {
images: {
sortOrder: number;
imageUrl440x240: string;
imageUrl100x100: string;
}[];
}

export type CreateGroupImagePayload = PreUploadGroupImageResponse;

export interface CreateGroupPayload {
title: string;
location: string;
locationDetail?: string | null;
startTime: string;
endTime?: string;
tags?: string[] | null;
description: string;
maxParticipants: number;
images?: CreateGroupImagePayload['images'] | null;
}

export interface CreateGroupResponse {
id: number;
title: string;
location: string;
locationDetail?: string | null;
startTime: string;
endTime?: string;
tags?: string[] | null;
description: string;
participantCount: number;
maxParticipants: number;
createdBy: {
userId: number;
nickName: string;
profileImage?: string | null;
};
createdAt: string;
updatedAt: string;
images?: PreUploadGroupImageResponse | null;
}