Skip to content
2 changes: 1 addition & 1 deletion web-ui/src/api/guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getGuildLeaders = async (id, cookie) => {
url: `${guildLeadersUrl}/${id}`,
headers: { 'X-CSRF-Header': cookie, Accept: 'application/json' }
});
}
};

export const updateGuild = async (guild, cookie) => {
return resolve({
Expand Down
94 changes: 68 additions & 26 deletions web-ui/src/api/notifications.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from './api.js';
import { getMember } from "./member.js";
import { getMember } from './member.js';

const emailNotificationURL = '/services/email-notifications';
const emailURL = '/services/email';
Expand Down Expand Up @@ -50,49 +50,91 @@ export const sendEmail = async (subject, content, html, recipients, cookie) => {

export const emailPDLAssignment = async (member, cookie) => {
if (member.pdlId && member.lastName && member.firstName && member.workEmail) {
let res = await getMember(member.pdlId)
let pdl = res.payload?.data && !res.error
? res.payload.data
: null;
let res = await getMember(member.pdlId);
let pdl = res.payload?.data && !res.error ? res.payload.data : null;
if (pdl?.workEmail) {
await sendEmail("You have been assigned as the PDL of " + member.firstName + " " + member.lastName,
member.firstName + " " + member.lastName +
" will now report to you as their PDL. Please engage with them: " + member.workEmail,
false, [pdl.workEmail], cookie)
await sendEmail(
'You have been assigned as the PDL of ' +
member.firstName +
' ' +
member.lastName,
member.firstName +
' ' +
member.lastName +
' will now report to you as their PDL. Please engage with them: ' +
member.workEmail,
false,
[pdl.workEmail],
cookie
);
} else {
console.warn("Unable to send email regarding " + member.firstName + " " + member.lastName + "'s PDL update as the PDL was unable to be pulled up correctly")
console.warn(
'Unable to send email regarding ' +
member.firstName +
' ' +
member.lastName +
"'s PDL update as the PDL was unable to be pulled up correctly"
);
}
} else {
console.warn("Unable to send email regarding as member was not valid and missing required fields", member)
console.warn(
'Unable to send email regarding as member was not valid and missing required fields',
member
);
}
}
};
export const emailSupervisorAssignment = async (member, cookie) => {
if (member.supervisorid && member.lastName && member.firstName && member.workEmail) {
let res = await getMember(member.supervisorid)
let supervisor = res.payload?.data && !res.error
? res.payload.data
: null;
if (
member.supervisorid &&
member.lastName &&
member.firstName &&
member.workEmail
) {
let res = await getMember(member.supervisorid);
let supervisor = res.payload?.data && !res.error ? res.payload.data : null;
if (supervisor?.workEmail) {
await sendEmail("You have been assigned as the supervisor of " + member.firstName + " " + member.lastName,
member.firstName + " " + member.lastName +
" will now report to you as their supervisor. Please engage with them: " + member.workEmail,
false, [supervisor.workEmail], cookie)
await sendEmail(
'You have been assigned as the supervisor of ' +
member.firstName +
' ' +
member.lastName,
member.firstName +
' ' +
member.lastName +
' will now report to you as their supervisor. Please engage with them: ' +
member.workEmail,
false,
[supervisor.workEmail],
cookie
);
} else {
console.warn("Unable to send email regarding " + member.firstName + " " + member.lastName + "'s supervisor update as the supervisor was unable to be pulled up correctly")
console.warn(
'Unable to send email regarding ' +
member.firstName +
' ' +
member.lastName +
"'s supervisor update as the supervisor was unable to be pulled up correctly"
);
}
} else {
console.warn("Unable to send email regarding as member was not valid and missing required fields", member)
console.warn(
'Unable to send email regarding as member was not valid and missing required fields',
member
);
}
}
};
export const emailGuildLeaders = async (members, guild, cookie) => {
members.forEach(member => {
if (!member.workEmail || !guild?.name) {
console.warn("Unable to send guild leader email as member is missing required fields", member);
console.warn(
'Unable to send guild leader email as member is missing required fields',
member
);
return;
}

const subject = `You have been assigned as a guild leader of ${guild.name}`;
const body = `Congratulations, you have been assigned as a guild leader of ${guild.name}`;
sendEmail(subject, body, false, [member.workEmail], cookie);
});
}
};
21 changes: 16 additions & 5 deletions web-ui/src/components/admin/users/Users.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
import { useQueryParameters } from '../../../helpers/query-parameters';

import './Users.css';
import { emailPDLAssignment, emailSupervisorAssignment } from "../../../api/notifications.js";
import {
emailPDLAssignment,
emailSupervisorAssignment
} from '../../../api/notifications.js';

const PREFIX = 'Users';
const classes = {
Expand Down Expand Up @@ -186,14 +189,22 @@ const Users = () => {
payload: [...memberProfiles, data]
});
try {
member.pdlId && await emailPDLAssignment(member, csrf)
member.pdlId &&
(await emailPDLAssignment(member, csrf));
} catch (e) {
console.error("Unable to send PDL assignment email", e)
console.error(
'Unable to send PDL assignment email',
e
);
}
try {
member.supervisorid && await emailSupervisorAssignment(member, csrf)
member.supervisorid &&
(await emailSupervisorAssignment(member, csrf));
} catch (e) {
console.error("Unable to send supervisor assignment email", e)
console.error(
'Unable to send supervisor assignment email',
e
);
}
}
handleClose();
Expand Down
55 changes: 33 additions & 22 deletions web-ui/src/components/guild-results/GuildResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import GuildSummaryCard from './GuildSummaryCard';
import SkeletonLoader from '../skeleton_loader/SkeletonLoader';
import { useQueryParameters } from '../../helpers/query-parameters';
import './GuildResults.css';
import { emailGuildLeaders } from "../../api/notifications.js";
import { emailGuildLeaders } from '../../api/notifications.js';

const PREFIX = 'GuildResults';
const classes = {
Expand Down Expand Up @@ -95,19 +95,30 @@ const GuildResults = () => {
onSave={async guild => {
if (csrf) {
const res = await createGuild(guild, csrf);
const data = res.payload?.data && !res.error
? res.payload.data
: null;
const data =
res.payload?.data && !res.error ? res.payload.data : null;
if (data) {
dispatch({ type: ADD_GUILD, payload: data });
const resGuildLeader = await getGuildLeaders(data.id, csrf);
const guildLeaders = resGuildLeader.payload?.data && !resGuildLeader.error
? resGuildLeader.payload.data
: null;
const resGuildLeader = await getGuildLeaders(
data.id,
csrf
);
const guildLeaders =
resGuildLeader.payload?.data && !resGuildLeader.error
? resGuildLeader.payload.data
: null;
try {
guildLeaders && await emailGuildLeaders(guildLeaders, data, csrf).then();
guildLeaders &&
(await emailGuildLeaders(
guildLeaders,
data,
csrf
).then());
} catch (e) {
console.error("Unable to email guild leader assignment(s)", e)
console.error(
'Unable to email guild leader assignment(s)',
e
);
}
}
handleClose();
Expand All @@ -122,19 +133,19 @@ const GuildResults = () => {
<div className="guilds">
{guilds?.length
? guilds?.map((guild, index) =>
guild.name.toLowerCase().includes(searchText.toLowerCase()) ? (
<GuildSummaryCard
key={`guild-summary-${guild.id}`}
index={index}
guild={guild}
isOpen={guild.id === openedGuildId}
onGuildSelect={setOpenedGuildId}
/>
) : null
)
guild.name.toLowerCase().includes(searchText.toLowerCase()) ? (
<GuildSummaryCard
key={`guild-summary-${guild.id}`}
index={index}
guild={guild}
isOpen={guild.id === openedGuildId}
onGuildSelect={setOpenedGuildId}
/>
) : null
)
: Array.from({ length: 20 }).map((_, index) => (
<SkeletonLoader key={index} type="guild" />
))}
<SkeletonLoader key={index} type="guild" />
))}
</div>
</Root>
);
Expand Down
41 changes: 26 additions & 15 deletions web-ui/src/components/guild-results/GuildSummaryCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import PropTypes from 'prop-types';
import { deleteGuild, getGuildLeaders, updateGuild } from '../../api/guild.js';
import SplitButton from '../split-button/SplitButton';
import { emailGuildLeaders } from "../../api/notifications.js";
import { emailGuildLeaders } from '../../api/notifications.js';

const PREFIX = 'GuildSummaryCard';
const classes = {
Expand Down Expand Up @@ -264,34 +264,45 @@ const GuildSummaryCard = ({ guild, index, isOpen, onGuildSelect }) => {
open={open}
onClose={handleClose}
onSave={async editedGuild => {
const resGetOldGuildLeader = await getGuildLeaders(editedGuild.id, csrf);
const oldGuildLeaders = resGetOldGuildLeader.payload?.data && !resGetOldGuildLeader.error
? resGetOldGuildLeader.payload.data
: null;
const resGetOldGuildLeader = await getGuildLeaders(
editedGuild.id,
csrf
);
const oldGuildLeaders =
resGetOldGuildLeader.payload?.data && !resGetOldGuildLeader.error
? resGetOldGuildLeader.payload.data
: null;
const res = await updateGuild(editedGuild, csrf);
const data = res.payload?.data && !res.error
? res.payload.data
: null;
const data =
res.payload?.data && !res.error ? res.payload.data : null;
if (data) {
const copy = [...guilds];
copy[index] = data;
dispatch({
type: UPDATE_GUILDS,
payload: copy
});
const resGetGuildLeaders = await getGuildLeaders(editedGuild.id, csrf);
const guildLeaders = resGetGuildLeaders.payload?.data && !resGetGuildLeaders.error
? resGetGuildLeaders.payload.data
: null;
const resGetGuildLeaders = await getGuildLeaders(
editedGuild.id,
csrf
);
const guildLeaders =
resGetGuildLeaders.payload?.data && !resGetGuildLeaders.error
? resGetGuildLeaders.payload.data
: null;
if (guildLeaders && oldGuildLeaders) {
// Filter out the new leaders that were not in the old leaders
const newLeaders = guildLeaders.filter(
newLeader => !oldGuildLeaders.some(oldLeader => oldLeader.id === newLeader.id)
newLeader =>
!oldGuildLeaders.some(
oldLeader => oldLeader.id === newLeader.id
)
);
try {
newLeaders.length > 0 && await emailGuildLeaders(newLeaders, guild, csrf).then();
newLeaders.length > 0 &&
(await emailGuildLeaders(newLeaders, guild, csrf).then());
} catch (e) {
console.error("Unable to email guild leader assignment(s)", e)
console.error('Unable to email guild leader assignment(s)', e);
}
}
}
Expand Down
33 changes: 16 additions & 17 deletions web-ui/src/components/member-directory/AdminMemberCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import PriorityHighIcon from '@mui/icons-material/PriorityHigh';
import './MemberSummaryCard.css';
import SplitButton from '../split-button/SplitButton';

import {
updateMember,
deleteMember,
getMember
} from '../../api/member.js';
import { updateMember, deleteMember, getMember } from '../../api/member.js';
import { DELETE_MEMBER_PROFILE, UPDATE_TOAST } from '../../context/actions.js';

import {
Expand All @@ -34,7 +30,10 @@ import {
DialogTitle,
Typography
} from '@mui/material';
import { emailPDLAssignment, emailSupervisorAssignment } from "../../api/notifications.js";
import {
emailPDLAssignment,
emailSupervisorAssignment
} from '../../api/notifications.js';

const PREFIX = 'AdminMemberCard';
const classes = {
Expand Down Expand Up @@ -216,14 +215,13 @@ const AdminMemberCard = ({ member, index }) => {
onClose={handleClose}
onSave={async member => {
const resGetMember = await getMember(member.id, csrf);
const oldMember = resGetMember.payload?.data && !resGetMember.error
? resGetMember.payload.data
: null;
const oldMember =
resGetMember.payload?.data && !resGetMember.error
? resGetMember.payload.data
: null;
const res = await updateMember(member, csrf);
const data =
res.payload?.data && !res.error
? res.payload.data
: null;
res.payload?.data && !res.error ? res.payload.data : null;
if (data) {
const copy = [...memberProfiles];
const index = copy.findIndex(
Expand All @@ -235,15 +233,16 @@ const AdminMemberCard = ({ member, index }) => {
payload: copy
});
try {
oldMember.pdlId !== member.pdlId && await emailPDLAssignment(member, csrf);
oldMember.pdlId !== member.pdlId &&
(await emailPDLAssignment(member, csrf));
} catch (e) {
console.error("Unable to email PDL assignment", e)
console.error('Unable to email PDL assignment', e);
}
try {
oldMember.supervisorid !== member.supervisorid && await emailSupervisorAssignment(member, csrf);
oldMember.supervisorid !== member.supervisorid &&
(await emailSupervisorAssignment(member, csrf));
} catch {
console.error("Unable to email supervisor assignment", e)

console.error('Unable to email supervisor assignment', e);
}
handleClose();
}
Expand Down
Loading