more
This commit is contained in:
@@ -24,10 +24,11 @@ import "../../styles/docedit-page.scss";
|
||||
|
||||
const DocEditPage = (props) => {
|
||||
const { documentId, caseId } = useParams();
|
||||
const [document, setDocument] = useState();
|
||||
const [docType, setDocType] = useState();
|
||||
const [fetchedCase, setFetchedCase] = useState();
|
||||
const [parsedRogs, setParsedRogs] = useState();
|
||||
const [document, setDocument] = useState(null);
|
||||
const [docType, setDocType] = useState(null);
|
||||
const [fetchedCase, setFetchedCase] = useState(null);
|
||||
const [parsedRogs, setParsedRogs] = useState(null);
|
||||
const [docLoaded, setDocLoaded] = useState(false);
|
||||
const { appState } = useContext(AppContext);
|
||||
const { group } = appState;
|
||||
const appUserId = group ? group.appUserId : null;
|
||||
@@ -37,36 +38,43 @@ const DocEditPage = (props) => {
|
||||
? process.env.REACT_APP_API_DEV
|
||||
: process.env.REACT_APP_API_PROD;
|
||||
|
||||
useEffect(() => {
|
||||
if (!documentId) {
|
||||
return;
|
||||
async function getParsedRequests(docId, docType) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${apiUrl}/getParsedRequests/${documentId}/${docType}`,
|
||||
{
|
||||
method: "GET",
|
||||
}
|
||||
);
|
||||
const res = await response.json();
|
||||
console.log("res", res);
|
||||
const req = res[0].requests;
|
||||
if (req.length > 1) {
|
||||
setParsedRogs(req);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Error occured GET parsed req:", err);
|
||||
}
|
||||
getDocument(documentId);
|
||||
console.log("eff doc", document);
|
||||
setDocType(document?.docType);
|
||||
}, [documentId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!caseId) {
|
||||
return;
|
||||
}
|
||||
getCase(caseId);
|
||||
}, [caseId]);
|
||||
|
||||
useEffect(() => {
|
||||
getParsedRequests(documentId, docType);
|
||||
}, [documentId, docType]);
|
||||
|
||||
function getDocument(docId) {
|
||||
async function getDocument(docId) {
|
||||
try {
|
||||
const docRef = doc(db, "documents", `${docId}`);
|
||||
const unsub = onSnapshot(docRef, (snapshot) => {
|
||||
if (snapshot.exists() && snapshot.data().ownerId === appUserId) {
|
||||
setDocument({ ...snapshot.data(), documentId: snapshot.id });
|
||||
} else {
|
||||
setDocument(null);
|
||||
const docSnap = await getDoc(docRef);
|
||||
if (docSnap.exists()) {
|
||||
const bar = docSnap.data();
|
||||
if (bar.docType) {
|
||||
console.log(bar.docType);
|
||||
let zib = bar.docType;
|
||||
console.log("zib", zib);
|
||||
getz(docId, zib);
|
||||
}
|
||||
} else {
|
||||
console.log("DB item does not exist");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`A system error has occurred: ${error}`);
|
||||
}
|
||||
});
|
||||
return unsub;
|
||||
}
|
||||
|
||||
async function getCase(caseId) {
|
||||
@@ -76,7 +84,6 @@ const DocEditPage = (props) => {
|
||||
if (docSnap.exists()) {
|
||||
const _case = docSnap.data();
|
||||
_case.id = docSnap._key.path.segments[1];
|
||||
console.log("_case", _case);
|
||||
setFetchedCase(_case);
|
||||
} else {
|
||||
console.log("DB item does not exist");
|
||||
@@ -86,27 +93,45 @@ const DocEditPage = (props) => {
|
||||
}
|
||||
}
|
||||
|
||||
async function getParsedRequests(docId, docType) {
|
||||
if (!docId) {
|
||||
return;
|
||||
}
|
||||
async function getz(docId, zib) {
|
||||
console.log("zibbbt", zib);
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${apiUrl}/getParsedRequests/${documentId}/${docType}`,
|
||||
{
|
||||
fetch(`${apiUrl}/v1/get-parsed-requests/${documentId}/${zib}`, {
|
||||
method: "GET",
|
||||
}
|
||||
);
|
||||
const res = await response.json();
|
||||
|
||||
const req = res[0].requests;
|
||||
if (req.length > 1) {
|
||||
setParsedRogs(req);
|
||||
}
|
||||
})
|
||||
.then(function (response) {
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
const respArray = data[0].responses;
|
||||
const result = respArray?.map((item, index) => {
|
||||
let obj = {};
|
||||
obj["showInputEle"] = false;
|
||||
obj["resp"] = item.text;
|
||||
obj["index"] = index;
|
||||
return obj;
|
||||
});
|
||||
setParsedRogs(result);
|
||||
console.log("parsedRogs", parsedRogs);
|
||||
});
|
||||
} catch (err) {
|
||||
console.log("Error occured:", err);
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
if (!documentId) {
|
||||
return;
|
||||
}
|
||||
getDocument(documentId);
|
||||
}, [documentId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!caseId) {
|
||||
return;
|
||||
}
|
||||
getCase(caseId);
|
||||
getDocument(documentId);
|
||||
}, [caseId, documentId]);
|
||||
|
||||
return <div>Doc Edit</div>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user