From 9b4556245e0476e63f8354611acb03500f080af9 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Thu, 17 Apr 2025 22:34:32 +0200 Subject: [PATCH] Fixed hardcoded world id for calendar creation --- components/calendar/dialog/Create.vue | 2 +- components/calendar/form/Create.vue | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/components/calendar/dialog/Create.vue b/components/calendar/dialog/Create.vue index 0013ea8..428a5b4 100644 --- a/components/calendar/dialog/Create.vue +++ b/components/calendar/dialog/Create.vue @@ -41,7 +41,7 @@ function handleClose() { - + diff --git a/components/calendar/form/Create.vue b/components/calendar/form/Create.vue index 9263c6e..0899ef3 100644 --- a/components/calendar/form/Create.vue +++ b/components/calendar/form/Create.vue @@ -2,7 +2,11 @@ import type { Calendar } from "~/models/CalendarConfig"; import { PhAlarm, PhCalendarDots, PhCircleNotch, PhWrench } from "@phosphor-icons/vue"; -const defaultSkeleton: Calendar = { name: "", today: { day: 1, month: 0, year: 0 }, months: [], events: [], state: "draft", color: "white" } +const props = defineProps<{ + worldId: number +}>() + +const defaultSkeleton: Calendar = { name: "", today: { day: 1, month: 0, year: 0 }, months: [], events: [], categories: [], state: "draft", color: "white" } const calendarSkeleton = ref({ ...defaultSkeleton }) onMounted(() => { @@ -38,16 +42,18 @@ const validSkeleton = computed(() => validSkeletonGeneral.value && validSkeleton const isCreatingCalendar = ref(false) async function handleSubmit() { - try { - isCreatingCalendar.value = true - await $fetch("/api/calendars/create", { method: "POST", body: { ...calendarSkeleton.value, worldId: 1 } }) + isCreatingCalendar.value = true - emit("on-close") - } catch (err) { - console.log(err) - } finally { + const { error } = await tryCatch($fetch("/api/calendars/create", { method: "POST", body: { ...calendarSkeleton.value, worldId: props.worldId } })) + + if (error) { + console.log(error) isCreatingCalendar.value = false + return } + + emit("on-close") + isCreatingCalendar.value = false } /**