diff --git a/components/calendar/Calendar.vue b/components/calendar/Calendar.vue index b16f81e..202e877 100644 --- a/components/calendar/Calendar.vue +++ b/components/calendar/Calendar.vue @@ -7,8 +7,6 @@ import CenturyLayout from './state/centennially/Layout.vue' import DecadeLayout from './state/decennially/Layout.vue' import YearLayout from './state/yearly/Layout.vue' -const { isAdvancedSearchOpen, isEditEventModalOpen } = storeToRefs(useCalendar()) - const route = useRoute() const worldId = route.params.id @@ -109,7 +107,8 @@ onMounted(() => { - - + + + diff --git a/components/calendar/CalendarEventDetails.vue b/components/calendar/CalendarEventDetails.vue index 9816ace..e588198 100644 --- a/components/calendar/CalendarEventDetails.vue +++ b/components/calendar/CalendarEventDetails.vue @@ -11,8 +11,8 @@ import { PhDotsThreeOutlineVertical } from '@phosphor-icons/vue' -const { defaultDate, getFormattedDateTitle, jumpToDate, revealEditEventModal, getRelativeString } = useCalendar() -const { deleteEvent } = useCalendarEvents() +const { defaultDate, getFormattedDateTitle, jumpToDate, getRelativeString } = useCalendar() +const { revealEditEventModal, revealDeleteEventModal } = useCalendarEvents() const { lastActiveEvent } = storeToRefs(useCalendarEvents()) const props = defineProps<{ @@ -47,6 +47,15 @@ function deployEditModal() { revealEditEventModal() commandMenuOpened.value = false } + +/** + * Confirm event deletion + */ +function deployDeleteModal() { + lastActiveEvent.value = { ...props.event } + revealDeleteEventModal() + commandMenuOpened.value = false +} @@ -146,7 +155,7 @@ function deployEditModal() { Modifier - Supprimer + Supprimer diff --git a/components/calendar/form/DeleteEvent.vue b/components/calendar/form/DeleteEvent.vue new file mode 100644 index 0000000..224d563 --- /dev/null +++ b/components/calendar/form/DeleteEvent.vue @@ -0,0 +1,69 @@ + + + + + + Supprimer l'évènement + + + Les données associés à cet évènement seront supprimées et vous ne pourrez plus les récupérer ! + + + + + + + {{ formErrors.message }} + + + + + + + + Annuler + + + Supprimer + + + + + diff --git a/components/calendar/form/UpdateEvent.vue b/components/calendar/form/UpdateEvent.vue index 58c4c8a..3347aba 100644 --- a/components/calendar/form/UpdateEvent.vue +++ b/components/calendar/form/UpdateEvent.vue @@ -2,7 +2,8 @@ import { PhAlarm } from '@phosphor-icons/vue' import { VisuallyHidden } from 'radix-vue' -const isModalOpened = defineModel({ default: false }) +const { isEditEventModalOpen } = storeToRefs(useCalendarEvents()) + const { resetSkeleton, updateEventFromSkeleton } = useCalendarEvents() const { eventSkeleton, lastActiveEvent } = storeToRefs(useCalendarEvents()) @@ -11,30 +12,30 @@ const formErrors = reactive<{ message: string | null }>({ }) // Watch the popover state -watch(isModalOpened, (hasOpened, _o) => { +watch(isEditEventModalOpen, (hasOpened, _o) => { if (hasOpened && lastActiveEvent.value) { eventSkeleton.value = { ...lastActiveEvent.value } - } else { - resetSkeleton() } }) -async function handleSubmit() { +async function handleAction() { try { await updateEventFromSkeleton() - isModalOpened.value = false + isEditEventModalOpen.value = false } catch (err) { if (err instanceof Error) { formErrors.message = err.message } + } finally { + resetSkeleton() } } - - + - Modifier l'évènement + Modifier l'évènement - + Mettre à jour les données de l'évènement - + - + - - - - Sauvegarder - - - - + + + Annuler + + + Sauvegarder + + + + diff --git a/components/calendar/search/CalendarSearch.vue b/components/calendar/search/CalendarSearch.vue index 2b2a457..74dba7b 100644 --- a/components/calendar/search/CalendarSearch.vue +++ b/components/calendar/search/CalendarSearch.vue @@ -27,10 +27,9 @@ import { import SearchList from './lists/SearchList.vue' import type { Category } from '~/models/Category' -const { characters } = storeToRefs(useCharacters()) +const { isAdvancedSearchOpen } = storeToRefs(useCalendar()) const { allEvents } = storeToRefs(useCalendarEvents()) - -const modalOpen = defineModel({ default: false }) +const { characters } = storeToRefs(useCharacters()) const searchQuery = ref('') // const searchEnough = computed(() => searchQuery.value.length >= 2) @@ -170,14 +169,14 @@ function resetSearch() { * Opens the search Uidialog */ function openUiDialog() { - modalOpen.value = true + isAdvancedSearchOpen.value = true } /** * Closes the search Uidialog */ function closeUiDialog() { - modalOpen.value = false + isAdvancedSearchOpen.value = false } /** @@ -233,7 +232,7 @@ function handleCategorySelect(e: (Category)) { - + +import { type AlertDialogEmits, type AlertDialogProps, AlertDialogRoot, useForwardPropsEmits } from 'radix-vue' + +const props = defineProps() +const emits = defineEmits() + +const forwarded = useForwardPropsEmits(props, emits) + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogAction.vue b/components/ui/alert-dialog/AlertDialogAction.vue new file mode 100644 index 0000000..d3414bf --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogAction.vue @@ -0,0 +1,20 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogCancel.vue b/components/ui/alert-dialog/AlertDialogCancel.vue new file mode 100644 index 0000000..08302c0 --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogCancel.vue @@ -0,0 +1,20 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogContent.vue b/components/ui/alert-dialog/AlertDialogContent.vue new file mode 100644 index 0000000..9f09909 --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogContent.vue @@ -0,0 +1,42 @@ + + + + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogDescription.vue b/components/ui/alert-dialog/AlertDialogDescription.vue new file mode 100644 index 0000000..9682cbb --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogDescription.vue @@ -0,0 +1,25 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogFooter.vue b/components/ui/alert-dialog/AlertDialogFooter.vue new file mode 100644 index 0000000..55d0a0e --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogFooter.vue @@ -0,0 +1,21 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogHeader.vue b/components/ui/alert-dialog/AlertDialogHeader.vue new file mode 100644 index 0000000..c61c449 --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogHeader.vue @@ -0,0 +1,16 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogTitle.vue b/components/ui/alert-dialog/AlertDialogTitle.vue new file mode 100644 index 0000000..50c583d --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogTitle.vue @@ -0,0 +1,22 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogTrigger.vue b/components/ui/alert-dialog/AlertDialogTrigger.vue new file mode 100644 index 0000000..4f5e2fd --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogTrigger.vue @@ -0,0 +1,11 @@ + + + + + + + diff --git a/components/ui/alert-dialog/index.ts b/components/ui/alert-dialog/index.ts new file mode 100644 index 0000000..91d138a --- /dev/null +++ b/components/ui/alert-dialog/index.ts @@ -0,0 +1,9 @@ +export { default as AlertDialog } from './AlertDialog.vue' +export { default as AlertDialogTrigger } from './AlertDialogTrigger.vue' +export { default as AlertDialogContent } from './AlertDialogContent.vue' +export { default as AlertDialogHeader } from './AlertDialogHeader.vue' +export { default as AlertDialogTitle } from './AlertDialogTitle.vue' +export { default as AlertDialogDescription } from './AlertDialogDescription.vue' +export { default as AlertDialogFooter } from './AlertDialogFooter.vue' +export { default as AlertDialogAction } from './AlertDialogAction.vue' +export { default as AlertDialogCancel } from './AlertDialogCancel.vue' diff --git a/stores/CalendarStore.ts b/stores/CalendarStore.ts index 1b7fe75..2d9fd4f 100644 --- a/stores/CalendarStore.ts +++ b/stores/CalendarStore.ts @@ -298,15 +298,6 @@ export const useCalendar = defineStore('calendar', () => { isAdvancedSearchOpen.value = true } - /** - * State for advanced search modal - */ - const isEditEventModalOpen: Ref = ref(false) - - function revealEditEventModal() { - isEditEventModalOpen.value = true - } - /** * Switches the active viewType * @@ -649,8 +640,6 @@ export const useCalendar = defineStore('calendar', () => { isCurrentScreenActive, isAdvancedSearchOpen, revealAdvancedSearch, - isEditEventModalOpen, - revealEditEventModal, convertDateToDays, getDifferenceInDays, areDatesIdentical, diff --git a/stores/EventStore.ts b/stores/EventStore.ts index d703b5a..454bd24 100644 --- a/stores/EventStore.ts +++ b/stores/EventStore.ts @@ -165,6 +165,24 @@ export const useCalendarEvents = defineStore('calendar-events', () => { } } + /** + * State for event modal edition + */ + const isEditEventModalOpen: Ref = ref(false) + + function revealEditEventModal() { + isEditEventModalOpen.value = true + } + + /** + * State for event modal edition + */ + const isDeleteEventModalOpen: Ref = ref(false) + + function revealDeleteEventModal() { + isDeleteEventModalOpen.value = true + } + /** * EVENT CREATION FUNCTIONS */ @@ -205,19 +223,31 @@ export const useCalendarEvents = defineStore('calendar-events', () => { } } - async function deleteEvent(eventId: number) { - if (!eventId) { - throw new Error('ID of the event is required') - } - + async function deleteEventFromSkeleton() { try { - await $fetch(`/api/calendars/events/${eventId}`, { method: 'DELETE' }) - const eventIndex = baseEvents.value.findIndex(e => e.id === eventId) + await $fetch(`/api/calendars/events/${eventSkeleton.value.id}`, { method: 'DELETE' }) + const eventIndex = baseEvents.value.findIndex(e => e.id === eventSkeleton.value.id) baseEvents.value.splice(eventIndex, 1) } catch (err) { console.log(err) } } - return { allEvents, setEvents, currentEvents, getRelativeEventFromDate, getRelativeEventFromEvent, eventSkeleton, resetSkeleton, submitSkeleton, lastActiveEvent, updateEventFromSkeleton, deleteEvent } + return { + allEvents, + setEvents, + currentEvents, + getRelativeEventFromDate, + getRelativeEventFromEvent, + eventSkeleton, + resetSkeleton, + submitSkeleton, + lastActiveEvent, + updateEventFromSkeleton, + deleteEventFromSkeleton, + isEditEventModalOpen, + revealEditEventModal, + isDeleteEventModalOpen, + revealDeleteEventModal + } })