Add deep links to email authorization notices

[MAILPOET-3830]
This commit is contained in:
wxa
2021-10-05 13:38:22 +03:00
committed by Veljko V
parent 67d11c9eed
commit dbb52a758e
6 changed files with 91 additions and 10 deletions

View File

@@ -26,15 +26,16 @@ type error = {
message: string;
}
const getErrorMessage = (error: error | null): string => {
const getErrorMessage = (error: error | null, address: string | null): string => {
if (!error) {
return MailPoet.I18n.t('setFromAddressEmailUnknownError');
}
if (error.error === 'unauthorized') {
const fromAddress = encodeURIComponent(address);
return MailPoet.I18n.t('setFromAddressEmailNotAuthorized').replace(
/\[link\](.*?)\[\/link\]/g,
'<a href="https://account.mailpoet.com/authorization" target="_blank" rel="noopener noreferrer">$1</a>'
`<a href="https://account.mailpoet.com/authorization?email=${fromAddress}" target="_blank" rel="noopener noreferrer">$1</a>`
);
}
@@ -143,7 +144,7 @@ const SetFromAddressModal = ({ onRequestClose, setAuthorizedAddress }: Props) =>
notices.success(getSuccessMessage(), { timeout: false });
} catch (e) {
const error = e.errors && e.errors[0] ? e.errors[0] : null;
const message = getErrorMessage(error);
const message = getErrorMessage(error, address);
addressValidator.addError('saveError', { message });
}
}}