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_NAME=$npm_package_name
REACT_APP_GUEST_CONSENT_STEP_ENABLED=true
REACT_APP_SUPPORT_MAIL=test@example.org
REACT_APP_INST=uio
REACT_APP_SUPPORT_URL=https://example.org
......
......@@ -23,6 +23,10 @@ export const appInst: string = env.REACT_APP_INST as string
export const appStagingWarning: boolean =
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 */
export const appTechnicalSupportLink: string =
env.REACT_APP_SUPPORT_URL as string
......
import React, { Suspense, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Box, Button, CircularProgress } from '@mui/material'
import Page from 'components/page'
import { useHistory } from 'react-router-dom'
import {
CountryCode,
......@@ -12,7 +8,11 @@ import {
} from 'libphonenumber-js'
import format from 'date-fns/format'
import parse from 'date-fns/parse'
import { Box, Button, CircularProgress } from '@mui/material'
import { splitPhoneNumber, submitJsonOpts, fetchJsonOpts } from 'utils'
import { guestConsentStepEnabled } from 'appConfig'
import Page from 'components/page'
import OverviewGuestButton from '../../components/overviewGuestButton'
import { GuestRegisterCallableMethods } from './guestRegisterCallableMethods'
import { GuestRegisterData, GuestConsentData } from './enteredGuestData'
......@@ -84,6 +84,7 @@ export default function GuestRegister() {
useState<GuestInviteInformation | null>(null)
const [guestRegisterData, setGuestRegisterData] =
useState<GuestRegisterData | null>(null)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [guestConsentData, setGuestConsentData] =
useState<GuestConsentData | null>(null)
......@@ -236,16 +237,22 @@ export default function GuestRegister() {
return payload
}
const submitPayload = () => {
if (!guestRegisterData) {
const submitPayload = (
registerData: GuestRegisterData,
consentData: GuestConsentData | null
) => {
if (!registerData) {
setActiveStep(Step.RegisterStep)
return
}
if (!guestConsentData) {
if (guestConsentStepEnabled && !consentData) {
setActiveStep(Step.ConsentStep)
return
}
const payload: any = makePayload(guestRegisterData, guestConsentData)
const consents = guestConsentStepEnabled
? consentData ?? { consents: [] }
: { consents: [] }
const payload: any = makePayload(registerData, consents)
console.log('submitting payload', payload)
fetch('/api/ui/v1/invited/', submitJsonOpts('POST', payload))
.then((response) => {
......@@ -266,21 +273,25 @@ export default function GuestRegister() {
const handleForwardFromRegister = (registerData: GuestRegisterData): void => {
console.log('handleForwardFromRegister')
setGuestRegisterData(registerData)
if (!guestConsentStepEnabled) {
submitPayload(registerData, null)
return
}
setActiveStep(Step.ConsentStep)
}
const handleForwardFromConsent = (consentData: GuestConsentData): void => {
console.log('handleForwardFromConsent')
console.log('handleForwardFromConsent consentData is', consentData)
setGuestConsentData(consentData)
if (!guestRegisterData) {
setActiveStep(Step.RegisterStep)
return
}
if (!guestConsentData) {
if (!consentData) {
setActiveStep(Step.ConsentStep)
return
}
submitPayload()
submitPayload(guestRegisterData, consentData)
}
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