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 */} + + {links.map((link, index) => ( + goToSurvey(link)}> + Survey {index + 1} + + ))} + + + ); +}; + +export default SurveyLink; diff --git a/frontend/front/src/pages/Admin/assignment/AssignProfile.js b/frontend/front/src/pages/Admin/assignment/AssignProfile.js index dc415ec2..13aaf32e 100644 --- a/frontend/front/src/pages/Admin/assignment/AssignProfile.js +++ b/frontend/front/src/pages/Admin/assignment/AssignProfile.js @@ -20,6 +20,7 @@ import { ADMIN_ASSIGNMENT, withAdminPrefix, } from "../../../routing/routes"; +import SurveyLink from "../../../components/SurveyLink"; const AssignProfile = () => { const { aid } = useParams(); @@ -103,16 +104,17 @@ const AssignProfile = () => { headerName: "Survey", minWidth: 50, maxWidth: 80, - renderCell: (params) => ( - - ), + renderCell: (params) => + params.row.completed ? ( + + ) : null, }, { field: "unassign", 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" ),