-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #769 from Lunatic-Labs/SKIL-487
SKIL-487
- Loading branch information
Showing
7 changed files
with
374 additions
and
186 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
258 changes: 146 additions & 112 deletions
258
FrontEndReact/src/View/Admin/View/ViewTeams/AdminViewTeams.js
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 |
---|---|---|
@@ -1,118 +1,152 @@ | ||
import 'bootstrap/dist/css/bootstrap.css'; | ||
import React, { Component } from 'react'; | ||
import ErrorMessage from '../../../Error/ErrorMessage.js'; | ||
import ViewTeams from './ViewTeams.js'; | ||
import { genericResourceGET, parseUserNames } from '../../../../utility.js'; | ||
import { Box, Button, Typography } from '@mui/material'; | ||
import Loading from '../../../Loading/Loading.js'; | ||
import SuccessMessage from '../../../Success/SuccessMessage.js'; | ||
|
||
|
||
import "bootstrap/dist/css/bootstrap.css"; | ||
import React, { Component } from "react"; | ||
import ErrorMessage from "../../../Error/ErrorMessage.js"; | ||
import ViewTeams from "./ViewTeams.js"; | ||
import { genericResourceGET, | ||
parseUserNames } from "../../../../utility.js"; | ||
import { Box, Button, Typography } from "@mui/material"; | ||
import Loading from "../../../Loading/Loading.js"; | ||
import SuccessMessage from "../../../Success/SuccessMessage.js"; | ||
|
||
class AdminViewTeams extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
errorMessage: null, | ||
isLoaded: false, | ||
teams: null, | ||
users: null | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
var navbar = this.props.navbar; | ||
var state = navbar.state; | ||
var chosenCourse = state.chosenCourse; | ||
|
||
genericResourceGET(`/team?course_id=${chosenCourse["course_id"]}`, "teams", this); | ||
|
||
var url = ( | ||
chosenCourse["use_tas"] ? | ||
`/user?course_id=${chosenCourse["course_id"]}&role_id=4` : | ||
`/user?uid=${chosenCourse["admin_id"]}` | ||
); | ||
|
||
genericResourceGET(url, "users", this); | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
errorMessage: null, | ||
isLoaded: false, | ||
teams: null, | ||
users: null, | ||
prevTeamsLength: 0, | ||
successMessage: null | ||
}; | ||
} | ||
|
||
|
||
fetchData = () => { | ||
var navbar = this.props.navbar; | ||
var state = navbar.state; | ||
var chosenCourse = state.chosenCourse; | ||
|
||
genericResourceGET( | ||
`/team?course_id=${chosenCourse["course_id"]}`, | ||
"teams", | ||
this, | ||
); | ||
|
||
var url = chosenCourse["use_tas"] | ||
? `/user?course_id=${chosenCourse["course_id"]}&role_id=4` | ||
: `/user?uid=${chosenCourse["admin_id"]}`; | ||
|
||
genericResourceGET(url, "users", this); | ||
}; | ||
|
||
componentDidMount() { | ||
this.fetchData(); | ||
} | ||
|
||
|
||
componentDidUpdate(){ | ||
if (this.state.teams && this.state.teams.length !== this.state.prevTeamsLength) { | ||
this.setState({ prevTeamsLength: this.state.teams.length }); | ||
this.fetchData(); | ||
} | ||
|
||
render() { | ||
const { | ||
errorMessage, | ||
isLoaded, | ||
teams, | ||
users | ||
} = this.state; | ||
|
||
var navbar = this.props.navbar; | ||
|
||
navbar.adminViewTeams.teams = teams; | ||
navbar.adminViewTeams.users = users ? parseUserNames(users) : []; | ||
|
||
var setNewTab = navbar.setNewTab; | ||
var setAddTeamTabWithUsers = navbar.setAddTeamTabWithUsers; | ||
|
||
if (errorMessage) { | ||
return( | ||
<div className='container'> | ||
<ErrorMessage | ||
fetchedResource={"Teams"} | ||
errorMessage={errorMessage} | ||
/> | ||
</div> | ||
) | ||
|
||
} else if (!isLoaded || !teams || !users) { | ||
return( | ||
<Loading /> | ||
) | ||
|
||
} else { | ||
return( | ||
<Box> | ||
{navbar.state.successMessage !== null && | ||
<div className='container'> | ||
<SuccessMessage | ||
successMessage={navbar.state.successMessage} | ||
aria-label="adminViewTeamsSuccessMessage" | ||
/> | ||
</div> | ||
} | ||
<Box sx={{mb:"20px"}}className="subcontent-spacing" > | ||
<Typography sx={{fontWeight:'700'}} variant="h5">Teams</Typography> | ||
<Box sx={{display:"flex", gap:"20px"}}> | ||
<Button className='primary-color' | ||
variant='contained' | ||
onClick={() => { | ||
setNewTab("AdminTeamBulkUpload"); | ||
}} | ||
aria-label="adminBulkUploadButton" | ||
> | ||
Team Bulk Upload | ||
</Button> | ||
<Button className='primary-color' | ||
variant='contained' | ||
onClick={() => { | ||
setAddTeamTabWithUsers(users); | ||
}} | ||
aria-label="adminAddTeamButton" | ||
> | ||
Add Team | ||
</Button> | ||
</Box> | ||
</Box> | ||
<Box className="table-spacing"> | ||
<ViewTeams | ||
navbar={this.props.navbar} | ||
teams={teams} | ||
users={users ? parseUserNames(users) : []} | ||
/> | ||
</Box> | ||
</Box> | ||
) | ||
} | ||
} | ||
setErrorMessage = (message) => { | ||
this.setState({ errorMessage: message }); | ||
// Clear error message after 3 seconds | ||
setTimeout(() => { | ||
this.setState({ errorMessage: null }); | ||
}, 3000); | ||
} | ||
|
||
setSuccessMessage = (message) => { | ||
this.setState({ successMessage: message }); | ||
// Clear success message after 3 seconds | ||
setTimeout(() => { | ||
this.setState({ successMessage: null }); | ||
}, 3000); | ||
} | ||
render() { | ||
const { errorMessage, isLoaded, teams, users, successMessage } = this.state; | ||
|
||
var navbar = this.props.navbar; | ||
|
||
navbar.adminViewTeams.teams = teams; | ||
navbar.adminViewTeams.users = users ? parseUserNames(users) : []; | ||
|
||
var setNewTab = navbar.setNewTab; | ||
var setAddTeamTabWithUsers = navbar.setAddTeamTabWithUsers; | ||
|
||
if (errorMessage) { | ||
return ( | ||
<div className="container"> | ||
<ErrorMessage fetchedResource={"Teams"} errorMessage={errorMessage} /> | ||
</div> | ||
); | ||
} else if (!isLoaded || !teams || !users) { | ||
return <Loading />; | ||
} else { | ||
return ( | ||
<Box> | ||
{successMessage && ( | ||
<div className="container"> | ||
<SuccessMessage | ||
successMessage={successMessage} | ||
aria-label="adminViewTeamsSuccessMessage" | ||
/> | ||
</div> | ||
)} | ||
{errorMessage && ( | ||
<div className="container"> | ||
<ErrorMessage | ||
fetchedResource={"Teams"} | ||
errorMessage={errorMessage} | ||
aria-label="adminViewTeamsErrorMessage" | ||
/> | ||
</div> | ||
)} | ||
<Box sx={{ mb: "20px" }} className="subcontent-spacing"> | ||
<Typography sx={{ fontWeight: "700" }} variant="h5"> | ||
Teams | ||
</Typography> | ||
<Box sx={{ display: "flex", gap: "20px" }}> | ||
<Button | ||
className="primary-color" | ||
variant="contained" | ||
onClick={() => { | ||
setNewTab("AdminTeamBulkUpload"); | ||
}} | ||
aria-label="adminBulkUploadButton" | ||
> | ||
Team Bulk Upload | ||
</Button> | ||
<Button | ||
className="primary-color" | ||
variant="contained" | ||
onClick={() => { | ||
setAddTeamTabWithUsers(users); | ||
}} | ||
aria-label="adminAddTeamButton" | ||
> | ||
Add Team | ||
</Button> | ||
</Box> | ||
</Box> | ||
<Box className="table-spacing"> | ||
<ViewTeams | ||
navbar={this.props.navbar} | ||
teams={teams} | ||
users={users ? parseUserNames(users) : []} | ||
onError={this.setErrorMessage} | ||
onSuccess={this.setSuccessMessage} | ||
refreshData={this.fetchData} | ||
/> | ||
</Box> | ||
</Box> | ||
); | ||
} | ||
} | ||
} | ||
|
||
export default AdminViewTeams; | ||
export default AdminViewTeams; |
Oops, something went wrong.