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
8 changes: 7 additions & 1 deletion src/api/service/group-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { api } from '@/api/core';
import {
CreateGroupPayload,
CreateGroupResponse,
GetGroupDetailsPayload,
GetGroupDetailsResponse,
GetGroupsPayload,
GetGroupsResponse,
GetMyGroupsPayload,
Expand Down Expand Up @@ -35,6 +37,10 @@ export const groupServiceRemote = () => ({
},

createGroup: (payload: CreateGroupPayload) => {
return api.post<CreateGroupResponse>('/groups/create', payload);
return api.post<CreateGroupResponse>('/groups/groups/create', payload);
},

getGroupDetails: (payload: GetGroupDetailsPayload) => {
return api.post<GetGroupDetailsResponse>(`/groups/${payload}`);
},
});
17 changes: 16 additions & 1 deletion src/app/post-meetup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { useForm } from '@tanstack/react-form';
import { z } from 'zod';

import {
MeetupCapField,
Expand All @@ -18,6 +19,14 @@ import { CreateGroupPayload } from '@/types/service/group';
const PostMeetupPage = () => {
const { mutate } = useCreateGroup();

const CreateGroupSchema = {
title: z.string().min(2),
location: z.string().min(2),
startTime: z.string().min(2),
description: z.string().min(2),
maxParticipants: z.number().min(2),
};

const form = useForm({
defaultValues: {
title: '',
Expand All @@ -30,6 +39,9 @@ const PostMeetupPage = () => {
maxParticipants: 0,
images: [],
} as CreateGroupPayload,
validators: {
onChange: () => CreateGroupSchema,
},
onSubmit: ({ value }) => {
console.log(value);
const res = mutate(value);
Expand Down Expand Up @@ -61,7 +73,10 @@ const PostMeetupPage = () => {
<form.Field children={(field) => <MeetupTagsField field={field} />} name='tags' />
</section>

<MeetupSubmitButton />
<form.Subscribe
children={(state) => <MeetupSubmitButton state={state} />}
selector={(state) => state}
/>
</form>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const MeetupDetailField = ({ field }: Props) => {
className='bg-mono-white focus:border-mint-500 text-text-md-medium h-40 w-full resize-none rounded-2xl border border-gray-300 px-5 py-4 text-gray-800 focus:outline-none'
maxLength={300}
placeholder='모임에 대해 설명해주세요'
required
value={field.state.value}
onChange={(e) => field.handleChange(e.target.value)}
/>
Expand Down
5 changes: 4 additions & 1 deletion src/components/pages/post-meetup/fields/tags-field/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useState } from 'react';
import { useRef, useState } from 'react';

import { AnyFieldApi } from '@tanstack/react-form';
import clsx from 'clsx';
Expand All @@ -13,6 +13,7 @@ interface Props {
}

export const MeetupTagsField = ({ field }: Props) => {
const inputRef = useRef<HTMLInputElement | null>(null);
const [inputValue, setInputValue] = useState('');

const onEnter = (e: React.KeyboardEvent<HTMLInputElement>) => {
Expand All @@ -25,13 +26,15 @@ export const MeetupTagsField = ({ field }: Props) => {
field.pushValue(inputValue);
}

if (inputRef.current) inputRef.current.focus();
setInputValue('');
};

return (
<div className='flex w-full flex-col gap-1'>
<Label htmlFor='post-meetup-tags'>태그</Label>
<Input
ref={inputRef}
id='post-meetup-tags'
className='bg-mono-white focus:border-mint-500 rounded-2xl border border-gray-300'
frontIcon={
Expand Down
12 changes: 10 additions & 2 deletions src/components/pages/post-meetup/post-button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { AnyFormState } from '@tanstack/react-form';

import { Button } from '@/components/ui';

export const MeetupSubmitButton = () => {
interface Props {
state: AnyFormState;
}

export const MeetupSubmitButton = ({ state }: Props) => {
return (
<div className='mt-6 border-t-1 border-gray-200 bg-white px-4 py-3'>
<Button type='submit'>모임 생성</Button>
<Button disabled={!state.canSubmit} type='submit'>
모임 생성
</Button>
</div>
);
};
12 changes: 12 additions & 0 deletions src/hooks/use-group/use-group-get-details/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useQuery } from '@tanstack/react-query';

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

export const useGetGroupDetails = (payload: GetGroupDetailsPayload) => {
const query = useQuery({
queryKey: ['somekey'],
queryFn: () => API.groupService.getGroupDetails(payload),
});
return query;
};
42 changes: 42 additions & 0 deletions src/types/service/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,45 @@ export interface CreateGroupResponse {
updatedAt: string;
images?: PreUploadGroupImageResponse | null;
}

export interface GetGroupDetailsPayload {
groupId: number;
}

export interface GetGroupDetailsResponse {
id: number;
title: string;
location: string;
locationDetail: string;
startTime: string;
endTime: string;
images: {
sortOrder: number;
imageId440x240: number;
imageId100x100: number;
imageUrl440x240: string;
imageUrl100x100: string;
}[];
tags: string[];
description: string;
participantCount: number;
maxParticipants: number;
createdBy: {
userId: number;
nickName: string;
profileImage: string;
};
createdAt: string;
updatedAt: string;
userStatus: {
isJoined: boolean;
joinedAt: string;
};
joinedMembers: {
userId: 0;
groupRole: 'HOST' | 'MEMBER';
nickName: string;
profileImage: string;
joinedAt: string;
}[];
}