Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: redirect present subscribers to dashboard instead of plans page #897

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/assets/javascripts/components/ApplicationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ export class ApplicationView extends PureComponent<Props, State> {
const renderAppContents = !this.state.needsUnlock && this.state.launched;

return (
<PremiumModalProvider state={this.appState?.features}>
<PremiumModalProvider
application={this.application}
appState={this.appState}
>
<div className={this.platformString + ' main-ui-view sn-component'}>
{renderAppContents && (
<div
Expand Down
24 changes: 17 additions & 7 deletions app/assets/javascripts/components/Premium/usePremiumModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FeaturesState } from '@/ui_models/app_state/features_state';
import { WebApplication } from '@/ui_models/application';
import { AppState } from '@/ui_models/app_state';
import { observer } from 'mobx-react-lite';
import { FunctionalComponent } from 'preact';
import { useContext } from 'preact/hooks';
Expand All @@ -24,24 +25,33 @@ export const usePremiumModal = (): PremiumModalContextData => {
};

interface Props {
state: FeaturesState;
application: WebApplication;
appState: AppState;
}

export const PremiumModalProvider: FunctionalComponent<Props> = observer(
({ state, children }) => {
const featureName = state._premiumAlertFeatureName;
const activate = state.showPremiumAlert;
const close = state.closePremiumAlert;
({ application, appState, children }) => {
const featureName = appState.features._premiumAlertFeatureName;
const activate = appState.features.showPremiumAlert;
const close = appState.features.closePremiumAlert;

const showModal = !!featureName;

const hasSubscription = Boolean(
appState.subscription.userSubscription &&
!appState.subscription.isUserSubscriptionExpired &&
!appState.subscription.isUserSubscriptionCanceled
);

return (
<>
{showModal && (
<PremiumFeaturesModal
showModal={!!featureName}
application={application}
featureName={featureName}
hasSubscription={hasSubscription}
onClose={close}
showModal={!!featureName}
/>
)}
<PremiumModalProvider_ value={{ activate }}>
Expand Down
16 changes: 12 additions & 4 deletions app/assets/javascripts/components/PremiumFeaturesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ import { FunctionalComponent } from 'preact';
import { Icon } from './Icon';
import { PremiumIllustration } from '@standardnotes/stylekit';
import { useRef } from 'preact/hooks';
import { WebApplication } from '@/ui_models/application';
import { openSubscriptionDashboard } from '@/hooks/manageSubscription';

type Props = {
application: WebApplication;
featureName: string;
hasSubscription: boolean;
onClose: () => void;
showModal: boolean;
};

export const PremiumFeaturesModal: FunctionalComponent<Props> = ({
application,
featureName,
hasSubscription,
onClose,
showModal,
}) => {
const plansButtonRef = useRef<HTMLButtonElement>(null);

const onClickPlans = () => {
if (window._plans_url) {
const handleClick = () => {
if (hasSubscription) {
openSubscriptionDashboard(application);
} else if (window._plans_url) {
window.location.assign(window._plans_url);
}
};
Expand Down Expand Up @@ -61,11 +69,11 @@ export const PremiumFeaturesModal: FunctionalComponent<Props> = ({
</AlertDialogDescription>
<div className="p-4">
<button
onClick={onClickPlans}
onClick={handleClick}
className="w-full rounded no-border py-2 font-bold bg-info color-info-contrast hover:brightness-130 focus:brightness-130 cursor-pointer"
ref={plansButtonRef}
>
See Plans
{hasSubscription ? 'Upgrade plan' : 'See Plans'}
amanharwara marked this conversation as resolved.
Show resolved Hide resolved
</button>
</div>
</div>
Expand Down