-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BugFix] label 및 sprint 이름 중복시 예외처리 추가 및 toast 추가 #152
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
648de76
feat: useSprintMutations에 제너릭 타입 추가
PMtHk fc7cf17
fix: sprint 생성 시 중복 이름 예외 처리 추가
PMtHk e5197b4
fix: 레이아웃 사이즈 조절
PMtHk 35de62b
refactor: 파일 오타 수정
PMtHk 69b372d
fix: 불필요한 타입 제거
PMtHk bd454f0
feat: useLabelMutations에 제너릭 타입 추가
PMtHk fccb8c9
feat: label 생성 시 중복 이름 예외 처리 추가
PMtHk 1bb65b7
feat: 성공시 form values 초기화 추가
PMtHk b47b3ef
feat: label 편집 시 중복 이름 예외 처리 추가
PMtHk f11ce6a
chore: shadcn/ui sonner 추가
PMtHk 9b8f8f0
feat: toast 유틸 추가
PMtHk 32c392b
feat: label 에 toast 적용
PMtHk 0852939
feat: sprint 에 toast 적용
PMtHk a30c3dd
feat: date-picker label 의 width 조정
PMtHk 7bdd5ef
fix: 헤더에 프로젝트 id 가 아닌 title 로 수정
PMtHk ec2253b
style: SlashIcon 색상 변경
PMtHk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useTheme } from 'next-themes'; | ||
import { Toaster as Sonner } from 'sonner'; | ||
|
||
type ToasterProps = React.ComponentProps<typeof Sonner>; | ||
|
||
function Toaster({ ...props }: ToasterProps) { | ||
const { theme = 'system' } = useTheme(); | ||
|
||
return ( | ||
<Sonner | ||
theme={theme as ToasterProps['theme']} | ||
className="toaster group" | ||
toastOptions={{ | ||
classNames: { | ||
toast: | ||
'group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg', | ||
description: 'group-[.toast]:text-muted-foreground', | ||
actionButton: 'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground', | ||
cancelButton: 'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground', | ||
}, | ||
}} | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
export { Toaster }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { useForm } from 'react-hook-form'; | ||
import { Plus, Shuffle } from 'lucide-react'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { UseMutationResult } from '@tanstack/react-query'; | ||
import { AxiosError } from 'axios'; | ||
import { Input } from '@/components/ui/input.tsx'; | ||
import { Button } from '@/components/ui/button.tsx'; | ||
import { | ||
|
@@ -14,13 +16,27 @@ import { | |
import { ColorInput } from '@/features/project/label/components/ColorInput.tsx'; | ||
import { generateRandomColor } from '@/features/project/label/generateRandomColor.ts'; | ||
import { labelFormSchema, LabelFormValues } from '@/features/project/label/labelSchema.ts'; | ||
import { BaseResponse } from '@/features/types.ts'; | ||
import { CreateLabelDto } from '@/features/project/types.ts'; | ||
import { useToast } from '@/lib/useToast.tsx'; | ||
|
||
interface CreateLabelProps { | ||
onCreate: (data: LabelFormValues) => void; | ||
createMutation: UseMutationResult<BaseResponse, AxiosError, CreateLabelDto>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 외부에서 한번 mutation 을 wrapping 해서 사용했었는데, |
||
} | ||
|
||
export function CreateLabel({ onCreate }: CreateLabelProps) { | ||
const createForm = useForm<LabelFormValues>({ | ||
export function CreateLabel({ createMutation }: CreateLabelProps) { | ||
const toast = useToast(); | ||
|
||
const { mutate } = createMutation; | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
setValue, | ||
watch, | ||
setError, | ||
formState: { errors }, | ||
} = useForm<LabelFormValues>({ | ||
resolver: zodResolver(labelFormSchema), | ||
defaultValues: { | ||
name: '', | ||
|
@@ -29,17 +45,37 @@ export function CreateLabel({ onCreate }: CreateLabelProps) { | |
}, | ||
}); | ||
|
||
const handleRandomColor = () => { | ||
createForm.setValue('color', generateRandomColor(), { shouldValidate: true }); | ||
const onCreate = (data: LabelFormValues) => { | ||
mutate( | ||
{ | ||
name: data.name.trim(), | ||
description: data.description.trim(), | ||
color: data.color, | ||
}, | ||
{ onSuccess, onError } | ||
); | ||
}; | ||
|
||
const handleSubmit = (data: LabelFormValues) => { | ||
onCreate(data); | ||
createForm.reset({ | ||
name: '', | ||
description: '', | ||
color: generateRandomColor(), | ||
}); | ||
const onSuccess = () => { | ||
toast.success('Label created successfully'); | ||
setValue('name', ''); | ||
setValue('description', ''); | ||
setValue('color', generateRandomColor()); | ||
}; | ||
|
||
const onError = (error: AxiosError) => { | ||
if (error?.response?.status === 409) { | ||
setError('name', { | ||
message: 'Label with this name already exists', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 에러 메세지들은 나중에 하나의 객체로 분리하면 더 좋을 것 같습니다. |
||
}); | ||
return; | ||
} | ||
|
||
toast.error('Failed to create label'); | ||
}; | ||
|
||
const handleRandomColor = () => { | ||
setValue('color', generateRandomColor(), { shouldValidate: true }); | ||
}; | ||
|
||
return ( | ||
|
@@ -49,23 +85,19 @@ export function CreateLabel({ onCreate }: CreateLabelProps) { | |
<CardDescription>Add a new label to your project.</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<form onSubmit={createForm.handleSubmit(handleSubmit)} className="space-y-4"> | ||
<form onSubmit={handleSubmit(onCreate)} className="space-y-4"> | ||
<div className="flex gap-4"> | ||
<div className="flex-1"> | ||
<label htmlFor="name" className="block text-sm font-medium text-gray-700"> | ||
Name | ||
<Input | ||
{...createForm.register('name')} | ||
{...register('name')} | ||
placeholder="Label name" | ||
className="mt-1 h-10" | ||
id="name" | ||
/> | ||
</label> | ||
{createForm.formState.errors.name && ( | ||
<p className="mt-1 text-sm text-red-500"> | ||
{createForm.formState.errors.name.message} | ||
</p> | ||
)} | ||
{errors.name && <p className="mt-1 text-sm text-red-500">{errors.name.message}</p>} | ||
</div> | ||
<div className="flex"> | ||
<div className="mt-1 flex min-w-[200px] items-end gap-2"> | ||
|
@@ -75,8 +107,8 @@ export function CreateLabel({ onCreate }: CreateLabelProps) { | |
> | ||
Color | ||
<ColorInput | ||
value={createForm.watch('color')} | ||
onChange={(value) => createForm.setValue('color', value)} | ||
value={watch('color')} | ||
onChange={(value) => setValue('color', value)} | ||
className="flex-1" | ||
/> | ||
</label> | ||
|
@@ -96,16 +128,14 @@ export function CreateLabel({ onCreate }: CreateLabelProps) { | |
<label htmlFor="description" className="block text-sm font-medium text-gray-700"> | ||
Description | ||
<Input | ||
{...createForm.register('description')} | ||
{...register('description')} | ||
placeholder="Label description" | ||
className="mt-1" | ||
id="description" | ||
/> | ||
</label> | ||
{createForm.formState.errors.description && ( | ||
<p className="mt-1 text-sm text-red-500"> | ||
{createForm.formState.errors.description.message} | ||
</p> | ||
{errors.description && ( | ||
<p className="mt-1 text-sm text-red-500">{errors.description.message}</p> | ||
)} | ||
</div> | ||
<Button type="submit" className="w-full bg-black hover:bg-black/80"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 shadcn/ui 의 sonner 를 사용한 부분입니다.
리뷰 대상이 아닙니다.