Skip to content

Commit

Permalink
Merge pull request #499 from EfrainAD/Efrain_#471_Adimin-assignment-p…
Browse files Browse the repository at this point in the history
…age-link-to-survey
  • Loading branch information
EfrainAD authored Nov 9, 2023
2 parents f842ab8 + 05dba75 commit c55736c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
44 changes: 44 additions & 0 deletions frontend/front/src/components/SurveyLink.js
Original file line number Diff line number Diff line change
@@ -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 (
<>
<Button
{...styles}
onClick={(e) => {
if (links.length === 1) goToSurvey(links[0]);
else openDropdown(e);
}}
>
{label}
</Button>
{/* Dropdown */}
<Menu
anchorEl={dropdownButtonEl}
open={!!dropdownButtonEl}
onClose={closeDropdown}
>
{links.map((link, index) => (
<MenuItem key={index} onClick={() => goToSurvey(link)}>
Survey {index + 1}
</MenuItem>
))}
</Menu>
</>
);
};

export default SurveyLink;
22 changes: 12 additions & 10 deletions frontend/front/src/pages/Admin/assignment/AssignProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ADMIN_ASSIGNMENT,
withAdminPrefix,
} from "../../../routing/routes";
import SurveyLink from "../../../components/SurveyLink";

const AssignProfile = () => {
const { aid } = useParams();
Expand Down Expand Up @@ -103,16 +104,17 @@ const AssignProfile = () => {
headerName: "Survey",
minWidth: 50,
maxWidth: 80,
renderCell: (params) => (
<Button
variant="text"
color="primary"
size="small"
onClick={() => handleUserLink(params.row)}
>
View
</Button>
),
renderCell: (params) =>
params.row.completed ? (
<SurveyLink
label="VIEW"
links={params.row.survey_visit_ids}
variant="text"
sx={{ minWidth: "unset", padding: "0px" }}
color="primary"
size="small"
/>
) : null,
},
{
field: "unassign",
Expand Down
16 changes: 5 additions & 11 deletions frontend/front/src/pages/Admin/home/HomeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -27,7 +27,6 @@ export const getAddress = (params) => {

const HomeTable = () => {
const goToBreadcrumb = useGoToBreadcrumb();
const navigate = useNavigate();

useInitBreadcrumbs(
[{ url: withAdminPrefix(ADMIN_HOME), description: "homes" }],
Expand All @@ -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);

Expand Down Expand Up @@ -90,15 +85,14 @@ const HomeTable = () => {
headerName: "Completed",
renderCell: (params) =>
params.row.completed ? (
<Button
<SurveyLink
label={"Yes ✅"}
links={params.row.survey_visit_ids}
variant="text"
sx={{ minWidth: "unset", padding: "0px" }}
color="primary"
size="small"
onClick={() => handleUserLink(params.row)}
>
Yes ✅
</Button>
/>
) : (
"No"
),
Expand Down

0 comments on commit c55736c

Please sign in to comment.