Skip to content

Commit

Permalink
Add form respose toast messages
Browse files Browse the repository at this point in the history
  • Loading branch information
salhotra committed Jul 29, 2024
1 parent da11e0b commit e93ab03
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"react-dom": "^18",
"react-hook-form": "^7.52.1",
"react-icons": "^5.2.1",
"react-toastify": "^10.0.5",
"three": "^0.165.0",
"three-orbit-controls": "^82.1.0",
"three-stdlib": "^2.30.4"
Expand Down
9 changes: 8 additions & 1 deletion src/app/components/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "react-hook-form";
import { upperFirst } from "../utils/upperFirst";
import Button from "../ui/Button";
import { toast } from "react-toastify";

interface ContactFormValues {
name: string;
Expand Down Expand Up @@ -111,9 +112,15 @@ function ContactForm(): JSX.Element {
);

console.log({ response });

toast("Form submitted successfully!", {
type: "success",
});
} catch (e) {
console.error(e);
alert("Failed to submit form. Please try again later.");
toast("Failed to submit form. Please try again later.", {
type: "error",
});
}
};

Expand Down
8 changes: 7 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import { ToastContainer } from "react-toastify";

import "react-toastify/dist/ReactToastify.css";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });
Expand All @@ -16,7 +19,10 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>
{children}
<ToastContainer />
</body>
</html>
);
}

0 comments on commit e93ab03

Please sign in to comment.