diff --git a/src/api/service/group-service/index.ts b/src/api/service/group-service/index.ts index 37b68463..b7444ee3 100644 --- a/src/api/service/group-service/index.ts +++ b/src/api/service/group-service/index.ts @@ -1,5 +1,7 @@ import { api } from '@/api/core'; import { + CreateGroupPayload, + CreateGroupResponse, GetGroupsPayload, GetGroupsResponse, GetMyGroupsPayload, @@ -31,4 +33,8 @@ export const groupServiceRemote = () => ({ return api.get(`/groups/me?${params.toString()}`); }, + + createGroup: (payload: CreateGroupPayload) => { + return api.post('/groups/create', payload); + }, }); diff --git a/src/app/post-meetup/page.tsx b/src/app/post-meetup/page.tsx index dfb49c95..002940a9 100644 --- a/src/app/post-meetup/page.tsx +++ b/src/app/post-meetup/page.tsx @@ -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); }, }); diff --git a/src/hooks/use-group/use-group-create/index.ts b/src/hooks/use-group/use-group-create/index.ts new file mode 100644 index 00000000..edfb259c --- /dev/null +++ b/src/hooks/use-group/use-group-create/index.ts @@ -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; +}; diff --git a/src/types/service/group.ts b/src/types/service/group.ts index af73d6f0..0c769d3f 100644 --- a/src/types/service/group.ts +++ b/src/types/service/group.ts @@ -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; +}