Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Team-Partage/partage_web
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
Si-off committed Jul 26, 2024
2 parents a45c9e0 + 8d5096a commit 75b9134
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/components/TagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const TagInput = ({ onChange, color, value = '', ...rest }: Props) => {

/** 태그 입력 */
const handleEnter = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
if (e.key === 'Enter' && !e.nativeEvent.isComposing) {
/** 태그 길이 및 중복 태그 검사 */
if (inputValue.length === 0 || tags.includes(inputValue)) {
setInputValue('');
return;
}
const newTags = [...tags, inputValue];
onChange && onChange(newTags.join(' '));
onChange && onChange(newTags.join());
setTags(newTags);
setInputValue('');
}
Expand All @@ -33,7 +33,7 @@ const TagInput = ({ onChange, color, value = '', ...rest }: Props) => {
const handleClick = (index: number) => {
const newTags = tags.filter((_, i) => i !== index);
setTags(newTags);
onChange && onChange(newTags.join(' '));
onChange && onChange(newTags.join());
};

return (
Expand Down
28 changes: 17 additions & 11 deletions src/components/modal/CreateChannelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useRouter } from 'next/navigation';
import ColorChips from '../ColorChips';
import TagInput from '../TagInput';
import { Button } from '../ui/button';
import { DialogContent, DialogHeader, DialogTitle, DialogFooter } from '../ui/dialog';
import { DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogClose } from '../ui/dialog';
import { Input } from '../ui/input';
import { Label } from '../ui/label';

Expand Down Expand Up @@ -48,8 +48,12 @@ const CreateChannelModal = () => {
const router = useRouter();

const handleSubmit = async () => {
const res = await createChannel(state);
router.push(`/channel/${res.channel.channel_id}`);
try {
const res = await createChannel(state);
router.push(`/channel/${res.channel.channel_id}`);
} catch (error) {
alert('채널이 이미 존재합니다.');
}
};

return (
Expand Down Expand Up @@ -84,14 +88,16 @@ const CreateChannelModal = () => {
</div>
</div>
<DialogFooter className="items-center">
<Button
className="w-full tablet:w-fit"
variant="active"
disabled={state.name === '' || state.hashtag.length === 0}
onClick={handleSubmit}
>
생성
</Button>
<DialogClose asChild>
<Button
className="w-full tablet:w-fit"
variant="active"
disabled={state.name === '' || state.hashtag.length === 0}
onClick={handleSubmit}
>
생성
</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/fetcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Fetcher {
}

async post<T>(endpoint: string, params: object, options?: FetcherRequestInit): Promise<T> {
const url = new URL(endpoint, this.baseURL);
const url = this.makeURL(endpoint);

const res = await fetch(url, {
method: 'POST',
Expand All @@ -77,7 +77,7 @@ class Fetcher {
}

async put<T>(endpoint: string, params: object, options?: FetcherRequestInit): Promise<T> {
const url = new URL(endpoint, this.baseURL);
const url = this.makeURL(endpoint);

const res = await fetch(url, {
method: 'PUT',
Expand All @@ -91,7 +91,7 @@ class Fetcher {
}

async patch<T>(endpoint: string, params: object, options?: FetcherRequestInit): Promise<T> {
const url = new URL(endpoint, this.baseURL);
const url = this.makeURL(endpoint);

const res = await fetch(url, {
method: 'PATCH',
Expand All @@ -105,7 +105,7 @@ class Fetcher {
}

async delete<T>(endpoint: string, options?: FetcherRequestInit): Promise<T> {
const url = new URL(endpoint, this.baseURL);
const url = this.makeURL(endpoint);

const res = await fetch(url, {
method: 'DELETE',
Expand Down

0 comments on commit 75b9134

Please sign in to comment.