import { Check, CheckCheck, Search, SquarePen } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/router"; import { useCallback, useState } from "react"; import { Etichetta, EtichetteModal } from "~/components/etichette"; import { LoadingPage } from "~/components/loading"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "~/components/ui/alert-dialog"; import { Button, buttonVariants } from "~/components/ui/button"; import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "~/components/ui/command"; import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, } from "~/components/ui/context-menu"; import Input from "~/components/ui/input"; import { UserAvatar } from "~/components/user_avatar"; import { useMediaQuery } from "~/hooks/use-media-query"; import { cn } from "~/lib/utils"; import type { ChatsChatid } from "~/schemas/public/Chats"; import type { UsersId } from "~/schemas/public/Users"; import type { ActiveChatsType } from "~/server/controllers/chat.controller"; import type { NonNullableUser } from "~/server/controllers/user.controller"; import { api } from "~/utils/api"; export const ChatSidebar = ({ chatId, userId, }: { chatId: ChatsChatid | null; userId: UsersId; }) => { const utils = api.useUtils(); api.chatSSE.onSidebarUpdate.useSubscription(undefined, { onData() { void utils.chat.getActiveChats.invalidate(); }, }); const { data: activeChats, isLoading: loadingActiveChats } = api.chat.getActiveChats.useQuery(undefined, { refetchOnWindowFocus: true, }); const { data: inactiveUsers, isLoading: loadingInactiveUsers } = api.users.getActiveUsersWithoutChat.useQuery(); const router = useRouter(); const isDesktop = useMediaQuery("(min-width: 768px)"); const [selectedChat, setSelectedChat] = useState(null); const [addDialogOpen, setAddDialogOpen] = useState(false); const [searchDialogOpen, setSearchDialogOpen] = useState(false); const [deleteModalOpen, setDeleteModalOpen] = useState(false); const [editEtichettaModalOpen, setEditEtichettaModalOpen] = useState(false); const { mutate: deletechat } = api.chat.deleteChat.useMutation({ onSuccess: async () => { await utils.chat.getActiveChats.invalidate(); await utils.users.getActiveUsersWithoutChat.invalidate(); }, }); const handleChatSelection = useCallback( async (new_chatid: ChatsChatid) => { if (chatId === new_chatid) return; await router.push(`/area-riservata/admin/chats/${new_chatid}`); setSearchDialogOpen(false); }, [chatId, router], ); if (loadingActiveChats || loadingInactiveUsers) return ; if (!activeChats || !inactiveUsers) return
Errore caricamento
; return (
{isDesktop ? (
) : ( )}
); }; const SearchUserComponent = ({ isOpen, OpenChange, activeChats, handleChatSelection, }: { isOpen: boolean; OpenChange: (status: boolean) => void; activeChats: ActiveChatsType[]; handleChatSelection: (chatId: ChatsChatid) => void; }) => { return ( Nessun risultato 0 ? "Suggerimenti" : undefined} > {activeChats?.map((chat) => ( { handleChatSelection(chat.chatid); }} > {chat.username} ))} ); }; const NewUserComponent = ({ isOpen, OpenChange, inactiveUsers, }: { isOpen: boolean; OpenChange: (status: boolean) => void; inactiveUsers: NonNullableUser[]; }) => { const utils = api.useUtils(); const { mutate: createNewChat } = api.chatSSE.createChat.useMutation({ onSuccess: async () => { await utils.chat.getActiveChats.invalidate(); OpenChange(false); }, }); return ( Nessun risultato 0 ? "Suggerimenti" : undefined} > {inactiveUsers?.map((user) => ( { createNewChat({ userId: user.id, }); }} > {user.username} ))} ); }; const ChatSidebarContextMenu = ({ chatid, setSelectedChat, setDeleteModalOpen, setEditEtichettaModalOpen, }: { chatid: ChatsChatid; setSelectedChat: (chat: ChatsChatid | null) => void; setDeleteModalOpen: (status: boolean) => void; setEditEtichettaModalOpen: (status: boolean) => void; }) => { const { data: chatData } = api.chat.getChatInfobyId.useQuery({ chatId: chatid, }); if (!chatData) return null; return ( <> Etichette Profilo Ordini Allegati Altro { setSelectedChat(chatid); setDeleteModalOpen(true); }} > Elimina Chat ); };