Skip to content

Commit

Permalink
feat: show Stripe link only to logged in users (#560)
Browse files Browse the repository at this point in the history
Should reduce premature purchases that cause email linking issues.
  • Loading branch information
aalemayhu authored Jul 7, 2024
1 parent e6096c9 commit c2cc17d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/components/NavigationBar/NavigationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import { useState } from 'react';
import { useCookies } from 'react-cookie';

import { Navbar } from './styled';
import { RightSide } from './components/RightSide';
import useNavbarEnd from './helpers/useNavbarEnd';
import { get2ankiApi } from '../../lib/backend/get2ankiApi';
import { useIsLoggedIn } from '../../lib/useIsLoggedIn';

function NavigationBar() {
const [cookies] = useCookies(['token']);
const [active, setActive] = useState(false);
const path = window.location.pathname;
const loggedInNavbar = useNavbarEnd(path, get2ankiApi());
const isLoggedIn = useIsLoggedIn();

return (
<Navbar
Expand Down Expand Up @@ -44,8 +44,8 @@ function NavigationBar() {
id="navbar"
className={`is-flex-grow-0 navbar-menu ${active ? 'is-active' : ''}`}
>
{cookies.token && loggedInNavbar}
{!cookies.token && <RightSide path={path} />}
{isLoggedIn && loggedInNavbar}
{!isLoggedIn && <RightSide path={path} />}
</div>

</Navbar>
Expand Down
6 changes: 6 additions & 0 deletions src/lib/useIsLoggedIn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useCookies } from 'react-cookie';

export const useIsLoggedIn = () => {
const [cookies] = useCookies(['token']);
return cookies.token;
};
6 changes: 5 additions & 1 deletion src/pages/PricingPage/PricingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { getVisibleText } from '../../lib/text/getVisibleText';
import { getSubscribeLink } from './getSubscribeLink';
import { PricingCard } from './components/PricingCard';
import TopMessage from '../../components/TopMessage/TopMessage';
import { useIsLoggedIn } from '../../lib/useIsLoggedIn';

export default function PricingPage() {
const isLoggedIn = useIsLoggedIn();
const subcribeLink = isLoggedIn ? getSubscribeLink() : '/login';

return (
<PageContainer>
<div className="container content">
Expand All @@ -29,7 +33,7 @@ export default function PricingPage() {
</div>
<div className="column is-4">
<PricingCard price="$2" title="Subscriber Plan" benefits={['Unlimited Flashcards (9GB++)']}
link={getSubscribeLink()} linkText="Subscribe" />
link={subcribeLink} linkText="Subscribe" />
</div>
</div>
</div>
Expand Down

0 comments on commit c2cc17d

Please sign in to comment.