Unverified Commit d6b54702 authored by Vinod Kumar Shyave's avatar Vinod Kumar Shyave Committed by GitHub
Browse files

Merge pull request #275 from RoopashreeLakshmikeshava/one_form_poc

POC for single form Approach
No related merge requests found
Showing with 83 additions and 6 deletions
+83 -6
......@@ -2,6 +2,7 @@ import axios from "axios";
import { getCookie, makeHasuraCalls } from "../utils";
import customPost from "./customPost";
import customPostPdf from "./customPostPdf";
import {APIS} from "../constants/index";
//nconst BASE_URL = process.env.REACT_APP_USER_SERVICE_URL;
const KEYCLOAK_BASE_URL =
......@@ -500,3 +501,11 @@ export const editUserKeycloak = async (postData) => {
);
return res;
};
export const getFormData = async (postData) => {
const res = await customPost.post(
APIS.groundAnalysis.viewForm,
postData
);
return res;
};
export const APIS = {
groundAnalysis: {
viewForm: `/rest/getFormData`,
}
};
\ No newline at end of file
export { APIS } from './apiConstants';
\ No newline at end of file
......@@ -142,10 +142,13 @@ const AssessmentType = () => {
let courses_data = response?.data?.institute_form;
if (courses_data?.length) {
courses_data = courses_data.map((obj) => {
console.log("obj=>", obj.applicant_form_id);
if (obj?.course?.formObject) {
obj.course.formObject = obj.course.formObject?.replace(/\\/g, "");
obj.course.formObject = JSON.parse(obj.course.formObject);
obj.course.formObject.forEach((eachObj) => {
// appended form id
eachObj.form_id = obj.applicant_form_id;
if (
formNames.includes(
eachObj.name.substring(0, eachObj.name.lastIndexOf(".xml"))
......@@ -203,6 +206,7 @@ const AssessmentType = () => {
};
const handleNavigateToForms = (formObj) => {
console.log("formObj =>", formObj);
if (formObj?.status !== "completed" || !formObj?.status) {
let form_name = "";
if (formObj.name.includes(".xml")) {
......@@ -211,7 +215,7 @@ const AssessmentType = () => {
form_name = formObj.path?.trim();
}
navigate(`${ROUTE_MAP.otherforms_param_formName}${form_name}`);
navigate(`${ROUTE_MAP.otherforms_param_formName}${form_name}/${formObj?.form_id}`);
} else {
setError("The form has already completed!");
setTimeout(() => {
......
......@@ -12,10 +12,11 @@ import {
saveFormSubmission,
updateFormStatus,
getPrefillXML,
getFormData,
} from "../../api";
import {
getCookie,
getFormData,
// getFormData,
handleFormEvents,
updateFormData,
removeItemFromLocalForage,
......@@ -37,7 +38,7 @@ let previewFlag = false;
const GenericOdkForm = (props) => {
const user = getCookie("userData");
let { formName, date } = useParams();
let { formName, date, formID } = useParams();
const scheduleId = useRef();
const [isPreview, setIsPreview] = useState(false);
const [surveyUrl, setSurveyUrl] = useState("");
......@@ -90,6 +91,11 @@ const GenericOdkForm = (props) => {
const [errorModal, setErrorModal] = useState(false);
const [previewModal, setPreviewModal] = useState(false);
const { state } = useContext(StateContext);
const userDetails = getCookie("userData");
const userId = userDetails?.userRepresentation?.id;
const [formDataFromApi, setFormDataFromApi] = useState();
const [formStatus, setFormStatus] = useState("");
const [onSubmit, setOnSubmit] = useState(false);
let courseObj = undefined;
const loading = useRef(false);
......@@ -108,7 +114,10 @@ const GenericOdkForm = (props) => {
let formData = await getFromLocalForage(
`${formName}_${new Date().toISOString().split("T")[0]}`
);
if(formData == null) {
fetchFormData();
}
else {
let fileGCPPath = GCP_URL + formName + ".xml";
let formURI = await getPrefillXML(
......@@ -119,6 +128,48 @@ const GenericOdkForm = (props) => {
);
setEncodedFormURI(formURI);
}
};
const fetchFormData = async () => {
let formData = {};
let filePath =
process.env.REACT_APP_GCP_AFFILIATION_LINK + formName + ".xml";
let data = await getFromLocalForage(
`${userId}_${formName}_${new Date().toISOString().split("T")[0]}`
);
const postData = { form_id: date };
try {
const res = await getFormData(postData);
formData = res.data.form_submissions[0];
console.log("formData ===>", formData);
const postDataEvents = { id: formID };
const events = await getStatusOfForms(postDataEvents);
setFormStatus(events?.events);
setFormDataFromApi(res.data.form_submissions[0]);
await setToLocalForage(
`${userId}_${startingForm}_${new Date().toISOString().split("T")[0]}`,
{
formData: formData?.form_data,
imageUrls: { ...data?.imageUrls },
}
);
let formURI = await getPrefillXML(
`${filePath}`,
formSpec.onSuccess,
formData?.form_data,
formData?.imageUrls
);
setEncodedFormURI(formURI);
} catch (error) {
console.log(error);
} finally {
// setSpinner(false);
}
};
const updateSubmissionForms = async (course_id) => {
......@@ -265,7 +316,6 @@ const GenericOdkForm = (props) => {
if (window.location.host.includes("localhost")) {
return;
}
const iframeElem = document.getElementById("enketo-form");
var iframeContent =
iframeElem?.contentDocument || iframeElem?.contentWindow.document;
......@@ -273,12 +323,17 @@ const GenericOdkForm = (props) => {
var section = iframeContent?.getElementsByClassName("or-group");
if (!section) return;
for (var i = 0; i < section?.length; i++) {
console.log(section[i]);
var inputElements = section[i].querySelectorAll("input");
inputElements.forEach((input) => {
input.disabled = true;
// hide admin remarks and label in assessor form
if(input.name.toLowercase().includes('admin')) {
input.previousSibling.style.display = 'none';
input.style.display = 'none';
}
});
}
iframeContent.getElementById("submit-form").style.display = "none";
iframeContent.getElementById("save-draft").style.display = "none";
}
......@@ -290,6 +345,7 @@ const GenericOdkForm = (props) => {
};
const handleRenderPreview = () => {
alert("1");
setPreviewModal(true);
previewFlag = true;
......@@ -328,6 +384,7 @@ const GenericOdkForm = (props) => {
useEffect(() => {
bindEventListener();
getSurveyUrl();
getDataFromLocal();
getCourseFormDetails();
getFormData({
loading,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment