mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Fixed loading and error handling bugs in portal settings (#19225)
fixes ADM-31
This commit is contained in:
parent
6d0dfbafb1
commit
ede2d9c1b7
2 changed files with 31 additions and 5 deletions
|
@ -6,7 +6,9 @@ import {useGlobalData} from '../../../providers/GlobalDataProvider';
|
|||
|
||||
const AccountPage: React.FC<{
|
||||
updateSetting: (key: string, setting: SettingValue) => void
|
||||
}> = ({updateSetting}) => {
|
||||
errors: Record<string, string | undefined>
|
||||
setError: (key: string, error: string | undefined) => void
|
||||
}> = ({updateSetting, errors, setError}) => {
|
||||
const {siteData, settings, config} = useGlobalData();
|
||||
const [membersSupportAddress, supportEmailAddress] = getSettingValues(settings, ['members_support_address', 'support_email_address']);
|
||||
const calculatedSupportAddress = supportEmailAddress?.toString() || fullEmailAddress(membersSupportAddress?.toString() || '', siteData!, config);
|
||||
|
@ -15,6 +17,12 @@ const AccountPage: React.FC<{
|
|||
|
||||
const updateSupportAddress: FocusEventHandler<HTMLInputElement> = (e) => {
|
||||
let supportAddress = e.target.value;
|
||||
|
||||
if (!supportAddress) {
|
||||
setError('members_support_address', 'Please enter an email address');
|
||||
return;
|
||||
}
|
||||
|
||||
let settingValue = emailDomain && supportAddress === `noreply@${emailDomain}` ? 'noreply' : supportAddress;
|
||||
|
||||
updateSetting('members_support_address', settingValue);
|
||||
|
@ -26,7 +34,14 @@ const AccountPage: React.FC<{
|
|||
}, [calculatedSupportAddress]);
|
||||
|
||||
return <div className='mt-7'><Form>
|
||||
<TextField title='Support email address' value={value} onBlur={updateSupportAddress} onChange={e => setValue(e.target.value)} />
|
||||
<TextField
|
||||
error={!!errors.members_support_address}
|
||||
hint={errors.members_support_address}
|
||||
title='Support email address'
|
||||
value={value}
|
||||
onBlur={updateSupportAddress}
|
||||
onChange={e => setValue(e.target.value)}
|
||||
/>
|
||||
</Form></div>;
|
||||
};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import PortalPreview from './PortalPreview';
|
|||
import React, {useEffect, useState} from 'react';
|
||||
import SignupOptions from './SignupOptions';
|
||||
import useQueryParams from '../../../../hooks/useQueryParams';
|
||||
import {ConfirmationModal, PreviewModalContent, Tab, TabView} from '@tryghost/admin-x-design-system';
|
||||
import {ConfirmationModal, PreviewModalContent, Tab, TabView, showToast} from '@tryghost/admin-x-design-system';
|
||||
import {Dirtyable, useForm, useHandleError} from '@tryghost/admin-x-framework/hooks';
|
||||
import {Setting, SettingValue, getSettingValues, useEditSettings} from '@tryghost/admin-x-framework/api/settings';
|
||||
import {Tier, useBrowseTiers, useEditTier} from '@tryghost/admin-x-framework/api/tiers';
|
||||
|
@ -45,7 +45,7 @@ const Sidebar: React.FC<{
|
|||
{
|
||||
id: 'accountPage',
|
||||
title: 'Account page',
|
||||
contents: <AccountPage updateSetting={updateSetting} />
|
||||
contents: <AccountPage errors={errors} setError={setError} updateSetting={updateSetting} />
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -154,6 +154,12 @@ const PortalModal: React.FC = () => {
|
|||
onSaveError: handleError
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!formState.tiers.length && allTiers?.length) {
|
||||
setFormState(state => ({...state, tiers: allTiers}));
|
||||
}
|
||||
}, [allTiers, formState.tiers, setFormState]);
|
||||
|
||||
const [errors, setErrors] = useState<Record<string, string | undefined>>({});
|
||||
|
||||
const updateSetting = (key: string, value: SettingValue) => {
|
||||
|
@ -223,7 +229,12 @@ const PortalModal: React.FC = () => {
|
|||
testId='portal-modal'
|
||||
title='Portal'
|
||||
onOk={async () => {
|
||||
if (!Object.values(errors).filter(Boolean).length) {
|
||||
if (Object.values(errors).filter(Boolean).length) {
|
||||
showToast({
|
||||
type: 'pageError',
|
||||
message: 'Can\'t save settings, please double check that you\'ve filled all mandatory fields.'
|
||||
});
|
||||
} else {
|
||||
await handleSave({force: true});
|
||||
}
|
||||
}}
|
||||
|
|
Loading…
Add table
Reference in a new issue