Skip to content

Commit

Permalink
fixed the toast issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Kashyap1ankit committed Dec 23, 2024
1 parent d7ea486 commit 8d9751b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 78 deletions.
31 changes: 8 additions & 23 deletions app/(auth)/sign-in/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -42,8 +42,6 @@ export default function SignInForm() {
},
});

const { toast } = useToast();

const onSubmit = async (data) => {
setIsLoading(true);
try {
Expand All @@ -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);
}
Expand Down
14 changes: 3 additions & 11 deletions app/(auth)/sign-up/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -42,7 +42,6 @@ const Page = () => {
);

const router = useRouter();
const { toast } = useToast();

const form = useForm({
resolver: zodResolver(signUpSchema),
Expand Down Expand Up @@ -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}`);

Expand All @@ -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);
}
Expand Down
14 changes: 3 additions & 11 deletions app/(auth)/verify/[username]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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),
Expand All @@ -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);
}
};

Expand Down
4 changes: 2 additions & 2 deletions app/blogs/[slug]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const getData = async (slug) => {
if (!data) {
throw new Error("Blog post not found");
}
return data;
return data;
};

const components = {
Expand All @@ -41,7 +41,7 @@ const components = {
const page = async ({ params }) => {
const data = await getData(params.slug);
if (!data) {
return <div>Blog post not found.</div>;
return <div>Blog post not found.</div>;
}
return (
<div className="flex flex-col items-center gap-7">
Expand Down
16 changes: 3 additions & 13 deletions app/create/team/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand All @@ -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: {
Expand Down Expand Up @@ -71,10 +69,7 @@ export default function CreateTeamForm() {
dataWithPlayersArray,
);

toast({
title: "Success",
description: response.data.message,
});
toast.success(response.data.message);

reset();
setTeamname("");
Expand All @@ -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");
}
};

Expand Down
9 changes: 2 additions & 7 deletions app/tournaments/[id]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down
17 changes: 7 additions & 10 deletions components/BracketForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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({
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -227,7 +221,10 @@ export default function BracketForm() {
Add Another Team
</Button>
<div>
<Button type="submit" disabled={form.formState.isSubmitting}>
<Button
type="submit"
disabled={bracketForm.formState.isSubmitting}
>
Submit Teams
</Button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"types": ["react-reconciler"],
"target": "ES2017",
"forceConsistentCasingInFileNames": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"**/*.js",
Expand Down

0 comments on commit 8d9751b

Please sign in to comment.