Move newsletter stats translaton inside component
The reason is, that translation strings outside weren't translated at all, even if they are present in .pot [MAILPOET-6262]
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
6a8a209d11
commit
2bc29c8b0a
@ -10,7 +10,41 @@ type StatsBadgeProps = {
|
||||
isInverted?: boolean;
|
||||
};
|
||||
|
||||
const stats = {
|
||||
export const getBadgeType = (stat, rate) => {
|
||||
if (!stat) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (rate < 0 || rate > 100) {
|
||||
return null;
|
||||
}
|
||||
const len = stat.badgeRanges.length;
|
||||
for (let i = 0; i < len; i += 1) {
|
||||
if (rate > stat.badgeRanges[i]) {
|
||||
return stat.badgeTypes[i];
|
||||
}
|
||||
}
|
||||
// rate must be zero at this point
|
||||
return stat.badgeTypes[len - 1];
|
||||
};
|
||||
|
||||
function StatsBadge(props: StatsBadgeProps) {
|
||||
const { isInverted = true } = props;
|
||||
const badges = {
|
||||
excellent: {
|
||||
name: __('Excellent', 'mailpoet'),
|
||||
tooltipTitle: __('Congrats!', 'mailpoet'),
|
||||
},
|
||||
good: {
|
||||
name: __('Good', 'mailpoet'),
|
||||
tooltipTitle: __('Good stuff.', 'mailpoet'),
|
||||
},
|
||||
critical: {
|
||||
name: __('Critical', 'mailpoet'),
|
||||
tooltipTitle: __('Something to improve.', 'mailpoet'),
|
||||
},
|
||||
};
|
||||
const stats = {
|
||||
opened: {
|
||||
badgeRanges: [30, 10, 0],
|
||||
badgeTypes: ['excellent', 'good', 'critical'],
|
||||
@ -59,45 +93,9 @@ const stats = {
|
||||
critical: __('above 0.7%', 'mailpoet'),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const getBadgeType = (statName, rate) => {
|
||||
const stat = stats[statName] || null;
|
||||
if (!stat) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (rate < 0 || rate > 100) {
|
||||
return null;
|
||||
}
|
||||
const len = stat.badgeRanges.length;
|
||||
for (let i = 0; i < len; i += 1) {
|
||||
if (rate > stat.badgeRanges[i]) {
|
||||
return stat.badgeTypes[i];
|
||||
}
|
||||
}
|
||||
// rate must be zero at this point
|
||||
return stat.badgeTypes[len - 1];
|
||||
};
|
||||
|
||||
function StatsBadge(props: StatsBadgeProps) {
|
||||
const { isInverted = true } = props;
|
||||
const badges = {
|
||||
excellent: {
|
||||
name: __('Excellent', 'mailpoet'),
|
||||
tooltipTitle: __('Congrats!', 'mailpoet'),
|
||||
},
|
||||
good: {
|
||||
name: __('Good', 'mailpoet'),
|
||||
tooltipTitle: __('Good stuff.', 'mailpoet'),
|
||||
},
|
||||
critical: {
|
||||
name: __('Critical', 'mailpoet'),
|
||||
tooltipTitle: __('Something to improve.', 'mailpoet'),
|
||||
},
|
||||
};
|
||||
|
||||
const badgeType = getBadgeType(props.stat, props.rate);
|
||||
const badgeType = getBadgeType(stats[props.stat], props.rate);
|
||||
const badge = badges[badgeType] || null;
|
||||
if (!badge) {
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user