diff --git a/src/Components/Document/DocEditPage.js b/src/Components/Document/DocEditPage.js index 7efc596..7a4062f 100644 --- a/src/Components/Document/DocEditPage.js +++ b/src/Components/Document/DocEditPage.js @@ -6,15 +6,7 @@ import { useParams } from "react-router-dom"; import { Link, useNavigate } from "react-router-dom"; import EditElement from "../../pageElements/EditElement"; import { db } from "../../firebase"; -import { - collection, - updateDoc, - onSnapshot, - doc, - getDoc, - setDoc, - increment, -} from "firebase/firestore"; +import { doc, getDoc } from "firebase/firestore"; import { AppContext } from "../../Hooks/useContext/appContext"; import Button from "../../pageElements/Button"; import ConfirmModal from "../Modals/ConfirmModal"; @@ -270,7 +262,7 @@ const DocEditPage = (props) => { async function createAndReturnDocx() { setIsBusy(true); const response = await handleCreateDocx(); - if (response.status === 200) { + if (response?.status === 200) { setTimeout(getDocx, 5000); setTimeout(cleanUpDocx, 10000); } else { @@ -295,7 +287,19 @@ const DocEditPage = (props) => { }); } + async function postDocxData(obj) { + const docId = documentId; + console.log("obj", obj); + const response = await fetch(`${apiUrl}/v1/store-docx-data/${docId}`, { + method: "POST", + body: JSON.stringify(obj), + }); + console.log("res~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", response); + //return res; + } + async function handleCreateDocx() { + console.log("handleCreateDocx FIRED ------------------------------->"); // TODO: compare to see if any changes made before gen, save those const docId = documentId; const leadAttorneys = fetchedCase?.leadAttorneys @@ -313,12 +317,11 @@ const DocEditPage = (props) => { const clientPosition = fetchedCase?.clientPosition ? fetchedCase?.clientPosition : null; - + const currentRequestType = docType; try { - const response = await fetch(`${apiUrl}/genDocx/${docId}/${reqType}`, { + const response = await fetch(`${apiUrl}/v1/store-docx-data/${docId}`, { method: "POST", headers: { - Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify({ @@ -326,6 +329,7 @@ const DocEditPage = (props) => { caseCaption2: captionTwo, caseNumber: caseNum, clientPosition: clientPosition, + currentRequestType: currentRequestType, defendant: defendants, firm: lawFirm, firmCity: city, @@ -341,10 +345,40 @@ const DocEditPage = (props) => { venue: venued, }), }); + if (response.status === 200) { + const response = await fetch( + `${apiUrl}/v1/generate-request-docx/${docId}`, + { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + } + ); + return response; + } + } catch (err) { + console.log("err inpostDocxData", err); + } + + /* + try { + const response = await fetch( + `${apiUrl}/v1/generate-request-docx/${docId}`, + { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + } + ); return response; } catch (error) { console.error("Error sending responses to the server:", error); } + */ } const handleConfirmReport = () => { @@ -437,8 +471,6 @@ const DocEditPage = (props) => { navigate(`/documents`); }; - console.log("parsedRogs", parsedRogs); - console.log("responses", responses); const editingContent = () => { return ( <> @@ -552,8 +584,7 @@ const DocEditPage = (props) => { }; const readyToEdit = fetchedCase && responses.length > 1; - console.log("readyToEdit", readyToEdit); - console.log("fetchedCase", fetchedCase); + return isLoading ? ( ) : isBusy ? (