Skip to content

Commit

Permalink
add feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vcapretz committed Aug 20, 2024
1 parent 2b12202 commit 6b660b0
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 13 deletions.
18 changes: 11 additions & 7 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import './ui/global.css'
import "./ui/global.css";
import { Toaster } from "./ui/toaster";

export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}
title: "Next.js",
description: "Generated by Next.js",
};

export default function RootLayout({
children,
}: {
children: React.ReactNode
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>{children}</body>
<body>
{children}
<Toaster />
</body>
</html>
)
);
}
8 changes: 5 additions & 3 deletions app/lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { VercelInviteUserEmail } from "../../emails/vercel-invite-user";

const resend = new Resend(process.env.RESEND_API_KEY);

export async function send(prevState: string | undefined, formData: FormData) {
type State = { error: string } | { data: string };

export async function send(prevState: State, formData: FormData) {
const email = formData.get("email") as string;

const { data, error } = await resend.emails.send({
Expand All @@ -16,10 +18,10 @@ export async function send(prevState: string | undefined, formData: FormData) {
});

if (error) {
return error.message;
return { error: error.message };
}

console.log(data);

return "Email sent!";
return { data: "Email sent!" };
}
17 changes: 15 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@
import clsx from "clsx";
import { useFormState, useFormStatus } from "react-dom";
import { send } from "./lib/actions";
import React from "react";
import * as React from "react";
import { toast } from "sonner";

export default function Page() {
const [, dispatch] = useFormState(send, undefined);
const [state, dispatch] = useFormState(send, undefined);

React.useEffect(() => {
if (!state) {
return;
}

if ("data" in state) {
toast(state.data);
} else if ("error" in state) {
toast(`Error when sending email: ${state.error}`);
}
}, [state]);

return (
<div className="bg-zinc-950 p-8 min-h-screen flex justify-center items-center sm:items-start sm:p-24">
Expand Down
24 changes: 24 additions & 0 deletions app/ui/toaster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use client";

import { Toaster as Sonner } from "sonner";

type ToasterProps = React.ComponentProps<typeof Sonner>;

const Toaster = ({ ...props }: ToasterProps) => {
return (
<Sonner
theme="dark"
className="toaster group"
toastOptions={{
classNames: {
toast:
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
description: "group-[.toast]:text-muted-foreground",
},
}}
{...props}
/>
);
};

export { Toaster };
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-email": "2.1.6",
"resend": "4.0.0"
"resend": "4.0.0",
"sonner": "^1.5.0"
},
"devDependencies": {
"@types/node": "22.4.1",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 6b660b0

Please sign in to comment.