Skip to content

Commit

Permalink
chore: Refactor toast (#538)
Browse files Browse the repository at this point in the history
* Refactor toast so it's not just for errors.

* Address PR feedback.
  • Loading branch information
cmaddox5 authored Oct 25, 2024
1 parent 978c86c commit 89faf7c
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 96 deletions.
38 changes: 0 additions & 38 deletions assets/css/dashboard/error-toast.scss

This file was deleted.

52 changes: 52 additions & 0 deletions assets/css/dashboard/toast.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.toast-container {
margin-bottom: 40px;

.toast {
font-size: 16px;
display: flex;
align-items: center;

.btn-close {
&:hover {
background-color: transparent;
}
}

&--warning {
background-color: $alert-yellow;
}

&--info {
background-color: $accessibility-blue;
color: white;
}

&__icon {
height: 24px;
width: 24px;
opacity: 60%;
flex-shrink: 0;
}

&__text {
padding-left: 8px;

ul {
margin-bottom: 0;
}
}
}

.toast-header {
.btn-close {
margin-right: 4px;

&:hover {
background-color: transparent;
}
}

border: none;
border-radius: 4px;
}
}
2 changes: 1 addition & 1 deletion assets/css/screenplay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $form-feedback-invalid-color: $text-error;
@import "sort-label.scss";
@import "search-bar.scss";
@import "dashboard/picker.scss";
@import "dashboard/error-toast.scss";
@import "dashboard/toast.scss";

html {
font-size: 16px;
Expand Down
1 change: 1 addition & 0 deletions assets/css/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ $button-secondary-outline-active-bg: #d9d9d93d;
$text-button-blue-hover-color: #c1e4ff14;
$text-button-grey-hover-color: #f8f9fa14;
$alert-yellow: #ffdd00;
$accessibility-blue: #165c96;
54 changes: 0 additions & 54 deletions assets/js/components/Dashboard/ErrorToast.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SelectStationsAndZones from "./SelectStationsAndZones";
import AssociateAlert from "./AssociateAlert";
import { Alert, InformedEntity } from "Models/alert";
import { usePlacesWithPaEss } from "Hooks/usePlacesWithPaEss";
import ErrorToast from "Components/ErrorToast";
import Toast from "Components/Toast";
import { busRouteIdsAtPlaces, getRouteIdsForSign } from "../../../util";
import fp from "lodash/fp";

Expand Down Expand Up @@ -217,8 +217,9 @@ const PaMessageForm = ({
setEndWithEffectPeriod={setEndWithEffectPeriod}
/>
)}
<ErrorToast
errorMessage={errorMessage}
<Toast
variant="warning"
message={errorMessage}
errors={errors}
onClose={() => {
onErrorsChange([]);
Expand Down
63 changes: 63 additions & 0 deletions assets/js/components/Dashboard/Toast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from "react";
import { Toast as BSToast, ToastContainer } from "react-bootstrap";
import {
CheckCircleFill,
ExclamationTriangleFill,
} from "react-bootstrap-icons";
import { classWithModifier } from "../../util";

interface ToastProps {
variant: "warning" | "info";
message: string | null;
errors?: string[];
onClose?: () => void;
}

const Toast = ({ message, errors = [], onClose, variant }: ToastProps) => {
const getErrorMessageFromField = (error: string) => {
switch (error) {
case "sign_ids":
return "Add Stations & Zones";
case "visual_text":
return "Visual Text";
case "audio_text":
return "Phonetic Audio";
case "start_datetime":
return "Start date/time";
case "end_datetime":
return "End date/time";
default:
return "";
}
};

const Icon =
variant === "warning" ? ExclamationTriangleFill : CheckCircleFill;

return (
<ToastContainer position="bottom-center" className="toast-container">
<BSToast
show={message != null}
onClose={onClose}
delay={5000}
autohide={true}
>
<BSToast.Header className={classWithModifier("toast", variant)}>
{<Icon className="toast__icon" />}
<div className="toast__text">
{message}
{errors.length > 0 && (
<ul>
{errors.map((error, i) => {
return <li key={i}>{getErrorMessageFromField(error)}</li>;
})}
</ul>
)}
</div>
</BSToast.Header>
</BSToast>
</ToastContainer>
);
};

export default Toast;

0 comments on commit 89faf7c

Please sign in to comment.