Skip to content

Commit

Permalink
Merge pull request #1530 from cityofaustin/mike/add-snackbar-to-dashb…
Browse files Browse the repository at this point in the history
…oard

Add snackbar to dashboard view
  • Loading branch information
mddilley authored Jan 30, 2025
2 parents b6e15a7 + 61beb1e commit 0494d08
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions moped-editor/src/views/dashboard/DashboardTimelineModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const DashboardTimelineModal = ({
projectId,
projectName,
dashboardRefetch,
handleSnackbar,
children,
}) => {
const classes = useStyles();
Expand Down Expand Up @@ -88,6 +89,7 @@ const DashboardTimelineModal = ({
loading={loading}
data={data}
refetch={refetch}
handleSnackbar={handleSnackbar}
/>
)}
{table === "milestones" && (
Expand All @@ -96,6 +98,7 @@ const DashboardTimelineModal = ({
loading={loading}
data={data}
refetch={refetch}
handleSnackbar={handleSnackbar}
/>
)}
</Box>
Expand Down
42 changes: 41 additions & 1 deletion moped-editor/src/views/dashboard/DashboardView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useCallback, useState } from "react";
import { useQuery } from "@apollo/client";
import { format } from "date-fns";

Expand All @@ -24,6 +24,7 @@ import DashboardStatusModal from "./DashboardStatusModal";
import DashboardTimelineModal from "./DashboardTimelineModal";
import ProjectStatusBadge from "../projects/projectView/ProjectStatusBadge";
import MilestoneProgressMeter from "./MilestoneProgressMeter";
import FeedbackSnackbar from "src/components/FeedbackSnackbar";

import typography from "../../theme/typography";

Expand Down Expand Up @@ -111,6 +112,38 @@ const DashboardView = () => {
fetchPolicy: "no-cache",
});

/* Snackbar state and handler for phase and milestone update feedback */
const [snackbarState, setSnackbarState] = useState(false);

/**
* Wrapper around snackbar state setter
* @param {boolean} open - The new state of open
* @param {String} message - The message for the snackbar
* @param {String} severity - The severity color of the snackbar
* @param {Object} error - The error to be displayed and logged
*/
const handleSnackbar = useCallback(
(open, message, severity, error) => {
// if there is an error, render error message,
// otherwise, render success message
if (error) {
setSnackbarState({
open: open,
message: `${message}. Refresh the page to try again.`,
severity: severity,
});
console.error(error);
} else {
setSnackbarState({
open: open,
message: message,
severity: severity,
});
}
},
[setSnackbarState]
);

if (error) {
console.log(error);
}
Expand Down Expand Up @@ -204,6 +237,7 @@ const DashboardView = () => {
projectId={entry.project_id}
projectName={entry.project.project_name_full}
dashboardRefetch={refetch}
handleSnackbar={handleSnackbar}
>
<ProjectStatusBadge
phaseName={entry.phase_name}
Expand All @@ -227,6 +261,7 @@ const DashboardView = () => {
modalParent="dashboard"
statusUpdate={entry.status_update}
queryRefetch={refetch}
handleSnackbar={handleSnackbar}
classes={classes}
>
{parse(String(entry.status_update))}
Expand All @@ -242,6 +277,7 @@ const DashboardView = () => {
table="milestones"
projectId={entry.project_id}
projectName={entry.project.project_name_full}
handleSnackbar={handleSnackbar}
dashboardRefetch={refetch}
>
<MilestoneProgressMeter
Expand Down Expand Up @@ -333,6 +369,10 @@ const DashboardView = () => {
</Grid>
</Card>
</Container>
<FeedbackSnackbar
snackbarState={snackbarState}
handleSnackbar={handleSnackbar}
/>
</Page>
</ActivityMetrics>
);
Expand Down

0 comments on commit 0494d08

Please sign in to comment.