Skip to content

Commit

Permalink
feat: add beta flag for main mfb button
Browse files Browse the repository at this point in the history
  • Loading branch information
kathleenkhy committed Apr 26, 2024
1 parent 832ff2f commit e8a0468
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import { useFeatureIsOn } from '@growthbook/growthbook-react'
import { isValidMotionProp, motion } from 'framer-motion'

import { featureFlags } from '~shared/constants'
import { SubmissionType } from '~shared/types'

import { BxsMagicWand } from '~assets/icons/BxsMagicWand'
import { BxsWidget } from '~assets/icons/BxsWidget'
import { useIsMobile } from '~hooks/useIsMobile'
import Button from '~components/Button'

import { useUser } from '~features/user/queries'

const ChakraBox = chakra(motion.div, {
/**
* Allow motion props and non-Chakra props to be forwarded.
Expand Down Expand Up @@ -53,7 +56,10 @@ export const EmptyFormPlaceholder = forwardRef<
: 'Drag a field from the Builder on the left to start'
}, [isDraggingOver, isMobile])

const showMagicFormButton = useFeatureIsOn(featureFlags.magicFormBuilder)
const { user } = useUser()

const showMagicFormButton =
useFeatureIsOn(featureFlags.magicFormBuilder) && user?.betaFlags?.mfb

const showMagicFormButtonFinal = useMemo(() => {
return showMagicFormButton ? (
Expand Down
1 change: 1 addition & 0 deletions shared/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const UserBase = z.object({
.object({
payment: z.boolean().optional(),
children: z.boolean().optional(),
mfb: z.boolean().optional(),
})
.optional(),
flags: z
Expand Down
1 change: 1 addition & 0 deletions src/app/models/user.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const compileUserModel = (db: Mongoose) => {
betaFlags: {
payment: Boolean,
children: Boolean,
mfb: Boolean,
},
flags: {
lastSeenFeatureUpdateVersion: Number,
Expand Down
9 changes: 8 additions & 1 deletion src/app/modules/form/admin-form/admin-form.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { celebrate, Joi as BaseJoi, Segments } from 'celebrate'
import { AuthedSessionData } from 'express-session'
import { StatusCodes } from 'http-status-codes'
import JSONStream from 'JSONStream'
import { ResultAsync } from 'neverthrow'
import { okAsync, ResultAsync } from 'neverthrow'

import {
MAX_UPLOAD_FILE_SIZE,
Expand Down Expand Up @@ -104,6 +104,7 @@ import { PermissionLevel } from './admin-form.types'
import {
mapGoGovErrors,
mapRouteError,
verifyUserBetaflag,
verifyValidUnicodeString,
} from './admin-form.utils'

Expand Down Expand Up @@ -1182,6 +1183,12 @@ export const createForm: ControllerHandler<
return (
// Step 1: Retrieve currently logged in user.
UserService.findUserById(sessionUserId)
.andThen((user) =>
formParams.responseMode === FormResponseMode.Encrypt ||
formParams.responseMode === FormResponseMode.Email
? verifyUserBetaflag(user, 'mfb')
: okAsync(user),
)
// Step 2: Create form with given params and set admin to logged in user.
.andThen((user) =>
AdminFormService.createForm(
Expand Down

0 comments on commit e8a0468

Please sign in to comment.