2022-04-09 02:56:05 +02:00
|
|
|
<template>
|
2022-12-04 00:34:34 +01:00
|
|
|
<main class="section">
|
2022-08-27 20:03:01 +02:00
|
|
|
<h1 class="title">
|
2022-12-25 23:56:01 +01:00
|
|
|
Modifier la séance du
|
|
|
|
<time :datetime="film.projectionDate">{{
|
|
|
|
new Date(film.projectionDate).toLocaleString()
|
|
|
|
}}</time>
|
2022-08-27 20:03:01 +02:00
|
|
|
</h1>
|
2022-08-27 16:53:52 +02:00
|
|
|
<AdminForm v-model="film" @save="saveDraft" @publish="publish" />
|
|
|
|
</main>
|
2022-04-09 02:56:05 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { Film } from "~/composables/types"
|
|
|
|
|
2022-12-30 22:27:11 +01:00
|
|
|
definePageMeta({ layout: "admin" })
|
2022-04-09 02:56:05 +02:00
|
|
|
const route = useRoute()
|
|
|
|
const id = route.params.id
|
|
|
|
|
|
|
|
const film = reactive<Film>({})
|
|
|
|
|
2022-07-14 01:39:19 +02:00
|
|
|
Object.assign(film, (await apiGet(`admin/films/${id}/`)).data.value)
|
2022-04-09 02:56:05 +02:00
|
|
|
// TODO manage errors
|
2022-12-30 22:27:11 +01:00
|
|
|
useHead({ title: `Édition de ${film.title}` })
|
2022-04-09 02:56:05 +02:00
|
|
|
|
|
|
|
async function save(publish: boolean) {
|
2022-07-14 01:39:19 +02:00
|
|
|
const { data } = await apiPatch(`admin/films/${id}/`, {
|
2022-04-09 02:56:05 +02:00
|
|
|
...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>
|