import {useFormContext} from 'react-hook-form'; import {AdminSettings} from '../../admin-settings'; import {ComponentType, Fragment} from 'react'; import {MailgunCredentials} from './mailgun-credentials'; import {SmtpCredentials} from './smtp-credentials'; import {SesCredentials} from './ses-credentials'; import {PostmarkCredentials} from './postmark-credentials'; import {ConnectGmailPanel} from './connect-gmail-panel'; import {SettingsErrorGroup} from '../../settings-error-group'; import {FormSelect, Option} from '../../../../ui/forms/select/select'; import {Trans} from '../../../../i18n/trans'; import {LearnMoreLink} from '../../learn-more-link'; export function OutgoingMailGroup() { const {watch, clearErrors} = useFormContext(); const selectedDriver = watch('server.mail_driver'); const credentialForms: ComponentType<{isInvalid: boolean}>[] = []; if (selectedDriver === 'mailgun') { credentialForms.push(MailgunCredentials); } if (selectedDriver === 'smtp') { credentialForms.push(SmtpCredentials); } if (selectedDriver === 'ses') { credentialForms.push(SesCredentials); } if (selectedDriver === 'postmark') { credentialForms.push(PostmarkCredentials); } if (selectedDriver === 'gmailApi') { credentialForms.push(ConnectGmailPanel); } return ( {isInvalid => ( { clearErrors(); }} invalid={isInvalid} selectionMode="single" name="server.mail_driver" label={} description={
} >
{credentialForms.length ? (
{credentialForms.map((CredentialsForm, index) => ( ))}
) : null}
)}
); }