From 469c426e0560d4c72a5c727afed22950ea919b74 Mon Sep 17 00:00:00 2001 From: Brett Heath-Wlaz Date: Thu, 31 Oct 2024 14:34:11 -0400 Subject: [PATCH] fix crash when canceling alert association (#547) --- .../PaMessageForm/AssociateAlert.tsx | 118 ++++++------------ .../Dashboard/PaMessageForm/PaMessageForm.tsx | 24 ++-- 2 files changed, 52 insertions(+), 90 deletions(-) diff --git a/assets/js/components/Dashboard/PaMessageForm/AssociateAlert.tsx b/assets/js/components/Dashboard/PaMessageForm/AssociateAlert.tsx index 6579c6c39..11e7444ae 100644 --- a/assets/js/components/Dashboard/PaMessageForm/AssociateAlert.tsx +++ b/assets/js/components/Dashboard/PaMessageForm/AssociateAlert.tsx @@ -1,10 +1,4 @@ -import React, { - Dispatch, - SetStateAction, - ComponentType, - useState, - useEffect, -} from "react"; +import React, { useState, useEffect } from "react"; import { Button, Container, @@ -15,32 +9,25 @@ import { Form, } from "react-bootstrap"; import { fetchActiveAndFutureAlerts } from "Utils/api"; -import { Alert, InformedEntity } from "Models/alert"; +import { Alert } from "Models/alert"; import classNames from "classnames"; import { getAlertEarliestStartLatestEnd } from "../../../util"; -import { Page } from "./types"; import moment from "moment"; interface AssociateAlertPageProps { - associatedAlert: Alert | string | null; - endWithEffectPeriod: boolean; - onImportMessage: (message: string) => void; - onImportLocations: (informedEntities: InformedEntity[]) => void; - navigateTo: (page: Page) => void; - setAssociatedAlert: Dispatch>; - setEndWithEffectPeriod: Dispatch>; + onApply: ( + alert: Alert, + endWithEffectPeriod: boolean, + importLocations: boolean, + importMessage: boolean, + ) => void; + onCancel: () => void; } -const AssociateAlert = ({ - associatedAlert, - endWithEffectPeriod, - onImportMessage, - onImportLocations, - navigateTo, - setAssociatedAlert, - setEndWithEffectPeriod, -}: AssociateAlertPageProps) => { +const AssociateAlert = ({ onApply, onCancel }: AssociateAlertPageProps) => { const [alerts, setAlerts] = useState([]); + const [selectedAlert, setSelectedAlert] = useState(null); + const [endWithEffectPeriod, setEndWithEffectPeriod] = useState(true); const [importLocations, setImportLocations] = useState(true); const [importMessage, setImportMessage] = useState(true); @@ -53,9 +40,6 @@ const AssociateAlert = ({ const [selectedMessageState, setSelectedMessageState] = useState("active"); const [selectedServiceType, setSelectedServiceType] = useState("All"); - const [showAlertModal, setShowAlertModal] = useState( - associatedAlert != null, - ); const serviceTypes = [ "All", @@ -76,7 +60,7 @@ const AssociateAlert = ({

Select alert to associate with PA/ESS Message

- @@ -132,22 +116,18 @@ const AssociateAlert = ({ - + { - setAssociatedAlert({} as Alert); - setShowAlertModal(false); - }} + onHide={() => setSelectedAlert(null)} > Select items from alert @@ -158,14 +138,10 @@ const AssociateAlert = ({ Alert ID:{" "}
- {typeof associatedAlert === "string" - ? associatedAlert - : associatedAlert?.id} + {selectedAlert?.id}
- {typeof associatedAlert === "string" - ? null - : associatedAlert?.header} + {selectedAlert?.header}
diff --git a/assets/js/components/Dashboard/PaMessageForm/PaMessageForm.tsx b/assets/js/components/Dashboard/PaMessageForm/PaMessageForm.tsx index bb44b31b9..50a744453 100644 --- a/assets/js/components/Dashboard/PaMessageForm/PaMessageForm.tsx +++ b/assets/js/components/Dashboard/PaMessageForm/PaMessageForm.tsx @@ -211,13 +211,23 @@ const PaMessageForm = ({ )} {page === Page.ALERTS && ( { + setAssociatedAlert(alert); + setEndWithEffectPeriod(endWithEffectPeriod); + if (importLocations) { + onImportLocations(alert.informed_entities); + } + if (importMessage) { + onImportMessage(alert.header); + } + setPage(Page.MAIN); + }} + onCancel={() => setPage(Page.MAIN)} /> )}