Skip to content

Commit

Permalink
toaster implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
sanidhyy authored Jan 13, 2024
1 parent a0182b0 commit fc3af46
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
42 changes: 17 additions & 25 deletions src/components/Contact.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useRef } from "react";
import { motion } from "framer-motion";
import { toast } from "sonner";
import emailjs from "@emailjs/browser";

import { styles } from "../styles";
Expand Down Expand Up @@ -94,31 +95,22 @@ const Contact = () => {
},
import.meta.env.VITE_APP_EMAILJS_KEY
)
.then(
() => {
// Success
setLoading(false);
alert("Thank You. I will get back to you as soon as possible.");

setForm({
name: "",
email: "",
message: "",
});
},
(error) => {
// Error handle
setLoading(false);
console.log(error);
alert("Sorry. Something went wrong.");

setForm({
name: "",
email: "",
message: "",
});
}
);
.then(() =>
toast.success("Thank You. I will get back to you as soon as possible.")
)
.catch((error) => {
// Error handle
console.log("[CONTACT_ERR]: ", error);
toast.error("Sorry. Something went wrong.");
})
.finally(() => {
setLoading(false);
setForm({
name: "",
email: "",
message: "",
});
});
};

return (
Expand Down
13 changes: 12 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { Toaster } from "sonner";

import App from "./App";

import "./index.css";

// Render react app
ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<Toaster
theme="dark"
richColors
closeButton
toastOptions={{
style: { background: "#050816", opacity: 0.95 },
}}
/>
<App />
</React.StrictMode>,
</React.StrictMode>
);

0 comments on commit fc3af46

Please sign in to comment.