From 8d9751b3884304aa72f1f6544ffe241a91b5dba4 Mon Sep 17 00:00:00 2001 From: Ankit Date: Mon, 23 Dec 2024 11:57:35 +0530 Subject: [PATCH] fixed the toast issue --- app/(auth)/sign-in/page.jsx | 31 +++++++-------------------- app/(auth)/sign-up/page.jsx | 14 +++--------- app/(auth)/verify/[username]/page.jsx | 14 +++--------- app/blogs/[slug]/page.jsx | 4 ++-- app/create/team/page.jsx | 16 +++----------- app/tournaments/[id]/page.js | 9 ++------ components/BracketForm.jsx | 17 ++++++--------- tsconfig.json | 2 +- 8 files changed, 29 insertions(+), 78 deletions(-) diff --git a/app/(auth)/sign-in/page.jsx b/app/(auth)/sign-in/page.jsx index f94bf5e..e455372 100644 --- a/app/(auth)/sign-in/page.jsx +++ b/app/(auth)/sign-in/page.jsx @@ -15,7 +15,7 @@ import { Button } from "../../../@/components/ui/button"; import { Input } from "../../../@/components/ui/input"; import Link from "next/link"; import { useRouter } from "next/navigation"; -import { useToast } from "../../../@/components/ui/use-toast"; +import toast from "react-hot-toast"; import { signInSchema } from "../../../model/Schema/signInSchema"; import React, { useState } from "react"; import { @@ -42,8 +42,6 @@ export default function SignInForm() { }, }); - const { toast } = useToast(); - const onSubmit = async (data) => { setIsLoading(true); try { @@ -54,32 +52,19 @@ export default function SignInForm() { }); if (result?.error) { - console.error("Sign in error:", result.error); - toast({ - title: "Error", - description: - result.error === "CredentialsSignin" - ? "Invalid email or password" - : result.error, - variant: "destructive", - }); + toast.error( + result.error === "CredentialsSignin" + ? "Invalid email or password" + : result.error, + ); } else if (result?.url) { router.push("/dashboard"); } else { - console.error("Unexpected result:", result); - toast({ - title: "Error", - description: "An unexpected error occurred", - variant: "destructive", - }); + toast.error("An unexpected error occurred"); } } catch (error) { console.error("Sign in error:", error); - toast({ - title: "Error", - description: "An unexpected error occurred", - variant: "destructive", - }); + toast.error("An unexpected error occurred"); } finally { setIsLoading(false); } diff --git a/app/(auth)/sign-up/page.jsx b/app/(auth)/sign-up/page.jsx index 4838754..451ef57 100644 --- a/app/(auth)/sign-up/page.jsx +++ b/app/(auth)/sign-up/page.jsx @@ -24,7 +24,7 @@ import { CardTitle, } from "../../../@/components/ui/card"; -import { useToast } from "../../../@/components/ui/use-toast"; +import toast from "react-hot-toast"; import axios from "axios"; import { Loader2 } from "lucide-react"; import { useRouter } from "next/navigation"; @@ -42,7 +42,6 @@ const Page = () => { ); const router = useRouter(); - const { toast } = useToast(); const form = useForm({ resolver: zodResolver(signUpSchema), @@ -77,10 +76,7 @@ const Page = () => { try { const response = await axios.post("/api/sign-up", data); - toast({ - title: "Success", - description: response.data.message, - }); + toast.success(response.data.message); router.replace(`/verify/${data.username}`); @@ -92,11 +88,7 @@ const Page = () => { error.response?.data.message ?? "There was a problem with your sign-up. Please try again."; - toast({ - title: "Sign Up Failed", - description: errorMessage, - variant: "destructive", - }); + toast.error(errorMessage); setIsSubmitting(false); } diff --git a/app/(auth)/verify/[username]/page.jsx b/app/(auth)/verify/[username]/page.jsx index e6cf711..f8e711e 100644 --- a/app/(auth)/verify/[username]/page.jsx +++ b/app/(auth)/verify/[username]/page.jsx @@ -10,7 +10,7 @@ import { FormMessage, } from "../../../../@/components/ui/form"; import { Input } from "../../../../@/components/ui/input"; -import { useToast } from "../../../../@/components/ui/use-toast"; +import toast from "react-hot-toast"; import { verifySchema } from "../../../../model/Schema/verifySchema"; import { zodResolver } from "@hookform/resolvers/zod"; import axios, { AxiosError } from "axios"; @@ -30,7 +30,6 @@ import Image from "next/image"; const VerifyAccount = () => { const router = useRouter(); const params = useParams(); - const { toast } = useToast(); const form = useForm({ resolver: zodResolver(verifySchema), @@ -43,20 +42,13 @@ const VerifyAccount = () => { code: data.code, }); - toast({ - title: "Success", - description: response.data.message, - }); + toast.success(response.data.message); router.replace("/sign-in"); } catch (error) { console.error("Error in sign-up of user", error); const axiosError = AxiosError; let errorMessage = axiosError.response?.data.message; - toast({ - title: "Signup failed", - description: errorMessage, - variant: "destructive", - }); + toast.error(errorMessage); } }; diff --git a/app/blogs/[slug]/page.jsx b/app/blogs/[slug]/page.jsx index 798cae8..413be9f 100644 --- a/app/blogs/[slug]/page.jsx +++ b/app/blogs/[slug]/page.jsx @@ -19,7 +19,7 @@ const getData = async (slug) => { if (!data) { throw new Error("Blog post not found"); } - return data; + return data; }; const components = { @@ -41,7 +41,7 @@ const components = { const page = async ({ params }) => { const data = await getData(params.slug); if (!data) { - return
Blog post not found.
; + return
Blog post not found.
; } return (
diff --git a/app/create/team/page.jsx b/app/create/team/page.jsx index a1ace23..2c3449f 100644 --- a/app/create/team/page.jsx +++ b/app/create/team/page.jsx @@ -15,7 +15,7 @@ import { Input } from "../../../@/components/ui/input"; import { useState } from "react"; import axios from "axios"; import { teamSchema } from "../../../model/Schema/teamSchema"; -import { useToast } from "../../../@/components/ui/use-toast"; +import toast from "react-hot-toast"; export default function CreateTeamForm() { const [teamname, setTeamname] = useState(""); @@ -28,8 +28,6 @@ export default function CreateTeamForm() { // const [requests, setRequests] = useState(""); const [participantCount, setParticipantCount] = useState(""); - const { toast } = useToast(); - const form = useForm({ resolver: zodResolver(teamSchema), defaultValues: { @@ -71,10 +69,7 @@ export default function CreateTeamForm() { dataWithPlayersArray, ); - toast({ - title: "Success", - description: response.data.message, - }); + toast.success(response.data.message); reset(); setTeamname(""); @@ -88,12 +83,7 @@ export default function CreateTeamForm() { setParticipantCount(""); } } catch (error) { - console.error("Error during create-team:", error); - toast({ - title: "Team Creation Failed", - description: error.response?.data?.message || "An error occurred", - variant: "destructive", - }); + toast.error(error.response?.data?.message || "An error occurred"); } }; diff --git a/app/tournaments/[id]/page.js b/app/tournaments/[id]/page.js index 8efb6d6..6f4fc2a 100644 --- a/app/tournaments/[id]/page.js +++ b/app/tournaments/[id]/page.js @@ -2,7 +2,7 @@ import Link from "next/link"; import { useEffect, useState } from "react"; // import { useRouter } from "next/navigation"; -import { useToast } from "../../../@/components/ui/use-toast"; +import toast from "react-hot-toast"; import TournamentBracket from "../../../components/TournamentBracket"; import { Button } from "../../../@/components/ui/button"; import { @@ -24,7 +24,6 @@ export default function TournamentPage({ params }) { const [error, setError] = useState(null); // const [registering, setRegistering] = useState(false); // const router = useRouter(); - const { toast } = useToast(); useEffect(() => { loadTournamentData(); @@ -38,11 +37,7 @@ export default function TournamentPage({ params }) { setError(null); } catch (err) { setError(err.message || "Failed to load tournament"); - toast({ - variant: "destructive", - title: "Error", - description: "Failed to load tournament data", - }); + toast.success("Failed to load tournament data"); } finally { setLoading(false); } diff --git a/components/BracketForm.jsx b/components/BracketForm.jsx index 541ba2e..bab2693 100644 --- a/components/BracketForm.jsx +++ b/components/BracketForm.jsx @@ -22,7 +22,7 @@ import { Input } from "../@/components/ui/input"; import { z } from "zod"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; -import { useToast } from "../@/components/ui/use-toast"; +import toast from "react-hot-toast"; import { useRouter } from "next/navigation"; import { revalidatePath } from "next/cache"; @@ -40,7 +40,6 @@ const teamSchema = z.object({ export default function BracketForm() { const [bracketCreated, setBracketCreated] = useState(false); const [bracketInfo, setBracketInfo] = useState(null); - const { toast } = useToast(); const router = useRouter(); const bracketForm = useForm({ @@ -76,16 +75,11 @@ export default function BracketForm() { }); if (!res.ok) { - toast({ - title: "An unexpected error occurred", - variant: "error", - }); + toast.error("An unexpected error occurred"); return; } - toast({ - title: "Bracket created successfully", - }); + toast.success("Bracket created successfully"); router.push("/bracket"); return; @@ -227,7 +221,10 @@ export default function BracketForm() { Add Another Team
-
diff --git a/tsconfig.json b/tsconfig.json index 55a4dc6..e23b779 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,7 @@ ], "types": ["react-reconciler"], "target": "ES2017", - "forceConsistentCasingInFileNames": true, + "forceConsistentCasingInFileNames": true }, "include": [ "**/*.js",