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

[Feat] 나의 과제 페이지 Tooltip, Popover 컴포넌트 구현 #49

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { padWithZero, parseISODate } from "@wow-class/utils";
import Image from "next/image";
import type { Assignment } from "types/dtos/studyDetail";

import { FailurePopover } from "./FailurePopover";
interface AssignmentSubmissionInfoProps {
assignment: Assignment;
}
Expand Down Expand Up @@ -39,6 +40,7 @@ export const AssignmentSubmissionInfo = ({
<styled.div color={isFailure ? "error" : "primary"}>
{isFailure ? failMapping[submissionFailureType] : "글자수 충족"}
</styled.div>
<FailurePopover submissionFailureType={submissionFailureType} />
</Flex>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Flex } from "@styled-system/jsx";
import { Text } from "@wow-class/ui";
import Popover from "components/Popover";
import type { SubmissionFailureType } from "types/entities/common/assignment";
import { Help as HelpIcon } from "wowds-icons";

interface FailurePopoverProps {
submissionFailureType: SubmissionFailureType;
}
export const FailurePopover = ({
submissionFailureType,
}: FailurePopoverProps) => {
if (
submissionFailureType === "NONE" ||
submissionFailureType === "NOT_SUBMITTED"
)
return null;
return (
<Popover
triggerContent={<HelpIcon fill="sub" stroke="sub" style={iconStyle} />}
>
<Flex direction="column" gap="xs">
<Text color="textWhite" typo="body3">
{submissionFailureType === "WORD_COUNT_INSUFFICIENT" &&
"Q. 글자수가 부족하다고 나와요."}
{submissionFailureType === "LOCATION_UNIDENTIFIABLE" &&
'Q. "위치 확인 불가" 라고 나와요.'}
</Text>
<Text as="div" color="outline" typo="body3">
{submissionFailureType === "LOCATION_UNIDENTIFIABLE" && (
<>
아래 조건에 맞게 WIL.md 파일을 제출했는지 확인해주세요. <br />
<br />
<ul style={ulStyle}>
<li>본인의 레포지터리가 맞는지</li>
<li>제출한 브랜치 이름이 main인지</li>
<li>파일 위치가 `WeekN/WIL.md` 가 맞는지</li>
<li>파일 위치가 `WeekN/WIL.md` 가 맞는지</li>
</ul>
<br />
<br />
커밋 후 원격 저장소에 push까지 완료했는지 제대로 제출한 후에도
계속 "경로 확인 불가"라고 나온다면,GDSC Hongik 카카오톡 채널로
문의해주세요.
</>
)}
{submissionFailureType === "WORD_COUNT_INSUFFICIENT" && (
<p>
WIL.md 파일에 배운 내용을 최소 300자 이상 작성해야 해요. <br />
<br />
제대로 제출한 후에도 계속 글자수가 부족하다고 나온다면,
<br />
GDSC Hongik 카카오톡 채널로 문의해주세요.
</p>
)}
</Text>
</Flex>
</Popover>
);
};

const iconStyle = {
cursor: "pointer",
};

const ulStyle = {
listStyleType: "disc",
paddingLeft: "15px",
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const AssignmentContent = () => {
//TODO: studyDashboard.isLinkEditable 가 false 면 이번 주 과제 조회 api 사용
const studyDashboard = studyDashBoardData;
return (
<>
<section>
<Flex className={boxContainerStyle} gap="lg">
{studyDashBoardData.isLinkEditable && (
<>
Expand All @@ -30,7 +30,7 @@ export const AssignmentContent = () => {
<AssignmentOverviewBox assignments={assignmentData} />
)}
</Flex>
</>
</section>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { css } from "@styled-system/css";
import { studyDetailApi } from "apis/studyDetailApi";
import Tooltip from "components/Tooltip";
import { studyDashBoardData } from "constants/assignmentMockData";
import Link from "next/link";

export const AssignmentDescription = async () => {
//const studyDashboard = await studyDetailApi.getStudyDetailDashboard(1);

const studyDashboard = studyDashBoardData;
return (
<p>
제출 완료하기 버튼을 누르면 등록한{" "}
{studyDashboard.isLinkEditable ? (
<span className={githubTextStyle}>GitHub 레포지토리</span>
) : (
<Tooltip
content={
<Link href="https://github.com/123456789012345678" target="_blank">
https://github.com/123456789012345678
</Link>
}
>
<span className={githubTextStyle}>GitHub 레포지토리</span>
</Tooltip>
)}
의 main 브랜치에서 가장 최신 상태의 WIL.md 파일이 제출돼요. <br />
과제는 기한 내에 여러 번 제출할 수 있으나, 가장 마지막 제출만 최종 제출로
인정해요.
</p>
);
};

const githubTextStyle = css({
color: "blueHover",
cursor: "pointer",
textDecoration: "underline",
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Flex, styled } from "@styled-system/jsx";
import Image from "next/image";

export const AssignmentHeader = () => {
//TODO: 스터디 정보 연결, 내가 수강 중인 스터디 api 호출
//const studyId = await myStudyApi.getMyOngoingStudyInfo()
//const { title } = await myStudyApi.getBasicStudyInfo(studyId)

return (
<header>
<Flex gap="sm" textStyle="h1">
<styled.h1 color="textBlack">나의 과제</styled.h1>
<Image alt="dot" height={6} src="/images/dot.svg" width={6} />
<styled.h1 color="primary">기초 웹 스터디</styled.h1>
</Flex>
</header>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const AssignmentHistory = async () => {

if (studyHistories.length === 0) {
return (
<>
<section>
<Space height={133} />
<Flex alignItems="center" direction="column" gap="xl">
<Image
Expand All @@ -23,12 +23,12 @@ export const AssignmentHistory = async () => {
<Text>진행된 과제가 없어요</Text>
</Flex>
<Space height={94} />
</>
</section>
);
}

return (
<>
<section>
<Text as="h2" typo="h2">
과제 히스토리
</Text>
Expand All @@ -41,6 +41,6 @@ export const AssignmentHistory = async () => {
key={history.assignmentHistoryId}
/>
))}
</>
</section>
);
};
23 changes: 6 additions & 17 deletions apps/client/app/(afterLogin)/my-study/my-assignment/page.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

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

p4;
해당 페이지 코드 보다가 든 생각인데, section 태그는 컴포넌트 내부에 숨기고 가장 외부 태그로 사용하면 더 좋을 거 같아요

<>
      <header>
        <Flex gap="sm" textStyle="h1">
          <styled.h1 color="textBlack">나의 과제</styled.h1>
          <Image alt="dot" height={6} src="/images/dot.svg" width={6} />
          <styled.h1 color="primary">기초 웹 스터디</styled.h1>
        </Flex>
      </header>
      <Space height={8} />
      <AssignmentDescription />
      <Space height={48} />
      <section>
        <AssignmentContent />
      </section>
      <Space height={64} />
      <section>
        <AssignmentHistory />
      </section>
    </>

Copy link
Collaborator

Choose a reason for hiding this comment

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

헤더 부분도 컴포넌트로 빼면 어떨까...하는 생각이 듭니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

생각해보니 Header 부분에서도 스터디 기본 정보 api를 호출해서 title 을 얻어와야 해서 Header 컴포넌트로 분리해씁니다!

Copy link
Collaborator

Choose a reason for hiding this comment

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

이거 반영해주셨는데 페이지 부분에 section 태그가 남아있어서 그 부분만 반영 부탁드려요!

Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,18 @@ import Image from "next/image";
import { AssignmentHistory } from "@/(afterLogin)/my-study/my-assignment/_components";

import { AssignmentContent } from "./_components/AssignmentContent";
import { AssignmentDescription } from "./_components/AssignmentDescription";
import { AssignmentHeader } from "./_components/AssignmentHeader";

const MyAssignmentPage = () => {
return (
<>
<header>
<Flex gap="sm" textStyle="h1">
<styled.h1 color="textBlack">나의 과제</styled.h1>
<Image alt="dot" height={6} src="/images/dot.svg" width={6} />
<styled.h1 color="primary">기초 웹 스터디</styled.h1>
</Flex>
</header>
<AssignmentHeader />
<Space height={8} />
<p>
제출 완료하기 버튼을 누르면 등록한
<styled.span color="blueHover"> GitHub 레포지토리</styled.span>의 main
브랜치에서 가장 최신 상태의 WIL.md 파일이 제출돼요. <br />
과제는 기한 내에 여러 번 제출할 수 있으나, 가장 마지막 제출만 최종
제출로 인정해요.
</p>
<AssignmentDescription />
<Space height={48} />
<section>
<AssignmentContent />
</section>

<AssignmentContent />
<Space height={64} />
<section>
<AssignmentHistory />
Expand Down
75 changes: 75 additions & 0 deletions apps/client/components/Popover.tsx
ghdtjgus76 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use client";

import { css } from "@styled-system/css";
import { useClickOutside, useOpenState } from "@wow-class/ui/hooks";
import type { PropsWithChildren, ReactNode } from "react";
import { Close as CloseIcon } from "wowds-icons";

interface PopoverProps extends PropsWithChildren {
triggerContent: ReactNode;
}

const Popover = ({ triggerContent, children }: PopoverProps) => {
const { open, setOpen, onClose } = useOpenState();

const popoverRef = useClickOutside<HTMLDivElement>(onClose);

const handleClickTrigger = () => {
setOpen((prev) => !prev);
};
const handleClickCloseButton = () => {
onClose();
};
return (
<div className={popoverContainerStyle}>
<button className={triggerStyle} onClick={handleClickTrigger}>
{triggerContent}
</button>
{open && (
<div className={popoverStyle} id="popover" ref={popoverRef}>
<CloseIcon
className={closeButtonStyle}
height={14}
stroke="white"
width={14}
onClick={handleClickCloseButton}
/>

{children}
</div>
)}
</div>
);
};

export default Popover;

const popoverContainerStyle = css({
position: "relative",
display: "inline-block",
});

const popoverStyle = css({
position: "absolute",
width: "344px",
top: "100%",
left: 0,
transform: "translateY(8px)",
borderRadius: "md",
backgroundColor: "rgba(0,0,0,0.6)",
zIndex: 10000,
paddingX: "md",
paddingY: "sm",
boxShadow: "mono",
backdropFilter: "blur(15px)",
});

const triggerStyle = css({
display: "flex",
});
const closeButtonStyle = css({
position: "absolute",
top: "sm",
right: "md",
cursor: "pointer",
});
53 changes: 53 additions & 0 deletions apps/client/components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use client";

import { css } from "@styled-system/css";
import { useOpenState } from "@wow-class/ui/hooks";
import type { PropsWithChildren, ReactNode } from "react";

interface TooltipProps extends PropsWithChildren {
content: ReactNode;
}

const Tooltip = ({ content, children }: TooltipProps) => {
const { open, onOpen, onClose } = useOpenState();

const handleMouseEnter = () => {
onOpen();
};

const handleMouseLeave = () => {
onClose();
};

return (
<span
className={tooltipContainerStyle}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
{children}
{open && <span className={tooltipStyle}>{content}</span>}
</span>
);
};

export default Tooltip;

const tooltipContainerStyle = css({
position: "relative",
display: "inline-block",
});

const tooltipStyle = css({
position: "absolute",
top: "100%",
left: 0,
borderRadius: "md",
backgroundColor: "rgba(0,0,0,0.6)",
zIndex: 10000,
paddingX: "md",
paddingY: "sm",
boxShadow: "mono",
backdropFilter: "blur(15px)",
color: "textWhite",
});
Loading