0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Added newsletter subscription status update

refs https://github.com/TryGhost/members.js/issues/95

- Adds a small update notification about newsletter subscription status update on toggle
This commit is contained in:
Rish 2020-09-08 17:54:32 +05:30
parent af160b19f1
commit e33c91f638
2 changed files with 34 additions and 5 deletions

View file

@ -102,11 +102,11 @@ async function cancelSubscription({data, api}) {
};
}
async function editBilling({data, updateState, state, api}) {
async function editBilling({data, api}) {
await api.member.editBilling();
}
async function updateMember({data, updateState, state, api}) {
async function updateMember({data, api}) {
const {name, subscribed} = data;
const member = await api.member.update({name, subscribed});
if (!member) {
@ -121,7 +121,22 @@ async function updateMember({data, updateState, state, api}) {
}
}
async function updateProfile({data, updateState, state, api}) {
async function updateNewsletter({data, api}) {
const {subscribed} = data;
const member = await api.member.update({subscribed});
if (!member) {
return {
action: 'updateNewsletter:failed'
};
} else {
return {
action: 'updateNewsletter:success',
member: member
};
}
}
async function updateProfile({data, api}) {
const {name, subscribed} = data;
const member = await api.member.update({name, subscribed});
if (!member) {
@ -150,6 +165,7 @@ const Actions = {
updateSubscription,
cancelSubscription,
updateMember,
updateNewsletter,
updateProfile,
editBilling,
checkoutPlan

View file

@ -196,7 +196,18 @@ const PaidAccountActions = ({member, openUpdatePlan, onEditBilling}) => {
return null;
};
const AccountActions = ({member, openEditProfile, openUpdatePlan, onEditBilling, onToggleSubscription}) => {
const NotifyNewsletterUpdated = ({action}) => {
if (action === 'updateNewsletter:success') {
return (
<p>
Newsletter updated
</p>
);
}
return null;
};
const AccountActions = ({member, action, openEditProfile, openUpdatePlan, onEditBilling, onToggleSubscription}) => {
const {name, email, subscribed} = member;
const label = subscribed ? 'Subscribed to email newsletters' : 'Not subscribed to email newsletters';
@ -216,6 +227,7 @@ const AccountActions = ({member, openEditProfile, openUpdatePlan, onEditBilling,
<div className='gh-portal-list-detail'>
<h3>Newsletter</h3>
<p>{label}</p>
<NotifyNewsletterUpdated action={action} />
</div>
<div>
<Switch onToggle={(e) => {
@ -323,6 +335,7 @@ const AccountMain = ({member, site, onAction, action, openSubscribe, brandColor,
<section>
<AccountWelcome member={member} site={site} openSubscribe={e => openSubscribe(e)} brandColor={brandColor} />
<AccountActions
action={action}
member={member}
openEditProfile={e => openEditProfile(e)}
onToggleSubscription={(e, subscribed) => onToggleSubscription(e, subscribed)}
@ -381,7 +394,7 @@ export default class AccountHomePage extends React.Component {
}
onToggleSubscription(e, subscribed) {
this.context.onAction('updateMember', {subscribed: !subscribed});
this.context.onAction('updateNewsletter', {subscribed: !subscribed});
}
handleSignout(e) {