Skip to content

Commit

Permalink
feat: migrate banners on React to non-'React'-suffixed env vars (#6441)
Browse files Browse the repository at this point in the history
* feat: migrate banners on React to non-'React'-suffixed env vars

* chore: cleam up TODO comments
  • Loading branch information
justynoh authored and KenLSM committed Jun 8, 2023
1 parent 4f2853c commit e91e580
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 74 deletions.
8 changes: 3 additions & 5 deletions frontend/src/features/admin-form/common/AdminFormLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ export const AdminFormLayout = (): JSX.Element => {
const { formId } = useParams()
if (!formId) throw new Error('No formId provided')

// TODO (#4279): Revert back to non-react banners post-migration.
const { data: { siteBannerContentReact, adminBannerContentReact } = {} } =
useEnv()
const { data: { siteBannerContent, adminBannerContent } = {} } = useEnv()

const bannerContent = useMemo(
// Use || instead of ?? so that we fall through even if previous banners are empty string.
() => siteBannerContentReact || adminBannerContentReact,
[adminBannerContentReact, siteBannerContentReact],
() => siteBannerContent || adminBannerContent,
[adminBannerContent, siteBannerContent],
)

const bannerProps = useMemo(
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/features/login/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,16 @@ const NonMobileSidebarGridArea: FC = ({ children }) => (
)

export const LoginPage = (): JSX.Element => {
const { data: { siteBannerContentReact, isLoginBannerReact } = {} } = useEnv()
const { data: { siteBannerContent, isLoginBanner } = {} } = useEnv()
const [, setIsAuthenticated] = useLocalStorage<boolean>(LOGGED_IN_KEY)
const [email, setEmail] = useState<string>()
const [otpPrefix, setOtpPrefix] = useState<string>('')
const { t } = useTranslation()

// TODO (#4279): Revert back to non-react banners post-migration.
const bannerContent = useMemo(
// Use || instead of ?? so that we fall through even if previous banners are empty string.
() => siteBannerContentReact || isLoginBannerReact,
[siteBannerContentReact, isLoginBannerReact],
() => siteBannerContent || isLoginBanner,
[siteBannerContent, isLoginBanner],
)

const bannerProps = useMemo(
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/features/public-form/components/FormBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,31 @@ import { usePublicFormContext } from '../PublicFormContext'
export const FormBanner = (): JSX.Element | null => {
const {
data: {
siteBannerContentReact,
isGeneralMaintenanceReact,
siteBannerContent,
isGeneralMaintenance,
isSPMaintenance,
isCPMaintenance,
myInfoBannerContent,
} = {},
} = useEnv()
const { form } = usePublicFormContext()

// TODO (#4279): Revert back to non-react banners post-migration.

const bannerContent = useMemo(
// Use || instead of ?? so that we fall through even if previous banners are empty string.
() =>
siteBannerContentReact ||
isGeneralMaintenanceReact ||
siteBannerContent ||
isGeneralMaintenance ||
(form?.authType === FormAuthType.SP && isSPMaintenance) ||
(form?.authType === FormAuthType.CP && isCPMaintenance) ||
(form?.authType === FormAuthType.MyInfo && myInfoBannerContent) ||
undefined,
[
form?.authType,
isCPMaintenance,
isGeneralMaintenanceReact,
isGeneralMaintenance,
isSPMaintenance,
myInfoBannerContent,
siteBannerContentReact,
siteBannerContent,
],
)

Expand Down
8 changes: 3 additions & 5 deletions frontend/src/features/workspace/WorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ import { WorkspaceProvider } from './WorkspaceProvider'
export const CONTAINER_MAXW = '69.5rem'

export const WorkspacePage = (): JSX.Element => {
const { data: { siteBannerContentReact, adminBannerContentReact } = {} } =
useEnv()
const { data: { siteBannerContent, adminBannerContent } = {} } = useEnv()

// TODO (#4279): Revert back to non-react banners post-migration.
const bannerContent = useMemo(
// Use || instead of ?? so that we fall through even if previous banners are empty string.
() => siteBannerContentReact || adminBannerContentReact,
[adminBannerContentReact, siteBannerContentReact],
() => siteBannerContent || adminBannerContent,
[adminBannerContent, siteBannerContent],
)

const bannerProps = useMemo(
Expand Down
6 changes: 1 addition & 5 deletions shared/types/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ export type ClientEnvVars = {
isSPMaintenance: string // Singpass maintenance message
isCPMaintenance: string // Corppass maintenance message
myInfoBannerContent: string // MyInfo maintenance message
// TODO: remove after React rollout #4786, #4279
// TODO: remove after React rollout #4786
GATrackingID: string | null
isGeneralMaintenanceReact: string
isLoginBannerReact: string
siteBannerContentReact: string
adminBannerContentReact: string

spcpCookieDomain: string // Cookie domain used for removing spcp cookies
stripePublishableKey: string
Expand Down
5 changes: 0 additions & 5 deletions src/app/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ const config: Config = {
isLoginBanner: basicVars.banner.isLoginBanner,
siteBannerContent: basicVars.banner.siteBannerContent,
adminBannerContent: basicVars.banner.adminBannerContent,
// TODO (#4279): Delete these when react migration is over. Revert back to original banner variables in react frontend.
isGeneralMaintenanceReact: basicVars.banner.isGeneralMaintenanceReact,
isLoginBannerReact: basicVars.banner.isLoginBannerReact,
siteBannerContentReact: basicVars.banner.siteBannerContentReact,
adminBannerContentReact: basicVars.banner.adminBannerContentReact,
rateLimitConfig: basicVars.rateLimit,
reactMigration: basicVars.reactMigration,
configureAws,
Expand Down
25 changes: 0 additions & 25 deletions src/app/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,31 +185,6 @@ export const optionalVarsSchema: Schema<IOptionalVarsSchema> = {
default: '',
env: 'ADMIN_BANNER_CONTENT',
},
// TODO (#4279): Delete these when react migration is over. Revert back to original banner variables in react frontend.
isGeneralMaintenanceReact: {
doc: 'Load env variable with General Maintenance banner text. For React only.',
format: String,
default: '',
env: 'IS_GENERAL_MAINTENANCE_REACT',
},
isLoginBannerReact: {
doc: 'The banner message on login page. Allows for HTML. For React only.',
format: String,
default: '',
env: 'IS_LOGIN_BANNER_REACT',
},
siteBannerContentReact: {
doc: 'The banner message to show on all pages. Allows for HTML. Will supersede all other banner content if it exists. For React only.',
format: String,
default: '',
env: 'SITE_BANNER_CONTENT_REACT',
},
adminBannerContentReact: {
doc: 'The banner message to show on on admin pages. Allows for HTML. For React only.',
format: String,
default: '',
env: 'ADMIN_BANNER_CONTENT_REACT',
},
},
formsgSdkMode: {
doc: 'Inform SDK which public keys are to be used to sign, encrypt, or decrypt data that is passed to it',
Expand Down
6 changes: 1 addition & 5 deletions src/app/modules/frontend/frontend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ export const getClientEnvVars = (): ClientEnvVars => {
isSPMaintenance: spcpMyInfoConfig.isSPMaintenance, // Singpass maintenance message
isCPMaintenance: spcpMyInfoConfig.isCPMaintenance, // Corppass maintenance message
myInfoBannerContent: spcpMyInfoConfig.myInfoBannerContent, // MyInfo maintenance message
// TODO: remove after React rollout #4786, #4279
// TODO: remove after React rollout #4786
GATrackingID: googleAnalyticsConfig.GATrackingID,
isGeneralMaintenanceReact: config.isGeneralMaintenanceReact,
isLoginBannerReact: config.isLoginBannerReact,
siteBannerContentReact: config.siteBannerContentReact,
adminBannerContentReact: config.adminBannerContentReact,

spcpCookieDomain: spcpMyInfoConfig.spcpCookieDomain, // Cookie domain used for removing spcp cookies
stripePublishableKey: paymentConfig.stripePublishableKey,
Expand Down
12 changes: 0 additions & 12 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ export type Config = {
isLoginBanner: string
siteBannerContent: string
adminBannerContent: string

// TODO (#4279): Delete these when react migration is over. Revert back to original banner variables in react frontend.
isGeneralMaintenanceReact: string
isLoginBannerReact: string
siteBannerContentReact: string
adminBannerContentReact: string

rateLimitConfig: RateLimitConfig
reactMigration: ReactMigrationConfig
secretEnv: string
Expand Down Expand Up @@ -154,11 +147,6 @@ export interface IOptionalVarsSchema {
isLoginBanner: string
siteBannerContent: string
adminBannerContent: string
// TODO (#4279): Delete these when react migration is over. Revert back to original banner variables in react frontend.
isGeneralMaintenanceReact: string
isLoginBannerReact: string
siteBannerContentReact: string
adminBannerContentReact: string
}
awsConfig: {
region: string
Expand Down

0 comments on commit e91e580

Please sign in to comment.