-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature/BAR-236] 저장하는 페이지 폴더 수정/삭제 기능 구현 (#66)
* feat(domain/저장하는): 폴더 삭제 기능 구현 * feat(domain/저장하는): 폴더 수정 기능 구현 * refactor(EditFolder): 로그 제거 * refactor(WriteInput): 공통 Button 컴포넌트로 변경 * feat(Modal): section 태그로 변경 * feat(NotFoundArchiveCard): 저장된 템플릿이 없을 경우, 메인으로 이동
- Loading branch information
Showing
21 changed files
with
430 additions
and
57 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const MEMO_FOLDERS = 'memo-folders'; | ||
|
||
export const MEMO_FOLDERS_KEY = { | ||
all: [MEMO_FOLDERS] as const, | ||
list: () => [...MEMO_FOLDERS_KEY.all, 'list'] as const, | ||
item: (args: unknown[]) => [...MEMO_FOLDERS_KEY.list(), ...args] as const, | ||
}; |
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,25 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { useToastStore } from '@stores/toast'; | ||
|
||
import { deleteMemoFolders } from '..'; | ||
import { MEMO_FOLDERS_KEY } from '../constants/queryKey'; | ||
|
||
const useDeleteMemoFolder = () => { | ||
const { showToast } = useToastStore(); | ||
|
||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: deleteMemoFolders, | ||
onSuccess: () => { | ||
showToast({ message: '선택한 폴더가 삭제되었어요' }); | ||
|
||
queryClient.invalidateQueries({ | ||
queryKey: MEMO_FOLDERS_KEY.all, | ||
}); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useDeleteMemoFolder; |
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,25 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { useToastStore } from '@stores/toast'; | ||
|
||
import { patchMemoFolders } from '..'; | ||
import { MEMO_FOLDERS_KEY } from '../constants/queryKey'; | ||
|
||
const useUpdateMemoFolder = () => { | ||
const { showToast } = useToastStore(); | ||
|
||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: patchMemoFolders, | ||
onSuccess: () => { | ||
showToast({ message: '폴더 이름이 수정되었어요' }); | ||
|
||
queryClient.invalidateQueries({ | ||
queryKey: MEMO_FOLDERS_KEY.all, | ||
}); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useUpdateMemoFolder; |
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
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,34 @@ | ||
import { type HTMLAttributes, type PropsWithChildren } from 'react'; | ||
|
||
import * as styles from '../style.css'; | ||
|
||
interface ModalProps extends HTMLAttributes<HTMLDivElement> {} | ||
|
||
export const ModalHeader = ({ | ||
children, | ||
...props | ||
}: PropsWithChildren<ModalProps>) => { | ||
return ( | ||
<header {...props} className={styles.modalHeader}> | ||
{children} | ||
</header> | ||
); | ||
}; | ||
|
||
export const ModalBody = ({ | ||
children, | ||
...props | ||
}: PropsWithChildren<ModalProps>) => { | ||
return ( | ||
<main {...props} className={styles.modalBody}> | ||
{children} | ||
</main> | ||
); | ||
}; | ||
|
||
export const ModalFooter = ({ | ||
children, | ||
...props | ||
}: PropsWithChildren<ModalProps>) => { | ||
return <footer {...props}>{children}</footer>; | ||
}; |
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,107 @@ | ||
import { type ChangeEvent, useState } from 'react'; | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { assignInlineVars } from '@vanilla-extract/dynamic'; | ||
import { AxiosError } from 'axios'; | ||
import clsx from 'clsx'; | ||
|
||
import useUpdateMemoFolder from '@api/memoFolder/mutations/useUpdateMemoFolder'; | ||
import Button from '@components/Button'; | ||
import Icon from '@components/Icon'; | ||
import { useModalStore } from '@stores/modal'; | ||
import { COLORS } from '@styles/tokens'; | ||
|
||
import ModalContainer from '../components/ModalContainer'; | ||
import * as styles from '../style.css'; | ||
|
||
const EditFolder = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
const { closeModal, memoFolderId, folderName } = useModalStore(); | ||
const [value, setValue] = useState(folderName); | ||
const [errorMessage, setErrorMessage] = useState(''); | ||
|
||
const { mutateAsync } = useUpdateMemoFolder(); | ||
|
||
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setErrorMessage(''); | ||
setValue(e.target.value); | ||
}; | ||
|
||
const handleFolderNameEdit = async () => { | ||
if (value.length > 10) return setErrorMessage('10자 내로 입력해주세요!'); | ||
|
||
await mutateAsync( | ||
{ memoFolderId, folderName: value }, | ||
{ | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries({ | ||
queryKey: ['memo-folders'], | ||
}); | ||
closeModal(); | ||
}, | ||
onError: (e) => { | ||
if (!(e instanceof AxiosError) || !e.response) throw e; | ||
if ( | ||
(e.response.data as { errorCode: string; message: string }) | ||
.errorCode === 'MF01' | ||
) | ||
return setErrorMessage('이미 사용 중인 폴더 이름이에요!'); | ||
throw e; | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
return ( | ||
<ModalContainer> | ||
<strong className={styles.makeFolderTitle}>폴더 수정하기</strong> | ||
<label htmlFor="makeFolder" className={styles.makeFolderDescription}> | ||
폴더 이름 | ||
</label> | ||
<div className={styles.makeFolderInputWrapper}> | ||
<input | ||
id="makeFolder" | ||
className={clsx( | ||
styles.makeFolderInput, | ||
errorMessage && styles.errorInput, | ||
)} | ||
value={value} | ||
onChange={handleInputChange} | ||
/> | ||
</div> | ||
{errorMessage && ( | ||
<span className={styles.errorMessage}> | ||
<div className={styles.errorIcon}> | ||
<Icon width={20} height={20} icon="error" /> | ||
</div> | ||
{errorMessage} | ||
</span> | ||
)} | ||
<div className={styles.makeFolderButtonWrapper}> | ||
<Button | ||
className={styles.button} | ||
style={assignInlineVars({ | ||
[styles.buttonColor]: COLORS['Grey/600'], | ||
[styles.buttonBackgroundColor]: COLORS['Grey/150'], | ||
})} | ||
onClick={closeModal} | ||
> | ||
취소 | ||
</Button> | ||
<Button | ||
className={clsx(styles.button, !value && styles.buttonDisabled)} | ||
disabled={!value} | ||
style={assignInlineVars({ | ||
[styles.buttonColor]: COLORS['Grey/White'], | ||
[styles.buttonBackgroundColor]: COLORS['Blue/Default'], | ||
})} | ||
onClick={handleFolderNameEdit} | ||
> | ||
저장하기 | ||
</Button> | ||
</div> | ||
</ModalContainer> | ||
); | ||
}; | ||
|
||
export default EditFolder; |
Oops, something went wrong.