Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable payment resume and duplicate modals in preview #6334

Merged
merged 6 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/features/admin-form/preview/PreviewFormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export const PreviewFormPage = (): JSX.Element => {
<FormStartPage />
<PublicFormWrapper>
<FormInstructions />
<FormFields isPreview />
<FormEndPage isPreview />
<FormFields />
<FormEndPage />
<FormFooter />
</PublicFormWrapper>
</FormSectionsProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export const PreviewFormProvider = ({
isLoading,
handleLogout: undefined,
isPaymentEnabled,
isPreview: true,
...commonFormValues,
...data,
...rest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export const TemplateFormPage = (): JSX.Element => {
<FormStartPage isTemplate />
<PublicFormWrapper>
<FormInstructions />
<FormFields isPreview />
<FormEndPage isPreview />
<FormFields />
<FormEndPage />
<FormFooter />
</PublicFormWrapper>
</FormSectionsProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export const TemplateFormProvider = ({
expiryInMs,
isLoading,
handleLogout: undefined,
isPreview: true,
isPaymentEnabled: false,
...commonFormValues,
...data,
...rest,
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/features/public-form/PublicFormContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export interface PublicFormContextProps

/** Whether payment is enabled */
isPaymentEnabled: boolean

/** Whether it is a preview form */
isPreview: boolean
}

export const PublicFormContext = createContext<
Expand Down
1 change: 1 addition & 0 deletions frontend/src/features/public-form/PublicFormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ export const PublicFormProvider = ({
expiryInMs,
isLoading: isLoading || (!!data?.form.hasCaptcha && !hasLoaded),
isPaymentEnabled,
isPreview: false,
...commonFormValues,
...data,
...rest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ import { usePublicFormContext } from '~features/public-form/PublicFormContext'
import { FeedbackFormInput } from './components/FeedbackBlock'
import { FormEndPage } from './FormEndPage'

interface FormEndPageContainerProps {
isPreview?: boolean
}

export const FormEndPageContainer = ({
isPreview,
}: FormEndPageContainerProps): JSX.Element | null => {
const { form, formId, submissionData } = usePublicFormContext()
export const FormEndPageContainer = (): JSX.Element | null => {
const { form, formId, submissionData, isPreview } = usePublicFormContext()
const { submitFormFeedbackMutation } = usePublicFormMutations(
formId,
submissionData?.id ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import { PublicSwitchEnvMessage } from '../PublicSwitchEnvMessage'
import { FormFields } from './FormFields'
import { FormFieldsSkeleton } from './FormFieldsSkeleton'

interface FormFieldsContainerProps {
isPreview?: boolean
}

export const FormFieldsContainer = ({
isPreview,
}: FormFieldsContainerProps): JSX.Element | null => {
const { form, isAuthRequired, isLoading, handleSubmitForm, submissionData } =
usePublicFormContext()
export const FormFieldsContainer = (): JSX.Element | null => {
const {
form,
isAuthRequired,
isLoading,
handleSubmitForm,
submissionData,
isPreview,
} = usePublicFormContext()

const renderFields = useMemo(() => {
// Render skeleton when no data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const PublicFormSubmitButton = ({
const isMobile = useIsMobile()
const { isSubmitting } = useFormState()
const formInputs = useWatch<FormFieldValues>({}) as FormFieldValues
const { formId, isPaymentEnabled } = usePublicFormContext()
const { formId, isPaymentEnabled, isPreview } = usePublicFormContext()

const paymentEmailField = formInputs[
PAYMENT_CONTACT_FIELD_ID
Expand Down Expand Up @@ -104,7 +104,7 @@ export const PublicFormSubmitButton = ({
isLoading={isSubmitting}
isDisabled={!!preventSubmissionLogic || !onSubmit}
loadingText="Submitting"
onClick={isPaymentEnabled ? checkBeforeOpen : onSubmit}
onClick={isPaymentEnabled && !isPreview ? checkBeforeOpen : onSubmit}
>
<VisuallyHidden>End of form.</VisuallyHidden>
{preventSubmissionLogic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ import { usePublicFormContext } from '../../PublicFormContext'
*/
export const PublicFormPaymentResumeModal = (): JSX.Element => {
const isMobile = useIsMobile()
const { isPaymentEnabled, formId } = usePublicFormContext()
const { isPaymentEnabled, formId, isPreview } = usePublicFormContext()

const [lastPaymentMemory, , clearPaymentMemory] = useBrowserStm(formId)

const { isOpen, onClose } = useDisclosure({
defaultIsOpen: Boolean(lastPaymentMemory && isPaymentEnabled),
defaultIsOpen: Boolean(lastPaymentMemory && isPaymentEnabled && !isPreview),
})

const navigate = useNavigate()
if (!isOpen) {
return <></>
}
const onSubmit = () => {
if (!lastPaymentMemory) {
if (!lastPaymentMemory || isPreview) {
onClose()
return
}
Expand Down