Skip to content

Commit

Permalink
fixed infinite loading on invalid invite
Browse files Browse the repository at this point in the history
  • Loading branch information
Sama-004 committed Sep 2, 2024
1 parent d622f77 commit 3d5e5a4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/app/invite/[...invitecode]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default function Page({ params }: { params: { invitecode: string } }) {
const router = useRouter();
const [loading, setLoading] = useState(true);
const { toast } = useToast();
console.log('Code is:', params.invitecode);

useEffect(() => {
joinRoom();
Expand All @@ -20,11 +19,10 @@ export default function Page({ params }: { params: { invitecode: string } }) {
try {
console.log('Invite code being sent:', params.invitecode);
const response = await axios.get(`/api/room/invite/${params.invitecode}`);
const data = response.data;
if (response) {
setLoading(false);
}
if (data.success) {
if (response.status === 200) {
toast({
title: 'Success',
description: 'Room joined successfully',
Expand All @@ -42,6 +40,12 @@ export default function Page({ params }: { params: { invitecode: string } }) {
router.push('/rooms');
}
} catch (error) {
router.push('/rooms');
toast({
description: 'Internal server error',
variant: 'destructive',
className: 'bg-red-600',
});
console.error(error);
}
};
Expand Down

0 comments on commit 3d5e5a4

Please sign in to comment.