answer vue component: use union type instead of enum

This commit is contained in:
Julien Fastré 2022-06-03 14:39:35 +02:00
parent c804462f15
commit 3a88ea0b0f

View File

@ -27,12 +27,10 @@
<script lang="ts">
import {defineComponent, PropType} from 'vue';
enum AnswerStatus {
ACCEPTED = 'accepted',
DECLINED = 'declined',
PENDING = 'pending',
TENTATIVELY_ACCEPTED = 'tentative',
};
const ACCEPTED = 'accepted';
const DECLINED = 'declined';
const PENDING = 'pending';
const TENTATIVELY_ACCEPTED = 'tentative';
const i18n = {
messages: {
@ -54,20 +52,25 @@ export default defineComponent({
i18n,
props: {
calendarId: { type: Number, required: true},
status: {type: Object as PropType<AnswerStatus>, required: true},
status: {type: String as PropType<"accepted" | "declined" | "pending" | "tentative">, required: true},
},
emits: {
statusChanged(payload: AnswerStatus) {
statusChanged(payload: "accepted" | "declined" | "pending" | "tentative") {
return true;
}
},
},
data() {
return {
Statuses: AnswerStatus,
Statuses: {
ACCEPTED,
DECLINED,
PENDING,
TENTATIVELY_ACCEPTED,
},
}
},
methods: {
changeStatus: function (newStatus: AnswerStatus) {
changeStatus: function (newStatus: "accepted" | "declined" | "pending" | "tentative") {
console.log('changeStatus', newStatus);
const url = `/api/1.0/calendar/calendar/${this.$props.calendarId}/answer/${newStatus}.json`;
window.fetch(url, {