-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forms): Add support for rendering form pages (#518)
* add form route * add nvmrc file * handle 404 when form is not available * isolate bootstrap for forms * add cacheKeys * add support for closed forms Co-authored-by: Sinu john <[email protected]>
- Loading branch information
1 parent
2692066
commit 7c16c84
Showing
12 changed files
with
14,004 additions
and
6,324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
10.13.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { string, bool } from "prop-types"; | ||
|
||
import styles from "./styles.m.css"; | ||
|
||
const Form = ({ formioUrl, disabled }) => { | ||
const [Formio, setFormComponent] = useState({}); | ||
useEffect(() => { | ||
// SSR is not supported by react-formio | ||
import(/* webpackChunkName: "qtc-react-formio" */ "react-formio") | ||
.then(Formio => { | ||
setFormComponent({ component: Formio.Form }); | ||
}) | ||
.catch(error => console.error("Error loading formio component", error)); | ||
}, []); | ||
|
||
return ( | ||
<div className={`bootstrap ${styles["form-container"]}`}> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://toert.github.io/Isolated-Bootstrap/versions/4.0.0-beta/iso_bootstrap4.0.0min.css" | ||
/> | ||
<link rel="stylesheet" href="https://unpkg.com/formiojs@latest/dist/formio.full.min.css" /> | ||
{Formio.component && <Formio.component src={formioUrl} options={{ readOnly: disabled }} />} | ||
</div> | ||
); | ||
}; | ||
|
||
Form.propTypes = { | ||
formioUrl: string, | ||
disabled: bool | ||
}; | ||
|
||
export { Form }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:global(.bootstrap).form-container { | ||
background-color: unset; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from "react"; | ||
import { shape, string } from "prop-types"; | ||
|
||
import { Form } from "../form"; | ||
|
||
const FormPage = props => { | ||
const { headline, subheadline, status, "formio-url": formioUrl } = props.data.form; | ||
const isClosed = status === "closed"; | ||
return ( | ||
<div> | ||
<h1>{headline}</h1> | ||
<h2>{subheadline}</h2> | ||
{isClosed && <p>The form is closed for submissions.</p>} | ||
<Form formioUrl={formioUrl} disabled={isClosed} /> | ||
</div> | ||
); | ||
}; | ||
|
||
FormPage.propTypes = { | ||
data: shape({ | ||
form: { | ||
"formio-url": string, | ||
headline: string, | ||
subheadline: string, | ||
status: string | ||
} | ||
}) | ||
}; | ||
|
||
export { FormPage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function loadFormPageData(client, formSlug, next) { | ||
return client | ||
.request(`/api/v1/forms/${formSlug}`) | ||
.then(result => ({ form: result.data, cacheKeys: result.cacheKeys })) | ||
.catch(response => { | ||
return response.statusCode === 404 ? next() : Promise.reject(response); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.