mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Fixed bugs with saving in portal modal (#18649)
refs https://github.com/TryGhost/Product/issues/3832 --- <!-- Leave the line below if you'd like GitHub Copilot to generate a summary from your commit --> <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8ad5f58</samp> This pull request enhances the portal modal component in the admin settings for membership. It improves how it handles errors, saves changes, and communicates with the user.
This commit is contained in:
parent
59d3882c9f
commit
ce9f6ec69a
1 changed files with 12 additions and 4 deletions
|
@ -113,9 +113,9 @@ const PortalModal: React.FC = () => {
|
|||
if (verifyEmail) {
|
||||
checkToken({token: verifyEmail});
|
||||
}
|
||||
}, [verifyEmail, verifyToken]);
|
||||
}, [handleError, verifyEmail, verifyToken]);
|
||||
|
||||
const {formState, saveState, handleSave, updateForm} = useForm({
|
||||
const {formState, setFormState, saveState, handleSave, updateForm} = useForm({
|
||||
initialState: {
|
||||
settings: settings as Dirtyable<Setting>[],
|
||||
tiers: tiers as Dirtyable<Tier>[]
|
||||
|
@ -123,8 +123,16 @@ const PortalModal: React.FC = () => {
|
|||
|
||||
onSave: async () => {
|
||||
await Promise.all(formState.tiers.filter(({dirty}) => dirty).map(tier => editTier(tier)));
|
||||
setFormState(state => ({...state, tiers: formState.tiers.map(tier => ({...tier, dirty: false}))}));
|
||||
|
||||
const {meta, settings: currentSettings} = await editSettings(formState.settings.filter(setting => setting.dirty));
|
||||
const changedSettings = formState.settings.filter(setting => setting.dirty);
|
||||
|
||||
if (!changedSettings.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {meta, settings: currentSettings} = await editSettings(changedSettings);
|
||||
setFormState(state => ({...state, settings: formState.settings.map(setting => ({...setting, dirty: false}))}));
|
||||
|
||||
if (meta?.sent_email_verification) {
|
||||
const newEmail = formState.settings.find(setting => setting.key === 'members_support_address')?.value;
|
||||
|
@ -221,7 +229,7 @@ const PortalModal: React.FC = () => {
|
|||
title='Portal'
|
||||
onOk={async () => {
|
||||
if (!Object.values(errors).filter(Boolean).length) {
|
||||
await handleSave();
|
||||
await handleSave({force: true});
|
||||
}
|
||||
}}
|
||||
onSelectURL={onSelectURL}
|
||||
|
|
Loading…
Add table
Reference in a new issue