-
Notifications
You must be signed in to change notification settings - Fork 2
[✨ Feature/278] 할 일 생성 수정 모달 구현 api 연결 #311
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
edff9cd
🐛 Fix: shrink-0 추가
aahreum 6d26b96
♻️ Refactor: updateCardType으로 변경
aahreum 96d7b5d
⚙️ Chore: 카드 편집 폼 타입 추가
aahreum 5dc93f8
✨ Feat: 컬럼 데이터 넘겨주도록 구현
aahreum 369ea98
✨ Feat: 컬럼 데이터 넘겨주도록 구현
aahreum 86aec13
🐛 Fix: selectedNode 제거
aahreum 396b1c0
✨ Feat: 타입 추가
aahreum 82e5f8e
🐛 Fix: 콤보박스 수정
aahreum 75b46a2
🐛 Fix: 타입에러 수정
aahreum 2bb4e23
🐛 Fix: 서버 기본값 안보이도록 수정
aahreum 2902b21
🚚 Rename: 파일명 변경
aahreum fb7d562
🐛 Fix: 옵셔널 값으로 변경
aahreum 9b1a469
🔥 Remove: null 제거
aahreum d124b87
✨ Feat: 카드 수정 값 변환 함수
aahreum b28c59d
✨ Feat: 카드 수정 api 연결
aahreum 0d09d89
🔥 Remove: formatDueDate 제거
aahreum 68eabef
🐛 Fix: 타입 에러 해결
aahreum dec8be0
🐛 Fix: null 리턴
aahreum 19bcfc5
🐛 Fix: 담당자 폴백 컬러 수정
aahreum 2b01193
🐛 Fix: selected 조건 명시
aahreum 2359d6e
🐛 Fix: useEffect 제거
aahreum 157ab3e
🐛 Fix: userId 전달
aahreum 795b9dd
🐛 Fix: 카드 디테일 모달 사이즈 수정
aahreum 49b4baa
🐛 Fix: 이미지 반영 수정
aahreum c55d0b6
🐛 Fix: 카드 디테일 모달 컬럼 타이틀 변경되도록 수정
aahreum 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
226 changes: 226 additions & 0 deletions
226
src/components/dashboard-detail/modal/ChangeCardModal.tsx
This file contains hidden or 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,226 @@ | ||
| import { useMemo, useState } from 'react'; | ||
| import Avatar from '@/components/common/avatar/Avatar'; | ||
| import Button from '@/components/common/Button'; | ||
| import ImageUpload from '@/components/common/ImageUpload'; | ||
| import Input from '@/components/common/input/Input'; | ||
| import Label from '@/components/common/Label'; | ||
| import FormModal from '@/components/common/modal/FormModal'; | ||
| import TextArea from '@/components/common/TextArea'; | ||
| import Combobox, { | ||
| type StatusComboboxValue, | ||
| type UserComboboxValue, | ||
| } from '@/components/dashboard/combobox/Combobox'; | ||
| import CardStatusBadge from '@/components/dashboard-detail/card/CardStatusBadge'; | ||
| import TagInput from '@/components/dashboard-detail/modal/TagInput'; | ||
| import { DUE_DATE, IMAGE_URL } from '@/constants/requestCardData'; | ||
| import { useModal } from '@/hooks/useModal'; | ||
| import type { CardEditFormValue } from '@/types/card'; | ||
| import type { ColumnsResponse } from '@/types/column'; | ||
| import type { MembersResponse } from '@/types/members'; | ||
|
|
||
| interface ChangeCardModalProps { | ||
| memberData: MembersResponse; | ||
| modalName: string; | ||
| initialValue: CardEditFormValue; | ||
| columnListData: ColumnsResponse | null; | ||
| serverErrorMessage: string | null; | ||
| onSubmit: (formValue: CardEditFormValue, imageFile: File | null) => Promise<void>; | ||
| } | ||
|
|
||
| export default function ChangeCardModal({ | ||
| memberData, | ||
| modalName, | ||
| initialValue, | ||
| columnListData, | ||
| serverErrorMessage, | ||
| onSubmit, | ||
| }: ChangeCardModalProps) { | ||
| const { handleModalClose } = useModal(modalName); | ||
| const [formValue, setFormValue] = useState(initialValue); | ||
| const [imageFile, setImageFile] = useState<File | null>(null); | ||
| const [defaultImageUrl, setDefaultImageUrl] = useState<string | null>(initialValue.imageUrl); | ||
| const [errorMessage, setErrorMessage] = useState(''); | ||
|
|
||
| const handleChange = (key: keyof CardEditFormValue) => (value: string | null) => { | ||
| setFormValue((prev) => ({ ...prev, [key]: value })); | ||
| }; | ||
|
|
||
| const handleComboboxChange = ( | ||
| key: 'columnId' | 'assigneeUser', | ||
| value: StatusComboboxValue | UserComboboxValue | null | ||
| ) => { | ||
| setFormValue((prev) => { | ||
| if (key === 'columnId') { | ||
| const newValue = value as StatusComboboxValue | null; | ||
| return { | ||
| ...prev, | ||
| columnId: newValue?.id ?? prev.columnId, | ||
| }; | ||
| } | ||
| if (key === 'assigneeUser') { | ||
| const newValue = value as UserComboboxValue | null; | ||
| return { | ||
| ...prev, | ||
| assigneeUser: newValue, | ||
| }; | ||
| } | ||
| return prev; | ||
| }); | ||
| }; | ||
|
|
||
| const isDisabled = useMemo(() => { | ||
| const original = initialValue; | ||
|
|
||
| const hasChanged = | ||
| original.columnId !== formValue.columnId | ||
| || original.imageUrl !== defaultImageUrl | ||
| || original.title !== formValue.title | ||
| || original.description !== formValue.description | ||
| || original.dueDate !== formValue.dueDate | ||
| || original.assigneeUser?.id !== formValue.assigneeUser?.id | ||
| || JSON.stringify(original.tags) !== JSON.stringify(formValue.tags) | ||
| || imageFile !== null; | ||
|
|
||
| return !hasChanged || formValue.title.trim() === '' || formValue.description.trim() === ''; | ||
| }, [formValue, initialValue, imageFile, defaultImageUrl]); | ||
|
|
||
| const handleSubmit = async () => { | ||
| try { | ||
| await onSubmit(formValue, imageFile); | ||
| } catch (err) { | ||
| const errorMsg = err instanceof Error ? err.message : '카드 수정 중 오류가 발생했습니다.'; | ||
| setErrorMessage(errorMsg); | ||
| } | ||
| }; | ||
|
|
||
| if (!columnListData) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <FormModal modalName={modalName}> | ||
| <FormModal.Title title='할 일 수정' /> | ||
| <FormModal.Form onSubmit={handleSubmit}> | ||
| <FormModal.Body> | ||
| <div className='scrollbar-hidden scrollbar-thin-gray -mr-[10px] flex h-[calc(100dvh-450px)] flex-col gap-[32px] overflow-y-auto sm:mr-0 sm:max-h-[calc(100dvh-380px)]'> | ||
| <div className='flex w-full flex-col gap-[32px] sm:flex-row'> | ||
| <div className='input-group-style w-full'> | ||
| <Label htmlFor='columnId' className='label-style'> | ||
| 상태 | ||
| </Label> | ||
| <Combobox | ||
| id='columnId' | ||
| value={ | ||
| columnListData.data | ||
| .map((col) => ({ id: col.id, title: col.title })) | ||
| .find((col) => col.id === formValue.columnId) ?? null | ||
| } | ||
| setValue={(value) => handleComboboxChange('columnId', value)}> | ||
| <Combobox.Trigger name='컬럼' placeholder='컬럼 선택' /> | ||
| <Combobox.List> | ||
| {columnListData.data.map((col) => ( | ||
| <Combobox.Item key={col.id} value={{ id: col.id, title: col.title }}> | ||
| <CardStatusBadge title={col.title} /> | ||
| </Combobox.Item> | ||
| ))} | ||
| </Combobox.List> | ||
| </Combobox> | ||
|
aahreum marked this conversation as resolved.
|
||
| </div> | ||
|
|
||
| <div className='input-group-style w-full'> | ||
| <Label htmlFor='assigneeUserId' className='label-style'> | ||
| 담당자 | ||
| </Label> | ||
| <Combobox | ||
| id='assigneeUserId' | ||
| value={formValue.assigneeUser} | ||
| setValue={(value) => handleComboboxChange('assigneeUser', value)}> | ||
| <Combobox.Trigger name='담당자' placeholder='이름을 입력해 주세요' /> | ||
| <Combobox.List> | ||
| {memberData.members.map((m) => ( | ||
| <Combobox.Item key={m.id} value={m}> | ||
| <Avatar size='s' user={m}> | ||
| <Avatar.Img /> | ||
| <Avatar.Fallback /> | ||
| </Avatar> | ||
| <span className='font-medium'>{m.nickname}</span> | ||
| </Combobox.Item> | ||
| ))} | ||
| </Combobox.List> | ||
| </Combobox> | ||
|
aahreum marked this conversation as resolved.
|
||
| </div> | ||
| </div> | ||
|
|
||
| <Input value={formValue.title} onChange={handleChange('title')}> | ||
| <Input.Label required className='label-style'> | ||
| 제목 | ||
| </Input.Label> | ||
| <Input.Group> | ||
| <Input.Field name='title' type='text' placeholder='제목을 입력해 주세요' /> | ||
| </Input.Group> | ||
| </Input> | ||
|
|
||
| <div className='input-group-style'> | ||
| <Label htmlFor='desc' required className='label-style'> | ||
| 설명 | ||
| </Label> | ||
| <TextArea | ||
| id='desc' | ||
| placeholder='설명을 입력해 주세요' | ||
| value={formValue.description} | ||
| onChange={handleChange('description')} | ||
| /> | ||
| </div> | ||
|
|
||
| <Input | ||
| value={formValue.dueDate === DUE_DATE ? '' : formValue.dueDate} | ||
| onChange={handleChange('dueDate')}> | ||
| <Input.Label className='label-style'>마감일</Input.Label> | ||
| <Input.Group className='h-[48px]'> | ||
| <Input.FieldDate placeholder='마감일을 선택해주세요' /> | ||
| </Input.Group> | ||
| </Input> | ||
|
|
||
| <div className='input-group-style'> | ||
| <Label htmlFor='tags' className='label-style'> | ||
| 태그 | ||
| </Label> | ||
| <TagInput | ||
| tags={formValue.tags} | ||
| setTags={(next) => setFormValue((prev) => ({ ...prev, tags: next }))} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className='input-group-style'> | ||
| <Label htmlFor='imageUrl' className='label-style'> | ||
| 이미지 | ||
| </Label> | ||
| <ImageUpload | ||
| edit | ||
| defaultImageUrl={defaultImageUrl === IMAGE_URL ? '' : defaultImageUrl} | ||
| setDefaultImageUrl={setDefaultImageUrl} | ||
| file={imageFile} | ||
| onFileChange={setImageFile} | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| {(serverErrorMessage || errorMessage) && ( | ||
| <span className='mt-[12px] inline-block font-md-medium text-error'> | ||
| {serverErrorMessage || errorMessage} | ||
| </span> | ||
| )} | ||
| </FormModal.Body> | ||
|
|
||
| <FormModal.Footer className='pt-[32px]'> | ||
| <Button theme='outlined' onClick={handleModalClose}> | ||
| 취소 | ||
| </Button> | ||
| <Button disabled={isDisabled} theme='primary' type='submit'> | ||
| 수정 | ||
| </Button> | ||
| </FormModal.Footer> | ||
| </FormModal.Form> | ||
| </FormModal> | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.