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(apply): link the my application page with the example judgment api #660

Merged
merged 22 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a8f5b24
refactor: 도메인 용어 통일 test-result -> judgment result
KangYunHo1221 Oct 11, 2022
6a50deb
refactor: API 수정사항 반영
KangYunHo1221 Oct 11, 2022
4d234ae
fix: arrow function typos
KangYunHo1221 Oct 11, 2022
bb3b2bf
refactor: judgment result text
KangYunHo1221 Oct 11, 2022
1b3dde1
feat: 미션 타임아웃 로직 추가
KangYunHo1221 Oct 11, 2022
08faffd
feat: 예제 테스트 실행 에러 핸들링(refetch 로직 추가)
KangYunHo1221 Oct 11, 2022
aadd98c
fix: API 변경점 적용
KangYunHo1221 Oct 11, 2022
57908d9
fix: timeout에 대한 버튼 상태 수정
KangYunHo1221 Oct 11, 2022
ee58aa7
feat: 새로고침에 대한 알림추가
KangYunHo1221 Oct 11, 2022
63f6bc4
refactor: ts->tsx로 파일 변경, testStatus -> judgmentStatus로 변경
KangYunHo1221 Oct 12, 2022
ce3526b
fix: typos (Fail -> Failed)
KangYunHo1221 Oct 12, 2022
18ec15c
refactor: 용어 변경 (pending -> started)
KangYunHo1221 Oct 12, 2022
5e12de3
refacor: dummy.ts 에서 const를 사용하도록 변경
KangYunHo1221 Oct 12, 2022
57a3003
refactor: isJudgmentTimedOut 인자 변경(isoTime -> Mission['judgment']
KangYunHo1221 Oct 12, 2022
6fe20a1
refactor: 실제로 새로고침 한 후 새로고침을 보여주도록 변경
KangYunHo1221 Oct 12, 2022
6c995a1
refactor: judgmentResultText type 분리
KangYunHo1221 Oct 12, 2022
deb64f0
refactor: judgebutton 실행 실패시 에러처리 변경
KangYunHo1221 Oct 12, 2022
a9c5bb3
refactor: timeout 변수 분리
KangYunHo1221 Oct 12, 2022
7f65aa9
feat: 예제테스트 실행에 대한 PR주소를 보여주지 않도록 수정
KangYunHo1221 Oct 12, 2022
a776f87
fix: judgment button 조건문 적용 및 dummy 추가
KangYunHo1221 Oct 12, 2022
1f5bcfc
refactor: 변경된 judgment 응답형식 적용(isAutomation -> runnable)
KangYunHo1221 Oct 13, 2022
b10c62c
fix: 툴팁 스타일 변경(툴팁이 버튼을 가리는 오류 수정)
KangYunHo1221 Oct 13, 2022
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
5 changes: 3 additions & 2 deletions frontend/src/api/recruitments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const fetchMyMissionJudgment = ({
token,
}: FetchMyMissionJudgmentRequest) =>
axios.get(
`/api/recruitments/${recruitmentId}/missions/${missionId}/judgment`,
`/api/recruitments/${recruitmentId}/missions/${missionId}/judgments/judge-example`,
headers({ token })
);

Expand All @@ -86,7 +86,8 @@ export const fetchAssignment = ({ token, recruitmentId, missionId }: FetchAssign

export const postMyMissionJudgment = ({ recruitmentId, missionId, token }: PostJudgmentRequest) =>
axios.post<PostJudgmentResponseData>(
`/api/recruitments/${recruitmentId}/missions/${missionId}/judgment`,
`/api/recruitments/${recruitmentId}/missions/${missionId}/judgments/judge-example`,
{},
headers({ token })
);

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/@common/Tooltip/Tooltip.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
padding: 0.5rem 0.25rem;
border-radius: 10px;
background-color: var(--gray-003);
z-index: var(--tooltip-z-index);
}

.tooltip {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.judgment-result-text {
margin-bottom: 0.2rem;
font-size: 1.125rem;
font-weight: bold;
}

.judgment-result-score.default {
color: var(--black);
}

.judgment-result-score.started {
color: var(--blue);
}

.judgment-result-score.pass {
color: var(--green);
}

.judgment-result-score.fail {
color: var(--red);
}

.judgment-result-score.error {
color: var(--red);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import TestResult from "./TestResult";
import { ISO8601DateString } from "../../../../types/domains/common";
import { startedJudgeDateTime } from "./../../../mock/dummy";
import JudgmentResultText from "./JudgmentResult";

export default {
title: "components/TestResult",
component: TestResult,
title: "components/JudgmentResult",
component: JudgmentResultText,
decorators: [
(Story) => (
<div
Expand All @@ -19,25 +21,27 @@ export default {
</div>
),
],
} as ComponentMeta<typeof TestResult>;
} as ComponentMeta<typeof JudgmentResultText>;

const Template: ComponentStory<typeof TestResult> = (args) => <TestResult {...args} />;
const Template: ComponentStory<typeof JudgmentResultText> = (args) => (
<JudgmentResultText {...args} />
);

export const NoResultText = Template.bind({});
NoResultText.args = {
judgment: null,
};

export const PendingResultText = Template.bind({});
PendingResultText.args = {
export const StartedResultText = Template.bind({});
StartedResultText.args = {
judgment: {
pullRequestUrl: "https://github.com/woowacourse/service-apply/pull/367",
commitHash: "642951e1324eaf66914bd53df339d94cad5667e3",
status: "STARTED",
passCount: 0,
totalCount: 0,
message: "빌드를 실패했습니다.",
startedDateTime: "2020-10-25T15:00:00",
message: "",
startedDateTime: startedJudgeDateTime as ISO8601DateString,
commitUrl:
"https://github.com/woowacourse/service-apply/pull/367/commits/642951e1324eaf66914bd53df339d94cad5667e3",
},
Expand All @@ -48,11 +52,11 @@ PassResultText.args = {
judgment: {
pullRequestUrl: "https://github.com/woowacourse/service-apply/pull/367",
commitHash: "642951e1324eaf66914bd53df339d94cad5667e3",
status: "SUCCESS",
status: "SUCCEEDED",
passCount: 5,
totalCount: 5,
message: "",
startedDateTime: "2020-10-25T15:00:00",
startedDateTime: startedJudgeDateTime as ISO8601DateString,
commitUrl:
"https://github.com/woowacourse/service-apply/pull/367/commits/642951e1324eaf66914bd53df339d94cad5667e3",
},
Expand All @@ -63,11 +67,11 @@ NoPassResultText.args = {
judgment: {
pullRequestUrl: "https://github.com/woowacourse/service-apply/pull/367",
commitHash: "642951e1324eaf66914bd53df339d94cad5667e3",
status: "SUCCESS",
status: "SUCCEEDED",
passCount: 4,
totalCount: 5,
message: "",
startedDateTime: "2020-10-25T15:00:00",
startedDateTime: startedJudgeDateTime as ISO8601DateString,
commitUrl:
"https://github.com/woowacourse/service-apply/pull/367/commits/642951e1324eaf66914bd53df339d94cad5667e3",
},
Expand All @@ -78,11 +82,11 @@ FailJudgmentMission.args = {
judgment: {
pullRequestUrl: "https://github.com/woowacourse/service-apply/pull/367",
commitHash: "642951e1324eaf66914bd53df339d94cad5667e3",
status: "FAIL",
status: "FAILED",
passCount: 0,
totalCount: 0,
message: "빌드에 실패했습니다",
startedDateTime: "2020-10-25T15:00:00",
startedDateTime: startedJudgeDateTime as ISO8601DateString,
commitUrl:
"https://github.com/woowacourse/service-apply/pull/367/commits/642951e1324eaf66914bd53df339d94cad5667e3",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import classNames from "classnames";
import { Mission } from "../../../../types/domains/recruitments";
import formatJudgmentResult from "./../../../utils/format/judgmentResult";
import styles from "./JudgmentResult.module.css";

export type JudgmentResultProps = {
judgment: Mission["judgment"];
};

const JudgmentResultText = ({ judgment }: JudgmentResultProps) => {
const { text, type } = formatJudgmentResult(judgment);

return (
<div className={styles["judgment-result-text"]}>
<span>예제 테스트 결과 : </span>
<span className={classNames(styles["judgment-result-score"], styles[type])}>{text}</span>
</div>
);
};

export default JudgmentResultText;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Mission } from "../../../../types/domains/recruitments";
import { MY_MISSION_TOOLTIP_MESSAGE } from "../../../constants/messages";
import Tooltip from "../../@common/Tooltip/Tooltip";
import CommitHash from "../CommitHash/CommitHash";
import PullRequestUrl from "../PullRequestUrl/PullRequestUrl";
import TestResult from "../TestResult/TestResult";
import JudgmentResultText from "../JudgmentResult/JudgmentResult";
import styles from "./MissionDetail.module.css";

type MissionDetailProps = {
Expand All @@ -13,8 +12,7 @@ type MissionDetailProps = {
const MissionDetail = ({ judgment }: MissionDetailProps) => {
return (
<div className={styles["detail-container"]}>
<TestResult judgment={judgment} />
<PullRequestUrl judgment={judgment} />
<JudgmentResultText judgment={judgment} />
<CommitHash judgment={judgment} />
<div className={styles["guide-container"]}>
<p>테스트 코드 실행이 끝나기까지 3 ~ 5분이 걸릴 수 있습니다</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { AxiosError } from "axios";
import classNames from "classnames";
import { Mission, Recruitment } from "../../../../types/domains/recruitments";
import { postMyMissionJudgment } from "../../../api/recruitments";
import { JUDGMENT_STATUS } from "../../../constants/judgment";
import { MISSION_STATUS } from "../../../constants/recruitment";
import useTokenContext from "../../../hooks/useTokenContext";
import Button, { BUTTON_VARIANT } from "../../@common/Button/Button";
import { isJudgmentTimedOut } from "./../../../utils/validation/judgmentTime";
import styles from "./ApplicationButtons.module.css";

type JudgmentButtonProps = {
Expand All @@ -18,6 +20,13 @@ const JudgmentButton = ({ missionItem, recruitmentId, setMission }: JudgmentButt
const missionStatus = missionItem.status;
const judgment = missionItem.judgment;

const handleJudgeError = async (error: AxiosError, missionId: string) => {
if (!error) return;

const errorMessage = error.response?.data.message;
alert(errorMessage);
};

const handleJudgeMission = async ({
missionId,
recruitmentId,
Expand All @@ -27,12 +36,16 @@ const JudgmentButton = ({ missionItem, recruitmentId, setMission }: JudgmentButt
recruitmentId: string;
token: string;
}) => {
const response = await postMyMissionJudgment({
recruitmentId: Number(recruitmentId),
missionId: Number(missionId),
token,
});
setMission({ ...missionItem, judgment: response.data });
try {
const response = await postMyMissionJudgment({
recruitmentId: Number(recruitmentId),
missionId: Number(missionId),
token,
});
setMission({ ...missionItem, judgment: response.data });
} catch (error) {
handleJudgeError(error as AxiosError, missionId);
}
};

return (
Expand All @@ -43,7 +56,7 @@ const JudgmentButton = ({ missionItem, recruitmentId, setMission }: JudgmentButt
cancel={false}
disabled={
missionItem.submitted === false ||
judgment?.status === JUDGMENT_STATUS.STARTED ||
(judgment?.status === JUDGMENT_STATUS.STARTED && !isJudgmentTimedOut(judgment)) ||
missionStatus === MISSION_STATUS.ENDED ||
missionStatus === MISSION_STATUS.UNSUBMITTABLE
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { AxiosError } from "axios";
import classNames from "classnames";
import { Mission, Recruitment } from "../../../../types/domains/recruitments";
import { fetchMyMissionJudgment } from "../../../api";
import { JUDGMENT_STATUS } from "../../../constants/judgment";
import { MISSION_STATUS } from "../../../constants/recruitment";
import useTokenContext from "../../../hooks/useTokenContext";
import Button, { BUTTON_VARIANT } from "../../@common/Button/Button";
import { isJudgmentTimedOut } from "./../../../utils/validation/judgmentTime";
import styles from "./ApplicationButtons.module.css";

type RefreshButtonProps = {
Expand All @@ -26,6 +28,10 @@ const RefreshButton = ({ recruitmentId, missionItem, setMission }: RefreshButton
return null;
}

if (isJudgmentTimedOut(missionItem.judgment)) {
return null;
}
Copy link
Contributor

@woowapark woowapark Oct 12, 2022

Choose a reason for hiding this comment

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

c: isJudgmentTimedOut에서 아예 missionItem.judgment를 받을 수 있게 하고, 함수 내에서 한번 방어처리하면 어떨까요?

const isJudgmentTimedOut = (judgment: Mission["judgment"]) => {
  if (!judgment) {
    return false;
  } 
  /*...*/
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

utils 성격상 time을 받아서 쓰려고 했는데,
이미 함수명에 judgment로 한정 돼 있고 방어처리도 내부에서 하는게 더 깔끔해 보이네요!
수정하였습니다.


const handleRefreshMission = async ({
missionId,
recruitmentId,
Expand All @@ -35,13 +41,18 @@ const RefreshButton = ({ recruitmentId, missionItem, setMission }: RefreshButton
recruitmentId: string;
token: string;
}) => {
const response = await fetchMyMissionJudgment({
recruitmentId: Number(recruitmentId),
missionId: Number(missionId),
token,
});
try {
const response = await fetchMyMissionJudgment({
recruitmentId: Number(recruitmentId),
missionId: Number(missionId),
token,
});
setMission({ ...missionItem, judgment: response.data });

setMission({ ...missionItem, judgment: response.data });
alert("새로고침 되었습니다");
} catch (error) {
alert((error as AxiosError).response?.data.message);
}
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const MyApplicationFormItem = ({ recruitment, submitted }: MyApplicationFormItem
const isButtonDisabled = isApplicationDisabled(submitted, recruitment.recruitable);
const buttonLabel = applicationLabel(submitted, recruitment.recruitable);

const routeToApplicationForm = (recruitment: Recruitment) => () => {
const routeToApplicationForm = (recruitment: Recruitment) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

a: 👏👏👏

navigate(
{
pathname: generatePath(PATH.APPLICATION_FORM, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ NotSubmittedMission.args = {
recruitmentId: "1",
};

export const PendingJudgmentMission = Template.bind({});
PendingJudgmentMission.args = {
export const StartedJudgmentMission = Template.bind({});
StartedJudgmentMission.args = {
mission: missionsDummy["2"][2],
recruitmentId: "1",
};
Expand Down

This file was deleted.

This file was deleted.

Loading