diff --git a/src/apps/opening-hours-editor/Dialog.tsx b/src/apps/opening-hours-editor/Dialog.tsx new file mode 100644 index 0000000000..f0623f5747 --- /dev/null +++ b/src/apps/opening-hours-editor/Dialog.tsx @@ -0,0 +1,39 @@ +// The dialog element allready has keyboard support +/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ +/* eslint-disable jsx-a11y/click-events-have-key-events */ +import React, { forwardRef } from "react"; + +type DialogType = { + children: React.ReactNode; + closeDialog: () => void; +}; + +const Dialog = forwardRef( + ({ children, closeDialog }, ref) => { + return ( + { + if (currentTarget === target) { + closeDialog(); + } + }} + > + + {children} + + ); + } +); +export default Dialog; diff --git a/src/apps/opening-hours-editor/DialogFomular.tsx b/src/apps/opening-hours-editor/DialogFomular.tsx new file mode 100644 index 0000000000..d86500d455 --- /dev/null +++ b/src/apps/opening-hours-editor/DialogFomular.tsx @@ -0,0 +1,35 @@ +import React from "react"; +import { EventImpl } from "@fullcalendar/core/internal"; + +type DialogFomularProps = { + evnetInfo: EventImpl; + handleEventEditing: (title: string) => void; +}; + +const DialogFomular: React.FC = ({ + evnetInfo, + handleEventEditing +}) => { + return ( + <> +

DialogFomular:

+
{JSON.stringify(evnetInfo, null, 2)}
+
+ {/* Should be type submit */} + +
+ + ); +}; + +export default DialogFomular; diff --git a/src/apps/opening-hours-editor/OpeningHoursEditor.tsx b/src/apps/opening-hours-editor/OpeningHoursEditor.tsx index 7506c7cc0d..0a0061deb3 100644 --- a/src/apps/opening-hours-editor/OpeningHoursEditor.tsx +++ b/src/apps/opening-hours-editor/OpeningHoursEditor.tsx @@ -6,35 +6,54 @@ import interactionPlugin from "@fullcalendar/interaction"; import da from "@fullcalendar/core/locales/da"; import OpeningHoursEditorEventContent from "./OpeningHoursEditorEventContent"; import useOpeningHours from "./useOpeningHours"; +import DialogFomular from "./DialogFomular"; +import Dialog from "./Dialog"; +import useDialog from "./useDialog"; const OpeningHoursEditor: React.FC = () => { - const { events, handleEventSelect, handleEventClick, handleEventRemove } = + const { events, handleEventSelect, handleEventEditing, handleEventRemove } = useOpeningHours(); + const { dialogContent, openDialogWithContent, closeDialog, dialogRef } = + useDialog(); + return ( - - OpeningHoursEditorEventContent({ - eventInput, - handleEventRemove - }) - } - events={events} - stickyHeaderDates - height="auto" - selectMirror - /> + <> + + {dialogContent} + + + + openDialogWithContent( + + ) + } + eventContent={(eventInput) => + OpeningHoursEditorEventContent({ + eventInput, + handleEventRemove + }) + } + events={events} + stickyHeaderDates + height="auto" + selectMirror + /> + ); }; diff --git a/src/apps/opening-hours-editor/useDialog.tsx b/src/apps/opening-hours-editor/useDialog.tsx new file mode 100644 index 0000000000..60d19bfd1c --- /dev/null +++ b/src/apps/opening-hours-editor/useDialog.tsx @@ -0,0 +1,25 @@ +import { useRef, useState } from "react"; + +const useDialog = () => { + const [dialogContent, setDialogContent] = useState(null); + + const dialogRef = useRef(null); + + const closeDialog = () => { + dialogRef.current?.close(); + }; + + const openDialogWithContent = (content: React.ReactNode) => { + setDialogContent(content); + dialogRef.current?.showModal(); + }; + + return { + dialogContent, + dialogRef, + openDialogWithContent, + closeDialog + }; +}; + +export default useDialog; diff --git a/src/apps/opening-hours-editor/useOpeningHours.tsx b/src/apps/opening-hours-editor/useOpeningHours.tsx index 81799ca1a5..88664085bb 100644 --- a/src/apps/opening-hours-editor/useOpeningHours.tsx +++ b/src/apps/opening-hours-editor/useOpeningHours.tsx @@ -53,6 +53,7 @@ const useOpeningHours = () => { calendarApi.unselect(); }; + // This will probably be replaced with handleEventEditing const handleEventClick = (clickInfo: EventClickArg) => { // eslint-disable-next-line no-alert const newTitle = prompt( @@ -65,6 +66,11 @@ const useOpeningHours = () => { } }; + const handleEventEditing = (string: string) => { + // eslint-disable-next-line no-alert + alert(string); + }; + const handleEventRemove = (eventToRemove: EventInput) => { setEvents(events.filter((event) => event.id !== eventToRemove.id)); }; @@ -73,7 +79,8 @@ const useOpeningHours = () => { events, handleEventSelect, handleEventClick, - handleEventRemove + handleEventRemove, + handleEventEditing }; };