Skip to content

Commit

Permalink
리스트아이템 눌렀을 때 key-result 상세가 나오도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hojunin committed Jul 12, 2023
1 parent 9b7ab91 commit f8843b5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 82 deletions.
4 changes: 2 additions & 2 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { fetchOkrYears } from '@api/okr';
import { getObjectives } from '@api/objectives';

const Page = async () => {
// const years = await fetchOkrYears();
// const objectiveList = await getObjectives(years?.[0]);
const years = await fetchOkrYears();
const objectiveList = await getObjectives(years?.[0]);

return <DashBoard />;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useRef } from 'react';
import styles from './KeyResultsParentItem.module.scss';
import KeyResultsListItem from '../KeyResultsListItem';
import LabelsHeader from '../labelHeader';
Expand All @@ -10,6 +10,8 @@ import ToggleArrow from '@components/common/toggleArrow';
import AddListItemButton from '../addListItemButton';
import { KEY_RESULT_DETAIL } from '@type/keyResult';
import { ID } from '@type/common';
import { useOverlay } from '@toss/use-overlay';
import KeyResultDetail from '@components/goal-management/keyResultDetail';

interface KeyResultsParentItemProps {
keyResultItem: KEY_RESULT_DETAIL;
Expand All @@ -24,6 +26,14 @@ const KeyResultsParentItem = ({
onClick,
onClickAddInitiative,
}: KeyResultsParentItemProps) => {
const { open } = useOverlay();

const onClickInitiativeItem = () => {
open(({ exit }) => (
<KeyResultDetail keyResultId={keyResultItem.id} close={exit} />
));
};

return (
<div className={styles.root}>
<div className={styles.colorBlock} />
Expand Down Expand Up @@ -51,7 +61,7 @@ const KeyResultsParentItem = ({
{keyResultItem.initiatives.map((initiative) => (
<KeyResultsListItem
initiativeItem={initiative}
onClick={() => {}}
onClick={onClickInitiativeItem}
key={initiative.id}
/>
))}
Expand Down
1 change: 0 additions & 1 deletion components/goal-management/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const GoalManagement = () => {
<SuspenseComponent>
<KeyResultsList />
</SuspenseComponent>
<KeyResultDetail ref={detailRef} />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
top: 68px;
height: calc(100vh - 68px);
z-index: 999;

&.show {
animation: slideIn 0.3s ease-in-out;
}

&.close {
animation: slideOut 0.3s ease-in-out forwards;
}
animation: slideIn 0.3s ease-in-out;

.content {
@apply p-6;
Expand All @@ -25,12 +18,3 @@
transform: translateX(0);
}
}

@keyframes slideOut {
from {
transform: translateX(0);
}
to {
transform: translateX(100%);
}
}
90 changes: 30 additions & 60 deletions components/goal-management/keyResultDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import OutsideClickDetector from '@components/common/outsideClickDetector';
import React, {
forwardRef,
useCallback,
useEffect,
useImperativeHandle,
useState,
} from 'react';
Expand All @@ -12,70 +13,39 @@ import KeyResultDetailSummary from './summary';
import KeyResultDetailInitiatives from './initiatives';
import { useOverlay } from '@toss/use-overlay';
import DropKeyResultModal from '@components/shared/dropKeyResultModal';
import { ID } from '@type/common';

interface KeyResultDetailProps {}
export interface KeyResultDetailRef {
open: () => void;
interface KeyResultDetailProps {
keyResultId: ID;
close: () => void;
}
const KeyResultDetail = ({ keyResultId, close }: KeyResultDetailProps) => {
const { open: openModal } = useOverlay();

const dropKeyResult = () => {
openModal(({ exit }) => {
return <DropKeyResultModal close={exit} />;
});
};

return (
<OutsideClickDetector onOutsideClick={close}>
<aside className={styles.root}>
<KeyResultDetailHeader
status={'달성완료'}
onClickClose={close}
onClickDrop={dropKeyResult}
onClickWrite={close}
/>
<div className={styles.content}>
<KeyResultDetailSummary />
<KeyResultDetailInitiatives />
</div>
</aside>
</OutsideClickDetector>
);
};

const KeyResultDetail = forwardRef<KeyResultDetailRef, KeyResultDetailProps>(
(props, ref) => {
const [isVisible, setIsVisible] = useState(false);
const { open: openModal } = useOverlay();

const open = useCallback(() => {
setTimeout(() => {
setIsVisible(true);
}, 0);
}, []);

const close = useCallback(() => {
setIsVisible(false);
}, []);

useImperativeHandle(
ref,
() => ({
open,
close,
}),
[open, close],
);

const dropKeyResult = () => {
openModal(({ exit }) => {
return <DropKeyResultModal close={exit} />;
});
};

if (!isVisible) {
return <></>;
}

return (
<OutsideClickDetector onOutsideClick={close}>
<aside
className={cn(styles.root, {
[styles.show]: isVisible,
[styles.close]: !isVisible,
})}
>
<KeyResultDetailHeader
status={'달성완료'}
onClickClose={close}
onClickDrop={dropKeyResult}
onClickWrite={close}
/>
<div className={styles.content}>
<KeyResultDetailSummary />
<KeyResultDetailInitiatives />
</div>
</aside>
</OutsideClickDetector>
);
},
);
export default KeyResultDetail;

KeyResultDetail.displayName = 'KeyResultDetail';

0 comments on commit f8843b5

Please sign in to comment.