Skip to content

Commit

Permalink
COM-3873: fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
Aude committed Dec 30, 2024
1 parent 5cd4b42 commit 5cd5f78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<script>
import { ref, toRefs, computed, watch } from 'vue';
import get from 'lodash/get';
import useVuelidate from '@vuelidate/core';
import { required } from '@vuelidate/validators';
import SurveyAnswer from 'src/modules/vendor/components/questionnaires/SurveyAnswer';
Expand All @@ -35,7 +36,7 @@ export default {
name: 'SurveyItem',
props: {
item: { type: Object, required: true },
isValidated: { type: Boolean, required: false },
isValidated: { type: Boolean, default: false },
},
components: {
'ni-labels-details': LabelsDetails,
Expand All @@ -48,16 +49,16 @@ export default {
const { item, isValidated } = toRefs(props);
const trainerValidation = ref(false);
const trainerReviewModal = ref(false);
const trainerAnswer = ref(isValidated.value ? item.value.trainerAnswer : 0);
const trainerAnswer = ref(get(item.value, 'trainerAnswer', 0));
const rules = computed(() => ({
trainerAnswer: { required, strictPositiveNumber, integerNumber },
}));
const v$ = useVuelidate(rules, { trainerAnswer });
watch(() => item.value.answers, () => {
watch(() => item.value, () => {
trainerValidation.value = false;
trainerAnswer.value = 0;
trainerAnswer.value = isValidated.value ? get(item.value, 'trainerAnswer', 0) : 0;
});
const openTrainerReviewModal = () => { trainerReviewModal.value = true; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
@update-trainer-review="updateTrainerReview" :is-validated="endQuestionnaireHistory.isValidated" />
<div v-if="get(endQuestionnaireHistory, '_id')" class="q-py-md">
<ni-input caption="Commentaire général sur la progression de l’apprenant" type="textarea" :rows="5"
v-model="trainerComment" :disabled="endQuestionnaireHistory.isValidated"
v-model="trainerComment" :disable="endQuestionnaireHistory.isValidated"
:read-only="endQuestionnaireHistory.isValidated" />
<div class="flex justify-end">
<ni-button class="bg-primary" color="white" label="Valider les réponses" @click="validateTrainerReview"
v-if="!endQuestionnaireHistory.isValidated" />
<ni-button v-if="!endQuestionnaireHistory.isValidated" class="bg-primary" color="white"
label="Valider les réponses" @click="validateTrainerReview" />
</div>
</div>
</template>
Expand Down Expand Up @@ -150,11 +150,9 @@ export default {
});
watch(() => endQuestionnaireHistory.value, () => {
if (get(endQuestionnaireHistory.value, 'isValidated')) {
trainerComment.value = get(endQuestionnaireHistory.value, 'trainerComment');
} else {
trainerComment.value = '';
}
trainerComment.value = get(endQuestionnaireHistory.value, 'isValidated')
? get(endQuestionnaireHistory.value, 'trainerComment', '')
: '';
});
const refreshQuestionnaireAnswers = async () => {
Expand Down Expand Up @@ -206,7 +204,7 @@ export default {
try {
const payload = {
trainerAnswers: trainerReview.value.map(a => omit(a, ['isValidated'])),
trainerComment: trainerComment.value,
...(trainerComment.value && { trainerComment: trainerComment.value }),
};
await QuestionnaireHistories.update(endQuestionnaireHistory.value._id, payload);
Expand Down

0 comments on commit 5cd5f78

Please sign in to comment.