Skip to content

Commit

Permalink
added join button for team details (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostOf0days authored Jan 22, 2024
1 parent cb724c2 commit 082f051
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pages/teams/details/[teamId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const TeamDescription = () => {
const [successMessage, setSuccessMessage] = useState("")
const [isOwnTeam, setIsOwnTeam] = useState(false)
const errorMessage = useSelector((state: RootState) => state?.teams?.error)
const [joinErrorMessage, setJoinErrorMessage] = useState(errorMessage)
const user = useSelector((state: RootState) => state?.accounts?.data)
const [isCaptain, setIsCaptain] = useState(false)
const [open, setOpen] = useState(dialogOpen.No)
Expand Down Expand Up @@ -114,6 +115,23 @@ const TeamDescription = () => {
}
}

const handleJoinTeam = async (e: any) => {
e.preventDefault()
try {
await dispatch(actions.teams.joinTeamRequest(teamInfo._id))
checkJoinError(false)
} catch (err) {
checkJoinError(true)
}
}

const checkJoinError = (isError: boolean) => {
setNotify(isError ? "error" : "success")
if (!isError) {
setSuccessMessage("Join request sent successfully")
}
}

useEffect(() => {
if (teamId === undefined || user._id === undefined) {
setLoading(false)
Expand Down Expand Up @@ -162,7 +180,14 @@ const TeamDescription = () => {
<WaveFooter />
<FloatingDiv>
{ownTeamFetched && !isOwnTeam ? (
<BackButton link="/teams" className={styles.backButton} />
<div className={styles.buttonContainer}>
<BackButton link="/teams" className={styles.backButton} />
<form onSubmit={handleJoinTeam}>
<RectangleButton type="submit" className={styles.joinButton}>
Join
</RectangleButton>
</form>
</div>
) : null}
<div className={styles.spinnerContainer}>
<Collapse in={loading}>
Expand Down
5 changes: 5 additions & 0 deletions styles/ViewTeam.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,8 @@
align-items: center;
justify-content: center;
}

.buttonContainer {
display: flex;
justify-content: space-between;
}

0 comments on commit 082f051

Please sign in to comment.