From c42a3b8eb4254eef8222388a6e0a9e4951c559a1 Mon Sep 17 00:00:00 2001 From: Biwas Bhandari Date: Mon, 11 Nov 2024 09:10:14 +0545 Subject: [PATCH 1/2] fix: remove unnecessary code --- src/components/public-crew/ClonePublicCrew.tsx | 8 +------- src/components/public-crew/PublicCrews.tsx | 11 +---------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/components/public-crew/ClonePublicCrew.tsx b/src/components/public-crew/ClonePublicCrew.tsx index e6d0ec07..7f2cc694 100644 --- a/src/components/public-crew/ClonePublicCrew.tsx +++ b/src/components/public-crew/ClonePublicCrew.tsx @@ -10,15 +10,10 @@ import type { PublicCrew } from "@/types/supabase"; interface ClonePublicCrewProps { crew: PublicCrew; - onCloneComplete: () => void; disabled: boolean; } -export function ClonePublicCrew({ - crew, - onCloneComplete, - disabled, -}: ClonePublicCrewProps) { +export function ClonePublicCrew({ crew, disabled }: ClonePublicCrewProps) { const [isCloning, setIsCloning] = useState(false); const [error, setError] = useState(null); const [hasCloned, setHasCloned] = useState(false); @@ -91,7 +86,6 @@ export function ClonePublicCrew({ } setHasCloned(true); - onCloneComplete(); toast({ title: "Success", description: `You've successfully cloned the "${crew.name}" crew. You can find it in your crews list.`, diff --git a/src/components/public-crew/PublicCrews.tsx b/src/components/public-crew/PublicCrews.tsx index 7cd52bb5..6025a645 100644 --- a/src/components/public-crew/PublicCrews.tsx +++ b/src/components/public-crew/PublicCrews.tsx @@ -50,11 +50,6 @@ export default function PublicCrews() { fetchCrews(); }, []); - const handleCloneComplete = () => { - // You can add any additional logic here after a crew has been cloned - console.log("Crew cloned successfully"); - }; - if (loading) { return
Loading crews...
; } @@ -173,11 +168,7 @@ export default function PublicCrews() { ))}
- +
From a8e1ec7f47ac95fad1e2f6f225aebb18e741740d Mon Sep 17 00:00:00 2001 From: Biwas Bhandari Date: Mon, 11 Nov 2024 09:15:35 +0545 Subject: [PATCH 2/2] fix: update state of switch --- src/components/crews/CrewManagement.tsx | 40 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/components/crews/CrewManagement.tsx b/src/components/crews/CrewManagement.tsx index a0d38bd9..0b428b92 100644 --- a/src/components/crews/CrewManagement.tsx +++ b/src/components/crews/CrewManagement.tsx @@ -1,19 +1,12 @@ "use client"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import { supabase } from "@/utils/supabase/client"; import { Button } from "@/components/ui/button"; -import { Circle, CheckCircle } from "lucide-react"; -import { useToast } from "@/hooks/use-toast"; -import { - Dialog, - DialogContent, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog"; import { + Circle, + CheckCircle, PlusIcon, Trash2Icon, UserIcon, @@ -21,6 +14,14 @@ import { Globe, Lock, } from "lucide-react"; +import { useToast } from "@/hooks/use-toast"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; import { Switch } from "@/components/ui/switch"; import CrewForm from "./CrewForm"; import { Crew, CrewManagementProps } from "@/types/supabase"; @@ -38,6 +39,25 @@ export function CrewManagement({ const { toast } = useToast(); const router = useRouter(); + useEffect(() => { + const fetchCrews = async () => { + const { data, error } = await supabase.from("crews").select("*"); + if (error) { + console.error("Error fetching crews:", error); + toast({ + title: "Error", + description: "Failed to fetch crews. Please refresh the page.", + variant: "destructive", + }); + } else if (data) { + setCrews(data); + onCrewUpdate(data); + } + }; + + fetchCrews(); + }, [onCrewUpdate, toast]); + const handleDelete = async (id: number) => { setLoading(true); try {