Skip to content

Commit

Permalink
Improve send manager ux (#251)
Browse files Browse the repository at this point in the history
Co-authored-by: raphaelblum <44967610+raphaelblum@users.noreply.github.com>
  • Loading branch information
juliawegmayr and raphaelblum authored Feb 14, 2025
1 parent 5059c86 commit c15195c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-weeks-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/brevo-admin": patch
---

Improve send manager UX by positioning the TargetGroup field at the top and adding an info icon to all other fields, indicating that the TargetGroup must be selected and saved first.
11 changes: 8 additions & 3 deletions packages/admin/src/emailCampaigns/form/EmailCampaignForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function EmailCampaignForm({ id, EmailCampaignContentBlock, scope }: Form
};

const isScheduledDateInPast = state.scheduledAt != undefined && isBefore(new Date(state.scheduledAt), new Date());
const isSchedulingDisabled = state.sendingState === "SENT" || mode === "add" || state.targetGroups.length === 0 || isScheduledDateInPast;
const isCampaignCreated = state.sendingState === "SENT" || mode === "add" || state.targetGroups.length === 0 || isScheduledDateInPast;

return (
<>
Expand Down Expand Up @@ -297,11 +297,16 @@ export function EmailCampaignForm({ id, EmailCampaignContentBlock, scope }: Form
<SendManagerWrapper scope={scope}>
<SendManagerFields
scope={scope}
isSchedulingDisabled={isSchedulingDisabled}
isCampaignCreated={isCampaignCreated}
isSendable={!hasChanges && state.targetGroups != undefined}
id={id}
/>
<TestEmailCampaignForm id={id} isSendable={!hasChanges && state.targetGroups != undefined} />
<TestEmailCampaignForm
id={id}
isSendable={!hasChanges && state.targetGroups != undefined}
scope={scope}
isCampaignCreated={isCampaignCreated}
/>
</SendManagerWrapper>
</BlocksFinalForm>
),
Expand Down
50 changes: 34 additions & 16 deletions packages/admin/src/emailCampaigns/form/SendManagerFields.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useApolloClient, useMutation } from "@apollo/client";
import { Field, FinalFormSelect, SaveButton, useAsyncOptionsProps, useStackSwitchApi } from "@comet/admin";
import { Field, FinalFormSelect, SaveButton, Tooltip, useAsyncOptionsProps, useStackSwitchApi } from "@comet/admin";
import { FinalFormDateTimePicker } from "@comet/admin-date-time";
import { Newsletter } from "@comet/admin-icons";
import { Info, Newsletter } from "@comet/admin-icons";
import { AdminComponentPaper, AdminComponentSectionGroup } from "@comet/blocks-admin";
import { ContentScopeInterface } from "@comet/cms-admin";
import { Card } from "@mui/material";
Expand All @@ -22,7 +22,7 @@ interface SendManagerFieldsProps {
scope: ContentScopeInterface;
id?: string;
isSendable: boolean;
isSchedulingDisabled?: boolean;
isCampaignCreated?: boolean;
}

const validateScheduledAt = (value: Date, now: Date) => {
Expand All @@ -38,7 +38,7 @@ const validateScheduledAt = (value: Date, now: Date) => {
}
};

export const SendManagerFields = ({ isSchedulingDisabled, scope, id, isSendable }: SendManagerFieldsProps) => {
export const SendManagerFields = ({ isCampaignCreated, scope, id, isSendable }: SendManagerFieldsProps) => {
const stackSwitchApi = useStackSwitchApi();
const apolloClient = useApolloClient();

Expand Down Expand Up @@ -66,17 +66,6 @@ export const SendManagerFields = ({ isSchedulingDisabled, scope, id, isSendable
<AdminComponentSectionGroup
title={<FormattedMessage id="cometBrevoModule.emailCampaigns.sendManager.title" defaultMessage="Send Manager" />}
>
<Field
name="scheduledAt"
disabled={isSchedulingDisabled}
fullWidth
clearable
label={<FormattedMessage id="cometBrevoModule.emailCampaigns.scheduledAt" defaultMessage="Schedule date and time" />}
component={FinalFormDateTimePicker}
validate={(value) => (isSchedulingDisabled ? undefined : validateScheduledAt(value, now))}
componentsProps={{ datePicker: { placeholder: "DD.MM.YYYY", minDate: now }, timePicker: { placeholder: "HH:mm" } }}
/>

<Field
component={FinalFormSelect}
getOptionLabel={(option: GQLTargetGroupSelectFragment) => option.title}
Expand All @@ -89,10 +78,39 @@ export const SendManagerFields = ({ isSchedulingDisabled, scope, id, isSendable
multiple
fullWidth
/>
<Field
name="scheduledAt"
disabled={isCampaignCreated}
fullWidth
clearable
label={
<>
<FormattedMessage id="cometBrevoModule.emailCampaigns.scheduledAt" defaultMessage="Schedule date and time" />{" "}
{isCampaignCreated && (
<Tooltip
title={
<FormattedMessage
id="cometBrevoModule.emailCampaigns.scheduledAt.info"
defaultMessage="Please select a target group and save the campaign before scheduling."
/>
}
>
<Info />
</Tooltip>
)}
</>
}
component={FinalFormDateTimePicker}
validate={(value) => (isCampaignCreated ? undefined : validateScheduledAt(value, now))}
componentsProps={{
datePicker: { placeholder: "DD.MM.YYYY", minDate: now },
timePicker: { placeholder: "HH:mm" },
}}
/>

<SaveButton
variant="contained"
disabled={!isSendable || isSchedulingDisabled}
disabled={!isSendable || isCampaignCreated}
saveIcon={<Newsletter />}
saving={sendEmailCampaignNowLoading}
hasErrors={!!sendEmailCampaignNowError}
Expand Down
34 changes: 26 additions & 8 deletions packages/admin/src/emailCampaigns/form/TestEmailCampaignForm.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { gql, useApolloClient, useQuery } from "@apollo/client";
import { Field, FinalForm, FinalFormSelect, SaveButton } from "@comet/admin";
import { Newsletter } from "@comet/admin-icons";
import { Field, FinalForm, FinalFormSelect, SaveButton, Tooltip } from "@comet/admin";
import { Info, Newsletter } from "@comet/admin-icons";
import { AdminComponentPaper, AdminComponentSectionGroup } from "@comet/blocks-admin";
import { useContentScope } from "@comet/cms-admin";
import { Card } from "@mui/material";
import React from "react";
import { FormattedMessage } from "react-intl";

import { useBrevoConfig } from "../../common/BrevoConfigProvider";
import { GQLEmailCampaignContentScopeInput } from "../../graphql.generated";
import { GQLBrevoTestContactsSelectListFragment } from "./TestEmailCampaignForm.generated";
import { SendEmailCampaignToTestEmailsMutation } from "./TestEmailCampaignForm.gql";
import { GQLSendEmailCampaignToTestEmailsMutation, GQLSendEmailCampaignToTestEmailsMutationVariables } from "./TestEmailCampaignForm.gql.generated";
Expand All @@ -19,6 +20,8 @@ interface FormProps {
interface TestEmailCampaignFormProps {
id?: string;
isSendable?: boolean;
scope: GQLEmailCampaignContentScopeInput;
isCampaignCreated: boolean;
}

const brevoTestContactsSelectFragment = gql`
Expand All @@ -40,7 +43,7 @@ const brevoTestContactsSelectQuery = gql`
${brevoTestContactsSelectFragment}
`;

export const TestEmailCampaignForm = ({ id, isSendable = false }: TestEmailCampaignFormProps) => {
export const TestEmailCampaignForm = ({ id, isSendable = false, isCampaignCreated }: TestEmailCampaignFormProps) => {
const client = useApolloClient();

const { scopeParts } = useBrevoConfig();
Expand Down Expand Up @@ -84,20 +87,35 @@ export const TestEmailCampaignForm = ({ id, isSendable = false }: TestEmailCampa
component={FinalFormSelect}
name="testEmails"
label={
<FormattedMessage
id="cometBrevoModule.emailCampaigns.testEmailCampaign.testEmails"
defaultMessage="Email addresses"
/>
<>
<FormattedMessage
id="cometBrevoModule.emailCampaigns.testEmailCampaign.testEmails"
defaultMessage="Email addresses"
/>{" "}
{isCampaignCreated && (
<Tooltip
title={
<FormattedMessage
id="cometBrevoModule.emailCampaigns.testEmails.info"
defaultMessage="Please select a target group and save the campaign before you can send test emails."
/>
}
>
<Info />
</Tooltip>
)}
</>
}
fullWidth
options={emailOptions}
isLoading={loading}
error={!!error}
value={values.testEmails || []}
getOptionLabel={(option: string) => option}
disabled={isCampaignCreated}
/>
<SaveButton
disabled={!values.testEmails || !isSendable || !id}
disabled={!values.testEmails || !isSendable || !id || isCampaignCreated}
saveIcon={<Newsletter />}
onClick={handleSubmit}
saving={submitting}
Expand Down

0 comments on commit c15195c

Please sign in to comment.