utilisation des fonctions Apis/admin.ts pour mettre un raport a un appointmentid
This commit is contained in:
parent
73aac1875a
commit
2e9d841709
@ -5,14 +5,14 @@
|
|||||||
<form @submit.prevent="submitReport">
|
<form @submit.prevent="submitReport">
|
||||||
<div>
|
<div>
|
||||||
<label for="appointmentId">ID du rendez-vous :</label>
|
<label for="appointmentId">ID du rendez-vous :</label>
|
||||||
<div style="display: flex; align-items: center; gap: 0.5rem">
|
<div style="display: flex; align-items: center; gap: 0.5rem;">
|
||||||
<button type="button" @click="decrementId">-</button>
|
<button type="button" @click="decrementId">-</button>
|
||||||
<input
|
<input
|
||||||
id="appointmentId"
|
id="appointmentId"
|
||||||
v-model.number="appointmentId"
|
v-model.number="appointmentId"
|
||||||
type="number"
|
type="number"
|
||||||
min="1"
|
min="1"
|
||||||
style="width: 60px; text-align: center"
|
style="width: 60px; text-align: center;"
|
||||||
/>
|
/>
|
||||||
<button type="button" @click="incrementId">+</button>
|
<button type="button" @click="incrementId">+</button>
|
||||||
</div>
|
</div>
|
||||||
@ -27,9 +27,7 @@
|
|||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit">
|
<button type="submit">{{ isUpdate ? "Mettre à jour" : "Créer" }} le rapport</button>
|
||||||
{{ isUpdate ? "Mettre à jour" : "Créer" }} le rapport
|
|
||||||
</button>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<p v-if="responseMessage">{{ responseMessage }}</p>
|
<p v-if="responseMessage">{{ responseMessage }}</p>
|
||||||
@ -37,6 +35,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {
|
||||||
|
createAppointmentReport,
|
||||||
|
updateAppointmentReport,
|
||||||
|
} from "@/services/Apis/Admin";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "AdminAppointmentsComponent",
|
name: "AdminAppointmentsComponent",
|
||||||
data() {
|
data() {
|
||||||
@ -63,38 +66,31 @@ export default {
|
|||||||
this.appointmentId--;
|
this.appointmentId--;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async submitReport() {
|
submitReport() {
|
||||||
const reportData = {
|
const reportData = { content: this.reportContent };
|
||||||
reportContent: this.reportContent,
|
const onSuccess = (response) => {
|
||||||
};
|
|
||||||
|
|
||||||
const url = `/admin/appointments/report/${this.appointmentId}`;
|
|
||||||
const method = this.isUpdate ? "PUT" : "POST";
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.$axios({
|
|
||||||
method,
|
|
||||||
url,
|
|
||||||
data: reportData,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status === 201 || response.status === 200) {
|
if (response.status === 201 || response.status === 200) {
|
||||||
this.responseMessage =
|
this.responseMessage =
|
||||||
"Rapport " +
|
"Rapport " +
|
||||||
(this.isUpdate ? "mis à jour" : "créé") +
|
(this.isUpdate ? "mis à jour" : "créé") +
|
||||||
" avec succès.";
|
" avec succès.";
|
||||||
}
|
}
|
||||||
} catch (error) {
|
};
|
||||||
|
const onError = (error) => {
|
||||||
|
console.error("Erreur lors de l'envoi du rapport :", error.response || error.message);
|
||||||
if (error.response && error.response.status === 400) {
|
if (error.response && error.response.status === 400) {
|
||||||
this.responseMessage =
|
this.responseMessage = "Requête invalide. Vérifiez les informations.";
|
||||||
"Requête invalide. Vérifiez les informations.";
|
|
||||||
} else if (error.response && error.response.status === 401) {
|
} else if (error.response && error.response.status === 401) {
|
||||||
this.responseMessage =
|
this.responseMessage = "Vous n'êtes pas autorisé à effectuer cette action.";
|
||||||
"Vous n'êtes pas autorisé à effectuer cette action.";
|
|
||||||
} else {
|
} else {
|
||||||
this.responseMessage =
|
this.responseMessage = "Une erreur est survenue. Veuillez réessayer.";
|
||||||
"Une erreur est survenue. Veuillez réessayer.";
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.isUpdate) {
|
||||||
|
updateAppointmentReport(this.appointmentId, reportData, onSuccess, onError);
|
||||||
|
} else {
|
||||||
|
createAppointmentReport(this.appointmentId, reportData, onSuccess, onError);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user