Skip to content

Commit

Permalink
Interim feedback name fixes again
Browse files Browse the repository at this point in the history
  • Loading branch information
Keskimaki committed Dec 19, 2023
1 parent 36acb31 commit 5860156
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@
"removeSuccess": "Programme survey removed"
},
"interimFeedback": {
"interimFeedback": "Interim Feedback",
"heading": "Interim feedback feature is still in the development stage and in a demo trial",
"emptySurveys": "There are no interim feedbacks for this programme yet; you can create a new interim feedback for the course here.",
"givenFeedback": "Feedbacks given",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@
"removeSuccess": "Koulutusohjelman kysely poistettu"
},
"interimFeedback": {
"interimFeedback": "Välipalaute",
"heading": "Välipalaute -toiminto on vielä kehitysvaiheessa ja demokokeilussa",
"emptySurveys": "Kurssilla ei ole yhtään välipalautetta, voit luoda välipalautteen kurssille täällä",
"givenFeedback": "Palautteita annettu",
Expand Down
19 changes: 11 additions & 8 deletions src/client/pages/FeedbackTarget/tabs/Share/ReminderEmailModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Box, Typography, Modal, Button, TextField } from '@mui/material'
import { useTranslation } from 'react-i18next'

import { getLanguageValue } from '../../../../util/languageUtils'
import { getPrimaryCourseName } from '../../../../util/courseIdentifiers'
import { getInterimFeedbackName, getPrimaryCourseName } from '../../../../util/courseIdentifiers'
import { formatClosesAt } from './utils'
import { TooltipButton } from '../../../../components/common/TooltipButton'
import { FEEDBACK_REMINDER_COOLDOWN } from '../../../../util/common'
Expand Down Expand Up @@ -43,15 +43,18 @@ const ReminderEmailModal = ({ open, onClose, feedbackTarget }) => {

const { t, i18n } = useTranslation()

const { courseUnit, courseRealisation, id, feedbackReminderLastSentAt, userCreated } = feedbackTarget
const courseName = getLanguageValue(
getPrimaryCourseName(courseUnit, courseRealisation, feedbackTarget),
i18n.language
)
const { courseUnit, courseRealisation, id, name, feedbackReminderLastSentAt, userCreated } = feedbackTarget
const isInterimFeedback = userCreated && !courseUnit.userCreated

const courseName = isInterimFeedback
? getInterimFeedbackName(name, courseUnit.name, t)
: getPrimaryCourseName(courseUnit, courseRealisation, feedbackTarget)
const lastSentAt = Date.parse(feedbackReminderLastSentAt)
const disabled = differenceInHours(Date.now(), lastSentAt) < FEEDBACK_REMINDER_COOLDOWN

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

const onEmailSend = () => {
onClose()
Expand All @@ -61,7 +64,7 @@ const ReminderEmailModal = ({ open, onClose, feedbackTarget }) => {
const closesAt = formatClosesAt(feedbackTarget.closesAt)

const emailMessage = t(`feedbackTargetResults:${userCreated ? 'customEmailMessage' : 'emailMessage'}`, {
courseName,
courseName: getLanguageValue(courseName, i18n.language),
closesAt,
})

Expand Down
2 changes: 1 addition & 1 deletion src/client/pages/MyFeedbacks/FeedbackTargetItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const FeedbackTargetItem = ({ feedbackTarget, divider }) => {
closesAt: endDate,
})

const courseName = getCourseName(feedbackTarget)
const courseName = getCourseName(feedbackTarget, t)
const translatedName = getLanguageValue(courseName, i18n.language)

const editPath = `/targets/${id}/feedback`
Expand Down
24 changes: 6 additions & 18 deletions src/client/pages/MyFeedbacks/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import groupBy from 'lodash/groupBy'

import { LANGUAGES, INCLUDE_COURSES } from '../../util/common'
import { getLanguageValue } from '../../util/languageUtils'
import { INCLUDE_COURSES } from '../../util/common'
import { getInterimFeedbackName } from '../../util/courseIdentifiers'

export const courseRealisationIsMisisingFeedback = courseRealisation => {
if (!Array.isArray(courseRealisation.feedbackTargets)) {
Expand Down Expand Up @@ -78,23 +78,11 @@ export const filterFeedbackTargets = feedbackTargets => {
}
}

const getInterimFeedbackName = (feedbackTargetName, courseUnitName) => {
const interimFeedbackName = {}
export const getCourseName = (feedbackTarget, t) => {
const { courseUnit, courseRealisation, userCreated } = feedbackTarget

LANGUAGES.forEach(language => {
const fbtName = getLanguageValue(feedbackTargetName, language)
const cuName = getLanguageValue(courseUnitName, language)

interimFeedbackName[language] = `${cuName}: ${fbtName}`
})

return interimFeedbackName
}

export const getCourseName = feedbackTarget => {
const { courseUnit, userCreated } = feedbackTarget

if (userCreated) return getInterimFeedbackName(feedbackTarget.name, courseUnit.name)
if (courseUnit.userCreated) return courseRealisation.name
if (userCreated) return getInterimFeedbackName(feedbackTarget.name, courseUnit.name, t)

return courseUnit.name
}
16 changes: 16 additions & 0 deletions src/client/util/courseIdentifiers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { LANGUAGES } from './common'
import { getLanguageValue } from './languageUtils'

export const getCourseCode = ({ courseCode, userCreated }) => (userCreated || !courseCode ? '' : courseCode)

export const getInterimFeedbackName = (feedbackTargetName, courseUnitName, t) => {
const interimFeedbackName = {}

LANGUAGES.forEach(language => {
const fbtName = getLanguageValue(feedbackTargetName, language)
const cuName = getLanguageValue(courseUnitName, language)

interimFeedbackName[language] = `${cuName}, ${t('interimFeedback:interimFeedback')}: ${fbtName}`
})

return interimFeedbackName
}

const getSurveyType = (courseUnit, feedbackTarget = {}) => {
const isOrganisationSurvey = courseUnit.userCreated
const isInterimSurvey = !isOrganisationSurvey && feedbackTarget?.userCreated
Expand Down

0 comments on commit 5860156

Please sign in to comment.