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

625: Application end screen #648

Merged
merged 9 commits into from
Dec 14, 2022
42 changes: 37 additions & 5 deletions administration/src/application/components/ApplyController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,42 @@ import useVersionedLocallyStoredState from '../useVersionedLocallyStoredState'
import DiscardAllInputsButton from './DiscardAllInputsButton'
import { useGarbageCollectArrayBuffers, useInitializeGlobalArrayBuffersManager } from '../globalArrayBuffersManager'
import ApplicationForm from './forms/ApplicationForm'
import { useCallback, useMemo } from 'react'
import { useCallback, useMemo, useState } from 'react'
import { SnackbarProvider, useSnackbar } from 'notistack'
import styled from 'styled-components'
import ApplicationErrorBoundary from '../ApplicationErrorBoundary'
import { useAppToaster } from '../../components/AppToaster'

// This env variable is determined by '../../../application_commit.sh'. It holds the hash of the last commit to the
// application form.
const lastCommitForApplicationForm = process.env.REACT_APP_APPLICATION_COMMIT as string

export const applicationStorageKey = 'applicationState'

const SuccessContent = styled.div`
white-space: pre-line;
display: flex;
justify-content: center;
margin-bottom: 1rem;
`

const ApplyController = () => {
const [addBlueEakApplication, { loading }] = useAddBlueEakApplicationMutation()
const [formSubmitted, setFormSubmitted] = useState<boolean>(false)
const appToaster = useAppToaster()
const [addBlueEakApplication, { loading }] = useAddBlueEakApplicationMutation({
onError: error => {
console.error(error)
appToaster?.show({ intent: 'danger', message: 'Beim Absenden des Antrags is ein Fehler aufgetreten.' })
},
onCompleted: result => {
if (result) {
setState(() => ApplicationForm.initialState)
setFormSubmitted(true)
} else {
appToaster?.show({ intent: 'danger', message: 'Beim Absenden des Antrags is ein Fehler aufgetreten.' })
f1sh1918 marked this conversation as resolved.
Show resolved Hide resolved
}
},
})
const { status, state, setState } = useVersionedLocallyStoredState(
ApplicationForm.initialState,
applicationStorageKey,
Expand Down Expand Up @@ -58,13 +82,21 @@ const ApplyController = () => {
},
})
}
const successText = `Ihr Antrag für die Ehrenamtskarte wurde erfolgreich übermittelt.
Sie können das Fenster schließen.`
f1sh1918 marked this conversation as resolved.
Show resolved Hide resolved

return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'start', margin: '16px' }}>
<div style={{ maxWidth: '1000px', width: '100%' }}>
<h2 style={{ textAlign: 'center' }}>Blaue Ehrenamtskarte beantragen</h2>
<ApplicationForm.Component state={state} setState={setState} onSubmit={submit} loading={loading} />
<DialogActions>{loading ? null : <DiscardAllInputsButton discardAll={discardAll} />}</DialogActions>
<h2 style={{ textAlign: 'center' }}>{formSubmitted ? 'Erfolgreich gesendet' : 'Ehrenamtskarte beantragen'}</h2>
{formSubmitted ? (
<SuccessContent>{successText}</SuccessContent>
) : (
<ApplicationForm.Component state={state} setState={setState} onSubmit={submit} loading={loading} />
)}
<DialogActions>
{loading || formSubmitted ? null : <DiscardAllInputsButton discardAll={discardAll} />}
</DialogActions>
</div>
</div>
)
Expand Down