Skip to content

Commit

Permalink
COM-3875: can select trainer when add attendance sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysseferreira committed Jan 8, 2025
1 parent b14fad5 commit 9655146
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/core/components/courses/AttendanceSheetAdditionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<template #title>
Ajouter une nouvelle <span class="text-weight-bold">feuille d'émargement</span>
</template>
<ni-select :model-value="newAttendanceSheet.trainer" :error="validations.trainer.$error"
@update:model-value="update($event, 'trainer')" in-modal required-field caption="Intervenant·e"
:options="trainerOptions" @blur="validations.trainer.$touch" :disable="course.trainers.length < 2" />
<ni-select v-if="course.type === INTER_B2B" :model-value="newAttendanceSheet.trainee"
:error="validations.trainee.$error" @update:model-value="update($event, 'trainee')" in-modal required-field
caption="Participant·e" :options="traineeOptions" @blur="validations.trainee.$touch" />
Expand Down Expand Up @@ -60,6 +63,8 @@ export default {
const traineeOptions = computed(() => formatAndSortIdentityOptions(course.value.trainees));
const trainerOptions = computed(() => formatAndSortIdentityOptions(course.value.trainers));
const dateOptions = computed(() => {
const dateOptionsSet = new Set(
course.value.slots.map(date => CompaniDate(date.startDate).startOf('day').toISO())
Expand Down Expand Up @@ -106,6 +111,7 @@ export default {
IMAGE_EXTENSIONS,
// Computed
traineeOptions,
trainerOptions,
dateOptions,
slotOptions,
stepsName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const useAttendanceSheets = (
newAttendanceSheet: {
file: { required },
trainee: { required: requiredIf(course.value.type === INTER_B2B) },
trainer: { required },
date: { required: requiredIf(course.value.type !== INTER_B2B) },
slots: { required: requiredIf(isSingleCourse.value) },
},
Expand Down Expand Up @@ -126,15 +127,23 @@ export const useAttendanceSheets = (
if (course.value.archivedAt) {
return NotifyWarning('Vous ne pouvez pas ajouter de feuilles d\'émargement à une formation archivée.');
}
if (!course.value.trainers.filter(t => t._id).length) {
return NotifyWarning('Vous ne pouvez pas ajouter de feuilles d\'émargement à une formation sans intervenant·e.');
}
if (!course.value.companies.length) {
return NotifyWarning('Au moins une structure doit être rattachée à la formation.');
}
if (course.value.type === INTER_B2B && !course.value.trainees.length) {
return NotifyWarning('Au moins un·e stagiaire doit être rattaché·e à la formation.');
}
if (isSingleCourse.value) {
if (!course.value.slots.length) return NotifyWarning('Il n\'y a aucun créneau planifier pour cette formation');
if (!notLinkedSlotOptions.value.length) {
return NotifyWarning('Tous les créneaux sont déjà rattachés à une feuille d\'émargement.');
}
newAttendanceSheet.value.slots = [];
}
if (course.value.trainers.length === 1) newAttendanceSheet.value.trainer = course.value.trainers[0]._id;

attendanceSheetAdditionModal.value = true;
};
Expand All @@ -145,10 +154,11 @@ export const useAttendanceSheets = (
};

const formatPayload = () => {
const { course: newAttendanceSheetCourse, file, trainee, date, slots } = newAttendanceSheet.value;
const { course: newAttendanceSheetCourse, file, trainee, trainer, date, slots } = newAttendanceSheet.value;
const form = new FormData();
course.value.type === INTER_B2B ? form.append('trainee', trainee) : form.append('date', date);
form.append('course', newAttendanceSheetCourse);
form.append('trainer', trainer);
form.append('file', file);

if (isSingleCourse.value) slots.forEach(slot => form.append('slots', slot));
Expand Down

0 comments on commit 9655146

Please sign in to comment.