Skip to content

Commit

Permalink
Merge pull request #1 from Eduardoooxd/feat/add-posthog
Browse files Browse the repository at this point in the history
Feat/add posthog
  • Loading branch information
Eduardoooxd authored Jul 29, 2024
2 parents 9f86104 + da52c9d commit 142a633
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 44 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
RESEND_API_KEY=
RESEND_FROM_EMAIL=
RESEND_TO_EMAIL=
RESEND_TO_EMAIL=
NEXT_PUBLIC_POSTHOG_KEY=
NEXT_PUBLIC_POSTHOG_HOST=
NEXT_PUBLIC_NODE_ENV=development
6 changes: 6 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/** @type {import('next').NextConfig} */
import createJiti from 'jiti';
import { fileURLToPath } from 'node:url';
const jiti = createJiti(fileURLToPath(import.meta.url));

jiti('./src/lib/environment');

const nextConfig = {};

export default nextConfig;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
"@radix-ui/react-toast": "^1.1.5",
"@react-email/components": "^0.0.19",
"@react-email/tailwind": "^0.0.18",
"@t3-oss/env-nextjs": "^0.11.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"framer-motion": "^11.2.10",
"jiti": "^1.21.6",
"lucide-react": "^0.372.0",
"next": "14.2.3",
"posthog-js": "^1.150.1",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.51.5",
Expand Down
74 changes: 69 additions & 5 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/actions/contact-form-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import { ContactFormSchema } from '@/domain/contact-form';
import ContactFormEmail from '@/email/contact-form-email';
import { environmentVariables } from '@/lib/environment';
import { ENV_VARS } from '@/lib/environment';
import { waitTime } from '@/lib/utils';
import React from 'react';
import { Resend } from 'resend';

const { RESEND_API_KEY, RESEND_FROM_EMAIL, RESEND_TO_EMAIL, NODE_ENV } = environmentVariables();
const { RESEND_API_KEY, RESEND_FROM_EMAIL, RESEND_TO_EMAIL, NODE_ENV } = ENV_VARS;

const resend = new Resend(RESEND_API_KEY);

Expand Down
25 changes: 14 additions & 11 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ActiveSectionProvider from '@/context/active-section-context';
import ThemeContextProvider from '@/context/theme-context';
import { WEBSITE_METADATA } from '@/lib/data';
import { cn } from '@/lib/utils';
import CSPostHogProvider from '@/providers/posthog';
import { Inter } from 'next/font/google';
import Footer from '../components/footer';
import './globals.css';
Expand All @@ -20,17 +21,19 @@ export const metadata = WEBSITE_METADATA;
export default function RootLayout({ children }: RootLayoutProps) {
return (
<html lang="en" className="h-full overflow-x-hidden !scroll-smooth">
<body className={cn('flex min-h-full flex-col bg-background antialiased', inter.className)}>
<ThemeContextProvider>
<ActiveSectionProvider>
<Header />
{children}
<Footer />
</ActiveSectionProvider>
<ThemeSwitch />
<Toaster />
</ThemeContextProvider>
</body>
<CSPostHogProvider>
<body className={cn('flex min-h-full flex-col bg-background antialiased', inter.className)}>
<ThemeContextProvider>
<ActiveSectionProvider>
<Header />
{children}
<Footer />
</ActiveSectionProvider>
<ThemeSwitch />
<Toaster />
</ThemeContextProvider>
</body>
</CSPostHogProvider>
</html>
);
}
13 changes: 10 additions & 3 deletions src/components/contact-section-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Textarea } from '@/components/shared/textarea';
import { ContactFormSchema, ContactFormType } from '@/domain/contact-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { Loader2, Send } from 'lucide-react';
import posthog from 'posthog-js';
import { useTransition } from 'react';
import { useForm } from 'react-hook-form';
import { useToast } from './shared/use-toast';
Expand Down Expand Up @@ -101,22 +102,28 @@ export default function ContactSectionForm() {
)}
/>

<ContactSectionSubmitButton isPending={isPending} />
<ContactSectionSubmitButton
isPending={isPending}
onClick={() => {
posthog.capture('SUBMITED_CONTACT_FORM', { property: form.getValues('email') });
}}
/>
</form>
</Form>
);
}

interface ContactSectionSubmitButtonProps {
interface ContactSectionSubmitButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
isPending: boolean;
}

function ContactSectionSubmitButton({ isPending }: ContactSectionSubmitButtonProps) {
function ContactSectionSubmitButton({ isPending, ...props }: ContactSectionSubmitButtonProps) {
return (
<Button
disabled={isPending}
className="group inline-flex w-fit gap-1 rounded-full px-6 hover:scale-105 focus:scale-105 active:scale-95"
type="submit"
{...props}
>
{isPending ? (
<>
Expand Down
15 changes: 14 additions & 1 deletion src/components/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { motion } from 'framer-motion';
import { ArrowDownToLine, ArrowUpRight, Github, Linkedin } from 'lucide-react';
import Image from 'next/image';
import Link from 'next/link';
import posthog from 'posthog-js';
import { Button } from './shared/button';

export default function Hero() {
Expand Down Expand Up @@ -118,6 +119,7 @@ export default function Hero() {
onClick={() => {
setActive('Contact');
setTimeOfLastClick(Date.now());
posthog.capture('CLICKED_CONTACT_HERO', { property: 'Clicked Contact Hero' });
}}
>
Contact me here
Expand All @@ -135,6 +137,9 @@ export default function Hero() {
href="/eduardo_couto_resume.pdf"
download
data-testid="download-cv-trigger"
onClick={() => {
posthog.capture('DOWNLOAD_CV', { property: 'Download CV' });
}}
>
Download CV
<ArrowDownToLine size={20} />
Expand All @@ -146,6 +151,9 @@ export default function Hero() {
variant="secondary"
className="rounded-full shadow-lg transition hover:scale-105 hover:underline hover:underline-offset-2 focus:scale-105 active:scale-95"
asChild
onClick={() => {
posthog.capture('CHECKED_LINKEDIN', { property: 'Checked Linkedin' });
}}
>
<a target="_blank" href={linkedin}>
<Linkedin size={20} />
Expand All @@ -158,7 +166,12 @@ export default function Hero() {
asChild
>
<a target="_blank" href={github}>
<Github size={20} />
<Github
onClick={() => {
posthog.capture('CHECKED_GITHUB', { property: 'Checked Github' });
}}
size={20}
/>
</a>
</Button>
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/components/project-showcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Project } from '@/lib/data';
import { motion, useScroll, useTransform } from 'framer-motion';
import Image from 'next/image';
import posthog from 'posthog-js';
import { useRef } from 'react';
import { Badge } from './shared/badge';

Expand Down Expand Up @@ -35,7 +36,13 @@ export default function ProjectShowcase({ project }: ProjectShowcaseProps) {
ref={containerRef}
className="relative max-w-2xl overflow-hidden rounded-lg border border-black/5 bg-gray-100 transition hover:bg-gray-200 dark:bg-white/10 dark:hover:bg-white/20 sm:h-72 sm:pr-8 sm:group-even:pl-8"
>
<a href={href} target="_blank">
<a
onClick={() => {
posthog.capture('CHECKED_PROJECT', { property: `Checked Project ${title}` });
}}
href={href}
target="_blank"
>
<div className="flex h-full flex-col px-5 pb-7 pt-4 sm:max-w-[50%] sm:pl-10 sm:pr-2 sm:pt-10 sm:group-even:ml-[18rem]">
<h3 className="text-2xl font-semibold transition group-hover:underline">{title}</h3>
<p className="mt-2 leading-relaxed text-gray-700 dark:text-white/70">{description}</p>
Expand Down
Loading

0 comments on commit 142a633

Please sign in to comment.