Skip to content

Commit d5e1b99

Browse files
authored
Merge pull request #1181 from JulianKniephoff/unused-stuff
Some minor refactorings
2 parents 458a674 + 28e822b commit d5e1b99

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

src/components/events/partials/modals/EventDetails.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ export type AssetTabHierarchy = "entry" | "add-asset" | "asset-attachments" | "a
7272
*/
7373
const EventDetails = ({
7474
eventId,
75-
close,
7675
policyChanged,
7776
setPolicyChanged,
7877
formikRef,
7978
}: {
8079
eventId: string,
81-
close?: () => void,
8280
policyChanged: boolean,
8381
setPolicyChanged: (value: boolean) => void,
8482
formikRef: React.RefObject<FormikProps<any> | null>

src/components/events/partials/modals/EventDetailsModal.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useAppDispatch, useAppSelector } from "../../../../store";
55
import { removeNotificationWizardForm } from "../../../../slices/notificationSlice";
66
import { getModalEvent } from "../../../../selectors/eventDetailsSelectors";
77
import { setModalEvent, setShowModal } from "../../../../slices/eventDetailsSlice";
8-
import { Modal, ModalHandle } from "../../../shared/modals/Modal";
8+
import { Modal } from "../../../shared/modals/Modal";
99
import { FormikProps } from "formik";
1010

1111
/**
@@ -14,7 +14,6 @@ import { FormikProps } from "formik";
1414
const EventDetailsModal = () => {
1515
const { t } = useTranslation();
1616
const dispatch = useAppDispatch();
17-
const modalRef = useRef<ModalHandle>(null);
1817

1918
// tracks, whether the policies are different to the initial value
2019
const [policyChanged, setPolicyChanged] = useState(false);
@@ -53,7 +52,6 @@ const EventDetailsModal = () => {
5352
closeCallback={close}
5453
header={t("EVENTS.EVENTS.DETAILS.HEADER", { name: event.title })}
5554
classId="details-modal"
56-
ref={modalRef}
5755
>
5856
<EventDetails
5957
eventId={event.id}

src/components/shared/modals/Modal.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { forwardRef, PropsWithChildren, useImperativeHandle, useState } from "react";
1+
import { forwardRef, PropsWithChildren, useCallback, useImperativeHandle, useState } from "react";
22
import ReactDOM from "react-dom";
33
import { useHotkeys } from "react-hotkeys-hook";
44
import { availableHotkeys } from "../../../configs/hotkeysConfig";
@@ -40,23 +40,23 @@ export const Modal = forwardRef<ModalHandle, PropsWithChildren<ModalProps>>(({
4040
const { t } = useTranslation();
4141

4242
const [isOpen, setOpen] = useState(open);
43+
const close = useCallback(() => {
44+
if (closeCallback !== undefined && !closeCallback()) {
45+
// Don't close modal
46+
return;
47+
}
48+
setOpen(false);
49+
}, [closeCallback]);
4350

4451
useImperativeHandle(ref, () => ({
4552
isOpen: () => isOpen,
4653
open: () => setOpen(true),
47-
close: () => {
48-
if (closeCallback !== undefined && !closeCallback()) {
49-
// Don't close modal
50-
return;
51-
}
52-
setOpen(false);
53-
},
54-
}), [closeCallback, isOpen]);
54+
close,
55+
}), [close, isOpen]);
5556

5657
useHotkeys(
5758
availableHotkeys.general.CLOSE_MODAL.sequence,
58-
//@ts-expect-error: TODO: Figure out what typescripts problem is
59-
() => ref?.current.close?.(),
59+
close,
6060
{ description: t(availableHotkeys.general.CLOSE_MODAL.description) ?? undefined },
6161
[ref],
6262
);
@@ -72,8 +72,7 @@ export const Modal = forwardRef<ModalHandle, PropsWithChildren<ModalProps>>(({
7272
<header>
7373
<ButtonLikeAnchor
7474
extraClassName="fa fa-times close-modal"
75-
//@ts-expect-error: TODO: Figure out what typescripts problem is
76-
onClick={() => ref?.current.close?.()}
75+
onClick={close}
7776
tabIndex={0}
7877
/>
7978
<h2>

0 commit comments

Comments
 (0)