Skip to content

Commit

Permalink
Merge pull request #256 from oneblink/ON-42474
Browse files Browse the repository at this point in the history
ON-42474 # add form not published message
  • Loading branch information
divporter authored Aug 7, 2024
2 parents 49b573e + fbbe527 commit 4ed15a5
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
OneBlinkAppsError,
} from '@oneblink/apps'
import { OneBlinkForm, useLoadDataState } from '@oneblink/apps-react'
import sanitizeHtml from '@oneblink/apps-react/dist/services/sanitize-html'
import OnLoading from '@oneblink/apps-react/dist/components/renderer/OnLoading'
import { useHistory } from 'react-router-dom'
import ErrorModal from './ErrorModal'
Expand All @@ -28,6 +29,11 @@ const formIsSubmittingContainerStyles: React.CSSProperties = {
opacity: 0.7,
}

const defaultUnpublishedHTML = `
<p style="font-size:1.5em">Form Unavailable</p>
<p>This form is currently unpublished.</p>
`

function Form({
formId,
formsAppId,
Expand Down Expand Up @@ -143,6 +149,28 @@ function Form({
}
}, [isSubmitting])

const [form, formsAppConfiguration] = React.useMemo(() => {
if (state.status === 'SUCCESS') {
return state.result
}
return []
}, [state])

const formNotPublishedError = React.useMemo(() => {
if (!form) {
return
}
const startDate = form.publishStartDate
? new Date(form.publishStartDate)
: null
const endDate = form.publishEndDate ? new Date(form.publishEndDate) : null
const now = new Date()
// If now is before startDate or after endDate
if ((startDate && now < startDate) || (endDate && now > endDate)) {
return sanitizeHtml(form.unpublishedUserMessage || defaultUnpublishedHTML)
}
}, [form])

if (state.status === 'LOADING') {
return <OnLoading className="has-text-centered" small />
}
Expand All @@ -159,7 +187,18 @@ function Form({
)
}

const [form, formsAppConfiguration] = state.result
if (formNotPublishedError || !form || !formsAppConfiguration) {
return (
<div
className="ob-form-unpublished-user-message__content ql-editor"
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: formNotPublishedError || defaultUnpublishedHTML,
}}
></div>
)
}

const googleMapsApiKey =
optionsGoogleMapsApiKey || formsAppConfiguration.googleMapsApiKey

Expand Down

0 comments on commit 4ed15a5

Please sign in to comment.