From ffc8b65474c3dd24fe75eb7d3f2f1a8ab9550278 Mon Sep 17 00:00:00 2001 From: "Efrain A. Davila" <105945226+EfrainAD@users.noreply.github.com> Date: Tue, 10 Oct 2023 00:22:37 -0400 Subject: [PATCH 1/4] fixed: Fixed broken servey link in the assingment table 1. Added a useGetHomesQuery to get the survey_visit_ids 2. When home clicked to view survey, it look up visit id from useGetHomesQuery array 3. Made the link to use the above, and display null if there is no survey --- .../pages/Admin/assignment/AssignProfile.js | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/frontend/front/src/pages/Admin/assignment/AssignProfile.js b/frontend/front/src/pages/Admin/assignment/AssignProfile.js index dc415ec2..7344691c 100644 --- a/frontend/front/src/pages/Admin/assignment/AssignProfile.js +++ b/frontend/front/src/pages/Admin/assignment/AssignProfile.js @@ -1,6 +1,7 @@ import { Box, Button, Stack, Typography } from "@mui/material"; import { useGetAssignmentQuery, + useGetHomesQuery, useGetSurveyorsQuery, } from "../../../api/apiSlice"; import { @@ -14,7 +15,7 @@ import { DataGrid } from "@mui/x-data-grid"; import Loader from "../../../components/Loader"; import React from "react"; import { getAddress } from "../home/HomeTable"; -import { useParams } from "react-router-dom"; +import { useNavigate, useParams } from "react-router-dom"; import { adminAssignmentProfile, ADMIN_ASSIGNMENT, @@ -24,6 +25,7 @@ import { const AssignProfile = () => { const { aid } = useParams(); const goToBreadcrumb = useGoToBreadcrumb(); + const navigate = useNavigate(); useInitBreadcrumbs([ { url: withAdminPrefix(ADMIN_ASSIGNMENT), description: "assignments" }, @@ -45,12 +47,23 @@ const AssignProfile = () => { isLoading: isSurveyorsDataLoading, } = useGetSurveyorsQuery(); + const { data: homesData } = useGetHomesQuery(); + const surveyors = surveyorsData ? surveyorsData.filter((surveyor) => assignmentData?.surveyor_ids.includes(surveyor.id) ) : "Unassigned"; + const handleSurveyLink = (home) => { + const homeData = homesData.find((homeData) => homeData.id === home.id); + const surveyVisitIds = + homeData.survey_visit_ids.length > 0 + ? homeData.survey_visit_ids[0] + : null; + + navigate(`/admin/survey/visit/${surveyVisitIds}`); + }; const handleUserLink = (user) => goToBreadcrumb("user", user); const handleHomeLink = (home) => { goToBreadcrumb("home", home); @@ -103,16 +116,18 @@ const AssignProfile = () => { headerName: "Survey", minWidth: 50, maxWidth: 80, - renderCell: (params) => ( - - ), + renderCell: (params) => + params.row.completed ? ( + + ) : null, }, { field: "unassign", From 64c62376508325d9692f32bb5a6bc209ec2167a6 Mon Sep 17 00:00:00 2001 From: "Efrain A. Davila" <105945226+EfrainAD@users.noreply.github.com> Date: Fri, 13 Oct 2023 18:17:48 -0400 Subject: [PATCH 2/4] feature: Add a dropdown button component for survey links. 1. Implement a button that will take the user to the survey, or display a dropdown if there is more then on survey 2. Then the user can click on the survey that they want to go to. --- frontend/front/src/components/SurveyLink.js | 44 +++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 frontend/front/src/components/SurveyLink.js diff --git a/frontend/front/src/components/SurveyLink.js b/frontend/front/src/components/SurveyLink.js new file mode 100644 index 00000000..b87565f9 --- /dev/null +++ b/frontend/front/src/components/SurveyLink.js @@ -0,0 +1,44 @@ +import { Button, Menu, MenuItem } from "@mui/material"; +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; + +const SurveyLink = ({ links, label = "VIEW", ...styles }) => { + const navigate = useNavigate(); + + // Dropdown for when there more then one servey + const [dropdownButtonEl, setDropdownButtonEl] = useState(null); + const openDropdown = (e) => setDropdownButtonEl(e.currentTarget); + const closeDropdown = () => setDropdownButtonEl(null); + + const goToSurvey = (surveyId) => { + navigate(`/admin/survey/visit/${surveyId}`); + }; + + return ( + <> + + {/* Dropdown */} +
+ > + ); +}; + +export default SurveyLink; From 7df9348b91866d0d689b5718e8dc2ea4822a4b41 Mon Sep 17 00:00:00 2001 From: "Efrain A. Davila" <105945226+EfrainAD@users.noreply.github.com> Date: Fri, 13 Oct 2023 18:25:48 -0400 Subject: [PATCH 3/4] feature: Integrate the SurveyLink component to handle seeing completed surveys 1. Replace the survey link button with the SurveyLink component. 2. Remove handleSurveyLink since the component now handles that. 3. useGetHomesQuery was removed since since the assignment homes array now have the desired survey ids --- .../pages/Admin/assignment/AssignProfile.js | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/frontend/front/src/pages/Admin/assignment/AssignProfile.js b/frontend/front/src/pages/Admin/assignment/AssignProfile.js index 7344691c..13aaf32e 100644 --- a/frontend/front/src/pages/Admin/assignment/AssignProfile.js +++ b/frontend/front/src/pages/Admin/assignment/AssignProfile.js @@ -1,7 +1,6 @@ import { Box, Button, Stack, Typography } from "@mui/material"; import { useGetAssignmentQuery, - useGetHomesQuery, useGetSurveyorsQuery, } from "../../../api/apiSlice"; import { @@ -15,17 +14,17 @@ import { DataGrid } from "@mui/x-data-grid"; import Loader from "../../../components/Loader"; import React from "react"; import { getAddress } from "../home/HomeTable"; -import { useNavigate, useParams } from "react-router-dom"; +import { useParams } from "react-router-dom"; import { adminAssignmentProfile, ADMIN_ASSIGNMENT, withAdminPrefix, } from "../../../routing/routes"; +import SurveyLink from "../../../components/SurveyLink"; const AssignProfile = () => { const { aid } = useParams(); const goToBreadcrumb = useGoToBreadcrumb(); - const navigate = useNavigate(); useInitBreadcrumbs([ { url: withAdminPrefix(ADMIN_ASSIGNMENT), description: "assignments" }, @@ -47,23 +46,12 @@ const AssignProfile = () => { isLoading: isSurveyorsDataLoading, } = useGetSurveyorsQuery(); - const { data: homesData } = useGetHomesQuery(); - const surveyors = surveyorsData ? surveyorsData.filter((surveyor) => assignmentData?.surveyor_ids.includes(surveyor.id) ) : "Unassigned"; - const handleSurveyLink = (home) => { - const homeData = homesData.find((homeData) => homeData.id === home.id); - const surveyVisitIds = - homeData.survey_visit_ids.length > 0 - ? homeData.survey_visit_ids[0] - : null; - - navigate(`/admin/survey/visit/${surveyVisitIds}`); - }; const handleUserLink = (user) => goToBreadcrumb("user", user); const handleHomeLink = (home) => { goToBreadcrumb("home", home); @@ -118,15 +106,14 @@ const AssignProfile = () => { maxWidth: 80, renderCell: (params) => params.row.completed ? ( - + /> ) : null, }, { From 05dba75c1a7b9fda2cfa0d3c3bb7e2864790f666 Mon Sep 17 00:00:00 2001 From: "Efrain A. Davila" <105945226+EfrainAD@users.noreply.github.com> Date: Fri, 13 Oct 2023 18:30:19 -0400 Subject: [PATCH 4/4] feature: Integrate the SurveyLink component to handle seeing completed surveys 1. Replace the survey link button with the SurveyLink component. 2. Remove handleUserLink since the component now handles that. --- frontend/front/src/pages/Admin/home/HomeTable.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/frontend/front/src/pages/Admin/home/HomeTable.js b/frontend/front/src/pages/Admin/home/HomeTable.js index 9e6bc398..1a5b61f0 100644 --- a/frontend/front/src/pages/Admin/home/HomeTable.js +++ b/frontend/front/src/pages/Admin/home/HomeTable.js @@ -10,8 +10,8 @@ import Loader from "../../../components/Loader"; import React from "react"; import { useGetHomesQuery } from "../../../api/apiSlice"; -import { useNavigate } from "react-router-dom"; import { ADMIN_HOME, withAdminPrefix } from "../../../routing/routes"; +import SurveyLink from "../../../components/SurveyLink"; // Formats addresses export const getAddress = (params) => { @@ -27,7 +27,6 @@ export const getAddress = (params) => { const HomeTable = () => { const goToBreadcrumb = useGoToBreadcrumb(); - const navigate = useNavigate(); useInitBreadcrumbs( [{ url: withAdminPrefix(ADMIN_HOME), description: "homes" }], @@ -36,10 +35,6 @@ const HomeTable = () => { const handleHomeLink = (home) => goToBreadcrumb("home", home); - const handleUserLink = (home) => { - navigate(`/admin/survey/visit/${home.survey_visit_ids[0]}`); - }; - const handleAssignmentLink = (assignment) => goToBreadcrumb("assignment", assignment); @@ -90,15 +85,14 @@ const HomeTable = () => { headerName: "Completed", renderCell: (params) => params.row.completed ? ( - + /> ) : ( "No" ),