Skip to content

Commit

Permalink
Merge pull request #91 from compsci-adl/refactor/header-ssr
Browse files Browse the repository at this point in the history
feat: enable ssr for header
  • Loading branch information
rayokamoto authored Feb 19, 2024
2 parents 64806b3 + bcc8e71 commit 558512b
Show file tree
Hide file tree
Showing 13 changed files with 357 additions and 290 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"redis": "^4.6.13",
"square": "^34.0.1",
"swr": "^2.2.5",
"usehooks-ts": "^2.14.0",
"zod": "^3.22.4",
"zustand": "^4.4.7"
},
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions src/app/api/payment/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { env } from '@/env.mjs';
import { redisClient } from '@/lib/redis';
import { squareClient } from '@/lib/square';
import { updateMemberExpiryDate } from '@/server/update-member-expiry-date';
import { verifyMembershipPayment } from '@/server/verify-membership-payment';
import { currentUser } from '@clerk/nextjs';
import { eq } from 'drizzle-orm';
import type { CreatePaymentLinkRequest } from 'square';
Expand Down Expand Up @@ -115,14 +114,3 @@ export async function PUT(request: Request) {
}
return Response.json({ success: true });
}

// Get membership payment status
export async function GET() {
const user = await currentUser();
if (!user) {
return new Response(null, { status: 401 });
}

const { paid } = await verifyMembershipPayment(user.id);
return Response.json({ paid });
}
12 changes: 0 additions & 12 deletions src/app/api/user-existence/route.ts

This file was deleted.

194 changes: 0 additions & 194 deletions src/components/Header.tsx

This file was deleted.

94 changes: 94 additions & 0 deletions src/components/Header/HeaderClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'use client';

import { useClerk } from '@clerk/clerk-react';
import { Transition } from '@headlessui/react';
import Image from 'next/image';
import { useRouter } from 'next/navigation';
import { useRef, useState } from 'react';
import { useOnClickOutside } from 'usehooks-ts';
import type { HeaderData } from '.';
import Button from '../Button';
import FancyRectangle from '../FancyRectangle';
import { Links, MenuLinks } from './components/Links';
import LogoTitle from './components/LogoTitle';
import ScrollShader from './components/ScrollShader';
import SignInJoin from './components/SignInJoin';

function UserButton({ data }: { data: HeaderData }) {
const [isMenuOpen, setMenuOpen] = useState(false);
const ref = useRef(null);
const closeMenu = () => {
setMenuOpen(false);
};
useOnClickOutside(ref, closeMenu);
const handleButtonClick = () => {
setMenuOpen(!isMenuOpen);
};

const { signOut } = useClerk();
const router = useRouter();
const handleSignOut = async () => {
await signOut();
router.push('/');
router.refresh();
};

const userExists = data.nextStep !== 'signup';
return (
<FancyRectangle colour="black" offset="4" filled>
<div className="relative flex w-11 gap-y-2 border-2 border-black" ref={ref}>
<button onClick={handleButtonClick}>
<Image src={data.avatar!} alt="Profile" width={100} height={100} />
</button>
<Transition
show={isMenuOpen}
enter="transition ease-out duration-100"
enterFrom="opacity-0 scale-90"
enterTo="opacity-100 scale-100"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-90"
>
<div className="absolute right-0 top-10 z-50 w-44 space-y-4 border-4 border-black bg-white p-4">
{userExists && <MenuLinks data={data} onClick={closeMenu} />}
<Button onClick={handleSignOut} colour="orange" width="w-40 md:w-32">
Sign Out
</Button>
</div>
</Transition>
</div>
</FancyRectangle>
);
}

export default function HeaderClient({
data,
className,
}: {
data: HeaderData;
className?: string;
}) {
return (
<header className={`${className} fixed z-[9999] w-full`}>
<ScrollShader />
<div className="mx-auto mt-8 w-responsive">
<div className="flex items-center gap-8 border-4 border-black bg-white px-8 py-4 text-grey">
<LogoTitle titleColor="text-grey" className="grow" />
<Links />
{data.nextStep === 'signup' && (
<Button colour="purple" href="/join">
Continue Signing Up
</Button>
)}
{data.nextStep === 'payment' && (
<Button colour="orange" href="/settings">
Continue to payment
</Button>
)}
{data.isSignedIn ? <UserButton data={data} /> : <SignInJoin />}
</div>
<div className="relative -right-[0.5rem] -top-[4.75rem] -z-10 h-[5.25rem] w-responsive border-4 border-black bg-white" />
</div>
</header>
);
}
Loading

0 comments on commit 558512b

Please sign in to comment.