-
Notifications
You must be signed in to change notification settings - Fork 3
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
Emailer: Load HTML templates from S3 #334
Changes from 20 commits
c2b5354
996adcf
6e07a0c
4fd5716
9e89c5f
15ee0ea
a23e48c
05c7ee8
e2c5186
32b2403
c595718
4e8ed0f
aada15a
8c5abfa
7a36e05
cf7a7db
aa777e8
7f88839
42c7186
708fc5c
8213776
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
SendEmailRequest, | ||
} from '../../../components/forms/ducks/types'; | ||
import { requiredRule } from '../../../utils/formRules'; | ||
import { FormInstance } from 'antd/es/form'; | ||
import { site } from '../../../constants'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { n } from '../../../utils/stringFormat'; | ||
|
@@ -33,9 +34,14 @@ const EmailPreview = styled.div` | |
|
||
interface SendEmailFormProps { | ||
readonly emails: string[]; | ||
readonly sendEmailForm: FormInstance<SendEmailRequest>; | ||
} | ||
|
||
const SendEmailForm: React.FC<SendEmailFormProps> = ({ emails }) => { | ||
const SendEmailForm: React.FC<SendEmailFormProps> = ({ | ||
emails, | ||
sendEmailForm, | ||
}) => { | ||
const SendEmailForm: React.FC<SendEmailFormProps> = ({ emails }) => { | ||
const { t } = useTranslation(n(site, ['forms']), { | ||
keyPrefix: 'volunteer_emailer', | ||
nsMode: 'fallback', | ||
|
@@ -62,7 +68,6 @@ const SendEmailForm: React.FC<SendEmailFormProps> = ({ emails }) => { | |
...values, | ||
emails, | ||
}; | ||
|
||
ProtectedApiClient.sendEmail(sendEmailRequest) | ||
.then(() => { | ||
message.success(t('success')); | ||
|
@@ -71,7 +76,6 @@ const SendEmailForm: React.FC<SendEmailFormProps> = ({ emails }) => { | |
message.error(t('response_error', { error: err.response.data })), | ||
); | ||
}; | ||
|
||
return ( | ||
<Form | ||
name="sendEmail" | ||
|
@@ -98,6 +102,11 @@ const SendEmailForm: React.FC<SendEmailFormProps> = ({ emails }) => { | |
rules={requiredRule(t('body_required'))} | ||
hidden={showPreview} | ||
> | ||
<Input.TextArea | ||
name="emailContent" | ||
rows={6} | ||
placeholder={'Email Body'} | ||
/> | ||
<Input.TextArea rows={8} placeholder={t('body_placeholder')} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
</Form.Item> | ||
{showPreview && ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { | |
Alert, | ||
Divider, | ||
SelectProps, | ||
Form, | ||
} from 'antd'; | ||
import { ArrowLeftOutlined } from '@ant-design/icons'; | ||
|
||
|
@@ -19,10 +20,10 @@ import PageLayout from '../../components/pageLayout'; | |
import { ReturnButton } from '../../components/themedComponents'; | ||
import PageHeader from '../../components/pageHeader'; | ||
import { | ||
EmailType, | ||
EmailerFilters, | ||
FilteredSite, | ||
FilterSitesParams, | ||
LoadTemplateResponse, | ||
} from './types'; | ||
import EmailerFilterControls from '../../components/emailerFilterControls'; | ||
import AdoptedSitesTable from '../../components/adoptedSitesTable'; | ||
|
@@ -63,6 +64,8 @@ const defaultFilters: EmailerFilters = { | |
lastActivityEnd: null, | ||
}; | ||
|
||
const defaultTemplate = 'Pick a Template'; | ||
|
||
enum LoadingState { | ||
SUCCESS = 'success', | ||
LOADING = 'loading', | ||
|
@@ -76,13 +79,37 @@ function neighborhoodToId(neighborhood: Neighborhoods): number { | |
} | ||
|
||
const Email: React.FC = () => { | ||
const [emailType, setEmailType] = useState<EmailType>(EmailType.INACTIVE); | ||
const [emailType, setEmailType] = useState<string>(defaultTemplate); | ||
const [templateNames, setTemplateNames] = useState<string[]>([]); | ||
const [filters, setFilters] = useState<EmailerFilters>(defaultFilters); | ||
const [fetchData, setFetchData] = useState<FilteredSite[]>([]); | ||
const [fetchSitesState, setFetchSitesState] = useState<LoadingState>( | ||
LoadingState.SUCCESS, | ||
); | ||
const [selectedEmails, setSelectedEmails] = useState<string[]>([]); | ||
const [sendEmailForm] = Form.useForm(); | ||
|
||
function fetchTemplateNames() { | ||
protectedApiClient | ||
.getEmailTemplateNames() | ||
.then((res) => { | ||
setTemplateNames(res.templates); | ||
}) | ||
.catch((err) => { | ||
setTemplateNames([defaultTemplate]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏️ Can we add an error message here in the |
||
}); | ||
} | ||
|
||
function fetchTemplateData(templateName: string) { | ||
protectedApiClient | ||
.loadEmailTemplateContent(templateName) | ||
.then((res) => { | ||
sendEmailForm.setFieldValue('emailBody', res.template); | ||
}) | ||
.catch((err) => { | ||
sendEmailForm.setFieldValue('emailBody', ''); | ||
}); | ||
} | ||
|
||
function onClickSearch() { | ||
setFetchSitesState(LoadingState.LOADING); | ||
|
@@ -188,16 +215,22 @@ const Email: React.FC = () => { | |
</Typography.Title> | ||
<EmailTypeSelect | ||
value={emailType} | ||
defaultValue={EmailType.INACTIVE} | ||
options={Object.entries(EmailType).map(([key, value]) => ({ | ||
value: key, | ||
label: value, | ||
defaultValue={defaultTemplate} | ||
onClick={fetchTemplateNames} | ||
options={templateNames.map((e) => ({ | ||
value: e, | ||
label: e, | ||
}))} | ||
onChange={(value: EmailType) => setEmailType(value)} | ||
disabled // TODO uncomment when ready | ||
onChange={(value: string) => { | ||
setEmailType(value); | ||
fetchTemplateData(value); | ||
}} | ||
/> | ||
<Typography.Title level={3}>Email</Typography.Title> | ||
<SendEmailForm emails={selectedEmails} /> | ||
<SendEmailForm | ||
emails={selectedEmails} | ||
sendEmailForm={sendEmailForm} | ||
/> | ||
</EmailPageContainer> | ||
</PageLayout> | ||
</> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Looks like you have some errors (from merging) - make sure to get rid of this extra declaration of the
SendEmailForm
component!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also make sure to remove line 50:
const [sendEmailForm] = Form.useForm();
since we're passing the form instance as a prop now (I can't comment on it since it's an unchanged line 😞)