diff --git a/src/app/services/breathecode.js b/src/app/services/breathecode.js index ee63b146..2a4d3597 100644 --- a/src/app/services/breathecode.js +++ b/src/app/services/breathecode.js @@ -343,6 +343,13 @@ class BreatheCodeClient { payload ); }, + addGithubUser: (payload) => { + return axios.bcPost( + "Invite", + `${this.host}/auth/academy/github/user`, + payload + ); + }, resendInvite: (user) => axios.bcPut( "Invite", diff --git a/src/app/views/admin/github-form/OrganizationUsers.jsx b/src/app/views/admin/github-form/OrganizationUsers.jsx index 20e860ff..2c609c32 100644 --- a/src/app/views/admin/github-form/OrganizationUsers.jsx +++ b/src/app/views/admin/github-form/OrganizationUsers.jsx @@ -16,6 +16,7 @@ import bc from '../../../services/breathecode'; import dayjs from 'dayjs'; import config from '../../../../config.js'; import { faLastfmSquare } from "@fortawesome/free-brands-svg-icons"; +import { PickCohortUserModal } from "./PickCohortUserModal"; const relativeTime = require('dayjs/plugin/relativeTime'); @@ -56,7 +57,7 @@ const getStatus = (u) => { const OrganizationUsers = ({ organization }) => { const [items, setItems] = useState([]); - + const [ userToAdd, setUserToAdd] = useState(false); const columns = [ { @@ -68,7 +69,7 @@ const OrganizationUsers = ({ organization }) => { return (
{item.user !== null &&
{item.user.first_name + " " + item.user.last_name}
} - {item.username} + {item.username ? {item.username} : No username found}
); }, @@ -105,8 +106,26 @@ const OrganizationUsers = ({ organization }) => { return data; } + const addToOrganization = async (cu) => { + if(!cu) return false; + + const result = await bc.auth().addGithubUser({ cohort: cu.cohort.id, user: cu.user.id }); + setUserToAdd(false); + loadData(); + } + return ( + { userToAdd == true && addToOrganization(_cu)} + />} +
+ +
{ + + const [cohort, setCohort] = useState(defaultCohort) + const [cohortUser, setCohortUser] = useState(defaultCohortUser) + const [ error, setError ] = useState(null) + + return ( + <> + onClose(false)} + aria-labelledby="alert-dialog-title" + aria-describedby="alert-dialog-description" + fullWidth="md" + > + + Find a cohort and user + + + setCohort(x)} + label="Search for active or prework cohorts" + value={cohort} + getOptionLabel={(option) => `${option.name} (${option.stage})`} + asyncSearch={async (searchTerm) => { + const resp = await bc.admissions().getAllCohorts({ ...cohortQuery, like: searchTerm }) + if(resp.ok) return resp.data + else setError("Error fetching cohorts") + }} + /> + {cohort && setCohortUser(x)} + label={`Search user in cohort ${cohort.name}`} + value={cohortUser} + debounced={false} + getOptionLabel={(option) => `${option.user.first_name} ${option.user.last_name} - ${option.user.email}`} + asyncSearch={async (searchTerm) => { + let q = { ...cohorUserQuery, cohorts: cohort.slug }; + if(searchTerm) q.like = searchTerm; + + const resp = await bc.admissions().getAllUserCohorts(q) + if(resp.ok) return resp.data + else setError("Error fetching cohort users") + }} + />} + {hint &&

{hint}

} +
+ + + +
+ + ) +} + +PickCohortUserModal.defaultProps = defaultProps; \ No newline at end of file diff --git a/src/app/views/admin/github.jsx b/src/app/views/admin/github.jsx index 011e7e91..a4725470 100644 --- a/src/app/views/admin/github.jsx +++ b/src/app/views/admin/github.jsx @@ -1,9 +1,10 @@ import React, { useEffect, useState } from "react"; -import { Grid } from "@material-ui/core"; +import { Grid, Button } from "@material-ui/core"; import { Alert, AlertTitle } from "@material-ui/lab"; import { useSelector } from 'react-redux'; import { Breadcrumb } from "../../../matx"; import bc from "../../services/breathecode"; +import { Link } from 'react-router-dom'; import OrganizationUsers from "./github-form/OrganizationUsers"; import GithubOrganization from "./github-form/GithubOrganization"; import { MatxLoading } from 'matx'; @@ -87,7 +88,7 @@ const GithubSettings = () => { return (
-
+