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

feat(form-v2/react-to-angular/3): remove infoboxes when rollout percentages hit thresholds #4514

Merged
merged 5 commits into from
Aug 10, 2022
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
19 changes: 16 additions & 3 deletions frontend/src/features/public-form/components/PublicFormWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useMemo } from 'react'
import { Flex, Spacer } from '@chakra-ui/react'

import { FormColorTheme } from '~shared/types'
import { FormColorTheme, FormResponseMode } from '~shared/types'

import { useEnv } from '~features/env/queries'

import { usePublicFormContext } from '../PublicFormContext'

Expand Down Expand Up @@ -38,18 +40,29 @@ export const PublicFormWrapper = ({
isPreview,
children,
}: PublicFormWrapperProps): JSX.Element => {
const REMOVE_RESPONDENTS_INFOBOX_THRESHOLD = 10
const { form, isLoading, isAuthRequired } = usePublicFormContext()
const { data: { respondentRolloutEmail, respondentRolloutStorage } = {} } =
useEnv()

const bgColour = useBgColor({
colorTheme: isLoading ? undefined : form?.startPage.colorTheme,
})

const isEmailForm = form?.responseMode === FormResponseMode.Email
const switchEnvRolloutPercentage = isEmailForm
? respondentRolloutEmail
: respondentRolloutStorage
// Remove the switch env message if the React rollout for public form respondents is >10%
const showSwitchEnvMessage = !!(
switchEnvRolloutPercentage &&
switchEnvRolloutPercentage <= REMOVE_RESPONDENTS_INFOBOX_THRESHOLD
)
return (
<Flex bg={bgColour} p={{ base: 0, md: '1.5rem' }} flex={1} justify="center">
{isAuthRequired ? null : <SectionSidebar />}
<Flex flexDir="column" maxW="57rem" w="100%">
{/* TODO(#4279): Remove switch env message on full rollout */}
{!isPreview && <PublicSwitchEnvMessage />}
{!isPreview && showSwitchEnvMessage && <PublicSwitchEnvMessage />}
{children}
</Flex>
{isAuthRequired ? null : <Spacer />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import Button from '~components/Button'
import InlineMessage from '~components/InlineMessage'

import { useEnvMutations } from '~features/env/mutations'
import { useEnv } from '~features/env/queries'

export const AdminSwitchEnvMessage = (): JSX.Element => {
const REMOVE_ADMIN_INFOBOX_THRESHOLD = 100
const { adminSwitchEnvMutation } = useEnvMutations()

return (
const { data: { adminRollout } = {} } = useEnv()
const showSwitchEnvMessage =
adminRollout && adminRollout < REMOVE_ADMIN_INFOBOX_THRESHOLD
return showSwitchEnvMessage ? (
<InlineMessage>
<Text>
Welcome to the new FormSG! You can still{' '}
Expand All @@ -19,5 +23,7 @@ export const AdminSwitchEnvMessage = (): JSX.Element => {
which is available until 28 May 2022.
</Text>
</InlineMessage>
) : (
<></>
)
}
3 changes: 3 additions & 0 deletions shared/types/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ export type ClientEnvVars = {
myInfoBannerContent: string // MyInfo maintenance message
GATrackingID: string | null
spcpCookieDomain: string // Cookie domain used for removing spcp cookies
respondentRolloutEmail: number
respondentRolloutStorage: number
adminRollout: number
}
8 changes: 8 additions & 0 deletions src/app/loaders/express/locals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const frontendVars = {
reactMigrationRespondentCookieName:
config.reactMigration.respondentCookieName,
reactMigrationAdminCookieName: config.reactMigration.adminCookieName,
reactMigrationRespondentRolloutEmail:
config.reactMigration.respondentRolloutEmail,
reactMigrationRespondentRolloutStorage:
config.reactMigration.respondentRolloutStorage,
reactMigrationAdminRollout: config.reactMigration.adminRollout,
}
const environment = ejs.render(
`
Expand All @@ -51,6 +56,9 @@ const environment = ejs.render(
// React Migration
var reactMigrationRespondentCookieName = "<%= reactMigrationRespondentCookieName%>"
var reactMigrationAdminCookieName = "<%= reactMigrationAdminCookieName%>"
var reactMigrationRespondentRolloutEmail = "<%= reactMigrationRespondentRolloutEmail%>"
var reactMigrationRespondentRolloutStorage = "<%= reactMigrationRespondentRolloutStorage%>"
var reactMigrationAdminRollout = "<%= reactMigrationAdminRollout%>"
`,
frontendVars,
)
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/frontend/frontend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ export const getClientEnvVars = (): ClientEnvVars => {
myInfoBannerContent: spcpMyInfoConfig.myInfoBannerContent, // MyInfo maintenance message
GATrackingID: googleAnalyticsConfig.GATrackingID,
spcpCookieDomain: spcpMyInfoConfig.spcpCookieDomain, // Cookie domain used for removing spcp cookies
respondentRolloutEmail: config.reactMigration.respondentRolloutEmail,
respondentRolloutStorage: config.reactMigration.respondentRolloutStorage,
adminRollout: config.reactMigration.adminRollout,
}
}
6 changes: 6 additions & 0 deletions src/public/utils/injectedVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface FrontendInjectedVariables {
myInfoBannerContent: string | null
GATrackingID: string | null
spcpCookieDomain: string | null
respondentRolloutEmail: number
respondentRolloutStorage: number
adminRollout: number
}

// NOTE: As these variables are not injected until runtime
Expand All @@ -35,4 +38,7 @@ export const injectedVariables: FrontendInjectedVariables = {
myInfoBannerContent: formsgWindow.myInfoBannerContent ?? null,
GATrackingID: formsgWindow.GATrackingID ?? null,
spcpCookieDomain: formsgWindow.spcpCookieDomain ?? null,
respondentRolloutEmail: formsgWindow.respondentRolloutEmail,
respondentRolloutStorage: formsgWindow.respondentRolloutStorage,
adminRollout: formsgWindow.adminRollout,
}