Skip to content

Commit

Permalink
fix: fix chromatic reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
g-tejas committed Jun 14, 2024
1 parent d4055ed commit 6c09ea2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
41 changes: 21 additions & 20 deletions frontend/src/features/admin-form/settings/SettingsEmailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
import { Skeleton, Stack, Wrap } from '@chakra-ui/react'
import { FormControl, Skeleton } from '@chakra-ui/react'

import { FormResponseMode } from '~shared/types'

import FormLabel from '~components/FormControl/FormLabel'
import { TagInput } from '~components/TagInput'

import { CategoryHeader } from './components/CategoryHeader'
import { EmailFormSection } from './components/EmailFormSection'
import { useAdminFormSettings } from './queries'

const AdminEmailSection = (): JSX.Element => {
const { data: settings, isLoading: isLoadingSettings } =
useAdminFormSettings()
const { data: settings } = useAdminFormSettings()

const isEmailOrStorageMode =
settings?.responseMode === FormResponseMode.Email ||
settings?.responseMode === FormResponseMode.Encrypt

if (settings && isEmailOrStorageMode) {
return <EmailFormSection settings={settings} />
} else {
return <EmailFormSectionSkeleton />
}
}

export const EmailFormSectionSkeleton = (): JSX.Element => {
return (
<Skeleton isLoaded={!isLoadingSettings && !!settings}>
<Stack spacing="2rem">
{settings && isEmailOrStorageMode ? (
<EmailFormSection settings={settings} />
) : null}
</Stack>
</Skeleton>
<FormControl isRequired>
<FormLabel>Send an email copy of new responses</FormLabel>
<Skeleton>
<TagInput placeholder="me@example.com" isDisabled />
</Skeleton>
</FormControl>
)
}

export const SettingsEmailsPage = (): JSX.Element => {
return (
<>
<Wrap
shouldWrapChildren
spacing="0.5rem"
justify="space-between"
mb="2.5rem"
>
<CategoryHeader mb={0} mr="2rem">
Email notifications
</CategoryHeader>
</Wrap>
<CategoryHeader>Email notifications</CategoryHeader>
<AdminEmailSection />
</>
)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/admin-form/settings/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const SettingsPage = (): JSX.Element => {
) {
// Add the Email Notifications page into the tab list, after singpass
baseConfig.splice(2, 0, {
label: 'Email Notifications',
label: 'Email notifications',
icon: BiMailSend,
component: SettingsEmailsPage,
path: 'email-notifications',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const EmailFormSection = ({
(settings.payments_channel.channel !== PaymentChannel.Unconnected ||
settings.payments_field.enabled)

const isEmailsDisabled = isFormPublic || isPaymentsEnabled

const handleSubmitEmails = useCallback(
({ emails }: { emails: string[] }) => {
if (isEqual(new Set(emails.filter(Boolean)), initialEmailSet)) return
Expand All @@ -91,10 +93,7 @@ export const EmailFormSection = ({
isFormResponseModeEmail={isEmailMode}
/>
<FormProvider {...formMethods}>
<FormControl
isInvalid={!isEmpty(errors)}
isDisabled={isFormPublic || isPaymentsEnabled}
>
<FormControl isInvalid={!isEmpty(errors)} isDisabled={isEmailsDisabled}>
<FormLabel
isRequired={isEmailMode}
useMarkdownForDescription
Expand All @@ -105,11 +104,20 @@ export const EmailFormSection = ({
>
Send an email copy of new responses
</FormLabel>
<AdminEmailRecipientsInput onSubmit={handleSubmitEmails} />
<AdminEmailRecipientsInput
onSubmit={handleSubmitEmails}
isEmailsDisabled={isEmailsDisabled}
/>
<FormErrorMessage>{get(errors, 'emails.message')}</FormErrorMessage>
<FormLabel.Description color="secondary.400" mt="0.5rem">
Separate multiple email addresses with a comma
</FormLabel.Description>
{isEmpty(errors) ? (
<FormLabel.Description
color="secondary.400"
mt="0.5rem"
opacity={isEmailsDisabled ? '0.3' : '1'}
>
Separate multiple email addresses with a comma
</FormLabel.Description>
) : null}
</FormControl>
</FormProvider>
</>
Expand All @@ -120,7 +128,7 @@ const MRFAdvertisingInfobox = () => {
const mdComponents = useMdComponents()

return (
<Flex bg="primary.100" p="1rem">
<Flex bg="primary.100" p="1rem" marginBottom="40px">
<Icon as={BiBulb} color="primary.500" fontSize="1.5rem" mr="0.5rem" />
<MarkdownText
components={mdComponents}
Expand All @@ -142,17 +150,16 @@ const EmailNotificationsHeader = ({
}: EmailNotificationsHeaderProps) => {
if (isFormPublic) {
return (
<InlineMessage>
<InlineMessage marginBottom="40px">
To change admin email recipients, close your form to new responses.
</InlineMessage>
)
}

if (isPaymentsEnabled) {
return (
<InlineMessage useMarkdown>
{`Email notifications for payment forms are not available in FormSG. You
can configure them using [Plumber](${OGP_PLUMBER}).`}
<InlineMessage useMarkdown marginBottom="40px">
{`Email notifications for payment forms are not available in FormSG. You can configure them using [Plumber](${OGP_PLUMBER}).`}
</InlineMessage>
)
}
Expand All @@ -166,6 +173,7 @@ const EmailNotificationsHeader = ({

interface AdminEmailRecipientsInputProps {
onSubmit: (params: { emails: string[] }) => void
isEmailsDisabled: boolean
}

const AdminEmailRecipientsInput = ({
Expand Down Expand Up @@ -202,7 +210,10 @@ const AdminEmailRecipientsInput = ({
<TagInput
{...(getValues('emails') && getValues('emails').length > 0
? {}
: { placeholder: 'me@example.com' })}
: {
placeholder: 'me@example.com',
_placeholder: { color: 'neutral.500' },
})}
{...field}
tagValidation={tagValidation}
onBlur={handleBlur}
Expand Down

0 comments on commit 6c09ea2

Please sign in to comment.