Use React.useContext instead of Context.Consumer

This commit is contained in:
Amine Ben hammou
2019-07-11 18:40:15 +01:00
committed by M. Shull
parent a327d7f80a
commit a49a6a6a65

View File

@@ -8,69 +8,60 @@ function SelectImportMethod({
activeMethod,
onMethodChange,
}) {
const renderSelection = () => (
<form className="mailpoet_import_selection_form">
<span className="mailpoet_import_heading">{MailPoet.I18n.t('methodSelectionHead')}</span>
<label htmlFor="import-paste-method">
<input
type="radio"
name="select_method"
data-automation-id="import-paste-method"
id="import-paste-method"
checked={activeMethod === 'paste-method'}
onChange={() => onMethodChange('paste-method')}
/>
{MailPoet.I18n.t('methodPaste')}
</label>
<label htmlFor="import-csv-method">
<input
type="radio"
name="select_method"
data-automation-id="import-csv-method"
id="import-csv-method"
checked={activeMethod === 'file-method'}
onChange={() => onMethodChange('file-method')}
/>
{MailPoet.I18n.t('methodUpload')}
</label>
<label htmlFor="import-mailchimp-method">
<input
type="radio"
name="select_method"
data-automation-id="import-mailchimp-method"
id="import-mailchimp-method"
checked={activeMethod === 'mailchimp-method'}
onChange={() => onMethodChange('mailchimp-method')}
/>
{MailPoet.I18n.t('methodMailChimp')}
</label>
</form>
const { isNewUser } = React.useContext(ImportContext);
const badgeClasses = classNames(
'mailpoet_badge',
'mailpoet_badge_video',
{ mailpoet_badge_video_grey: !isNewUser }
);
return (
<ImportContext.Consumer>
{({ isNewUser }) => {
const badgeClasses = classNames(
'mailpoet_badge',
'mailpoet_badge_video',
{ mailpoet_badge_video_grey: !isNewUser }
);
return (
<>
{renderSelection()}
<a
className={badgeClasses}
href="https://kb.mailpoet.com/article/242-video-guide-importing-subscribers-using-a-csv-file"
target="_blank"
rel="noopener noreferrer"
>
<span className="dashicons dashicons-format-video" />
{MailPoet.I18n.t('seeVideo')}
</a>
</>
);
}}
</ImportContext.Consumer>
<>
<form className="mailpoet_import_selection_form">
<span className="mailpoet_import_heading">{MailPoet.I18n.t('methodSelectionHead')}</span>
<label htmlFor="import-paste-method">
<input
type="radio"
name="select_method"
data-automation-id="import-paste-method"
id="import-paste-method"
checked={activeMethod === 'paste-method'}
onChange={() => onMethodChange('paste-method')}
/>
{MailPoet.I18n.t('methodPaste')}
</label>
<label htmlFor="import-csv-method">
<input
type="radio"
name="select_method"
data-automation-id="import-csv-method"
id="import-csv-method"
checked={activeMethod === 'file-method'}
onChange={() => onMethodChange('file-method')}
/>
{MailPoet.I18n.t('methodUpload')}
</label>
<label htmlFor="import-mailchimp-method">
<input
type="radio"
name="select_method"
data-automation-id="import-mailchimp-method"
id="import-mailchimp-method"
checked={activeMethod === 'mailchimp-method'}
onChange={() => onMethodChange('mailchimp-method')}
/>
{MailPoet.I18n.t('methodMailChimp')}
</label>
</form>
<a
className={badgeClasses}
href="https://kb.mailpoet.com/article/242-video-guide-importing-subscribers-using-a-csv-file"
target="_blank"
rel="noopener noreferrer"
>
<span className="dashicons dashicons-format-video" />
{MailPoet.I18n.t('seeVideo')}
</a>
</>
);
}