Changed organization for 2 mixed components

This commit is contained in:
Alexis
2024-12-03 15:29:06 +01:00
parent bb6df1d440
commit 4ddbfd9855
6 changed files with 265 additions and 248 deletions

View File

@@ -53,8 +53,8 @@ onMounted(() => {
<component :is="currentViewComponent" /> <component :is="currentViewComponent" />
<CalendarSearch /> <CalendarSearch />
<CalendarFormUpdateEvent /> <CalendarDialogUpdateEvent />
<CalendarFormDeleteEvent /> <CalendarDialogDeleteEvent />
</div> </div>
</div> </div>
</template> </template>

View File

@@ -0,0 +1,45 @@
<script lang="ts" setup>
const { isDeleteEventModalOpen, eventSkeleton, lastActiveEvent } = storeToRefs(useCalendar())
const isLoading = ref<boolean>(false)
// Watch the popover state
watch(isDeleteEventModalOpen, (hasOpened, _o) => {
if (hasOpened && lastActiveEvent.value) {
eventSkeleton.value = { ...lastActiveEvent.value }
}
})
/**
* Prevents the modal from closing if's still loading
*
* @param e The closing event (can be keydown or click)
*/
function handleClosing(e: Event): void {
if (isLoading.value) {
e.preventDefault()
}
}
</script>
<template>
<UiAlertDialog v-model:open="isDeleteEventModalOpen">
<UiAlertDialogContent
:disable-outside-pointer-events="true"
:trap-focus="true"
class="min-w-96 border-indigo-200 dark:bg-slate-950 dark:border-indigo-950"
@escape-key-down="handleClosing"
@focus-outside="handleClosing"
@interact-outside="handleClosing"
@pointer-down-outside="handleClosing"
>
<UiAlertDialogTitle>{{ $t('entity.calendar.event.deleteDialog.title') }}</UiAlertDialogTitle>
<UiAlertDialogDescription>
{{ $t('entity.calendar.event.deleteDialog.subtitle') }}
</UiAlertDialogDescription>
<CalendarFormDeleteEvent />
</UiAlertDialogContent>
</UiAlertDialog>
</template>

View File

@@ -19,7 +19,7 @@ function toggleDialog() {
</UiButton> </UiButton>
<UiDialog v-model:open="isDialogOpen"> <UiDialog v-model:open="isDialogOpen">
<UiDialogContent> <UiDialogContent class="border-indigo-200 dark:bg-slate-950 dark:border-indigo-950">
<UiDialogTitle> <UiDialogTitle>
{{ $t("entity.calendar.event.addSingle") }} {{ $t("entity.calendar.event.addSingle") }}
</UiDialogTitle> </UiDialogTitle>

View File

@@ -0,0 +1,49 @@
<script lang="ts" setup>
const { eventSkeleton, lastActiveEvent, isEditEventModalOpen } = storeToRefs(useCalendar())
const isLoading = ref(false)
// Watch the popover state
watch(isEditEventModalOpen, (hasOpened, _o) => {
if (hasOpened && lastActiveEvent.value) {
eventSkeleton.value = { ...lastActiveEvent.value }
}
})
/**
* Prevents the modal from closing if's still loading
*
* @param e The closing event (can be keydown or click)
*/
function handleClosing(e: Event) {
if (isLoading.value) {
e.preventDefault()
}
}
</script>
<template>
<UiDialog v-model:open="isEditEventModalOpen">
<UiDialogContent
:disable-outside-pointer-events="true"
:trap-focus="true"
class="pl-3 min-w-96 border-indigo-200 dark:bg-slate-950 dark:border-indigo-950"
@escape-key-down="handleClosing"
@focus-outside="handleClosing"
@interact-outside="handleClosing"
@pointer-down-outside="(e) => e.preventDefault()"
>
<header class="pl-8 grid gap-y-2">
<UiDialogTitle>
{{ $t('entity.calendar.event.editDialog.title') }}
</UiDialogTitle>
<UiDialogDescription>
{{ $t('entity.calendar.event.editDialog.subtitle') }}
</UiDialogDescription>
</header>
<CalendarFormUpdateEvent />
</UiDialogContent>
</UiDialog>
</template>

View File

@@ -3,7 +3,7 @@ import { PhCircleNotch } from "@phosphor-icons/vue";
import { useToast } from "~/components/ui/toast"; import { useToast } from "~/components/ui/toast";
const { resetSkeleton, deleteEventFromSkeleton, cancelLatestRequest } = useCalendar() const { resetSkeleton, deleteEventFromSkeleton, cancelLatestRequest } = useCalendar()
const { isDeleteEventModalOpen, eventSkeleton, lastActiveEvent } = storeToRefs(useCalendar()) const { isDeleteEventModalOpen, eventSkeleton } = storeToRefs(useCalendar())
const { toast } = useToast() const { toast } = useToast()
const { t } = useI18n() const { t } = useI18n()
@@ -14,13 +14,6 @@ const formErrors = reactive<{ message: string | null }>({
message: null message: null
}) })
// Watch the popover state
watch(isDeleteEventModalOpen, (hasOpened, _o) => {
if (hasOpened && lastActiveEvent.value) {
eventSkeleton.value = { ...lastActiveEvent.value }
}
})
async function handleAction(): Promise<void> { async function handleAction(): Promise<void> {
if (isLoading.value) return if (isLoading.value) return
@@ -48,17 +41,6 @@ async function handleAction(): Promise<void> {
} }
} }
/**
* Prevents the modal from closing if's still loading
*
* @param e The closing event (can be keydown or click)
*/
function handleClosing(e: Event): void {
if (isLoading.value) {
e.preventDefault()
}
}
/** /**
* Click on the cancel button * Click on the cancel button
* *
@@ -71,22 +53,6 @@ function handleCancel(): void {
</script> </script>
<template> <template>
<UiAlertDialog v-model:open="isDeleteEventModalOpen">
<UiAlertDialogContent
:disable-outside-pointer-events="true"
:trap-focus="true"
class="min-w-96 border-indigo-200 dark:bg-slate-950 dark:border-indigo-950"
@escape-key-down="handleClosing"
@focus-outside="handleClosing"
@interact-outside="handleClosing"
@pointer-down-outside="handleClosing"
>
<UiAlertDialogTitle>{{ $t('entity.calendar.event.deleteDialog.title') }}</UiAlertDialogTitle>
<UiAlertDialogDescription>
{{ $t('entity.calendar.event.deleteDialog.subtitle') }}
</UiAlertDialogDescription>
<form @submit.prevent="handleAction"> <form @submit.prevent="handleAction">
<div class="grid grid-cols-2 gap-y-4"> <div class="grid grid-cols-2 gap-y-4">
<div class="text-red-500 ml-8"> <div class="text-red-500 ml-8">
@@ -118,6 +84,4 @@ function handleCancel(): void {
</div> </div>
</footer> </footer>
</form> </form>
</UiAlertDialogContent>
</UiAlertDialog>
</template> </template>

View File

@@ -4,7 +4,7 @@ import { useToast } from "~/components/ui/toast";
import type { APIError } from "~/models/Errors"; import type { APIError } from "~/models/Errors";
const { resetSkeleton, updateEventFromSkeleton, cancelLatestRequest } = useCalendar() const { resetSkeleton, updateEventFromSkeleton, cancelLatestRequest } = useCalendar()
const { eventSkeleton, lastActiveEvent, isEditEventModalOpen } = storeToRefs(useCalendar()) const { eventSkeleton, lastActiveEvent } = storeToRefs(useCalendar())
const { toast } = useToast() const { toast } = useToast()
const { t } = useI18n() const { t } = useI18n()
@@ -15,13 +15,6 @@ const formErrors = reactive<{ message: string | null }>({
message: null message: null
}) })
// Watch the popover state
watch(isEditEventModalOpen, (hasOpened, _o) => {
if (hasOpened && lastActiveEvent.value) {
eventSkeleton.value = { ...lastActiveEvent.value }
}
})
async function handleAction() { async function handleAction() {
if (isLoading.value) return if (isLoading.value) return
@@ -44,18 +37,6 @@ async function handleAction() {
} finally { } finally {
resetSkeleton() resetSkeleton()
isLoading.value = false isLoading.value = false
isEditEventModalOpen.value = false
}
}
/**
* Prevents the modal from closing if's still loading
*
* @param e The closing event (can be keydown or click)
*/
function handleClosing(e: Event) {
if (isLoading.value) {
e.preventDefault()
} }
} }
@@ -71,26 +52,6 @@ function handleCancel() {
</script> </script>
<template> <template>
<UiDialog v-model:open="isEditEventModalOpen">
<UiDialogContent
:disable-outside-pointer-events="true"
:trap-focus="true"
class="pl-3 min-w-96 border-indigo-200 dark:bg-slate-950 dark:border-indigo-950"
@escape-key-down="handleClosing"
@focus-outside="handleClosing"
@interact-outside="handleClosing"
@pointer-down-outside="(e) => e.preventDefault()"
>
<header class="pl-8 grid gap-y-2">
<UiDialogTitle>
{{ $t('entity.calendar.event.editDialog.title') }}
</UiDialogTitle>
<UiDialogDescription>
{{ $t('entity.calendar.event.editDialog.subtitle') }}
</UiDialogDescription>
</header>
<form @submit.prevent="handleAction"> <form @submit.prevent="handleAction">
<div class="grid grid-cols-2 gap-y-3"> <div class="grid grid-cols-2 gap-y-3">
<div class="col-span-2"> <div class="col-span-2">
@@ -239,6 +200,4 @@ function handleCancel() {
</UiButton> </UiButton>
</footer> </footer>
</form> </form>
</UiDialogContent>
</UiDialog>
</template> </template>