diff --git a/src/Components/Case/CaseTypePage.js b/src/Components/Case/CaseTypePage.js index a6e92e4..c8a2db0 100644 --- a/src/Components/Case/CaseTypePage.js +++ b/src/Components/Case/CaseTypePage.js @@ -1,318 +1,32 @@ -import { useEffect, useContext, useState, useRef } from "react"; -import { useNavigate } from "react-router-dom"; -import Button from "../../pageElements/Button"; -import Form from "react-bootstrap/Form"; -import Col from "react-bootstrap/Col"; -import Row from "react-bootstrap/Row"; -import TextInput from "../../pageElements/TextInput"; -import Radiogroup from "../../pageElements/Radiogroup"; -import { - getFormDataDefaults, - getValidatedFormData, - handleFormDataChange, - isFormDataHasErrors, -} from "../../Utils/Form"; -import { db } from "../../firebase"; -import * as dJSON from "dirty-json"; -import { useParams } from "react-router-dom"; -import { AppContext } from "../../Hooks/useContext/appContext.js"; -import LoadingSpinner from "../../pageElements/LoadingSpinner"; -import { doc, onSnapshot } from "firebase/firestore"; -import { createCaseAdditionalFields as fields } from "../../Constants/Fields/CreateCaseFields.js"; -import { objectMap } from "../../Utils/Object"; -import { Typeahead } from "react-bootstrap-typeahead"; -import { caseTags } from "../../Constants/Tags/CaseTags"; +import { useState } from "react"; import "../../styles/casetype-page.scss"; - -const CaseTypePage = ({ caseData }) => { - const { caseId } = useParams(); - const navigate = useNavigate(); - const { appState } = useContext(AppContext); - const { group } = appState; - const [isEditing, setFsEditing] = useState(false); - const [subCase, setSubCase] = useState(null); - const [isLoading, setIsLoading] = useState(false); - const [selectedCaseTags, setSelectedCaseTags] = useState([]); - const typeaheadRef = useRef(); - const appUserId = group ? group.appUserId : null; - const [data, setData] = useState( - getFormDataDefaults(fields, isEditing ? caseData : undefined) - ); - const [isBusy, setIsBusy] = useState(false); - - const parsedTags = dJSON.parse(JSON.stringify(caseTags)); - - const handleNavigate = () => { - navigate("/documents"); - }; - - const handleBack = () => { - navigate("/cases"); - }; - - 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; - } - - useEffect(getCase, [caseId, appUserId]); - - const handleChangeInput = (e, name) => { - const newData = handleFormDataChange(e, name, data, fields); - if (newData !== null) { - setData(newData); - } - }; - - const setSelectedTag = (item) => { - const temp = [...selectedCaseTags, item.tagName]; - setSelectedCaseTags(temp); - console.log("selectedCaseTags", selectedCaseTags); - }; - - const validateData = () => { - const newData = getValidatedFormData(data, fields); - const hasErrors = isFormDataHasErrors(newData); - setData(newData); - return hasErrors ? null : objectMap(({ value }) => value, newData); - }; - - const handleTagClick = (clickedTag) => { - console.log("handleTagClick tag", clickedTag); - console.log("selectedCaseTags", selectedCaseTags); - const temp = selectedCaseTags; - const foo = temp.filter((tag) => { - if (tag != clickedTag) return tag; - }); - setSelectedCaseTags(foo); - }; - - const ButtonContent = () => { - return ( -