import { Plus } from "lucide-react"; import * as React from "react"; import { toast } from "sonner"; import type { Project } from "@/features/projects/hooks"; import { listLinkableProjectChannels } from "@/features/projects/lib/projectRelatedChannelAccess"; import { useChangeProjectRelatedChannelsMutation } from "@/features/projects/useChangeProjectRelatedChannels"; import type { Channel } from "@/shared/api/types"; import { Button } from "@/shared/ui/button"; import { AddProjectChannelDialog } from "./AddProjectChannelDialog"; export function ProjectChannelManagement({ canManage, channels, project, }: { canManage: boolean; channels: Channel[]; project: Project; }) { const [addOpen, setAddOpen] = React.useState(false); const changeMutation = useChangeProjectRelatedChannelsMutation(); const candidates = React.useMemo( () => listLinkableProjectChannels(project, channels), [channels, project], ); return ( <> {canManage ? ( { await changeMutation.mutateAsync({ add: [channel.id], project, }); toast.success(`Channel "#${channel.name}" added to project.`); }} onOpenChange={setAddOpen} open={addOpen} project={project} /> ) : null} ); }