-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Refactor] 모달 띄우는 로직, 데이터 상태 로직 리팩토링.. #197
base: develop
Are you sure you want to change the base?
Changes from 17 commits
23e3d6d
2f33596
1034e74
f566a02
13021a7
52a7280
73ca6e8
77ee9fc
5974228
50f68e9
da808c4
2535167
3a1feff
a741a89
44f9b0c
503f75f
bedbb83
f68a155
f825ceb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Modal from '@/common/component/Modal/Modal'; | ||
|
||
import { BlockProvider } from '@/shared/hook/common/useBlockContext'; | ||
import { WorkSpaceProvider } from '@/shared/hook/common/useWorkSpaceContext'; | ||
import { useCloseModal, useModalContent, useModalIsOpen } from '@/shared/store/modal'; | ||
|
||
const ModalContainer = () => { | ||
const isOpen = useModalIsOpen(); | ||
const content = useModalContent(); | ||
const closeModal = useCloseModal(); | ||
|
||
if (!isOpen || !content) return null; | ||
|
||
return ( | ||
<Modal isOpen={isOpen} onClose={closeModal}> | ||
<WorkSpaceProvider> | ||
<BlockProvider>{content}</BlockProvider> | ||
</WorkSpaceProvider> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ModalContainer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import BlockItem from '@/page/archiving/createTimeBlock/component/Upload/File/Li | |
import { flexStyle, scrollStyle } from '@/page/archiving/createTimeBlock/component/Upload/UploadModal.style'; | ||
import { useDeleteFileMutation } from '@/page/archiving/createTimeBlock/hook/api/useDeleteFileMutation'; | ||
import { usePostTimeBlockMutation } from '@/page/archiving/createTimeBlock/hook/api/usePostTimeBlockMutation'; | ||
import { BlockData } from '@/page/archiving/createTimeBlock/type/blockType'; | ||
import { formatDatePost } from '@/page/archiving/createTimeBlock/util/date'; | ||
import { getRandomColor } from '@/page/archiving/index/util/color'; | ||
|
||
|
@@ -13,23 +12,24 @@ import Button from '@/common/component/Button/Button'; | |
import Flex from '@/common/component/Flex/Flex'; | ||
|
||
import { Files } from '@/shared/api/time-blocks/team/time-block/type'; | ||
import WorkSapceInfo from '@/shared/component/createWorkSpace/info/WorkSpaceInfo'; | ||
import WorkSapceInfo from '@/shared/component/createWorkSpaceModal/info/WorkSpaceInfo'; | ||
import { useBlockContext } from '@/shared/hook/common/useBlockContext'; | ||
import { useModalStore } from '@/shared/store/modal'; | ||
import { useTeamStore } from '@/shared/store/team'; | ||
import { useToastStore } from '@/shared/store/toast'; | ||
|
||
interface UploadModalProps { | ||
onClose: () => void; | ||
teamId: number; | ||
type: string; | ||
blockData: BlockData; | ||
} | ||
const UploadModal = () => { | ||
const { teamId } = useTeamStore(); | ||
|
||
const { formData, reset } = useBlockContext(); | ||
const { closeModal } = useModalStore(); | ||
|
||
const UploadModal = ({ onClose, teamId, type, blockData }: UploadModalProps) => { | ||
const [files, setFiles] = useState<File[]>([]); | ||
const [fileUrls, setFileUrls] = useState<Files>({}); | ||
const [uploadStatus, setUploadStatus] = useState<{ [key: string]: boolean }>({}); | ||
const [isAllUploaded, setIsAllUploaded] = useState(true); | ||
|
||
const { mutate: timeBlockMutate } = usePostTimeBlockMutation(teamId, type); | ||
const { mutate: timeBlockMutate } = usePostTimeBlockMutation(+teamId, 'executive'); | ||
const { mutate: fileDeleteMutate } = useDeleteFileMutation(); | ||
const { createToast } = useToastStore(); | ||
|
||
|
@@ -77,19 +77,20 @@ const UploadModal = ({ onClose, teamId, type, blockData }: UploadModalProps) => | |
}; | ||
|
||
const data = { | ||
name: blockData.blockName, | ||
name: formData.blockName, | ||
color: getRandomColor(), | ||
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. 요기 서버에서 컬러색상코드를 전달해주니까 그 값을 넘겨주는 방향으로 수정 부탁드립니다 ㅎㅎ 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. 수정 완료 했습니다! |
||
startDate: formatDatePost(blockData.dates.startDate), | ||
endDate: formatDatePost(blockData.dates.endDate), | ||
blockType: blockData.blockType, | ||
startDate: formatDatePost(formData.startDate), | ||
endDate: formatDatePost(formData.endDate), | ||
blockType: formData.blockType, | ||
files: fileUrls, | ||
}; | ||
|
||
const handleSave = () => { | ||
timeBlockMutate(data, { | ||
onSuccess: () => { | ||
onClose(); | ||
createToast('활동 블록이 생성되었습니다', 'success'); | ||
closeModal(); | ||
reset(); | ||
}, | ||
}); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import BlockModal from '@/page/archiving/createTimeBlock/component/Block/BlockModal'; | ||
import UploadModal from '@/page/archiving/createTimeBlock/component/Upload/UploadModal'; | ||
import { buttonStyle, contentStyle, daySectionStyle, timelineStyle } from '@/page/archiving/index/ArchivingPage.style'; | ||
import DaySection from '@/page/archiving/index/component/DaySection/DaySection'; | ||
import DocumentBar from '@/page/archiving/index/component/DocumentBar/DocumentBar'; | ||
|
@@ -16,10 +14,11 @@ import { useState } from 'react'; | |
import AddIc from '@/common/asset/svg/add_btn.svg?react'; | ||
import Button from '@/common/component/Button/Button'; | ||
import Flex from '@/common/component/Flex/Flex'; | ||
import Modal from '@/common/component/Modal/Modal'; | ||
import { useModal, useOutsideClick } from '@/common/hook'; | ||
import { useOutsideClick } from '@/common/hook'; | ||
import { theme } from '@/common/style/theme/theme'; | ||
|
||
import { BlockFlow } from '@/shared/component/ModalFlow/BlockFlow'; | ||
import { useOpenModal } from '@/shared/store/modal'; | ||
import { useTeamStore } from '@/shared/store/team'; | ||
|
||
const ArchivingPage = () => { | ||
|
@@ -66,15 +65,10 @@ const ArchivingPage = () => { | |
const blockFloors = alignBlocks(timeBlocks, endDay, selectedMonth, currentYear); | ||
|
||
// 블록 생성 모달 관련 코드 | ||
const { isOpen, openModal, closeModal, setCurrentContent, currentContent } = useModal(); | ||
|
||
const handleNext = (blockData: { | ||
blockName: string; | ||
blockType: string; | ||
dates: { startDate: string; endDate: string }; | ||
}) => { | ||
const type = 'executive'; | ||
setCurrentContent(<UploadModal onClose={closeModal} teamId={+teamId} type={type} blockData={blockData} />); | ||
const openModal = useOpenModal(); | ||
|
||
const handleOpenBlockModal = () => { | ||
openModal(<BlockFlow />); | ||
}; | ||
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. 여기서 든 생각은, 제가 처음에 얘기했다시피 전역 상태로 만약 그렇게 된다면, 호출하는 컴포넌트에서는 모달의 content 타입에 맞는 openModal('create-block'); 과 같이 컨텐츠 타입에 관한 특정 인자만 호출해준다면, 전역 상태의 |
||
|
||
return ( | ||
|
@@ -148,17 +142,13 @@ const ArchivingPage = () => { | |
</div> | ||
</Flex> | ||
<Flex css={{ zIndex: theme.zIndex.overlayTop, marginLeft: 'auto' }}> | ||
<Button | ||
variant="action" | ||
css={buttonStyle(selectedBlock)} | ||
onClick={() => openModal(<BlockModal onNext={handleNext} />)}> | ||
<Button variant="action" css={buttonStyle(selectedBlock)} onClick={handleOpenBlockModal}> | ||
<AddIc width={24} height={24} /> | ||
블록 생성 | ||
</Button> | ||
</Flex> | ||
</section> | ||
|
||
<Modal isOpen={isOpen} children={currentContent} onClose={closeModal} /> | ||
<DocumentBar | ||
selectedBlock={selectedBlock} | ||
ref={sideBarRef} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,10 @@ import { ReactNode } from 'react'; | |
import Download from '@/common/asset/svg/download.svg?react'; | ||
import TrashBox from '@/common/asset/svg/trash_box.svg?react'; | ||
import Flex from '@/common/component/Flex/Flex'; | ||
import Modal from '@/common/component/Modal/Modal'; | ||
import Text from '@/common/component/Text/Text'; | ||
import { useModal } from '@/common/hook'; | ||
|
||
import DeleteModal from '@/shared/component/DeleteModal/DeleteModal'; | ||
import { useOpenModal } from '@/shared/store/modal'; | ||
import { useTeamStore } from '@/shared/store/team'; | ||
|
||
interface DocumentItemProps { | ||
|
@@ -28,12 +27,12 @@ interface DocumentItemProps { | |
} | ||
|
||
const DocumentItem = ({ documentId, children, selectedId, blockName, fileUrl, color }: DocumentItemProps) => { | ||
const { isOpen, openModal, closeModal, currentContent } = useModal(); | ||
|
||
const fileName = children?.toString(); | ||
|
||
const { teamId } = useTeamStore(); | ||
|
||
const openModal = useOpenModal(); | ||
|
||
//문서 클릭시 띄워주는 함수 | ||
const onClickDocumentItem = () => { | ||
window.open(fileUrl); | ||
|
@@ -46,30 +45,29 @@ const DocumentItem = ({ documentId, children, selectedId, blockName, fileUrl, co | |
|
||
const handleTrashClick = (e: React.MouseEvent<SVGSVGElement, MouseEvent>) => { | ||
e.stopPropagation(); | ||
openModal(<DeleteModal title="docs" detail="docs" onClose={closeModal} teamId={+teamId} id={documentId} />); | ||
// 모달 띄우기 | ||
const modalContent = <DeleteModal title="docs" detail="docs" teamId={+teamId} id={documentId} />; | ||
openModal(modalContent); | ||
}; | ||
|
||
return ( | ||
<> | ||
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */} | ||
<li css={containerStyle(selectedId)} onClick={onClickDocumentItem}> | ||
{color && ( | ||
<div> | ||
<Text tag="body8" css={blockNameTextStyle(color)}> | ||
{blockName} | ||
</Text> | ||
</div> | ||
)} | ||
<Flex> | ||
<Text tag="body6" css={fileNameStyle}> | ||
{fileName} | ||
/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ | ||
<li css={containerStyle(selectedId)} onClick={onClickDocumentItem}> | ||
{color && ( | ||
<div> | ||
<Text tag="body8" css={blockNameTextStyle(color)}> | ||
{blockName} | ||
</Text> | ||
<Download width={20} height={20} css={{ cursor: 'pointer' }} onClick={handleDownloadClick} /> | ||
<TrashBox width={20} height={20} onClick={(e) => handleTrashClick(e)} css={{ cursor: 'pointer' }} /> | ||
</Flex> | ||
</li> | ||
<Modal isOpen={isOpen} children={currentContent} onClose={closeModal} /> | ||
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. 오 요 modal 컴포넌트가 굉장히 애매했는데 이제 없앨수 있군요! 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. 맞아요! 빈태그도 지워줬습니다!! |
||
</> | ||
</div> | ||
)} | ||
<Flex> | ||
<Text tag="body6" css={fileNameStyle}> | ||
{fileName} | ||
</Text> | ||
<Download width={20} height={20} css={{ cursor: 'pointer' }} onClick={handleDownloadClick} /> | ||
<TrashBox width={20} height={20} onClick={(e) => handleTrashClick(e)} css={{ cursor: 'pointer' }} /> | ||
</Flex> | ||
</li> | ||
); | ||
}; | ||
export default DocumentItem; |
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.
추가적으로 폴더명이
동사 + 목적어
형태의 문장이 되어버리니까 좀 어색한 느낌이 드는 것 같아요.createTimeBlock
이나createWorkSpaceModal
둘다timeBlockModal
형태로 바꾸는 것은 어떤가요 ?