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

Add Advisor Role #588

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
13 changes: 13 additions & 0 deletions backend/scripts/add-advisor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { memberCollection, approvedMemberCollection } from '../src/firebase';

const addAdvisor = async (collection) => {
const docs = await collection.listDocuments();
docs.forEach(async (doc) => {
await doc.update({
isAdvisor: false
});
});
};

addAdvisor(memberCollection);
addAdvisor(approvedMemberCollection);
1 change: 1 addition & 0 deletions common-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface IdolMember {
readonly subteams: readonly string[];
readonly formerSubteams?: readonly string[] | null;
readonly role: Role;
readonly isAdvisor: boolean;
readonly roleDescription: RoleDescription;
}

Expand Down
Binary file modified frontend/public/sample_csv.zip
Binary file not shown.
38 changes: 37 additions & 1 deletion frontend/src/components/Admin/AddUser/AddUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default function AddUser(): JSX.Element {
pronouns: '',
email: '',
role: '' as Role,
isAdvisor: false,
graduation: '',
major: '',
doubleMajor: '',
Expand Down Expand Up @@ -149,6 +150,16 @@ export default function AddUser(): JSX.Element {
return;
}

// Check that no tpms are also advisors
if (member.role === 'tpm' && member.isAdvisor) {
Emitters.generalError.emit({
headerMsg: 'Invalid Role!',
contentMsg:
'TPM advisor is not a valid role. Please select a different role if this member is returning as an advisor. Note that previous TPMs may become dev advisors.'
});
return;
}

MembersAPI.setMember({
...member,
netid: getNetIDFromEmail(member.email),
Expand Down Expand Up @@ -194,6 +205,7 @@ export default function AddUser(): JSX.Element {
? m.formerSubteams.split(', ')
: currMember.formerSubteams,
role: m.role || currMember.role,
isAdvisor: m.isAdvisor || currMember.isAdvisor,
roleDescription: getRoleDescriptionFromRoleID(m.role)
} as IdolMember;
MembersAPI.updateMember(updatedMember);
Expand All @@ -216,6 +228,7 @@ export default function AddUser(): JSX.Element {
subteams: m.subteam ? [m.subteam] : [],
formerSubteams: m.formerSubteams ? m.formerSubteams.split(', ') : [],
role: m.role || ('' as Role),
isAdvisor: m.isAdvisor || false,
roleDescription: getRoleDescriptionFromRoleID(m.role)
} as IdolMember;
MembersAPI.setMember(updatedMember);
Expand Down Expand Up @@ -244,7 +257,7 @@ export default function AddUser(): JSX.Element {
const json = await csvtojson().fromString(csv);
const errors = json
.map((m) => {
const [email, role, subteam] = [m.email, m.role, m.subteam];
const [email, role, subteam, isAdvisor] = [m.email, m.role, m.subteam, m.isAdvisor];
const formerSubteams: string[] = m.formerSubteams ? m.formerSubteams.split(', ') : [];
const err = [];
if (!email) {
Expand All @@ -265,6 +278,9 @@ export default function AddUser(): JSX.Element {
if (formerSubteams.includes(subteam)) {
err.push('subteam cannot be in former subteams');
}
if (isAdvisor && role === 'tpm') {
err.push('tpm advisor is not a valid role');
}
return err.length > 0 ? `Row ${json.indexOf(m) + 1}: ${err.join(', ')}` : '';
})
.filter((err) => err.length > 0);
Expand Down Expand Up @@ -445,6 +461,26 @@ export default function AddUser(): JSX.Element {
}}
value={state.currentSelectedMember.role || ''}
/>
<Form.Field
control={Select}
label="Advisor"
options={[
{ key: true, text: 'Yes', value: true },
{ key: false, text: 'No', value: false }
]}
placeholder="Advisor"
disabled={state.currentSelectedMember.role === 'tpm'} // no tpm advisor
onChange={(
event: React.ChangeEvent<HTMLInputElement>,
data: HTMLInputElement
) => {
setCurrentlySelectedMember((currentSelectedMember) => ({
...currentSelectedMember,
isAdvisor: Boolean(data.value)
}));
}}
value={state.currentSelectedMember.isAdvisor || false}
/>
</Form.Group>
<Form.Group widths="equal">
<Form.Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const DevPortfolioForm: React.FC = () => {
// When the user is logged in, `useSelf` always return non-null data.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const userInfo = useSelf()!;
const isTpm = userInfo.role === 'tpm';
const [isTpm, isAdvisor] = [userInfo.role === 'tpm', userInfo.isAdvisor];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would just split this into two lines. Easier to read


const [devPortfolio, setDevPortfolio] = useState<DevPortfolio | undefined>(undefined);
const [devPortfolios, setDevPortfolios] = useState<DevPortfolio[]>([]);
Expand Down Expand Up @@ -86,7 +86,7 @@ const DevPortfolioForm: React.FC = () => {
? devPortfolio.lateDeadline
: devPortfolio?.deadline;

if (!isTpm && otherEmpty && (openedEmpty || reviewedEmpty)) {
if (!(isTpm || isAdvisor) && otherEmpty && (openedEmpty || reviewedEmpty)) {
Emitters.generalError.emit({
headerMsg: 'No opened or reviewed PR url submitted',
contentMsg: 'Please paste a link to a opened and reviewed PR!'
Expand All @@ -110,7 +110,7 @@ const DevPortfolioForm: React.FC = () => {
headerMsg: 'Documentation Empty',
contentMsg: 'Please write something for the documentation section of the assignment.'
});
} else if (!isTpm && !otherEmpty && textEmpty) {
} else if (!(isTpm || isAdvisor) && !otherEmpty && textEmpty) {
Emitters.generalError.emit({
headerMsg: 'Explanation Empty',
contentMsg: 'Please write an explanation for your other PR submission.'
Expand Down Expand Up @@ -225,6 +225,7 @@ const DevPortfolioForm: React.FC = () => {
label="Opened Pull Request Github Link:"
openOther={openOther}
isTpm={isTpm}
isAdvisor={isAdvisor}
/>
<PRInputs
prs={reviewPRs}
Expand All @@ -233,8 +234,9 @@ const DevPortfolioForm: React.FC = () => {
label="Reviewed Pull Request Github Link:"
openOther={openOther}
isTpm={isTpm}
isAdvisor={isAdvisor}
/>
{isTpm ? (
{isTpm || isAdvisor ? (
<></>
) : (
<OtherPRInputs
Expand Down Expand Up @@ -302,14 +304,16 @@ const PRInputs = ({
label,
placeholder,
openOther,
isTpm
isTpm,
isAdvisor
}: {
prs: string[];
setPRs: React.Dispatch<React.SetStateAction<string[]>>;
label: string;
placeholder: string;
openOther: boolean;
isTpm: boolean;
isAdvisor: boolean;
}) => {
const keyDownHandler = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.code === 'Enter') {
Expand All @@ -319,7 +323,7 @@ const PRInputs = ({
return (
<div className={styles.inline}>
<label className={styles.bold}>
{label} {!isTpm && !openOther && <span className={styles.red_color}>*</span>}
{label} {!(isTpm || isAdvisor) && !openOther && <span className={styles.red_color}>*</span>}
</label>
{prs.map((pr, index) => (
<div className={styles.prInputContainer} key={index}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const UserProfile: React.FC = () => {
lastName,
pronouns,
role: userRole,
isAdvisor: userInfoBeforeEdit?.isAdvisor ?? false,
roleDescription: getRoleDescriptionFromRoleID(userRole),
graduation,
major,
Expand Down
Loading