diff --git a/frontend/.env b/frontend/.env index 70faa8f9a589740601cce72e8d0c213c2e3fc2e8..b519139c7dc9390a44aca01d5b18906bacddf8f3 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1,6 +1,8 @@ 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 diff --git a/frontend/src/appConfig.ts b/frontend/src/appConfig.ts index 4af122b83bf0d65b3d035d5b1cab3c01f937db48..2758100a3a49bc7ac103e3409e6a49632e1561f4 100644 --- a/frontend/src/appConfig.ts +++ b/frontend/src/appConfig.ts @@ -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 diff --git a/frontend/src/routes/guest/register/index.tsx b/frontend/src/routes/guest/register/index.tsx index 02194ba0d2a6645f40e83524473fc16e11134088..c595bac7361717600f2670694d96eec2852f3782 100644 --- a/frontend/src/routes/guest/register/index.tsx +++ b/frontend/src/routes/guest/register/index.tsx @@ -1,9 +1,5 @@ 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 = () => {