Convert to TS

[MAILPOET-5770]
This commit is contained in:
Brezo Cordero
2023-12-15 23:13:24 -06:00
committed by Aschepikov
parent 5d80e01912
commit f68a360562
3 changed files with 16 additions and 22 deletions

View File

@ -1,21 +1,28 @@
import { useState } from 'react'; import { useState } from 'react';
import { __, _x } from '@wordpress/i18n'; import { __, _x } from '@wordpress/i18n';
import { extractEmailDomain } from 'common/functions';
import { MailPoet } from 'mailpoet'; import { MailPoet } from 'mailpoet';
import PropTypes from 'prop-types';
import { noop } from 'lodash';
import ReactStringReplace from 'react-string-replace'; import ReactStringReplace from 'react-string-replace';
import { AuthorizeSenderEmailAndDomainModal } from 'common/authorize-sender-email-and-domain-modal'; import { AuthorizeSenderEmailAndDomainModal } from 'common/authorize-sender-email-and-domain-modal';
const userHostDomain = window.location.hostname.replace('www.', ''); const userHostDomain = window.location.hostname.replace('www.', '');
const suggestedEmailAddress = `contact@${userHostDomain}`; const suggestedEmailAddress = `contact@${userHostDomain}`;
type Props = {
emailAddress: string;
mssActive: boolean;
isEmailAuthorized?: boolean;
showSenderDomainWarning?: boolean;
onSuccessfulEmailOrDomainAuthorization?: (data) => void;
};
function SenderEmailAddressWarning({ function SenderEmailAddressWarning({
emailAddress, emailAddress,
mssActive, mssActive,
isEmailAuthorized, isEmailAuthorized = true,
showSenderDomainWarning, showSenderDomainWarning = false,
onSuccessfulEmailOrDomainAuthorization, onSuccessfulEmailOrDomainAuthorization = () => {},
}) { }: Props) {
const [showAuthorizedEmailModal, setShowAuthorizedEmailModal] = const [showAuthorizedEmailModal, setShowAuthorizedEmailModal] =
useState(null); useState(null);
@ -28,7 +35,7 @@ function SenderEmailAddressWarning({
setShowAuthorizedEmailModal(newTab); setShowAuthorizedEmailModal(newTab);
}; };
const emailAddressDomain = emailAddress.split('@').pop().toLowerCase(); const emailAddressDomain = extractEmailDomain(emailAddress);
const displayElements = []; const displayElements = [];
@ -164,18 +171,5 @@ function SenderEmailAddressWarning({
return null; return null;
} }
SenderEmailAddressWarning.propTypes = {
emailAddress: PropTypes.string.isRequired,
mssActive: PropTypes.bool.isRequired,
isEmailAuthorized: PropTypes.bool,
showSenderDomainWarning: PropTypes.bool,
onSuccessfulEmailOrDomainAuthorization: PropTypes.func,
};
SenderEmailAddressWarning.defaultProps = {
isEmailAuthorized: true, // don't show error message by default
showSenderDomainWarning: false,
onSuccessfulEmailOrDomainAuthorization: noop,
};
SenderEmailAddressWarning.displayName = 'SenderEmailAddressWarning'; SenderEmailAddressWarning.displayName = 'SenderEmailAddressWarning';
export { SenderEmailAddressWarning }; export { SenderEmailAddressWarning };

View File

@ -2,7 +2,7 @@ import { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { MailPoet } from 'mailpoet'; import { MailPoet } from 'mailpoet';
import { FormFieldText } from 'form/fields/text.jsx'; import { FormFieldText } from 'form/fields/text.jsx';
import { SenderEmailAddressWarning } from 'common/sender-email-address-warning.jsx'; import { SenderEmailAddressWarning } from 'common/sender-email-address-warning.tsx';
import { import {
isFieldValid, isFieldValid,
addOrUpdateError, addOrUpdateError,

View File

@ -10,7 +10,7 @@ import {
} from 'common/functions'; } from 'common/functions';
import { Input } from 'common/form/input/input'; import { Input } from 'common/form/input/input';
import { useSetting, useSelector, useAction } from 'settings/store/hooks'; import { useSetting, useSelector, useAction } from 'settings/store/hooks';
import { SenderEmailAddressWarning } from 'common/sender-email-address-warning.jsx'; import { SenderEmailAddressWarning } from 'common/sender-email-address-warning';
import { checkSenderEmailDomainDmarcPolicy } from 'common/check-sender-domain-dmarc-policy'; import { checkSenderEmailDomainDmarcPolicy } from 'common/check-sender-domain-dmarc-policy';
export function DefaultSender() { export function DefaultSender() {