From 82a09f3f731dbd5f7d2360f66bfa18e710a5ac46 Mon Sep 17 00:00:00 2001 From: Kenneth Jannette Date: Wed, 31 Jan 2024 16:08:12 -0600 Subject: [PATCH] more --- src/Components/Case/CaseTypePage.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Components/Case/CaseTypePage.js b/src/Components/Case/CaseTypePage.js index 916f5e4..3ce1f48 100644 --- a/src/Components/Case/CaseTypePage.js +++ b/src/Components/Case/CaseTypePage.js @@ -1,18 +1,41 @@ -import { useState } from "react"; +import React, { useEffect, useContext, useState, useRef } from "react"; +import { useNavigate } from "react-router-dom"; +import { useParams } from "react-router-dom"; import { Typeahead } from "react-bootstrap-typeahead"; +import { AppContext } from "../../Hooks/useContext/appContext.js"; +import { doc, onSnapshot } from "firebase/firestore"; import Radiogroup from "../../pageElements/Radiogroup"; import { caseTags } from "../../Constants/Tags/CaseTags"; +import { db } from "../../firebase"; import "../../styles/casetype-page.scss"; const CaseTypePage = () => { + const { caseId } = useParams(); + const navigate = useNavigate(); + const { appState } = useContext(AppContext); + const { group } = appState; + const appUserId = group ? group.appUserId : null; + const [subCase, setSubCase] = useState(); const [email, setEmail] = useState(""); const [contactName, setContactName] = useState(""); const [billingCode, setBillingCode] = useState(""); const [leadAttorney, setLeadAttorney] = useState(""); const [radioValue, setRadioValue] = useState(); - const parsedTags = JSON.parse(JSON.stringify(caseTags)); + function getCase() { + const docRef = doc(db, "cases", caseId); + const unsub = onSnapshot(docRef, (snapshot) => { + if (snapshot.exists() && snapshot.data().ownerId === appUserId) { + setSubCase({ ...snapshot.data(), id: snapshot.id }); + } else { + setSubCase(null); + } + }); + return unsub; + } + const parsedTags = JSON.parse(JSON.stringify(caseTags)); + useEffect(getCase, [caseId, appUserId]); const radioOptions = [ { name: "Plaintiff", label: "Plaintiff", value: "Plaintiff" }, { name: "Defendant", label: "Defendant", value: "Defendant" },