Skip to content

Commit

Permalink
feature: Integrate the SurveyLink component to handle seeing complete…
Browse files Browse the repository at this point in the history
…d 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
  • Loading branch information
EfrainAD committed Oct 13, 2023
1 parent 64c6237 commit 7df9348
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions frontend/front/src/pages/Admin/assignment/AssignProfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Box, Button, Stack, Typography } from "@mui/material";
import {
useGetAssignmentQuery,
useGetHomesQuery,
useGetSurveyorsQuery,
} from "../../../api/apiSlice";
import {
Expand All @@ -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" },
Expand All @@ -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);
Expand Down Expand Up @@ -118,15 +106,14 @@ const AssignProfile = () => {
maxWidth: 80,
renderCell: (params) =>
params.row.completed ? (
<Button
<SurveyLink
label="VIEW"
links={params.row.survey_visit_ids}
variant="text"
sx={{ minWidth: "unset", padding: "0px" }}
color="primary"
size="small"
onClick={() => handleSurveyLink(params.row)}
>
VIEW
</Button>
/>
) : null,
},
{
Expand Down

0 comments on commit 7df9348

Please sign in to comment.