Skip to content

Commit

Permalink
refactor profile link router
Browse files Browse the repository at this point in the history
  • Loading branch information
vanxh committed Nov 6, 2023
1 parent efcea9a commit 3a7bc1c
Show file tree
Hide file tree
Showing 101 changed files with 968 additions and 913 deletions.
1 change: 0 additions & 1 deletion drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "dotenv/config";
import type { Config } from "drizzle-kit";

import { env } from "@/env.mjs";

export default {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"eslint-config-next": "^14.0.0",
"pg": "^8.11.3",
"postcss": "^8.4.31",
"prettier": "^2.8.8",
"prettier": "^3.0.3",
"prettier-plugin-tailwindcss": "^0.5.6",
"tailwindcss": "^3.3.5",
"ts-node": "^10.9.1",
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

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

7 changes: 2 additions & 5 deletions prettier.config.mjs → prettier.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ const config = {
"^(react/(.*)$)|^(react$)|^(react-native(.*)$)",
"^(next/(.*)$)|^(next$)",
"<THIRD_PARTY_MODULES>",
"",
"^@/public/(.*)$",
"",
"^@/",
"^~/",
"^[../]",
"^[./]",
],
importOrderParserPlugins: ["typescript", "jsx", "decorators-legacy"],
importOrderTypeScriptVersion: "4.4.0",
importOrderTypeScriptVersion: "5.2.2",
};

export default config;
module.exports = config;
3 changes: 1 addition & 2 deletions src/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Image from "next/image";
import Link from "next/link";
import { ChevronRight, Github } from "lucide-react";

import OpenBio from "@/public/openbio.png";
import { Button } from "@/components/ui/button";
import Pricing from "@/components/pricing";
import { Button } from "@/components/ui/button";

export default function Page() {
return (
Expand Down
3 changes: 1 addition & 2 deletions src/app/[link]/_components/action-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use client";

import { Link, Rocket } from "lucide-react";

import { cn } from "@/lib/utils";
import CreateLinkBentoModal from "@/components/modals/create-link-bento";
import { cn } from "@/lib/utils";

export default function ActionBar() {
const btnClass =
Expand Down
11 changes: 5 additions & 6 deletions src/app/[link]/_components/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import { useCallback, useState } from "react";
import Image from "next/image";
import { useDropzone, type FileWithPath } from "react-dropzone";
import { UploadCloud } from "lucide-react";
import { useDropzone, type FileWithPath } from "react-dropzone";
import { generateClientDropzoneAccept } from "uploadthing/client";

import { type RouterOutputs } from "@/trpc/react";
import { toast } from "@/components/ui/use-toast";
import { useUploadThing } from "@/lib/uploadthing";
import { cn } from "@/lib/utils";
import { toast } from "@/components/ui/use-toast";
import { type RouterOutputs } from "@/trpc/react";

type Props = {
profileLink: NonNullable<RouterOutputs["profileLink"]["getByLink"]>;
Expand Down Expand Up @@ -39,7 +38,7 @@ export default function ProfileLinkAvatar({ profileLink }: Props) {
});
setImg(URL.createObjectURL(acceptedFiles[0]!));
},
[profileLink.id, startUpload]
[profileLink.id, startUpload],
);

const { getRootProps, getInputProps } = useDropzone({
Expand All @@ -56,7 +55,7 @@ export default function ProfileLinkAvatar({ profileLink }: Props) {
"flex h-[100px] w-[100px] flex-col items-center justify-center gap-y-1 rounded-full border border-border bg-background/50 md:h-[150px] md:w-[150px]",
!profileLink.image && profileLink.isOwner && "border-dashed",
profileLink.isOwner && "cursor-pointer",
img && "border-0 border-transparent bg-transparent"
img && "border-0 border-transparent bg-transparent",
)}
>
{img && (
Expand Down
8 changes: 3 additions & 5 deletions src/app/[link]/_components/bento-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import "react-grid-layout/css/styles.css";
import "react-resizable/css/styles.css";

import { useMemo } from "react";
import { useParams } from "next/navigation";
import {
type Layouts,
Responsive,
WidthProvider,
type Layouts,
type ResponsiveProps,
} from "react-grid-layout";

import { api } from "@/trpc/react";
import { useParams } from "next/navigation";

export default function BentoLayout({
children,
Expand All @@ -22,7 +20,7 @@ export default function BentoLayout({
const { link } = useParams<{ link: string }>();
const ResponsiveGridLayout = useMemo(
() => WidthProvider(Responsive) as React.ComponentType<ResponsiveProps>,
[]
[],
);

const [profileLink] = api.profileLink.getByLink.useSuspenseQuery({
Expand Down
4 changes: 2 additions & 2 deletions src/app/[link]/_components/bento.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import { api } from "@/trpc/react";
import { useParams } from "next/navigation";
import BentoCard from "@/components/bento/card";
import { api } from "@/trpc/react";
import BentoLayout from "./bento-layout";
import { useParams } from "next/navigation";

export default function Bento() {
const { link } = useParams<{ link: string }>();
Expand Down
11 changes: 5 additions & 6 deletions src/app/[link]/_components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"use client";

import { useEffect, useState, useTransition } from "react";
import { useEditor, EditorContent, type Extension } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
import { useParams } from "next/navigation";
import Placeholder from "@tiptap/extension-placeholder";
import { EditorContent, useEditor, type Extension } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
import { QrCode } from "lucide-react";

import { api } from "@/trpc/react";
import LinkQRModal from "@/components/modals/link-qr-modal";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/ui/use-toast";
import { api } from "@/trpc/react";
import ProfileLinkAvatar from "./avatar";
import { useParams } from "next/navigation";

const extensions = [
StarterKit,
Expand Down Expand Up @@ -79,7 +78,7 @@ export default function ProfileLinkHeader() {
disabled={saving}
onClick={() => {
void navigator.clipboard.writeText(
`https://openbio.app/${profileLink.link}`
`https://openbio.app/${profileLink.link}`,
);
toast({
title: "Copied to clipboard!",
Expand Down
13 changes: 6 additions & 7 deletions src/app/[link]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { Suspense } from "react";
import type { Metadata } from "next";

import { notFound } from "next/navigation";
import {
defaultMetadata,
twitterMetadata,
ogMetadata,
twitterMetadata,
} from "@/app/shared-metadata";
import { Skeleton } from "@/components/ui/skeleton";
import { api } from "@/trpc/server";
import ProfileLinkHeader from "./_components/header";
import Bento from "./_components/bento";
import ActionBar from "./_components/action-bar";
import { notFound } from "next/navigation";
import { Suspense } from "react";
import { Skeleton } from "@/components/ui/skeleton";
import Bento from "./_components/bento";
import ProfileLinkHeader from "./_components/header";

type Props = {
params: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/actions/claim-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const claimLink = (link: string) => {

if (!userId) {
return redirect(
`/app/sign-up?redirectUrl=/create-link?link=${link.toLowerCase()}`
`/app/sign-up?redirectUrl=/create-link?link=${link.toLowerCase()}`,
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/app/api/og/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export const runtime = "edge";

export async function GET(req: Request) {
const calSans = await fetch(
new URL("../../../../public/fonts/CalSans-SemiBold.ttf", import.meta.url)
new URL("../../../../public/fonts/CalSans-SemiBold.ttf", import.meta.url),
).then((res) => res.arrayBuffer());
const inter = await fetch(
new URL("../../../../public/fonts/Inter-Regular.ttf", import.meta.url)
new URL("../../../../public/fonts/Inter-Regular.ttf", import.meta.url),
).then((res) => res.arrayBuffer());

const { searchParams } = new URL(req.url);
Expand Down Expand Up @@ -49,6 +49,6 @@ export async function GET(req: Request) {
weight: 400,
},
],
}
},
);
}
3 changes: 1 addition & 2 deletions src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { NextRequest } from "next/server";
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";

import { createTRPCContext } from "@/server/api/trpc";
import { appRouter } from "@/server/api/root";
import { createTRPCContext } from "@/server/api/trpc";

const handler = (req: NextRequest) =>
fetchRequestHandler({
Expand Down
3 changes: 1 addition & 2 deletions src/app/api/trpc/edge/[trpc]/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { NextRequest } from "next/server";
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";

import { createTRPCContext } from "@/server/api/trpc";
import { edgeRouter } from "@/server/api/edge";
import { createTRPCContext } from "@/server/api/trpc";

export const runtime = "edge";
export const preferredRegion = "iad1";
Expand Down
3 changes: 1 addition & 2 deletions src/app/api/trpc/serverless/[trpc]/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { NextRequest } from "next/server";
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";

import { createTRPCContext } from "@/server/api/trpc";
import { serverlessRouter } from "@/server/api/serverless";
import { createTRPCContext } from "@/server/api/trpc";

const handler = (req: NextRequest) =>
fetchRequestHandler({
Expand Down
1 change: 0 additions & 1 deletion src/app/api/uploadthing/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createNextRouteHandler } from "uploadthing/next";

import { appFileRouter } from "@/server/uploadthing";

export const { GET, POST } = createNextRouteHandler({
Expand Down
17 changes: 7 additions & 10 deletions src/app/api/webhook/clerk/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import type { WebhookEvent } from "@clerk/nextjs/server";
import type { WebhookRequiredHeaders } from "svix";
import { Webhook } from "svix";
import { type IncomingHttpHeaders } from "http";

import { createTRPCContext } from "@/server/api/trpc";
import { serverlessRouter } from "@/server/api/serverless";
import { clerkEvent } from "@/server/api/routers/clerk/type";
import { NextResponse, type NextRequest } from "next/server";
import type { WebhookEvent } from "@clerk/nextjs/server";
import { Webhook, type WebhookRequiredHeaders } from "svix";
import { env } from "@/env.mjs";
import { clerkEvent } from "@/server/api/routers/clerk/type";
import { serverlessRouter } from "@/server/api/serverless";
import { createTRPCContext } from "@/server/api/trpc";

export async function POST(req: NextRequestWithSvixRequiredHeaders) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand All @@ -17,7 +14,7 @@ export async function POST(req: NextRequestWithSvixRequiredHeaders) {
if (!parsed.success) {
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 }
{ status: 500 },
);
}
const payload = parsed.data;
Expand Down
12 changes: 5 additions & 7 deletions src/app/api/webhook/stripe/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { type NextRequest } from "next/server";
import { NextResponse } from "next/server";

import { createTRPCContext } from "@/server/api/trpc";
import { serverlessRouter } from "@/server/api/serverless";
import { stripe } from "@/lib/stripe";
import { NextResponse, type NextRequest } from "next/server";
import { env } from "@/env.mjs";
import { stripe } from "@/lib/stripe";
import { serverlessRouter } from "@/server/api/serverless";
import { createTRPCContext } from "@/server/api/trpc";

export async function POST(req: NextRequest) {
const payload = await req.text();
Expand All @@ -18,7 +16,7 @@ export async function POST(req: NextRequest) {
const event = stripe.webhooks.constructEvent(
payload,
signature,
env.STRIPE_WEBHOOK_SECRET
env.STRIPE_WEBHOOK_SECRET,
);

const ctx = createTRPCContext({ req });
Expand Down
2 changes: 1 addition & 1 deletion src/app/app/(dashboard)/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Skeleton } from "@/components/ui/skeleton";
import { ProfileLinkCardSkeleton } from "@/components/profile-link-card";
import { Skeleton } from "@/components/ui/skeleton";

export default function Page() {
return (
Expand Down
Loading

0 comments on commit 3a7bc1c

Please sign in to comment.