Set initial sending method

[MAILPOET-2693]
This commit is contained in:
Amine Ben hammou
2020-04-09 08:34:17 +02:00
committed by Veljko V
parent 75ec035cec
commit 4312dd3532
2 changed files with 7 additions and 7 deletions

View File

@@ -6,22 +6,21 @@ import { useSetting } from 'settings/store/hooks';
export default function SendingMethod() { export default function SendingMethod() {
const [provider, setProvider] = useSetting('smtp_provider'); const [provider, setProvider] = useSetting('smtp_provider');
const [, setMethod] = useSetting('mta', 'method'); const [, setMethod] = useSetting('mta', 'method');
const updateProvider = (value: 'server' | 'manual' | 'AmazonSES' | 'SendGrid') => { React.useEffect(() => {
setProvider(value); switch (provider) {
switch (value) {
case 'server': setMethod('PHPMail'); break; case 'server': setMethod('PHPMail'); break;
case 'manual': setMethod('SMTP'); break; case 'manual': setMethod('SMTP'); break;
case 'AmazonSES': setMethod('AmazonSES'); break; case 'AmazonSES': setMethod('AmazonSES'); break;
case 'SendGrid': setMethod('AmazonSES'); break; case 'SendGrid': setMethod('AmazonSES'); break;
default: default: setMethod('PHPMail');
} }
}; }, [provider, setMethod]);
return ( return (
<> <>
<Label title={t('method')} htmlFor="mailpoet_smtp_method" /> <Label title={t('method')} htmlFor="mailpoet_smtp_method" />
<Inputs> <Inputs>
<select id="mailpoet_smtp_method" value={provider} onChange={onChange(updateProvider)}> <select id="mailpoet_smtp_method" value={provider} onChange={onChange(setProvider)}>
<option value="server">{t('hostOption')}</option> <option value="server">{t('hostOption')}</option>
<option value="manual">{t('smtpOption')}</option> <option value="manual">{t('smtpOption')}</option>
<optgroup label={t('selectProvider')}> <optgroup label={t('selectProvider')}>

View File

@@ -1,3 +1,4 @@
import React from 'react';
import { Settings } from '../types'; import { Settings } from '../types';
import useSelector from './useSelector'; import useSelector from './useSelector';
import { ValueAndSetter } from './types'; import { ValueAndSetter } from './types';
@@ -26,6 +27,6 @@ export function useSetting(...path: string[]): [any, (value: any) => any] {
const setValue = useAction('setSetting'); const setValue = useAction('setSetting');
return [ return [
getValue(path), getValue(path),
(value) => setValue(path, value), React.useCallback((value) => setValue(path, value), path), // eslint-disable-line
]; ];
} }