-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apply): implement the mission view page
- Loading branch information
1 parent
ec25e40
commit 7ca413d
Showing
13 changed files
with
259 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.buttons { | ||
width: 100%; | ||
margin-top: 3.5rem; | ||
display: flex; | ||
justify-content: space-between; | ||
gap: 1rem; | ||
} | ||
|
||
.buttons li { | ||
flex: 1; | ||
} | ||
|
||
.buttons li > button { | ||
width: 100%; | ||
} | ||
|
||
.mission-viewer-body li { | ||
list-style: disc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { generatePath, useNavigate, useParams } from "react-router-dom"; | ||
import Button, { BUTTON_VARIANT } from "../../components/@common/Button/Button"; | ||
import Container from "../../components/@common/Container/Container"; | ||
import useTokenContext from "../../hooks/useTokenContext"; | ||
import styles from "./MissionView.module.css"; | ||
import { PARAM, PATH } from "../../constants/path"; | ||
import { fetchMissionRequirements } from "../../api"; | ||
import { useEffect, useState } from "react"; | ||
import highlighter from "highlight.js"; | ||
import "github-markdown-css/github-markdown-light.css"; | ||
import "highlight.js/styles/github.css"; | ||
import { Mission } from "../../../types/domains/recruitments"; | ||
import { getMissionLabel } from "../../hooks/useMission"; | ||
import { MISSION_STATUS } from "../../constants/recruitment"; | ||
import { AxiosError } from "axios"; | ||
|
||
const MissionView = () => { | ||
const { token } = useTokenContext(); | ||
const navigate = useNavigate(); | ||
|
||
const { recruitmentId, missionId } = useParams<{ recruitmentId: string; missionId: string }>(); | ||
const [mission, setMission] = useState<Mission | null>(null); | ||
const description = mission?.description ?? ""; | ||
|
||
const isMissionSubmittable = | ||
!mission || | ||
mission?.submittable || | ||
mission?.status === MISSION_STATUS.SUBMITTABLE || | ||
mission?.status === MISSION_STATUS.SUBMITTING; | ||
|
||
const missionLabel = getMissionLabel( | ||
mission?.submitted ?? false, | ||
mission?.status ?? MISSION_STATUS.UNSUBMITTABLE | ||
); | ||
|
||
const goBack = () => { | ||
navigate(-1); | ||
}; | ||
|
||
const routeToAssignmentSubmit = () => { | ||
const isSubmitted = mission?.submitted; | ||
|
||
navigate( | ||
{ | ||
pathname: generatePath(PATH.ASSIGNMENT, { | ||
status: isSubmitted ? PARAM.ASSIGNMENT_STATUS.EDIT : PARAM.ASSIGNMENT_STATUS.NEW, | ||
}), | ||
}, | ||
{ | ||
state: { | ||
recruitmentId, | ||
currentMission: mission, | ||
}, | ||
} | ||
); | ||
}; | ||
|
||
const fetchRequirement = async () => { | ||
if (!recruitmentId || !missionId) { | ||
return; | ||
} | ||
|
||
try { | ||
const response = await fetchMissionRequirements({ | ||
token, | ||
recruitmentId: parseInt(recruitmentId, 10), | ||
missionId: parseInt(missionId, 10), | ||
}); | ||
|
||
setMission(response?.data); | ||
} catch (error) { | ||
alert((error as AxiosError).response?.data.message); | ||
|
||
goBack(); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (!recruitmentId || !missionId) { | ||
goBack(); | ||
return; | ||
} | ||
|
||
fetchRequirement(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
/* | ||
url - https://highlightjs.org/ | ||
<pre><code> 태그 내의 코드를 자동으로 감지하여 하이라이팅합니다. | ||
자동 감지가 실패할 경우, class 속성에 언어를 명시적으로 지정할 수 있습니다. | ||
*/ | ||
highlighter.highlightAll(); | ||
}, [description]); | ||
|
||
return ( | ||
<Container> | ||
<div | ||
className={`${styles["mission-viewer-body"]} markdown-body`} | ||
dangerouslySetInnerHTML={{ __html: description }} | ||
/> | ||
<ul className={styles.buttons}> | ||
<li> | ||
<Button type="button" variant={BUTTON_VARIANT.OUTLINED} onClick={goBack}> | ||
뒤로가기 | ||
</Button> | ||
</li> | ||
<li> | ||
<Button type="button" onClick={routeToAssignmentSubmit} disabled={!isMissionSubmittable}> | ||
{missionLabel} | ||
</Button> | ||
</li> | ||
</ul> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default MissionView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters