Skip to content

Commit

Permalink
[RELEASE] - Release to 1.3.0 is coming! πŸ’š (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
neopromic authored Dec 4, 2024
2 parents a175fbe + 264a617 commit 4d15fcc
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 54 deletions.
9 changes: 5 additions & 4 deletions app/(authenticated)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { Suspense } from "react";
import type React from "react";
import { Suspense } from "react";
import Header from "../_components/Header";
import { auth } from "@clerk/nextjs/server";
import { redirect } from "next/navigation";
import { PostHogProvider } from "../_lib/providers";
import { ClientProviders } from "../_lib/providers";

export default async function AuthenticatedLayout({
children,
Expand All @@ -17,10 +18,10 @@ export default async function AuthenticatedLayout({

return (
<Suspense>
<PostHogProvider>
<ClientProviders>
<Header isEnabled />
<div className="flex flex-col overflow-hidden">{children}</div>
</PostHogProvider>
</ClientProviders>
</Suspense>
);
}
2 changes: 1 addition & 1 deletion app/_components/ui/calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import * as React from "react";
import type * as React from "react";
import { ChevronLeft, ChevronRight } from "lucide-react";
import { DayPicker } from "react-day-picker";

Expand Down
2 changes: 1 addition & 1 deletion app/_components/ui/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { cn } from "@/app/_lib/utils";
import { Button } from "./button";
import { Calendar } from "./calendar";
import { Popover, PopoverContent, PopoverTrigger } from "./popover";
import { SelectSingleEventHandler } from "react-day-picker";
import type { SelectSingleEventHandler } from "react-day-picker";

interface DatePickerProps {
value?: Date;
Expand Down
6 changes: 5 additions & 1 deletion app/_components/user-avatar-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const UserAvatarButton = () => {
<DropdownMenuItem>Perfil</DropdownMenuItem>
<DropdownMenuItem>Configuraçáes</DropdownMenuItem>
<DropdownMenuItem
className="lg:hidden"
onClick={() =>
router.push(`/dashboard?month=${new Date().getMonth() + 1}`)
}
Expand All @@ -55,7 +56,10 @@ const UserAvatarButton = () => {
<DropdownMenuItem onClick={() => router.push("/subscriptions")}>
Planos
</DropdownMenuItem>
<DropdownMenuItem onClick={() => router.push("/transactions")}>
<DropdownMenuItem
className="lg:hidden"
onClick={() => router.push("/transactions")}
>
Transaçáes
</DropdownMenuItem>
<DropdownMenuItem onClick={handleLogout}>Logout</DropdownMenuItem>
Expand Down
1 change: 1 addition & 0 deletions app/_lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const env = {
DATABASE_URL: process.env.DATABASE_URL ?? "",
CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY ?? "",
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY ?? "",
CLERK_SECRET_WEBHOOK: process.env.CLERK_SECRET_WEBHOOK ?? "",
};
39 changes: 39 additions & 0 deletions app/_lib/providers/PostHogProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"use client";

import posthog from "posthog-js";
import { PostHogProvider as Provider } from "posthog-js/react";
import { usePathname, useSearchParams } from "next/navigation";
import { useEffect } from "react";
import { env } from "../env";
if (typeof window !== "undefined") {
posthog.init(env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: env.NEXT_PUBLIC_POSTHOG_HOST,
capture_pageview: true,
person_profiles: "always",
autocapture: true,
capture_heatmaps: true,
});
}

export default function PostHogProvider({
children,
}: {
children: React.ReactNode;
}) {
const pathname = usePathname();
const searchParams = useSearchParams();

useEffect(() => {
if (pathname) {
let url = window.origin + pathname;
if (searchParams?.toString()) {
url = `${url}?${searchParams.toString()}`;
}
posthog.capture("$pageview", {
$current_url: url,
});
}
}, [pathname, searchParams]);

return <Provider client={posthog}>{children}</Provider>;
}
46 changes: 13 additions & 33 deletions app/_lib/providers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
"use client";

import posthog from "posthog-js";
import { PostHogProvider as Provider } from "posthog-js/react";
import { usePathname, useSearchParams } from "next/navigation";
import { useEffect } from "react";
import { env } from "../env";
if (typeof window !== "undefined") {
posthog.init(env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: env.NEXT_PUBLIC_POSTHOG_HOST,
capture_pageview: true,
person_profiles: "always",
autocapture: true,
capture_heatmaps: true,
});
}

export function PostHogProvider({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const searchParams = useSearchParams();

useEffect(() => {
if (pathname) {
let url = window.origin + pathname;
if (searchParams?.toString()) {
url = url + `?${searchParams.toString()}`;
}
posthog.capture("$pageview", {
$current_url: url,
});
}
}, [pathname, searchParams]);

return <Provider client={posthog}>{children}</Provider>;
}
import PostHogProvider from "./PostHogProvider";

export const ClientProviders = ({
children,
}: {
children: React.ReactNode;
}) => {
return (
<>
<PostHogProvider>{children}</PostHogProvider>
</>
);
};
3 changes: 3 additions & 0 deletions app/_styles/typography.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const typography = {
h1: "text-2xl font-bold",
};
38 changes: 38 additions & 0 deletions app/api/webhooks/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NextResponse } from "next/server";
import { clerkClient } from "@clerk/nextjs/server";

export async function POST(req: Request) {
try {
const payload = await req.json();

// Verificar o evento do webhook
if (payload.type === "user.created") {
const userId = payload.data.id;

// Atualizar os metadata do usuΓ‘rio
await (
await clerkClient()
).users.updateUser(userId, {
publicMetadata: {
stripeCustomerId: null, // Adicione isso quando integrar o Stripe
subscriptionStatus: "free", // Defina o plano inicial como "free"
},
});

return NextResponse.json({
message: "User metadata updated successfully",
});
}

return NextResponse.json(
{ error: "Unhandled event type" },
{ status: 400 },
);
} catch (error) {
console.error("Erro ao processar webhook Clerk:", error);
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 },
);
}
}
16 changes: 12 additions & 4 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ import { Mulish } from "next/font/google";
import "./globals.css";
import { ClerkProvider } from "@clerk/nextjs";
import { dark } from "@clerk/themes";
import { PostHogProvider } from "./_lib/providers";
import { ClientProviders } from "./_lib/providers";
import { Suspense } from "react";

const mulish = Mulish({
subsets: ["latin-ext"],
});

export const metadata: Metadata = {
title: "Finance AI",
title: "Jupiter Finance",
description:
"Uma plataforma de gerenciamento de finanças pessoais e para pequenas empresas.",
keywords: ["finance", "controle financeiro", "gerenciamento financeiro"],
applicationName: "Jupiter Finance",
authors: {
name: "Wesley Souza",
url: "https://dev-wesleysouza.vercel.app/",
},
};

export default function RootLayout({
Expand All @@ -22,15 +30,15 @@ export default function RootLayout({
return (
<html lang="pt-BR">
<Suspense>
<PostHogProvider>
<ClientProviders>
<ClerkProvider appearance={{ baseTheme: dark }}>
<body
className={`${mulish.className} dark flex h-full flex-col overflow-hidden antialiased`}
>
{children}
</body>
</ClerkProvider>
</PostHogProvider>
</ClientProviders>
</Suspense>
</html>
);
Expand Down
90 changes: 89 additions & 1 deletion app/subscriptions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,98 @@
import { Check, SparklesIcon, X } from "lucide-react";
import Header from "../_components/Header";
import { Badge } from "../_components/ui/badge";
import {
Card,
CardContent,
CardFooter,
CardHeader,
} from "../_components/ui/card";
import { cn } from "../_lib/utils";
import { typography } from "../_styles/typography";
import { Button } from "../_components/ui/button";
import { ScrollArea } from "../_components/ui/scroll-area";

const Subscriptions = () => {
return (
<>
<Header />
<div>Subscriptions</div>
<ScrollArea>
<section className="h-screen space-y-6 overflow-hidden p-6 lg:pb-0">
<h1 className={cn(typography.h1)}>Assinaturas</h1>
<div className="flex w-full flex-col gap-6 lg:flex-row lg:justify-center">
<Card className="h-96 w-80">
<CardHeader className="relative flex h-44 flex-col items-center justify-center gap-2 border-b">
<div className="space-y-4">
<h2 className={cn(typography.h1, "text-2xl font-medium")}>
Plano PRO
</h2>
<div className="flex items-center gap-2">
<p className="text-2xl">R$</p>
<p className={cn(typography.h1, "text-4xl")}>19</p>
<p className="text-2xl text-muted-foreground">/ mΓͺs</p>
</div>
</div>
</CardHeader>
<CardContent className="flex min-h-32 flex-grow flex-col items-start justify-start gap-2 p-6">
<div className="flex items-center gap-2">
<Check className="text-primary" />
<p>Transaçáes ilimitadas.</p>
</div>
<div className="flex items-center gap-2">
<Check className="text-primary" />
<p>RelatΓ³rios de IA ilimitados. </p>
</div>
</CardContent>
<CardFooter className="mt-auto">
<Button className="w-full">
<SparklesIcon className="text-primary-foreground" />
Assinar agora!
</Button>
</CardFooter>
</Card>
<Card className="h-96 w-80">
<CardHeader className="relative flex h-44 flex-col items-center justify-center gap-2 border-b">
<div className="">
<Badge className="pointer-events-none select-none bg-primary/10 text-primary hover:bg-primary/10">
Atual
</Badge>
</div>
<div className="space-y-4">
<h2 className={cn(typography.h1, "text-2xl font-medium")}>
Plano BΓ‘sico
</h2>
<div className="flex items-center gap-2">
<p className="text-2xl">R$</p>
<p className={cn(typography.h1, "text-4xl")}>0</p>
<p className="text-2xl text-muted-foreground">/ mΓͺs</p>
</div>
</div>
</CardHeader>
<CardContent className="flex min-h-32 flex-1 flex-col items-start justify-start gap-2 p-6">
<div className="flex items-center gap-2">
<Check className="text-primary" />
<p>
Apenas 10 transaçáes por dia{" "}
<span className="font-bold text-primary">0</span>/10
</p>
</div>
<div className="flex items-center gap-2">
<X className="text-muted-foreground" />
<p>RelatΓ³rios de IA limitados. </p>
</div>
</CardContent>
<CardFooter className="">
<Button
variant={"outline"}
className="w-full border-primary text-primary"
>
Faça o upgrade
</Button>
</CardFooter>
</Card>
</div>
</section>
</ScrollArea>
</>
);
};
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@
"@radix-ui/react-scroll-area": "^1.2.0",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-slot": "^1.1.0",
"@stripe/stripe-js": "^5.2.0",
"@tanstack/react-table": "^8.20.5",
"@types/node": "^20.17.6",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
"eslint": "^8.57.1",
"lucide-react": "^0.454.0",
"next": "14.2.16",
"next-nprogress-bar": "^2.3.15",
"nextjs-progressbar": "^0.0.16",
"postcss": "^8.4.47",
"posthog-js": "^1.188.0",
"prisma": "^5.22.0",
Expand All @@ -45,6 +49,7 @@
"react-hook-form": "^7.53.1",
"react-number-format": "^5.4.2",
"recharts": "^2.13.3",
"stripe": "^17.4.0",
"tailwind-merge": "^2.5.4",
"tailwindcss": "^3.4.14",
"tailwindcss-animate": "^1.0.7",
Expand All @@ -55,7 +60,7 @@
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^11.0.1",
"eslint": "^8.57.1",
"@types/nprogress": "^0.2.3",
"eslint-config-next": "14.2.16",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.8"
Expand Down
Loading

0 comments on commit 4d15fcc

Please sign in to comment.