Skip to content

Commit 7c3fd96

Browse files
Session: Hide remaining days for coaches on "My sessions" page - refs BT#22640
1 parent 47246c4 commit 7c3fd96

File tree

1 file changed

+62
-8
lines changed

1 file changed

+62
-8
lines changed

assets/vue/components/course/CourseCard.vue

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import { useI18n } from "vue-i18n"
9393
import { useCourseRequirementStatus } from "../../composables/course/useCourseRequirementStatus"
9494
import BaseButton from "../basecomponents/BaseButton.vue"
9595
import CatalogueRequirementModal from "./CatalogueRequirementModal.vue"
96+
import { useUserSessionSubscription } from "../../composables/userPermissions"
9697
9798
const { abbreviatedDatetime } = useFormatDate()
9899
@@ -120,25 +121,66 @@ const props = defineProps({
120121
121122
const { t } = useI18n()
122123
const platformConfigStore = usePlatformConfig()
124+
const { isCoach } = useUserSessionSubscription(props.session, props.course)
125+
123126
const showRemainingDays = computed(
124127
() => platformConfigStore.getSetting("session.session_list_view_remaining_days") === "true",
125128
)
126129
127130
const daysRemainingText = computed(() => {
128-
if (!showRemainingDays.value || !props.session?.displayEndDate) return null
131+
if (!showRemainingDays.value || !props.session?.displayEndDate) {
132+
return null
133+
}
129134
130135
const endDate = new Date(props.session.displayEndDate)
131-
if (isNaN(endDate)) return null
136+
if (isNaN(endDate)) {
137+
return null
138+
}
132139
133140
const today = new Date()
134141
const diff = Math.floor((endDate - today) / (1000 * 60 * 60 * 24))
135142
136-
if (diff > 1) return `${diff} days remaining`
137-
if (diff === 1) return t("Ends tomorrow")
138-
if (diff === 0) return t("Ends today")
143+
if (diff > 1) {
144+
return `${diff} days remaining`
145+
}
146+
if (diff === 1) {
147+
return t("Ends tomorrow")
148+
}
149+
if (diff === 0) {
150+
return t("Ends today")
151+
}
152+
139153
return t("Expired")
140154
})
141155
156+
const sessionDurationText = computed(() => {
157+
// Only show duration in days when the setting is enabled and the user is a coach
158+
if (!showRemainingDays.value || !isCoach.value) {
159+
return null
160+
}
161+
162+
if (!props.session?.displayStartDate || !props.session?.displayEndDate) {
163+
return null
164+
}
165+
166+
const start = new Date(props.session.displayStartDate)
167+
const end = new Date(props.session.displayEndDate)
168+
169+
if (isNaN(start) || isNaN(end)) {
170+
return null
171+
}
172+
173+
const msPerDay = 1000 * 60 * 60 * 24
174+
const rawDiff = Math.floor((end - start) / msPerDay) + 1
175+
const days = rawDiff > 0 ? rawDiff : 1
176+
177+
if (days === 1) {
178+
return "1 day duration"
179+
}
180+
181+
return `${days} days duration`
182+
})
183+
142184
const showCourseDuration = computed(() => platformConfigStore.getSetting("course.show_course_duration") === "true")
143185
144186
const teachers = computed(() => {
@@ -159,11 +201,23 @@ const teachers = computed(() => {
159201
})
160202
161203
const sessionDisplayDate = computed(() => {
162-
if (daysRemainingText.value) return daysRemainingText.value
204+
// When setting is enabled, decide between duration (for coaches) and remaining days (for regular users)
205+
if (sessionDurationText.value) {
206+
return sessionDurationText.value
207+
}
208+
209+
if (daysRemainingText.value) {
210+
return daysRemainingText.value
211+
}
163212
213+
// Fallback: show the original date range
164214
const parts = []
165-
if (props.session?.displayStartDate) parts.push(abbreviatedDatetime(props.session.displayStartDate))
166-
if (props.session?.displayEndDate) parts.push(abbreviatedDatetime(props.session.displayEndDate))
215+
if (props.session?.displayStartDate) {
216+
parts.push(abbreviatedDatetime(props.session.displayStartDate))
217+
}
218+
if (props.session?.displayEndDate) {
219+
parts.push(abbreviatedDatetime(props.session.displayEndDate))
220+
}
167221
168222
return parts.join("")
169223
})

0 commit comments

Comments
 (0)