Add days sentence to component

[MAILPOET-3224]
This commit is contained in:
Pavel Dohnal
2021-04-13 09:28:24 +02:00
committed by Veljko V
parent c759193b93
commit 0bffa09c40
3 changed files with 38 additions and 0 deletions

View File

@@ -17,6 +17,12 @@ interface Props {
item: EmailFormItem;
}
function replaceElementsInDaysSentence(fn): JSX.Element[] {
return MailPoet.I18n.t('emailActionOpensDaysSentence')
.split(/({days})/gim)
.map(fn);
}
export const EmailOpensAbsoluteCountFields: React.FunctionComponent<Props> = ({
onChange,
item,
@@ -76,6 +82,35 @@ export const EmailOpensAbsoluteCountFields: React.FunctionComponent<Props> = ({
}
)}
</Grid.CenteredRow>
<Grid.CenteredRow>
{replaceElementsInDaysSentence(
(match) => {
if (match === '{days}') {
return (
<Input
key="input"
type="number"
value={item.days}
onChange={(e): void => compose([
onChange,
assign(item),
])({ days: e.target.value })}
min="0"
placeholder={MailPoet.I18n.t('emailActionDays')}
/>
);
}
if ((typeof match === 'string') && match.trim().length > 1) {
return (
<div key={match}>
{match}
</div>
);
}
return null;
}
)}
</Grid.CenteredRow>
</>
);
};

View File

@@ -43,6 +43,7 @@ export interface EmailFormItem extends FormItem {
link_id?: string;
operator?: string;
opens?: string;
days?: string;
}
export type AnyFormItem = WordpressRoleFormItem | WooCommerceFormItem | EmailFormItem;

View File

@@ -136,7 +136,9 @@
'emailActionOpened': _x('opened', 'Dynamic segment creation: when newsletter was opened'),
'emailActionOpensAbsoluteCount': __('# of opens'),
'emailActionOpens': __('opens'),
'emailActionDays': __('days'),
'emailActionOpensSentence': _x('{condition} {opens} opens', 'The result will be "more than 20 opens"'),
'emailActionOpensDaysSentence': _x('in the last {days} days', 'The result will be "in the last 5 days"'),
'moreThan': __('more than'),
'lessThan': __('less than'),
'emailActionNotOpened': _x('not opened', 'Dynamic segment creation: when newsletter was not opened'),