20-calendar-system #37
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { toTypedSchema } from "@vee-validate/zod"
|
import { toTypedSchema } from "@vee-validate/zod"
|
||||||
import { ref, defineExpose, watch } from "vue"
|
import { ref, defineExpose, watch, nextTick } from "vue"
|
||||||
import * as z from "zod"
|
import * as z from "zod"
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
@@ -52,7 +52,7 @@ const formSchema = toTypedSchema(calendarEventSchema)
|
|||||||
const clickedDate = ref<string | null>(null);
|
const clickedDate = ref<string | null>(null);
|
||||||
const dialogOpen = ref(false)
|
const dialogOpen = ref(false)
|
||||||
function openDialog(dateStr?: string) {
|
function openDialog(dateStr?: string) {
|
||||||
clickedDate.value=dateStr ?? null;
|
clickedDate.value = dateStr ?? null;
|
||||||
dialogOpen.value = true
|
dialogOpen.value = true
|
||||||
initialValues.value = makeInitialValues()
|
initialValues.value = makeInitialValues()
|
||||||
}
|
}
|
||||||
@@ -83,13 +83,14 @@ const initialValues = ref(null)
|
|||||||
|
|
||||||
const formKey = ref(0)
|
const formKey = ref(0)
|
||||||
|
|
||||||
watch(dialogOpen, (isOpen) => {
|
watch(dialogOpen, async (isOpen) => {
|
||||||
if (!isOpen) {
|
if (isOpen) {
|
||||||
formKey.value++ // remounts the form -> picks up fresh initialValues
|
await nextTick();
|
||||||
|
formRef.value?.resetForm({ values: makeInitialValues() })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// ---------- submit ----------
|
// ---------- submit ----------
|
||||||
function onSubmit(vals: z.infer<typeof calendarEventSchema>) {
|
async function onSubmit(vals: z.infer<typeof calendarEventSchema>) {
|
||||||
const start = parseLocalDateTime(vals.startDate, vals.startTime)
|
const start = parseLocalDateTime(vals.startDate, vals.startTime)
|
||||||
const end = parseLocalDateTime(vals.endDate, vals.endTime)
|
const end = parseLocalDateTime(vals.endDate, vals.endTime)
|
||||||
|
|
||||||
@@ -104,7 +105,8 @@ function onSubmit(vals: z.infer<typeof calendarEventSchema>) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("Submitting CalendarEvent:", event)
|
console.log("Submitting CalendarEvent:", event)
|
||||||
createCalendarEvent(event);
|
await createCalendarEvent(event);
|
||||||
|
emit('reload');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
@@ -112,10 +114,15 @@ function onSubmit(vals: z.infer<typeof calendarEventSchema>) {
|
|||||||
// close after success
|
// close after success
|
||||||
dialogOpen.value = false
|
dialogOpen.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'reload'): void
|
||||||
|
}>()
|
||||||
|
const formRef = ref(null);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Form :key="formKey" v-slot="{ handleSubmit, resetForm }" :validation-schema="formSchema"
|
<Form ref="formRef" :key="formKey" v-slot="{ handleSubmit, resetForm }" :validation-schema="formSchema"
|
||||||
:initial-values="initialValues" keep-values as="">
|
:initial-values="initialValues" keep-values as="">
|
||||||
<Dialog v-model:open="dialogOpen">
|
<Dialog v-model:open="dialogOpen">
|
||||||
<DialogContent class="sm:max-w-[520px]">
|
<DialogContent class="sm:max-w-[520px]">
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<CreateCalendarEvent ref="dialogRef"></CreateCalendarEvent>
|
<CreateCalendarEvent ref="dialogRef" @reload="loadEvents()"></CreateCalendarEvent>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="flex-1 min-h-0 mt-5">
|
<div class="flex-1 min-h-0 mt-5">
|
||||||
<div class="h-[80vh] min-h-0">
|
<div class="h-[80vh] min-h-0">
|
||||||
|
|||||||
Reference in New Issue
Block a user