-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COM-343: Add additional functionality to email campaign admin (send n…
…ow & test emails) (#33) * add test email section to email campaign edit * add send now button to email campaign form --------- Co-authored-by: Denise Buder <[email protected]>
- Loading branch information
1 parent
7784108
commit ebcc444
Showing
8 changed files
with
238 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/admin/src/emailCampaigns/form/SendEmailCampaignNowDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CancelButton, SaveButton } from "@comet/admin"; | ||
import { Dialog, DialogActions, DialogContent, DialogTitle } from "@mui/material"; | ||
import React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
interface SendEmailCampaignNowDialogProps { | ||
dialogOpen: boolean; | ||
handleNoClick: () => void; | ||
handleYesClick: () => void; | ||
} | ||
|
||
const SendEmailCampaignNowDialog = ({ dialogOpen, handleNoClick, handleYesClick }: SendEmailCampaignNowDialogProps) => { | ||
return ( | ||
<Dialog open={dialogOpen} onClose={handleNoClick}> | ||
<DialogTitle> | ||
<FormattedMessage id="cometBrevoModule.emailCampaigns.sendNow.dialog.title" defaultMessage="Send email campaign now?" /> | ||
</DialogTitle> | ||
<DialogContent> | ||
<FormattedMessage | ||
id="cometBrevoModule.emailCampaigns.sendNow.dialog.contentText" | ||
defaultMessage="Are you sure you want to send the email campaign now?" | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<CancelButton onClick={handleNoClick} /> | ||
<SaveButton onClick={handleYesClick}> | ||
<FormattedMessage id="cometBrevoModule.emailCampaigns.sendNow.dialog.sendText" defaultMessage="Send now" /> | ||
</SaveButton> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export { SendEmailCampaignNowDialog }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/admin/src/emailCampaigns/form/TestEmailCampaignForm.gql.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { gql } from "@apollo/client"; | ||
|
||
export const SendEmailCampaignToTestEmailsMutation = gql` | ||
mutation SendEmailCampaignToTestEmails($id: ID!, $data: SendTestEmailCampaignArgs!) { | ||
sendEmailCampaignToTestEmails(id: $id, data: $data) | ||
} | ||
`; |
114 changes: 114 additions & 0 deletions
114
packages/admin/src/emailCampaigns/form/TestEmailCampaignForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { useApolloClient } from "@apollo/client"; | ||
import { Field, FinalForm, FinalFormInput, SaveButton } from "@comet/admin"; | ||
import { Newsletter } from "@comet/admin-icons"; | ||
import { AdminComponentPaper, AdminComponentSectionGroup } from "@comet/blocks-admin"; | ||
import { Card, FormHelperText, Typography } from "@mui/material"; | ||
import React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import { SendEmailCampaignToTestEmailsMutation } from "./TestEmailCampaignForm.gql"; | ||
import { GQLSendEmailCampaignToTestEmailsMutation, GQLSendEmailCampaignToTestEmailsMutationVariables } from "./TestEmailCampaignForm.gql.generated"; | ||
|
||
interface FormProps { | ||
testEmails: string; | ||
} | ||
|
||
interface TestEmailCampaignFormProps { | ||
id?: string; | ||
isSendable?: boolean; | ||
} | ||
|
||
export const TestEmailCampaignForm = ({ id, isSendable = false }: TestEmailCampaignFormProps) => { | ||
const client = useApolloClient(); | ||
|
||
async function submitTestEmails({ testEmails }: FormProps) { | ||
const emailsArray = testEmails.trim().split("\n"); | ||
|
||
if (id) { | ||
const { data } = await client.mutate<GQLSendEmailCampaignToTestEmailsMutation, GQLSendEmailCampaignToTestEmailsMutationVariables>({ | ||
mutation: SendEmailCampaignToTestEmailsMutation, | ||
variables: { id, data: { emails: emailsArray } }, | ||
}); | ||
return data?.sendEmailCampaignToTestEmails; | ||
} | ||
} | ||
|
||
return ( | ||
<Card sx={{ mt: 4 }}> | ||
<AdminComponentPaper> | ||
<AdminComponentSectionGroup | ||
title={ | ||
<FormattedMessage id="cometBrevoModule.emailCampaigns.testEmailCampaign.title" defaultMessage="Send test email campaign" /> | ||
} | ||
> | ||
<FinalForm<FormProps> | ||
mode="edit" | ||
onSubmit={submitTestEmails} | ||
onAfterSubmit={() => { | ||
// override default behavior | ||
}} | ||
> | ||
{({ handleSubmit, submitting, values }) => { | ||
return ( | ||
<> | ||
<Field | ||
name="testEmails" | ||
label={ | ||
<FormattedMessage | ||
id="cometBrevoModule.emailCampaigns.testEmailCampaign.testEmails" | ||
defaultMessage="Email addresses" | ||
/> | ||
} | ||
component={FinalFormInput} | ||
multiline | ||
placeholder={["First test email address", "Second test email address"].join("\n")} | ||
fullWidth | ||
minRows={4} | ||
/> | ||
<FormHelperText sx={{ marginTop: -2, marginBottom: 4 }}> | ||
<Typography sx={{ display: "flex", alignItems: "center" }}> | ||
<FormattedMessage | ||
id="cometBrevoModule.emailCampaigns.testEmailCampaign.oneEmailAddressEachLine" | ||
defaultMessage="One email address each line" | ||
/> | ||
</Typography> | ||
<Typography /> | ||
</FormHelperText> | ||
<SaveButton | ||
disabled={!values.testEmails || !isSendable || !id} | ||
saveIcon={<Newsletter />} | ||
onClick={handleSubmit} | ||
saving={submitting} | ||
errorItem={ | ||
<FormattedMessage | ||
id="cometBrevoModule.emailCampaigns.testEmailCampaign.errorText" | ||
defaultMessage="There was an error sending the email campaign to the test addresses." | ||
/> | ||
} | ||
successItem={ | ||
<FormattedMessage | ||
id="cometBrevoModule.emailCampaigns.testEmailCampaign.successText" | ||
defaultMessage="Test email campaign was sent successfully." | ||
/> | ||
} | ||
savingItem={ | ||
<FormattedMessage | ||
id="cometBrevoModule.emailCampaigns.testEmailCampaign.sendingText" | ||
defaultMessage="Sending..." | ||
/> | ||
} | ||
> | ||
<FormattedMessage | ||
id="cometBrevoModule.emailCampaigns.testEmailCampaign.sendText" | ||
defaultMessage="Send test email campaign" | ||
/> | ||
</SaveButton> | ||
</> | ||
); | ||
}} | ||
</FinalForm> | ||
</AdminComponentSectionGroup> | ||
</AdminComponentPaper> | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters