From f189e8c59796ea4d5d0e4e589691b08f474aa3a6 Mon Sep 17 00:00:00 2001 From: Morgan Ludtke <42942267+ludtkemorgan@users.noreply.github.com> Date: Wed, 12 Jun 2024 17:18:44 -0500 Subject: [PATCH] fix: add error message for incorrect listing approval (#4134) --- .../src/components/listings/ListingFormActions.tsx | 12 ++++++++++-- sites/partners/src/pages/listings/[id]/index.tsx | 11 +++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sites/partners/src/components/listings/ListingFormActions.tsx b/sites/partners/src/components/listings/ListingFormActions.tsx index 39fc1156df..4af89b611a 100644 --- a/sites/partners/src/components/listings/ListingFormActions.tsx +++ b/sites/partners/src/components/listings/ListingFormActions.tsx @@ -28,6 +28,7 @@ type ListingFormActionsProps = { showRequestChangesModal?: () => void showSubmitForApprovalModal?: () => void submitFormWithStatus?: (confirm?: boolean, status?: ListingsStatusEnum) => void + setErrorAlert?: (alertMessage: string) => void } const ListingFormActions = ({ @@ -37,6 +38,7 @@ const ListingFormActions = ({ showRequestChangesModal, showSubmitForApprovalModal, submitFormWithStatus, + setErrorAlert, }: ListingFormActionsProps) => { const listing = useContext(ListingContext) const { profile, listingsService } = useContext(AuthContext) @@ -270,10 +272,16 @@ const ListingFormActions = ({ await router.push(`/`) } } catch (err) { + // if it is a bad request (is missing fields or incorrect data) then display an error banner + if (err.response?.status === 400) { + setErrorAlert( + "There are errors in this listing that must be resolved before publishing. To see the errors, please try to approve this listing from the edit view." + ) + } addToast( err.response?.data?.message === "email failed" - ? "errors.alert.listingsApprovalEmailError" - : "errors.somethingWentWrong", + ? t("errors.alert.listingsApprovalEmailError") + : t("errors.somethingWentWrong"), { variant: "warn" } ) } diff --git a/sites/partners/src/pages/listings/[id]/index.tsx b/sites/partners/src/pages/listings/[id]/index.tsx index 3be1b33468..723f66a8b5 100644 --- a/sites/partners/src/pages/listings/[id]/index.tsx +++ b/sites/partners/src/pages/listings/[id]/index.tsx @@ -42,7 +42,7 @@ interface ListingProps { export default function ListingDetail(props: ListingProps) { const { listing } = props - const [errorAlert, setErrorAlert] = useState(false) + const [errorAlert, setErrorAlert] = useState(null) const [unitDrawer, setUnitDrawer] = useState(null) if (!listing) return null @@ -80,11 +80,11 @@ export default function ListingDetail(props: ListingProps) { {errorAlert && ( setErrorAlert(false)} + onClose={() => setErrorAlert(null)} closeable type="alert" > - {t("authentication.signIn.errorGenericMessage")} + {errorAlert || t("authentication.signIn.errorGenericMessage")} )} @@ -111,7 +111,10 @@ export default function ListingDetail(props: ListingProps) {
- +