Skip to content

Commit

Permalink
fix: added toast for signin error
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas0924 committed Feb 2, 2024
1 parent 67ca6e0 commit 9e57b15
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"react-notion-x": "^6.16.0",
"react-resizable-panels": "^1.0.7",
"recoil": "^0.7.7",
"sonner": "^1.4.0",
"tailwind-merge": "^2.2.1",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.8.9",
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Providers } from './providers';
import { GoogleAnalytics } from '@/components/analytics/GoogleAnalytics';
import { siteConfig } from '@/config/site-config';
import Footer from '@/components/landing/footer/footer';
import { Toaster } from '@/components/ui/sonner';

const fontSans = FontSans({
subsets: ['latin'],
Expand Down Expand Up @@ -43,6 +44,7 @@ export default function RootLayout({
<Appbar />
<div className="min-h-screen">{children}</div>
<Footer />
<Toaster />
</Providers>
</body>
</html>
Expand Down
10 changes: 10 additions & 0 deletions src/app/signin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Toaster } from '@/components/ui/sonner';
import { signIn } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import React, { useRef, useState } from 'react';

import { toast } from 'sonner';
const Signin = () => {
const [isPasswordVisible, setIsPasswordVisible] = useState(false);

Expand All @@ -26,6 +28,13 @@ const Signin = () => {

if (!res?.error) {
router.push('/');
} else {
toast('Error Signing in', {
action: {
label: 'Close',
onClick: () => console.log('Closed Toast'),
},
});
}
};
return (
Expand Down Expand Up @@ -105,6 +114,7 @@ const Signin = () => {
</Button>
</CardContent>
</Card>
<Toaster />
</section>
);
};
Expand Down
32 changes: 32 additions & 0 deletions src/components/ui/sonner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client';

import { useTheme } from 'next-themes';
import React from 'react';
import { Toaster as Sonner } from 'sonner';

type ToasterProps = React.ComponentProps<typeof Sonner>

const Toaster = ({ ...props }: ToasterProps) => {
const { theme = 'system' } = useTheme();

return (
<Sonner
theme={theme as ToasterProps['theme']}
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',
actionButton:
'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',
cancelButton:
'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground',
},
}}
{...props}
/>
);
};

export { Toaster };
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,7 @@ next-auth@^4.24.5:

next-themes@^0.2.1:
version "0.2.1"
resolved "https://registry.npmjs.org/next-themes/-/next-themes-0.2.1.tgz"
resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.2.1.tgz#0c9f128e847979daf6c67f70b38e6b6567856e45"
integrity sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==

next@14.0.2:
Expand Down Expand Up @@ -3159,6 +3159,11 @@ slash@^3.0.0:
resolved "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz"
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==

sonner@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/sonner/-/sonner-1.4.0.tgz#f71b0576909043f6b32f05ff796c86ef6b97350a"
integrity sha512-nvkTsIuOmi9e5Wz5If8ldasJjZNVfwiXYijBi2dbijvTQnQppvMcXTFNxL/NUFWlI2yJ1JX7TREDsg+gYm9WyA==

source-map-js@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz"
Expand Down

0 comments on commit 9e57b15

Please sign in to comment.