diff --git a/apps/wrapper/src/api/index.js b/apps/wrapper/src/api/index.js index 65f45d91027337f4fa3b54b9b64397ccac89a48c..5222deafcca973eb4789efaa7c318466e20a9a74 100644 --- a/apps/wrapper/src/api/index.js +++ b/apps/wrapper/src/api/index.js @@ -2,7 +2,7 @@ const GITPOD_URL = process.env.REACT_APP_GITPOD_WORKSPACE_URL const makeHasuraCalls = async (query) => { // const userData = getCookie("userData"); - return fetch(`${GITPOD_URL.slice(0, GITPOD_URL.indexOf('/') + 2) + "8080-" + GITPOD_URL.slice(GITPOD_URL.indexOf('/') + 2)}`, { + return fetch(`${GITPOD_URL.slice(0, GITPOD_URL.indexOf('/') + 2) + "8080-" + GITPOD_URL.slice(GITPOD_URL.indexOf('/') + 2)}/v1/graphql`, { method: "POST", headers: { Accept: "application/json", diff --git a/apps/wrapper/src/components/GenericForm/index.js b/apps/wrapper/src/components/GenericForm/index.js index 55c926f7a503ebc8f191b05ae43a552c7c7066b0..94ec7676c5004655f71270dcc513f9529ee9fbbc 100644 --- a/apps/wrapper/src/components/GenericForm/index.js +++ b/apps/wrapper/src/components/GenericForm/index.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import styles from './index.module.css'; import beautify from "xml-beautifier"; import { saveFormSubmission } from '../../api'; @@ -18,7 +18,7 @@ const GenericForm = (props) => { } const getFormURI = (form, ofsd, prefillSpec) => { - console.log(form, ofsd, prefillSpec); + // console.log(form, ofsd, prefillSpec); // return encodeURIComponent(`https://3006-samagradevelop-workflow-gkbrz650idv.ws-us89b.gitpod.io/prefill?form=${form}&onFormSuccessData=${encodeFunction(ofsd)}&prefillSpec=${encodeFunction(prefillSpec)}`); return encodeURIComponent(`${GITPOD_URL.slice(0, GITPOD_URL.indexOf('/') + 2) + "3006-" + GITPOD_URL.slice(GITPOD_URL.indexOf('/') + 2)}/prefill?form=${form}&onFormSuccessData=${encodeFunction(ofsd)}&prefillSpec=${encodeFunction(prefillSpec)}`); } @@ -29,6 +29,7 @@ const GenericForm = (props) => { const [onFormSuccessData, setOnFormSuccessData] = useState(undefined); const [onFormFailureData, setOnFormFailureData] = useState(undefined); const [encodedFormURI, setEncodedFormURI] = useState(getFormURI(formId, formSpec.forms[formId].onFormSuccess, formSpec.forms[formId].prefill)); + const formSubmitted = useRef(false); useEffect(() => { // Manage onNext @@ -36,17 +37,21 @@ const GenericForm = (props) => { const data = typeof e.data === "string" ? JSON.parse(e.data) : e.data; try { const { nextForm, formData, onSuccessData, onFailureData } = data; - // console.log({ nextForm, formData, onSuccessData, onFailureData }); - if (formData) { + // console.log("data--->", data) + + if (data?.state != "ON_FORM_SUCCESS_COMPLETED" && formData) { setFormData(beautify(formData)) let jsonRes = await parseFormData(formData); - if (jsonRes) setFormDataJSON(JSON.stringify(jsonRes.data, null, 2)); + if (jsonRes) setFormDataJSON(JSON.stringify(jsonRes, null, 2)); } - if (data?.state == "ON_FORM_SUCCESS_COMPLETED" && selectedFlow.submitToHasura) { - saveFormSubmission({ + + if (data?.state == "ON_FORM_SUCCESS_COMPLETED" && selectedFlow.submitToHasura && !formSubmitted.current) { + formSubmitted.current = true; + await saveFormSubmission({ form_data: formData, form_name: formSpec.startingForm, }); + formSubmitted.current = false; } if (nextForm.type === 'form') { setFormId(nextForm.id); @@ -57,9 +62,10 @@ const GenericForm = (props) => { } else { window.location.href = nextForm.url; } + } catch (e) { - // console.log(e) + console.log(e) } }); }, []); @@ -86,7 +92,6 @@ const GenericForm = (props) => { return jsonRes?.data; } - return ( <div className={styles.container}> <div className={styles.header}> diff --git a/apps/wrapper/src/workflow_first.json b/apps/wrapper/src/workflow_first.json index b15ffd5d3963a45dba13d76777d4153ca0687d68..a6a755350fcdf5aaf49c50741f19261efbdf09cf 100644 --- a/apps/wrapper/src/workflow_first.json +++ b/apps/wrapper/src/workflow_first.json @@ -22,15 +22,11 @@ "onSuccess": { "notificationMessage": "Form submitted successfully", "sideEffect": "async (formData) => { console.log(formData); }", - "message": "Form submitted successfully" - }, - "nextFormOnSuccess": { - "type": "form", - "id": "jumping_form_2" - }, - "nextFormOnFailure": { - "type": "url", - "id": "https://google.com" + "message": "Form submitted successfully", + "next": { + "type": "form", + "id": "jumping_form_2" + } } }, "jumping_form_2": { @@ -39,17 +35,17 @@ "name": " Jumping Form Second", "isSuccess": "async (formData) => { console.log('From isSuccess', formData.getElementsByTagName('reg_no')[0].textContent); return formData.getElementsByTagName('reg_no')[0].textContent === 'registration123'; }", "messageOnFailure": "Form submission failed", - "messageOnSuccess": "Form submitted successfully or Maybe you are already registered", + "messageOnSuccess": "Form submitted successfully", "onFormSuccess": "async (formData) => { return JSON.parse(decodeURIComponent('%7B%0A%20%20%20%20%20%20%20%20%22name%22%3A%20%22DEVA%22%2C%0A%20%20%20%20%20%20%20%20%22batch%22%3A%20%222021-2023%22%2C%0A%20%20%20%20%20%20%20%20%22id%22%3A%208%2C%0A%20%20%20%20%20%20%20%20%22DOB%22%3A%20%222005-03-04%22%2C%0A%20%20%20%20%20%20%20%20%22affiliationType%22%3A%20%22NCVT%22%2C%0A%20%20%20%20%20%20%20%20%22registrationNumber%22%3A%20%22ICA211021569832%22%2C%0A%20%20%20%20%20%20%20%20%22tradeName%22%3A%20%22Electrician%22%2C%0A%20%20%20%20%20%20%20%20%22iti%22%3A%207%2C%0A%20%20%20%20%20%20%20%20%22industry%22%3A%201%2C%0A%20%20%20%20%20%20%20%20%22itiByIti%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22id%22%3A%207%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22GITI%20Nagina%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22industryByIndustry%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22id%22%3A%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22Kaushal%20Bhawan%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22latitude%22%3A%2030.695753%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22longitude%22%3A%2076.872025%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22schedules%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22is_industry%22%3A%20true%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D')); }", "onFormFailure": "async (formData) => { console.log(formData); }", "onSuccess": { "notificationMessage": "Form submitted successfully", "sideEffect": "async (formData) => { console.log(formData); }", - "message": "Form submitted successfully" - }, - "nextFormOnFailure": { - "type": "url", - "id": "https://google.com" + "message": "Form submitted successfully", + "next": { + "type": "url", + "url": "https://google.com" + } } } },