Skip to content
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

Merged
merged 25 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
23e3d6d
#187 feat: 모달 상태 store
cindy-chaewon Jul 31, 2024
2f33596
#187 fix: 모달 상태 store toggle 추가
cindy-chaewon Jul 31, 2024
1034e74
#187 feat: 모달 zustand로 띄우기
cindy-chaewon Aug 1, 2024
f566a02
#187 fix: 모달 닫힐 때 workspace 클릭 상태 해제
cindy-chaewon Aug 1, 2024
13021a7
#187 fix: 타임블록 생성도 적용 & 오류 해결
cindy-chaewon Aug 1, 2024
52a7280
#187 fix: 사진 미리보기 안되던 오류 해결
cindy-chaewon Aug 1, 2024
73ca6e8
#187 feat: delete 모달에도 적용
cindy-chaewon Aug 1, 2024
77ee9fc
#187 refactor: 필요없는 코드 삭제
cindy-chaewon Aug 1, 2024
5974228
#187 fix: 절대경로 수정
cindy-chaewon Aug 1, 2024
50f68e9
#187 refactor: 워크스페이스, 블록생성
cindy-chaewon Aug 1, 2024
da808c4
#187 fix: 오류 해결
cindy-chaewon Aug 1, 2024
2535167
#187 fix: 불필요한 코드 제거
cindy-chaewon Aug 1, 2024
3a1feff
#187 refactor: 코드리뷰 반영
cindy-chaewon Aug 6, 2024
a741a89
#187 fix: 스토리북 코드 수정
cindy-chaewon Aug 6, 2024
44f9b0c
#187 refactor: 코드리뷰 반영
cindy-chaewon Aug 13, 2024
503f75f
#187 fix: 스토리북 모달 수정
cindy-chaewon Aug 13, 2024
bedbb83
#187 fix: useCallback 제거
cindy-chaewon Aug 13, 2024
f68a155
#187 refactor: 삭제 모달 zustand 로
cindy-chaewon Sep 13, 2024
f825ceb
#187 refactor: 리팩토링
cindy-chaewon Sep 20, 2024
764eacc
#187 refactor: 코드리뷰 반영
cindy-chaewon Sep 29, 2024
404f9a5
#187 fix: 스토리북 파일 에러 해결
cindy-chaewon Sep 30, 2024
aa418e7
#187 fix: svg 네이밍 정리
cindy-chaewon Sep 30, 2024
6ae06bc
#187 fix: 오류 해결
cindy-chaewon Sep 30, 2024
8b41e31
#187 fix : 머지 충돌 해결
cindy-chaewon Sep 30, 2024
fb23c44
#187 fix: 코드리뷰 반영
cindy-chaewon Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Login from '@/shared/component/Login/Login';
import { HTTP_STATUS_CODE } from '@/shared/constant/api';
import { PATH } from '@/shared/constant/path';
import ErrorPage from '@/shared/page/errorPage/ErrorPage';
import { BlockModalProvider, WorkSpaceProvider } from '@/shared/store/modalContext';

const App = () => {
useEffect(() => {
Expand Down Expand Up @@ -43,18 +42,14 @@ const App = () => {

return (
<ErrorBoundary fallback={ErrorPage} onReset={handleResetError}>
<WorkSpaceProvider>
<BlockModalProvider>
<Login>
<div css={containerStyle}>
<LeftSidebar />
<main css={layoutStyle}>
<Outlet />
</main>
</div>
</Login>
</BlockModalProvider>
</WorkSpaceProvider>
<Login>
<div css={containerStyle}>
<LeftSidebar />
<main css={layoutStyle}>
<Outlet />
</main>
</div>
</Login>
</ErrorBoundary>
);
};
Expand Down
40 changes: 40 additions & 0 deletions src/common/component/Modal/ModalManager.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Modal from '@/common/component/Modal/Modal';

import { useModalStore } from '@/shared/store/modal';
import { BlockFlow, BlockProvider } from '@/shared/store/useBlockContext';
import { WorkSpaceFlow, WorkSpaceProvider } from '@/shared/store/useWorkSpaceContext';

const ModalManager = () => {
const { isOpen, content, closeModal, id } = useModalStore();

if (!isOpen || !content) return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 조건문 안에 or 연산 넣은거 깔끔하고 이해도 잘되네용 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니당!


let ModalContent;

switch (id) {
case 'workspace':
ModalContent = (
<WorkSpaceProvider>
<WorkSpaceFlow />
</WorkSpaceProvider>
);
break;
case 'block':
ModalContent = (
<BlockProvider>
<BlockFlow />
</BlockProvider>
);
break;
default:
return null;
}

return (
<Modal isOpen={isOpen} onClose={closeModal}>
{content}
</Modal>
);
};

export default ModalManager;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가적으로 폴더명이 동사 + 목적어 형태의 문장이 되어버리니까 좀 어색한 느낌이 드는 것 같아요.

createTimeBlock이나 createWorkSpaceModal 둘다 timeBlockModal 형태로 바꾸는 것은 어떤가요 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다! 변경완료 했습니다!

Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import Input from '@/common/component/Input/Input';
import Text from '@/common/component/Text/Text';

import WorkSapceInfo from '@/shared/component/createWorkSpace/info/WorkSpaceInfo';
import { useNextStep } from '@/shared/store/modal';
import { useBlockModalContext } from '@/shared/store/modalContext';
import { useBlockContext } from '@/shared/store/useBlockContext';

const BlockModal = () => {
const [selectedIcon, setSelectedIcon] = useState<number>(-1);
const [isDateRangeValid, setIsDateRangeValid] = useState(false);

const { blockName, setBlockName, setBlockType, startDate, setStartDate, endDate, setEndDate } =
useBlockModalContext();
const nextStep = useNextStep();
const { blockName, setBlockName, setBlockType, startDate, setStartDate, endDate, setEndDate, nextStep } =
useBlockContext();

const handleBlockNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.value.length <= 25) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import SupportingText from '@/common/component/SupportingText/SupportingText';
interface BlockDateProps {
startDate: string;
endDate: string;
onSetStartDate: (date: string | ((prev: string) => string)) => void;
onSetEndDate: (date: string | ((prev: string) => string)) => void;
onSetStartDate: (date: string) => void;
onSetEndDate: (date: string) => void;
onSetIsDateRangeValid: (isValid: boolean) => void;
}

const BlockDate = ({ startDate, endDate, onSetStartDate, onSetEndDate, onSetIsDateRangeValid }: BlockDateProps) => {
const { dates, validation, handleChange } = useDateRange(
startDate,
endDate,
onSetStartDate,
onSetEndDate,
(date: string) => onSetStartDate(date),
(date: string) => onSetEndDate(date),
onSetIsDateRangeValid
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ 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 { useBlockModalContext } from '@/shared/store/modalContext';
import { useModalStore } from '@/shared/store/modal';
import { useTeamStore } from '@/shared/store/team';
import { useToastStore } from '@/shared/store/toast';
import { useBlockContext } from '@/shared/store/useBlockContext';

const UploadModal = () => {
const { teamId } = useTeamStore();

const { blockName, blockType, startDate, endDate, closeModal, resetBlockData } = useBlockModalContext();
const { blockName, blockType, startDate, endDate, reset } = useBlockContext();
const { closeModal } = useModalStore();

const [files, setFiles] = useState<File[]>([]);
const [fileUrls, setFileUrls] = useState<Files>({});
const [uploadStatus, setUploadStatus] = useState<{ [key: string]: boolean }>({});
Expand Down Expand Up @@ -87,7 +90,7 @@ const UploadModal = () => {
onSuccess: () => {
createToast('활동 블록이 생성되었습니다', 'success');
closeModal();
resetBlockData();
reset();
},
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { useState } from 'react';
const useDateRange = (
initialStartDate = '',
initialEndDate = '',
onSetStartDate: (date: string | ((prev: string) => string)) => void,
onSetEndDate: (date: string | ((prev: string) => string)) => void,
onSetStartDate: (date: string) => void,
onSetEndDate: (date: string) => void,
onSetIsDateRangeValid: (isValid: boolean) => void
) => {
const [dates, setDates] = useState({ startDate: initialStartDate, endDate: initialEndDate });
Expand Down
14 changes: 8 additions & 6 deletions src/page/archiving/index/ArchivingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +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 { useOutsideClick } from '@/common/hook';
import { useModal, useOutsideClick } from '@/common/hook';
import { theme } from '@/common/style/theme/theme';

import { useToggleModal } from '@/shared/store/modal';
import { useModalStore } from '@/shared/store/modal';
import { useTeamStore } from '@/shared/store/team';
import { ModalManager } from '@/shared/util/modal';

const ArchivingPage = () => {
const [selectedId, setSelectedId] = useState('total');
Expand Down Expand Up @@ -65,7 +64,11 @@ const ArchivingPage = () => {
const blockFloors = alignBlocks(timeBlocks, endDay, selectedMonth, currentYear);

// 블록 생성 모달 관련 코드
const toggleModal = useToggleModal();
const openModal = useModalStore((state) => state.openModal);

const handleOpenBlockModal = () => {
openModal('block', null);
};

return (
<Flex
Expand Down Expand Up @@ -138,7 +141,7 @@ const ArchivingPage = () => {
</div>
</Flex>
<Flex css={{ zIndex: theme.zIndex.overlayTop, marginLeft: 'auto' }}>
<Button variant="action" css={buttonStyle(selectedBlock)} onClick={() => toggleModal('block')}>
<Button variant="action" css={buttonStyle(selectedBlock)} onClick={handleOpenBlockModal}>
<AddIc width={24} height={24} />
블록 생성
</Button>
Expand All @@ -152,7 +155,6 @@ const ArchivingPage = () => {
onSelectId={handleSelectedId}
onClickClose={handleClose}
/>
<ModalManager />
</Flex>
);
};
Expand Down
50 changes: 24 additions & 26 deletions src/shared/component/DeleteModal/DeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Text from '@/common/component/Text/Text';

import { cancelStyle, deleteStyle } from '@/shared/component/DeleteModal/DeleteModal.style';
import { DELETE_DETAIL, DELETE_TITLE } from '@/shared/constant';
import { useDeleteModalStore } from '@/shared/store/modal';
import { useModalStore } from '@/shared/store/modal';

interface DeleteModalProps {
title: 'block' | 'docs';
Expand All @@ -22,7 +22,7 @@ const DeleteModal = ({ title, detail, teamId, id }: DeleteModalProps) => {
const { mutateAsync: blockMutate } = useDeleteBlockMutation();
const { mutateAsync: documentMutate } = useDeleteDocumentMutation();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반환되는 Promise를 통해 추가적인 작업을 하지 않을 것이라면 mutate를 사용하는 것이 더욱 좋을 것 같아요 !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵!! mutate로 수정 완료 했습니다!


const { isOpen, closeModal } = useDeleteModalStore();
const { closeModal } = useModalStore();

const handleDeleteBlock = (teamId: number, id: number) => {
blockMutate(
Expand All @@ -49,32 +49,30 @@ const DeleteModal = ({ title, detail, teamId, id }: DeleteModalProps) => {
const handleDelete = title === 'block' ? handleDeleteBlock : handleDeleteDocs;

return (
<Modal isOpen={isOpen} onClose={closeModal}>
<Flex
styles={{
direction: 'column',
align: 'center',
justify: 'center',
paddingRight: '9.35rem',
paddingLeft: '9.35rem',
}}>
<Heading tag="H5" css={{ fontWeight: 600 }}>
{DELETE_TITLE[title.toUpperCase() as keyof typeof DELETE_TITLE]}
</Heading>
<Text tag="body4" css={{ marginTop: '1rem', fontWeight: 400 }}>
{DELETE_DETAIL[detail.toUpperCase() as keyof typeof DELETE_DETAIL]}
</Text>
<Flex
styles={{
direction: 'column',
align: 'center',
justify: 'center',
paddingRight: '9.35rem',
paddingLeft: '9.35rem',
}}>
<Heading tag="H5" css={{ fontWeight: 600 }}>
{DELETE_TITLE[title.toUpperCase() as keyof typeof DELETE_TITLE]}
</Heading>
<Text tag="body4" css={{ marginTop: '1rem', fontWeight: 400 }}>
{DELETE_DETAIL[detail.toUpperCase() as keyof typeof DELETE_DETAIL]}
</Text>

<Flex styles={{ direction: 'row', align: 'center', justify: 'center', gap: '0.8rem', marginTop: '2.4rem' }}>
<Button variant="secondary" size="large" onClick={closeModal} css={cancelStyle}>
취소
</Button>
<Button variant="primary" size="large" onClick={() => handleDelete(teamId, id)} css={deleteStyle}>
삭제
</Button>
</Flex>
<Flex styles={{ direction: 'row', align: 'center', justify: 'center', gap: '0.8rem', marginTop: '2.4rem' }}>
<Button variant="secondary" size="large" onClick={() => closeModal()} css={cancelStyle}>
취소
</Button>
<Button variant="primary" size="large" onClick={() => handleDelete(teamId, id)} css={deleteStyle}>
삭제
</Button>
</Flex>
</Modal>
</Flex>
);
};

Expand Down
9 changes: 3 additions & 6 deletions src/shared/component/LeftSidebar/LeftSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import LeftSidebarItem from '@/shared/component/LeftSidebar/LeftSidebarItem/Left
import SettingMenu from '@/shared/component/LeftSidebar/LeftSidebarItem/SettingMenu/SettingMenu';
import { PATH } from '@/shared/constant/path';
import { useClubInfoQuery } from '@/shared/hook/api/useClubInfoQuery';
import { useToggleModal } from '@/shared/store/modal';
import { useModalStore } from '@/shared/store/modal';
import { useTeamStore } from '@/shared/store/team';
import { Team } from '@/shared/type/team';
import { ModalManager } from '@/shared/util/modal';

const LeftSidebar = () => {
const openModal = useModalStore((state) => state.openModal);
const { isOpen: isNavOpen, close, open } = useOverlay();

const sidebarRef = useOutsideClick(close);
Expand Down Expand Up @@ -72,11 +72,9 @@ const LeftSidebar = () => {
close();
};

const toggleModal = useToggleModal();

const handleWorkspaceClick = () => {
setIsWorkspaceClicked(true);
toggleModal('workspace');
openModal('workspace', null);
};

const handleModalClose = () => {
Expand Down Expand Up @@ -133,7 +131,6 @@ const LeftSidebar = () => {
</LeftSidebarItem>
<SettingMenu isModalOpen={isSettingOpen} />
</div>
<ModalManager onClose={handleModalClose} />
</aside>
);
};
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category, image, name 등등.. 모두 워크스페이스를 생성하는 모달 폼 과정에서의 Step 들이라고 생각해요!

그렇다면 하나의 폴더안에서 관리하는 것이 훨씬 더 가독성에 좋을 것 같아요. 특정 폴더 하위에, 각 컨텐츠에 해당하는 컴포넌트들을 모아 둔다면 훨씬 더 알아보기 쉬울 것 같아요 !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주용님 말에 동의합니다!
그리고 createWorkSpace 대신 createWorkSpaceModal이라는 폴더명은 어떤지 제안해봅니다
DeleteModal 폴더명처럼 모달 컴포넌트와 관련된 코드라는 걸 더 잘 알 수 있을 것 같아요 !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 동의합니다! 현재 createWorkSpaceModal 폴더안에 modalContents 폴더를 생성하여 그 안에 category, image, name과 같은 모달 폼 과정의 코드들을 넣었는데요..! 이렇게 바꾸는 거 괜찮을까요??

Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ import {
import WorkSapceInfo from '@/shared/component/createWorkSpace/info/WorkSpaceInfo';
import { buttonStyle, sectionStyle } from '@/shared/component/createWorkSpace/name/WorkSpaceName.style';
import useCategoryListQuery from '@/shared/hook/api/useCategoryListQuery';
import { useNextStep } from '@/shared/store/modal';
import { useWorkSpaceContext } from '@/shared/store/modalContext';
import { useWorkSpaceContext } from '@/shared/store/useWorkSpaceContext';

const WorkSpaceCategory = () => {
const { isOpen, close, toggle } = useOverlay();
const ref = useOutsideClick<HTMLDivElement>(close, 'select-container');
const nextStep = useNextStep();
const { setCategory } = useWorkSpaceContext();
const { setCategory, nextStep } = useWorkSpaceContext();
const [selected, setSelected] = useState('');

// 카테고리 데이터
Expand Down
8 changes: 3 additions & 5 deletions src/shared/component/createWorkSpace/image/WorkSpaceImage.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createWorkSpace 폴더도 삭제한거죵 ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옹 넵..!! createWorkSpace 없애고
image
이런 식으로 변경했는데 깃헙에서 변경사항이 적용이 안되었나봐유....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋아융 ~

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
} from '@/shared/component/createWorkSpace/image/WorkSpaceImage.style';
import WorkSapceInfo from '@/shared/component/createWorkSpace/info/WorkSpaceInfo';
import { sectionStyle } from '@/shared/component/createWorkSpace/name/WorkSpaceName.style';
import { useNextStep } from '@/shared/store/modal';
import { useWorkSpaceContext } from '@/shared/store/modalContext';
import { useWorkSpaceContext } from '@/shared/store/useWorkSpaceContext';

const WorkSpaceImage = () => {
const [fileURL, setFileURL] = useState<string>('');
Expand All @@ -33,8 +32,7 @@ const WorkSpaceImage = () => {
const { data: fileData } = useGetFileQuery(file as File);

// 모달
const nextStep = useNextStep();
const { setFileUrlData, name, category, resetBlockData } = useWorkSpaceContext();
const { setFileUrlData, nextStep, reset, name, category } = useWorkSpaceContext();
const { mutate: postTeamMutate } = usePostTeamMutation();

useEffect(() => {
Expand Down Expand Up @@ -100,7 +98,7 @@ const WorkSpaceImage = () => {
{
onSuccess: () => {
nextStep();
resetBlockData();
reset();
},
}
);
Expand Down
8 changes: 3 additions & 5 deletions src/shared/component/createWorkSpace/name/WorkSpaceName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ import {
inputWrapperStyle,
sectionStyle,
} from '@/shared/component/createWorkSpace/name/WorkSpaceName.style';
import {useNextStep} from '@/shared/store/modal';
import { useWorkSpaceContext } from '@/shared/store/modalContext';
import { useWorkSpaceContext } from '@/shared/store/useWorkSpaceContext';

const WorkSpaceName = () => {
const [inputValue, setInputValue] = useState('');
const nextStep = useNextStep();
const { setName } = useWorkSpaceContext();
const { setName, nextStep } = useWorkSpaceContext();

const handleNext = () => {
setName(inputValue);
nextStep();
nextStep();
};

const isButtonActive = inputValue.trim().length > 0;
Expand Down
Loading