Skip to content

Commit

Permalink
Merge pull request #415 from NIAEFEUP/feature/custom-mailto
Browse files Browse the repository at this point in the history
Custom mailto for exchanges and enrollments
  • Loading branch information
racoelhosilva authored Feb 3, 2025
2 parents bf8da1f + 677a2f3 commit c89212c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/components/admin/requests/AdminSendEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const AdminSendEmail = ({
nmec
}: Props) => {
return <>
<a href={mailtoStringBuilder(nmec)}>
<a href={`${mailtoStringBuilder(nmec)}?subject=Pedido de Inscrição em Turmas&[email protected]&body=Viva, Foram alocadas turmas nas UCs indicadas. Cmpts, Daniel Silva (pela comissão de inscrição em turmas)`}>
<Button
variant="secondary"
>
Expand Down
18 changes: 8 additions & 10 deletions src/components/admin/requests/cards/AdminRequestCardFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { TreatExchangeButton } from "./TreatExchangeButton"

type Props = {
nmecs: Array<string>,
rejectMessage: string,
acceptMessage: string,
exchangeMessage: string,
requestType: AdminRequestType,
requestId: number,
showTreatButton?: boolean,
Expand All @@ -22,15 +21,15 @@ type Props = {

const rejectRequest = async (
nmecs: Array<string>,
rejectMessage: string,
exchangeMessage: string,
requestType: AdminRequestType,
id: number
) => {
try {
await exchangeRequestService.adminRejectExchangeRequest(requestType, id);

const a = document.createElement('a');
a.href = `${mailtoStringBuilder(nmecs)}?subject=Pedido de troca rejeitado&body=${rejectMessage}`;
a.href = `${mailtoStringBuilder(nmecs)}?subject=Pedido de Alteração de Turma&[email protected]&body=Viva, A alteração pedida não pode ser efetuada. ${exchangeMessage} Cmpts, Daniel Silva (pela comissão de inscrição em turmas)`;
a.click();
} catch (e) {
console.error(e);
Expand All @@ -39,15 +38,15 @@ const rejectRequest = async (

const acceptRequest = async (
nmecs: Array<string>,
acceptMessage: string,
exchangeMessage: string,
requestType: AdminRequestType,
id: number
) => {
try {
await exchangeRequestService.adminAcceptExchangeRequest(requestType, id);

const a = document.createElement('a');
a.href = `${mailtoStringBuilder(nmecs)}?subject=Pedido de troca aceito&body=${acceptMessage}`;
a.href = `${mailtoStringBuilder(nmecs)}?subject=Pedido de Troca de Turma&[email protected]&body=Viva, A alteração pedida foi efetuada. ${exchangeMessage} Cmpts, Daniel Silva (pela comissão de inscrição em turmas)`;
a.click();
} catch (e) {
console.error(e);
Expand All @@ -64,8 +63,7 @@ const markRequestAsAwaitingInformation = async (requestType: AdminRequestType, i

export const AdminRequestCardFooter = ({
nmecs,
rejectMessage,
acceptMessage,
exchangeMessage,
requestType,
requestId,
showTreatButton = true,
Expand All @@ -80,7 +78,7 @@ export const AdminRequestCardFooter = ({
<Button
variant="destructive"
onClick={async () => {
await rejectRequest(nmecs, rejectMessage, requestType, requestId);
await rejectRequest(nmecs, exchangeMessage, requestType, requestId);
setExchange(prev => {
const newPrev = {...prev };
newPrev.admin_state = "rejected";
Expand All @@ -93,7 +91,7 @@ export const AdminRequestCardFooter = ({

<Button
onClick={async () => {
await acceptRequest(nmecs, acceptMessage, requestType, requestId);
await acceptRequest(nmecs, exchangeMessage, requestType, requestId);
setExchange(prev => {
const newPrev = {...prev };
newPrev.admin_state = "accepted";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ExchangeStatus } from "./ExchangeStatus";
import { PersonExchanges } from "./PersonExchanges";
import { AdminRequestCardFooter } from "./AdminRequestCardFooter";
import { RequestDate } from "./RequestDate";
import { rejectEmailExchanges } from "../../../../utils/mail";
import { listEmailExchanges } from "../../../../utils/mail";
import { AdminRequestType } from "../../../../utils/exchange";
import { ValidateRequestButton } from "./ValidateRequestButton";

Expand Down Expand Up @@ -105,20 +105,13 @@ export const MultipleStudentExchangeCard = ({
nmecs={
exchange.options.map(option => option.participant_nmec)
}
rejectMessage={rejectEmailExchanges(
exchangeMessage={listEmailExchanges(
exchange.options.map(option => ({
goes_from: option.class_participant_goes_from.name,
goes_to: option.class_participant_goes_to.name,
course_acronym: option.course_unit
}))
)}
acceptMessage={"mensagem"/*acceptEmailExchanges(
exchange.options.map(option => ({
goes_from: option.class_participant_goes_from.name,
goes_to: option.class_participant_goes_to.name,
course_acronym: option.course_unit
}))
)*/}
requestType={AdminRequestType.DIRECT_EXCHANGE}
requestId={exchange.id}
showTreatButton={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AdminPreviewSchedule } from "../AdminPreviewSchedule";
import { AdminRequestCardFooter } from "./AdminRequestCardFooter";
import useStudentsSchedule from "../../../../hooks/admin/useStudentsSchedule";
import { RequestDate } from "./RequestDate";
import { rejectEmailExchanges } from "../../../../utils/mail";
import { listEmailExchanges } from "../../../../utils/mail";
import { AdminRequestType } from "../../../../utils/exchange";

type Props = {
Expand Down Expand Up @@ -107,14 +107,13 @@ export const SingleStudentExchangeCard = ({
{open &&
<AdminRequestCardFooter
nmecs={[exchange.user_nmec]}
rejectMessage={rejectEmailExchanges(
exchangeMessage={listEmailExchanges(
exchange.options.map(option => ({
goes_from: option.class_user_goes_from.name,
goes_to: option.class_user_goes_to.name,
course_acronym: option.course_unit.acronym
}))
)}
acceptMessage={"mensagem"}
requestType={AdminRequestType.URGENT_EXCHANGE}
requestId={exchange.id}
courseUnitId={exchange.options.map(option => option.course_unit.id)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ export const StudentEnrollmentCard = ({
{open &&
<AdminRequestCardFooter
nmecs={[enrollment.user_nmec]}
rejectMessage={""}
acceptMessage="mensagem"
exchangeMessage={""}
requestType={AdminRequestType.ENROLLMENT}
requestId={enrollment.id}
courseUnitId={enrollment.options.map(option => option.course_unit.id)}
Expand Down
10 changes: 2 additions & 8 deletions src/utils/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ export const mailtoStringBuilder = (nmec: string | Array<string>) => {
return `mailto:up${nmec}@up.pt`
}

export const rejectEmailExchanges = (items: Array<{
export const listEmailExchanges = (items: Array<{
goes_from: string,
goes_to: string,
course_acronym: string
}>) => {
let msg: string = "Foi rejeitado o seguinte pedido de troca de turmas:\n"

for (const item of items) {
msg += `De ${item.goes_from} para ${item.goes_to} no curso ${item.course_acronym}\n`
}

return msg;
return items.map(item => `De ${item.goes_from} para ${item.goes_to} no curso ${item.course_acronym}.`).join("\n")
}

0 comments on commit c89212c

Please sign in to comment.