From 339dbf5027e8f32bc3dc43548e45ad533bfc9793 Mon Sep 17 00:00:00 2001 From: avenmia Date: Sun, 1 Sep 2024 13:07:22 -1000 Subject: [PATCH] Adding island and county areas --- src/pages/querysummary.tsx | 49 +++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/pages/querysummary.tsx b/src/pages/querysummary.tsx index db0e23f..ef265be 100644 --- a/src/pages/querysummary.tsx +++ b/src/pages/querysummary.tsx @@ -1,6 +1,6 @@ import { type NextPage } from "next"; import ProgressBar from "../components/ProgressBar"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { SurveyData } from "../components/survey/demographicssurvey"; import { api } from "../utils/api"; import Link from "next/link"; @@ -8,6 +8,9 @@ import Link from "next/link"; const QuerySummary: NextPage = () => { const [userCensusTract, setUserCensusTract] = useState(""); const [userZipCode, setUserZipCode] = useState(""); + const [userPlanningRegion, setUserPlanningRegion] = useState(""); + const [userIsland, setUserIsland] = useState(""); + const [userCounty, setUserCounty] = useState(""); const [demographicQuestions, setDemographicQuestions] = useState< SurveyData[] >([]); @@ -21,6 +24,32 @@ const QuerySummary: NextPage = () => { const demographicQuestionsDB = api.survey.getSurveyData.useQuery(); const userDemoSurveyAnswersDB = api.user.getDemoSurveyAnswers.useQuery(); + useEffect(() => { + if (userCensusTractDB && userCensusTractDB.data) { + if (userCensusTractDB.data.censustract !== null) { + setUserCensusTract(userCensusTractDB.data?.censustract); + } + } + if (userZipCodeDB && userZipCodeDB.data) { + if (userZipCodeDB.data.zipcode !== null) { + setUserZipCode(userZipCodeDB.data?.zipcode); + } + } + if (planningRegionDB && planningRegionDB.data) { + if (planningRegionDB.data.planningRegion !== null) { + const [islandData, countyData, planningRegionData] = + planningRegionDB.data.planningRegion.split(","); + setUserIsland(islandData ?? ""); + setUserCounty(countyData ?? ""); + setUserPlanningRegion(planningRegionData ?? ""); + } + } + }, [ + userCensusTractDB.data?.censustract, + userZipCodeDB.data?.zipcode, + planningRegionDB.data?.planningRegion, + ]); + const sortedDemoQuestions = demographicQuestionsDB.data?.sort((a, b) => { return a.position - b.position; @@ -66,19 +95,23 @@ const QuerySummary: NextPage = () => {
  • Census tract

    -

    - {userCensusTractDB.data?.censustract} -

    +

    {userCensusTract}

  • Zipcode

    -

    {userZipCodeDB.data?.zipcode}

    +

    {userZipCode}

    +
  • +
  • +

    Island

    +

    {userIsland}

    +
  • +
  • +

    County

    +

    {userCounty}

  • Planning Region

    -

    - {planningRegionDB.data?.planningRegion} -

    +

    {userPlanningRegion}