0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed mailgun integration not setting base URL on AdminX (#17774)

refs https://github.com/TryGhost/Product/issues/3349

- Adds an additional condition to set the 'default' mailgun base url in case it not need change, to prevent it from staying null in the database config, when setting the domain and api key.
- In other cases it will work as usual.
This commit is contained in:
Ronald Langeveld 2023-08-21 16:44:15 +02:00 committed by GitHub
parent a343f39559
commit ac16121899
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ import SettingGroupContent from '../../../admin-x-ds/settings/SettingGroupConten
import TextField from '../../../admin-x-ds/global/form/TextField';
import useSettingGroup from '../../../hooks/useSettingGroup';
import {getSettingValues} from '../../../api/settings';
import {useEditSettings} from '../../../api/settings';
const MAILGUN_REGIONS = [
{label: '🇺🇸 US', value: 'https://api.mailgun.net/v3'},
@ -23,6 +24,7 @@ const MailGun: React.FC<{ keywords: string[] }> = ({keywords}) => {
updateSetting,
handleEditingChange
} = useSettingGroup();
const {mutateAsync: editSettings} = useEditSettings();
const [mailgunRegion, mailgunDomain, mailgunApiKey] = getSettingValues(localSettings, [
'mailgun_base_url', 'mailgun_domain', 'mailgun_api_key'
@ -57,7 +59,6 @@ const MailGun: React.FC<{ keywords: string[] }> = ({keywords}) => {
const apiKeysHint = (
<>Find your Mailgun API keys <Link href="https://app.mailgun.com/app/account/security/api_keys" rel="noopener noreferrer" target="_blank">here</Link></>
);
const inputs = (
<SettingGroupContent>
<div className='grid grid-cols-[120px_auto] gap-x-3 gap-y-6'>
@ -106,7 +107,16 @@ const MailGun: React.FC<{ keywords: string[] }> = ({keywords}) => {
title='Mailgun'
onCancel={handleCancel}
onEditingChange={handleEditingChange}
onSave={handleSave}
onSave={async () => {
// this is a special case where we need to set the region to the default if it's not set,
// since when the Mailgun Region is not changed, the value doesn't get set in the updateSetting
// resulting in the mailgun base url remaining null
// this should not fire if the user has changed the region or if the region is already set
if (!mailgunRegion) {
await editSettings([{key: 'mailgun_base_url', value: MAILGUN_REGIONS[0].value}]);
}
handleSave();
}}
>
{isEditing ? inputs : values}
</SettingGroup>