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: gate mrf form creation on frontend and backend by beta-flags #6962

Merged
merged 1 commit into from
Dec 19, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { FormResponseMode } from '~shared/types/form/form'
import Badge from '~components/Badge'
import Tile from '~components/Tile'

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

export interface FormResponseOptionsProps {
onChange: (option: FormResponseMode) => void
value: FormResponseMode
Expand All @@ -29,6 +31,7 @@ export const FormResponseOptions = forwardRef<
FormResponseOptionsProps,
'button'
>(({ value, onChange }, ref) => {
const { user } = useUser()
return (
<Stack spacing="1rem" w="100%" direction={{ base: 'column', md: 'row' }}>
<Tile
Expand Down Expand Up @@ -69,28 +72,30 @@ export const FormResponseOptions = forwardRef<
]}
/>
</Tile>
<Tile
ref={ref}
variant="complex"
//TODO(MRF/FRM-1599): Fix this icon.
icon={BiGroup}
badge={<Badge colorScheme="success">New</Badge>}
isActive={value === FormResponseMode.Multirespondent}
onClick={() => onChange(FormResponseMode.Multirespondent)}
isFullWidth
flex={1}
>
<Tile.Title>Multi-respondent form</Tile.Title>
<Tile.Subtitle>
Create a workflow to collect responses from multiple respondents
</Tile.Subtitle>
<OptionDescription
listItems={[
'Route form to respondents according to a sequence',
'Specify up to two respondents to route form to for filling',
]}
/>
</Tile>
{user?.betaFlags?.mrf && (
<Tile
ref={ref}
variant="complex"
//TODO(MRF/FRM-1599): Fix this icon.
icon={BiGroup}
badge={<Badge colorScheme="success">New</Badge>}
isActive={value === FormResponseMode.Multirespondent}
onClick={() => onChange(FormResponseMode.Multirespondent)}
isFullWidth
flex={1}
>
<Tile.Title>Multi-respondent form</Tile.Title>
<Tile.Subtitle>
Create a workflow to collect responses from multiple respondents
</Tile.Subtitle>
<OptionDescription
listItems={[
'Route form to respondents according to a sequence',
'Specify up to two respondents to route form to for filling',
]}
/>
</Tile>
)}
</Stack>
)
})
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(),
mrf: 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 @@ -73,6 +73,7 @@ const compileUserModel = (db: Mongoose) => {
betaFlags: {
payment: Boolean,
children: Boolean,
mrf: Boolean,
},
flags: {
lastSeenFeatureUpdateVersion: Number,
Expand Down
8 changes: 7 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 @@ -105,6 +105,7 @@ import { PermissionLevel } from './admin-form.types'
import {
mapGoGovErrors,
mapRouteError,
verifyUserBetaflag,
verifyValidUnicodeString,
} from './admin-form.utils'

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