Added loading and cancelling to deleting popover
This commit is contained in:
@@ -1,9 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { PhCircleNotch } from '@phosphor-icons/vue';
|
||||||
|
|
||||||
const { isDeleteEventModalOpen } = storeToRefs(useCalendarEvents())
|
const { isDeleteEventModalOpen } = storeToRefs(useCalendarEvents())
|
||||||
|
|
||||||
const { resetSkeleton, deleteEventFromSkeleton } = useCalendarEvents()
|
const { resetSkeleton, deleteEventFromSkeleton, cancelLatestRequest } = useCalendarEvents()
|
||||||
const { eventSkeleton, lastActiveEvent } = storeToRefs(useCalendarEvents())
|
const { eventSkeleton, lastActiveEvent } = storeToRefs(useCalendarEvents())
|
||||||
|
|
||||||
|
const isLoading = ref(false)
|
||||||
|
|
||||||
const formErrors = reactive<{ message: string | null }>({
|
const formErrors = reactive<{ message: string | null }>({
|
||||||
message: null
|
message: null
|
||||||
})
|
})
|
||||||
@@ -16,6 +20,10 @@ watch(isDeleteEventModalOpen, (hasOpened, _o) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
async function handleAction() {
|
async function handleAction() {
|
||||||
|
if (isLoading.value) return
|
||||||
|
|
||||||
|
isLoading.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deleteEventFromSkeleton()
|
await deleteEventFromSkeleton()
|
||||||
|
|
||||||
@@ -26,8 +34,30 @@ async function handleAction() {
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
resetSkeleton()
|
resetSkeleton()
|
||||||
|
isLoading.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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Click on the cancel button
|
||||||
|
*
|
||||||
|
* Must cancel the abortController in the store, and stop the loading
|
||||||
|
*/
|
||||||
|
function handleCancel() {
|
||||||
|
cancelLatestRequest()
|
||||||
|
isLoading.value = false
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -39,6 +69,10 @@ async function handleAction() {
|
|||||||
:disable-outside-pointer-events="true"
|
:disable-outside-pointer-events="true"
|
||||||
:trap-focus="true"
|
:trap-focus="true"
|
||||||
class="min-w-96 bg-slate-900 border-slate-800"
|
class="min-w-96 bg-slate-900 border-slate-800"
|
||||||
|
@escape-key-down="handleClosing"
|
||||||
|
@focus-outside="handleClosing"
|
||||||
|
@interact-outside="handleClosing"
|
||||||
|
@pointer-down-outside="handleClosing"
|
||||||
>
|
>
|
||||||
<UiAlertDialogTitle> Supprimer l'évènement</UiAlertDialogTitle>
|
<UiAlertDialogTitle> Supprimer l'évènement</UiAlertDialogTitle>
|
||||||
|
|
||||||
@@ -46,7 +80,7 @@ async function handleAction() {
|
|||||||
Les données associés à cet évènement seront supprimées et vous ne pourrez plus les récupérer !
|
Les données associés à cet évènement seront supprimées et vous ne pourrez plus les récupérer !
|
||||||
</UiAlertDialogDescription>
|
</UiAlertDialogDescription>
|
||||||
|
|
||||||
<form>
|
<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">
|
||||||
<span class="text-sm">
|
<span class="text-sm">
|
||||||
@@ -54,16 +88,23 @@ async function handleAction() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
|
|
||||||
<UiAlertDialogFooter>
|
<footer class="flex gap-2 justify-end">
|
||||||
<UiAlertDialogCancel>
|
<Transition name="fade-delay">
|
||||||
Annuler
|
<UiButton v-if="isLoading" type="button" size="sm" variant="destructive" @click.prevent="handleCancel">
|
||||||
</UiAlertDialogCancel>
|
Annuler
|
||||||
<UiAlertDialogAction class="destructive" @click="handleAction">
|
</UiButton>
|
||||||
Supprimer
|
</Transition>
|
||||||
</UiAlertDialogAction>
|
|
||||||
</UiAlertDialogFooter>
|
<UiButton size="sm" :disabled="isLoading">
|
||||||
|
<Transition name="fade">
|
||||||
|
<PhCircleNotch v-if="isLoading" size="20" class="animate-spin"/>
|
||||||
|
</Transition>
|
||||||
|
|
||||||
|
Supprimer
|
||||||
|
</UiButton>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
</UiAlertDialogContent>
|
</UiAlertDialogContent>
|
||||||
</UiAlertDialog>
|
</UiAlertDialog>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ function handleCancel() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex gap-2 justify-end">
|
<footer class="flex gap-2 justify-end">
|
||||||
<Transition name="fade-delay">
|
<Transition name="fade-delay">
|
||||||
<UiButton v-if="isLoading" type="button" size="sm" variant="destructive" @click.prevent="handleCancel">
|
<UiButton v-if="isLoading" type="button" size="sm" variant="destructive" @click.prevent="handleCancel">
|
||||||
Annuler
|
Annuler
|
||||||
@@ -160,9 +160,9 @@ function handleCancel() {
|
|||||||
<PhCircleNotch v-if="isLoading" size="20" class="animate-spin"/>
|
<PhCircleNotch v-if="isLoading" size="20" class="animate-spin"/>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
||||||
Sauvegarder
|
Enregistrer
|
||||||
</UiButton>
|
</UiButton>
|
||||||
</div>
|
</footer>
|
||||||
</form>
|
</form>
|
||||||
</UiAlertDialogContent>
|
</UiAlertDialogContent>
|
||||||
</UiAlertDialog>
|
</UiAlertDialog>
|
||||||
|
|||||||
Reference in New Issue
Block a user