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: Add the email input box for encrypt form modal #8071

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion __tests__/e2e/helpers/createForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const addSettings = async (
await expect(page).toHaveURL(ADMIN_FORM_PAGE_SETTINGS(formId))

await addGeneralSettings(page, formSettings)
await addAdminEmails(page, formSettings)
// await addAdminEmails(page, formSettings)
await addAuthSettings(page, formSettings)
await addCollaborators(page, formSettings)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ export const CreateFormDetailsScreen = (): JSX.Element => {
</InlineMessage>
)}
</FormControl>
{responseModeValue === FormResponseMode.Email && (
<FormControl isRequired isInvalid={!!errors.emails} mb="2.25rem">
{(responseModeValue === FormResponseMode.Encrypt ||
responseModeValue === FormResponseMode.Email) && (
<FormControl
isRequired={responseModeValue === FormResponseMode.Email}
isInvalid={!!errors.emails}
mb="2.25rem"
>
<FormLabel
isRequired={responseModeValue === FormResponseMode.Email}
useMarkdownForDescription
description={`All email addresses below will be notified. Learn more on [how to guard against email bounces](${GUIDE_PREVENT_EMAIL_BOUNCE}).`}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Skeleton } from '@chakra-ui/react'
import { get } from 'lodash'
import isEmail from 'validator/lib/isEmail'

import { REQUIRED_ADMIN_EMAIL_VALIDATION_RULES } from '~utils/formValidation'
import { FormResponseMode } from '~shared/types/form/form'

import {
OPTIONAL_ADMIN_EMAIL_VALIDATION_RULES,
REQUIRED_ADMIN_EMAIL_VALIDATION_RULES,
} from '~utils/formValidation'
import FormErrorMessage from '~components/FormControl/FormErrorMessage'
import Input from '~components/Input'
import { TagInput } from '~components/TagInput'
Expand All @@ -15,6 +20,10 @@ import { useCreateFormWizard } from '../CreateFormWizardContext'
export const EmailFormRecipientsInput = (): JSX.Element => {
const { user, isLoading } = useUser()
const { formMethods } = useCreateFormWizard()

const { watch } = formMethods
const responseModeValue = watch('responseMode')

const {
control,
formState: { errors },
Expand All @@ -35,7 +44,11 @@ export const EmailFormRecipientsInput = (): JSX.Element => {
control={control}
defaultValue={[user.email]}
name="emails"
rules={REQUIRED_ADMIN_EMAIL_VALIDATION_RULES}
rules={
responseModeValue === FormResponseMode.Email
? REQUIRED_ADMIN_EMAIL_VALIDATION_RULES
: OPTIONAL_ADMIN_EMAIL_VALIDATION_RULES
}
render={({ field }) => (
<TagInput
placeholder="Separate emails with a comma"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ const useCreateFormWizardContext = (): CreateFormWizardContextReturn => {
const workspaceId = isDefaultWorkspace ? undefined : activeWorkspace._id

const handleCreateStorageModeOrMultirespondentForm = handleSubmit(
({ title, responseMode }) => {
({ title, responseMode, emails }) => {
switch (responseMode) {
case FormResponseMode.Encrypt:
return createStorageModeFormMutation.mutate({
title,
responseMode,
publicKey: keypair.publicKey,
workspaceId,
emails: [],
emails: emails.filter(Boolean),
})
case FormResponseMode.Email:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const useDupeFormWizardContext = (): CreateFormWizardContextReturn => {
const workspaceId = isDefaultWorkspace ? undefined : activeWorkspace._id

const handleCreateStorageModeOrMultirespondentForm = handleSubmit(
({ title, responseMode }) => {
({ title, responseMode, emails }) => {
if (!activeFormMeta?._id) {
return
}
Expand All @@ -85,6 +85,7 @@ export const useDupeFormWizardContext = (): CreateFormWizardContextReturn => {
responseMode,
publicKey: keypair.publicKey,
workspaceId,
emails: emails.filter(Boolean),
})
case FormResponseMode.Email:
return
Expand Down
1 change: 1 addition & 0 deletions shared/types/form/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ export type DuplicateFormOverwriteDto = {
| {
responseMode: FormResponseMode.Encrypt
publicKey: string
emails: string[]
}
| {
responseMode: FormResponseMode.Multirespondent
Expand Down
Loading