cineclub-site/front/pages/admin/[id]/edition.vue

38 lines
812 B
Vue
Raw Normal View History

<template>
<h1 class="title">Modifier la séance du {{ film.projectionDate }}</h1>
<AdminForm v-model="film" @save="saveDraft" @publish="publish" />
</template>
<script setup lang="ts">
import { Film } from "~/composables/types"
definePageMeta({
layout: "admin",
})
const route = useRoute()
const id = route.params.id
const film = reactive<Film>({})
Object.assign(film, (await apiGet(`films/${id}/`)).data.value)
// TODO manage errors
async function save(publish: boolean) {
const { data } = await apiPatch(`films/${id}/`, {
...film,
isConfirmed: publish,
})
Object.assign(film, data.value)
// TODO redirect to list ? to edit ?
}
async function saveDraft() {
return save(false)
}
async function publish() {
// TODO validate ? let API do the job ?
return save(true)
}
</script>