import React from "react" ; import { GET_PUBLISHED_FORM } from "./graphql" ; import { useQuery } from "@apollo/react-hooks" ; import FormRender from "./FormRender" ; import { FormLoadComponentPropsType } from "../../types" ; const FormLoad = ( props ) => { const variables = { } ; if ( props . parentId ) { variables [ "parent" ] = props . parentId ; } else { variables [ "revision" ] = props . revisionId ; } const { data , loading , error } = useQuery ( GET_PUBLISHED_FORM , { variables } ) ; if ( error ) { return ( < React . Fragment > < details > < summary > { error . message || "Something went wrong!" } < /summary> { error . stack } < /details> < /React.Fragment>); } if ( loading ) { return < span > Loading ... < /span>; } const { data : formData , error : formError } = data . formBuilder . getPublishedForm ; if ( ! formData ) { return < span > { formError ?. message || "Form not found." } < /span>; } return < FormRender { ... props } data = { formData } / > ; } ; export default FormLoad ;