Skip to content
Snippets Groups Projects
Commit d2030a63 authored by Jonas Braathen's avatar Jonas Braathen
Browse files

Make consent step configurable. Workaround state changes being async.

parent c851b780
No related branches found
No related tags found
1 merge request!173Consents
Pipeline #101456 passed
REACT_APP_VERSION=$npm_package_version REACT_APP_VERSION=$npm_package_version
REACT_APP_NAME=$npm_package_name REACT_APP_NAME=$npm_package_name
REACT_APP_GUEST_CONSENT_STEP_ENABLED=true
REACT_APP_SUPPORT_MAIL=test@example.org REACT_APP_SUPPORT_MAIL=test@example.org
REACT_APP_INST=uio REACT_APP_INST=uio
REACT_APP_SUPPORT_URL=https://example.org REACT_APP_SUPPORT_URL=https://example.org
......
...@@ -23,6 +23,10 @@ export const appInst: string = env.REACT_APP_INST as string ...@@ -23,6 +23,10 @@ export const appInst: string = env.REACT_APP_INST as string
export const appStagingWarning: boolean = export const appStagingWarning: boolean =
env.REACT_APP_STAGING_WARNING === 'true' env.REACT_APP_STAGING_WARNING === 'true'
/* Is there a consent step during guest registration? */
export const guestConsentStepEnabled: boolean =
env.REACT_APP_GUEST_CONSENT_STEP_ENABLED === 'true'
/* Footer content */ /* Footer content */
export const appTechnicalSupportLink: string = export const appTechnicalSupportLink: string =
env.REACT_APP_SUPPORT_URL as string env.REACT_APP_SUPPORT_URL as string
......
import React, { Suspense, useEffect, useRef, useState } from 'react' import React, { Suspense, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Box, Button, CircularProgress } from '@mui/material'
import Page from 'components/page'
import { useHistory } from 'react-router-dom' import { useHistory } from 'react-router-dom'
import { import {
CountryCode, CountryCode,
...@@ -12,7 +8,11 @@ import { ...@@ -12,7 +8,11 @@ import {
} from 'libphonenumber-js' } from 'libphonenumber-js'
import format from 'date-fns/format' import format from 'date-fns/format'
import parse from 'date-fns/parse' import parse from 'date-fns/parse'
import { Box, Button, CircularProgress } from '@mui/material'
import { splitPhoneNumber, submitJsonOpts, fetchJsonOpts } from 'utils' import { splitPhoneNumber, submitJsonOpts, fetchJsonOpts } from 'utils'
import { guestConsentStepEnabled } from 'appConfig'
import Page from 'components/page'
import OverviewGuestButton from '../../components/overviewGuestButton' import OverviewGuestButton from '../../components/overviewGuestButton'
import { GuestRegisterCallableMethods } from './guestRegisterCallableMethods' import { GuestRegisterCallableMethods } from './guestRegisterCallableMethods'
import { GuestRegisterData, GuestConsentData } from './enteredGuestData' import { GuestRegisterData, GuestConsentData } from './enteredGuestData'
...@@ -84,6 +84,7 @@ export default function GuestRegister() { ...@@ -84,6 +84,7 @@ export default function GuestRegister() {
useState<GuestInviteInformation | null>(null) useState<GuestInviteInformation | null>(null)
const [guestRegisterData, setGuestRegisterData] = const [guestRegisterData, setGuestRegisterData] =
useState<GuestRegisterData | null>(null) useState<GuestRegisterData | null>(null)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [guestConsentData, setGuestConsentData] = const [guestConsentData, setGuestConsentData] =
useState<GuestConsentData | null>(null) useState<GuestConsentData | null>(null)
...@@ -236,16 +237,22 @@ export default function GuestRegister() { ...@@ -236,16 +237,22 @@ export default function GuestRegister() {
return payload return payload
} }
const submitPayload = () => { const submitPayload = (
if (!guestRegisterData) { registerData: GuestRegisterData,
consentData: GuestConsentData | null
) => {
if (!registerData) {
setActiveStep(Step.RegisterStep) setActiveStep(Step.RegisterStep)
return return
} }
if (!guestConsentData) { if (guestConsentStepEnabled && !consentData) {
setActiveStep(Step.ConsentStep) setActiveStep(Step.ConsentStep)
return return
} }
const payload: any = makePayload(guestRegisterData, guestConsentData) const consents = guestConsentStepEnabled
? consentData ?? { consents: [] }
: { consents: [] }
const payload: any = makePayload(registerData, consents)
console.log('submitting payload', payload) console.log('submitting payload', payload)
fetch('/api/ui/v1/invited/', submitJsonOpts('POST', payload)) fetch('/api/ui/v1/invited/', submitJsonOpts('POST', payload))
.then((response) => { .then((response) => {
...@@ -266,21 +273,25 @@ export default function GuestRegister() { ...@@ -266,21 +273,25 @@ export default function GuestRegister() {
const handleForwardFromRegister = (registerData: GuestRegisterData): void => { const handleForwardFromRegister = (registerData: GuestRegisterData): void => {
console.log('handleForwardFromRegister') console.log('handleForwardFromRegister')
setGuestRegisterData(registerData) setGuestRegisterData(registerData)
if (!guestConsentStepEnabled) {
submitPayload(registerData, null)
return
}
setActiveStep(Step.ConsentStep) setActiveStep(Step.ConsentStep)
} }
const handleForwardFromConsent = (consentData: GuestConsentData): void => { const handleForwardFromConsent = (consentData: GuestConsentData): void => {
console.log('handleForwardFromConsent') console.log('handleForwardFromConsent consentData is', consentData)
setGuestConsentData(consentData) setGuestConsentData(consentData)
if (!guestRegisterData) { if (!guestRegisterData) {
setActiveStep(Step.RegisterStep) setActiveStep(Step.RegisterStep)
return return
} }
if (!guestConsentData) { if (!consentData) {
setActiveStep(Step.ConsentStep) setActiveStep(Step.ConsentStep)
return return
} }
submitPayload() submitPayload(guestRegisterData, consentData)
} }
const handleCancel = () => { const handleCancel = () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment