Added notification for default unsubscribed newsletter

refs https://github.com/TryGhost/Team/issues/1495
This commit is contained in:
Rishabh 2022-05-16 16:38:19 +05:30
parent 2e9735c5c4
commit 43a6b8c1ed
2 changed files with 21 additions and 0 deletions

View File

@ -110,6 +110,7 @@ function ShowPaidMemberMessage({site, isPaid}) {
} }
export default function NewsletterManagement({ export default function NewsletterManagement({
notification,
subscribedNewsletters, subscribedNewsletters,
updateSubscribedNewsletters, updateSubscribedNewsletters,
unsubscribeAll, unsubscribeAll,
@ -117,10 +118,15 @@ export default function NewsletterManagement({
}) { }) {
const isDisabled = !subscribedNewsletters?.length; const isDisabled = !subscribedNewsletters?.length;
const {brandColor, site} = useContext(AppContext); const {brandColor, site} = useContext(AppContext);
const EmptyNotification = () => {
return null;
};
const FinalNotification = notification || EmptyNotification;
return ( return (
<div className='gh-portal-content with-footer'> <div className='gh-portal-content with-footer'>
<CloseButton /> <CloseButton />
<AccountHeader /> <AccountHeader />
<FinalNotification />
<div className='gh-portal-section'> <div className='gh-portal-section'>
<div className='gh-portal-list'> <div className='gh-portal-list'>
<NewsletterPrefs <NewsletterPrefs

View File

@ -47,6 +47,7 @@ export default function UnsubscribePage() {
const defaultNewsletters = siteNewsletters.filter((d) => { const defaultNewsletters = siteNewsletters.filter((d) => {
return d.subscribe_on_signup; return d.subscribe_on_signup;
}); });
const [hasInteracted, setHasInteracted] = useState(false);
const [subscribedNewsletters, setSubscribedNewsletters] = useState(defaultNewsletters); const [subscribedNewsletters, setSubscribedNewsletters] = useState(defaultNewsletters);
const [showPrefs, setShowPrefs] = useState(false); const [showPrefs, setShowPrefs] = useState(false);
@ -115,14 +116,28 @@ export default function UnsubscribePage() {
</div> </div>
); );
} }
const HeaderNotification = () => {
const unsubscribedNewsletter = siteNewsletters?.find((d) => {
return d.uuid === pageData.newsletterUuid;
});
const hideClassName = hasInteracted ? 'hide' : '';
return (
<p className={`gh-portal-text-center ${hideClassName}`}><strong>{member?.email}</strong> will no longer receive <strong>{unsubscribedNewsletter?.name}</strong> newsletter.</p>
);
};
return ( return (
<NewsletterManagement <NewsletterManagement
notification={HeaderNotification}
subscribedNewsletters={subscribedNewsletters} subscribedNewsletters={subscribedNewsletters}
updateSubscribedNewsletters={async (newsletters) => { updateSubscribedNewsletters={async (newsletters) => {
setSubscribedNewsletters(newsletters); setSubscribedNewsletters(newsletters);
setHasInteracted(true);
await api.member.updateNewsletters({uuid: pageData.uuid, newsletters}); await api.member.updateNewsletters({uuid: pageData.uuid, newsletters});
}} }}
unsubscribeAll={async () => { unsubscribeAll={async () => {
setHasInteracted(true);
setSubscribedNewsletters([]); setSubscribedNewsletters([]);
onAction('showPopupNotification', { onAction('showPopupNotification', {
action: 'updated:success', action: 'updated:success',