Skip to content

Commit

Permalink
Manual feedback reminder email better name for interim feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Keskimaki committed Dec 19, 2023
1 parent 5860156 commit f0ad2e4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ReminderEmailModal = ({ open, onClose, feedbackTarget }) => {
const disabled = differenceInHours(Date.now(), lastSentAt) < FEEDBACK_REMINDER_COOLDOWN

const sendEmailReminder = useInteractiveMutation(() =>
sendReminderEmail.mutateAsync({ id, courseName, data: reminder })
sendReminderEmail.mutateAsync({ id, data: { reminder, courseName } })
)

const onEmailSend = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/client/pages/FeedbackTarget/tabs/Share/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { updateCache } from '../../../../util/reactQuery'
export const useSendReminderEmail = () => {
const mutationFn = async ({ id, data }) =>
apiClient.put(`/feedback-targets/${id}/remind-students`, {
data: { data },
data,
})

const mutation = useMutation(mutationFn, {
Expand Down
6 changes: 2 additions & 4 deletions src/server/mailer/mails/sendFeedbackReminderToStudents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { differenceInHours, format } = require('date-fns')
const { CourseUnit } = require('../../models')
const { FEEDBACK_REMINDER_COOLDOWN, PUBLIC_URL } = require('../../util/config')
const { ApplicationError } = require('../../util/customErrors')
const { pate } = require('../pateClient')
Expand Down Expand Up @@ -37,12 +36,11 @@ const sendReminderToGiveFeedbackToStudents = async (
return emails
}

const sendFeedbackReminderToStudents = async (feedbackTarget, reminder) => {
const sendFeedbackReminderToStudents = async (feedbackTarget, reminder, courseName) => {
if (differenceInHours(new Date(), feedbackTarget.feedbackReminderLastSentAt) < FEEDBACK_REMINDER_COOLDOWN) {
throw new ApplicationError(`Can send only 1 feedback reminder every ${FEEDBACK_REMINDER_COOLDOWN} hours`, 403)
}

const courseUnit = await CourseUnit.findByPk(feedbackTarget.courseUnitId)
const students = await feedbackTarget.getStudentsWhoHaveNotGivenFeedback()
const url = `${PUBLIC_URL}/targets/${feedbackTarget.id}/feedback`
const formattedStudents = students
Expand All @@ -58,7 +56,7 @@ const sendFeedbackReminderToStudents = async (feedbackTarget, reminder) => {
const emails = await sendReminderToGiveFeedbackToStudents(
url,
formattedStudents,
feedbackTarget.userCreated ? feedbackTarget.name : courseUnit.name,
courseName,
reminder,
formattedClosesAt,
feedbackTarget.userCreated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,12 @@ adRouter.put('/:id/response', async (req, res) => {
adRouter.put('/:id/remind-students', async (req, res) => {
const { user } = req
const feedbackTargetId = Number(req.params.id)
const { data: reminderText } = req.body.data
const { reminder: reminderText, courseName } = req.body.data

const feedbackTarget = await remindStudentsOnFeedback({
feedbackTargetId,
reminderText,
courseName,
user,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const { mailer } = require('../../mailer')
const { ApplicationError } = require('../../util/customErrors')
const { getFeedbackTargetContext } = require('./getFeedbackTargetContext')

const remindStudentsOnFeedback = async ({ feedbackTargetId, reminderText, user }) => {
const remindStudentsOnFeedback = async ({ feedbackTargetId, reminderText, courseName, user }) => {
const { feedbackTarget, access } = await getFeedbackTargetContext({
feedbackTargetId,
user,
})

if (!access?.canSendReminderEmail()) ApplicationError.Forbidden('Not allowed to send reminder')

await mailer.sendFeedbackReminderToStudents(feedbackTarget, reminderText)
await mailer.sendFeedbackReminderToStudents(feedbackTarget, reminderText, courseName)

return feedbackTarget
}
Expand Down

0 comments on commit f0ad2e4

Please sign in to comment.