From f5d153068390968d63bb9d0c2db35c79f007e5fc Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Wed, 22 Apr 2026 16:56:14 +0200 Subject: [PATCH] rem --- .../src/components/chat/chat-attachments.tsx | 196 -------- .../src/components/chat/chat-bottombar.tsx | 171 ------- .../src/components/chat/chat-bubble.tsx | 198 -------- .../src/components/chat/chat-list.tsx | 439 ----------------- .../src/components/chat/chat-message-list.tsx | 23 - .../src/components/chat/chat-sidebar.tsx | 447 ------------------ .../src/components/chat/chat-topbar.tsx | 268 ----------- apps/infoalloggi/src/components/chat/chat.tsx | 53 --- .../src/components/chat/message-loading.tsx | 46 -- 9 files changed, 1841 deletions(-) delete mode 100644 apps/infoalloggi/src/components/chat/chat-attachments.tsx delete mode 100644 apps/infoalloggi/src/components/chat/chat-bottombar.tsx delete mode 100644 apps/infoalloggi/src/components/chat/chat-bubble.tsx delete mode 100644 apps/infoalloggi/src/components/chat/chat-list.tsx delete mode 100644 apps/infoalloggi/src/components/chat/chat-message-list.tsx delete mode 100644 apps/infoalloggi/src/components/chat/chat-sidebar.tsx delete mode 100644 apps/infoalloggi/src/components/chat/chat-topbar.tsx delete mode 100644 apps/infoalloggi/src/components/chat/chat.tsx delete mode 100644 apps/infoalloggi/src/components/chat/message-loading.tsx diff --git a/apps/infoalloggi/src/components/chat/chat-attachments.tsx b/apps/infoalloggi/src/components/chat/chat-attachments.tsx deleted file mode 100644 index cc65b4d..0000000 --- a/apps/infoalloggi/src/components/chat/chat-attachments.tsx +++ /dev/null @@ -1,196 +0,0 @@ -"use client"; -import { differenceInDays, differenceInMinutes, format } from "date-fns"; -import { Paperclip } from "lucide-react"; -import Link from "next/link"; -import { ExtIcon } from "~/components/area-riservata/allegati"; -import { - Credenza, - CredenzaBody, - CredenzaClose, - CredenzaContent, - CredenzaDescription, - CredenzaFooter, - CredenzaHeader, - CredenzaTitle, - CredenzaTrigger, -} from "~/components/custom_ui/credenza"; -import { LoadingPage } from "~/components/loading"; -import { Button, buttonVariants } from "~/components/ui/button"; -import { UploadComponent } from "~/components/upload_modal"; -import { cn } from "~/lib/utils"; -import { useTranslation } from "~/providers/I18nProvider"; -import type { Session } from "~/server/api/trpc"; -import type { ChatUserInfo } from "~/server/services/chat.service"; -import { api } from "~/utils/api"; - -type ChatAttachmentsProps = { - userData: Session; - chatUserData: ChatUserInfo; -}; -export const ChatAttachments = ({ - userData, - chatUserData, -}: ChatAttachmentsProps) => { - const { t } = useTranslation(); - const { - data: attachments, - isLoading: attachmentsLoading, - refetch, - } = api.storage.retrieveUserFileData.useQuery( - { userId: chatUserData.id }, - { refetchOnMount: true }, - ); - - return ( - o && refetch()}> - - - - - - Allegati - - Chat Attachments - - - - - -
- {attachmentsLoading ? ( - - ) : ( - <> - {!attachments || attachments.length === 0 ? ( -
-

- {t.allegati.nessun_allegato} -

-
- ) : ( -
    -

    - {t.allegati.allegati_recenti} -

    - {attachments?.map((file, idx) => { - if (idx >= 3) return null; - - return ( -
  • - idx - }`} - > - console.log("touching")} - target="_blank" - > - - - - {TimeSince(new Date(file.uploadedAt))} - -
  • - ); - })} -
- )} - - )} -
- - {t.allegati.i_tuoi_allegati} - {attachments && attachments.length > 0 && ( - - {attachments.length} - - )} - -
- - - - - -
-
- ); -}; - -const TimeSince = (date: Date) => { - const minsSince = Math.abs(differenceInMinutes(date, new Date())); - const daysSince = Math.abs(differenceInDays(date, new Date())); - - const relevantMinsIncrements = [1, 3, 5, 10, 15, 30, 60, 120]; - - if (daysSince === 0) { - if (minsSince < 1) { - return "ora"; - } - - const closestToNow = relevantMinsIncrements.reduce((prev, curr) => { - return Math.abs(curr - minsSince) < Math.abs(prev - minsSince) - ? curr - : prev; - }); - - if (closestToNow === 60) { - return "~1 ora fa"; - } - - if (closestToNow === 120 && minsSince < 121) { - return "~2 ore fa"; - } - - return `~${closestToNow} min fa`; - } - - if (daysSince === 1) { - return "ieri"; - } - - if (daysSince < 30) { - return `${daysSince} giorni fa`; - } - - return format(date, "dd/MM/yyyy"); -}; diff --git a/apps/infoalloggi/src/components/chat/chat-bottombar.tsx b/apps/infoalloggi/src/components/chat/chat-bottombar.tsx deleted file mode 100644 index 8fbe306..0000000 --- a/apps/infoalloggi/src/components/chat/chat-bottombar.tsx +++ /dev/null @@ -1,171 +0,0 @@ -"use client"; - -import { SendHorizontal, SmilePlusIcon, ThumbsUp } from "lucide-react"; -import { - type ChangeEvent, - useCallback, - useEffect, - useRef, - useState, -} from "react"; -import { ChatAttachments } from "~/components/chat/chat-attachments"; -import { - type AutosizeTextAreaRef, - AutosizeTextarea, -} from "~/components/custom_ui/autoResizeTextArea"; -import { - EmojiPicker, - EmojiPickerContent, - EmojiPickerSearch, -} from "~/components/custom_ui/emoji-picker"; -import { Button } from "~/components/ui/button"; -import { - Popover, - PopoverContent, - PopoverTrigger, -} from "~/components/ui/popover"; -import { useThrottledIsTypingMutation } from "~/hooks/chatHooks"; -import { useMediaQuery } from "~/hooks/use-media-query"; -import { useTranslation } from "~/providers/I18nProvider"; -import type { ChatsChatid } from "~/schemas/public/Chats"; -import type { Session } from "~/server/api/trpc"; -import type { ChatUserInfo } from "~/server/services/chat.service"; -import { api } from "~/utils/api"; - -type ChatBottombarProps = { - chatId: ChatsChatid; - userData: Session; - chatUserData: ChatUserInfo; -}; - -export default function ChatBottombar({ - chatId, - userData, - chatUserData, -}: ChatBottombarProps) { - const { locale } = useTranslation(); - const [message, setMessage] = useState(""); - const [isFocused, setIsFocused] = useState(false); - const inputRef = useRef(null); - - const { mutate: addMutation } = api.messagesSSE.add.useMutation({}); - - const handleThumbsUp = useCallback(() => { - addMutation({ - chatId, - message: "👍", - sender: userData.id, - }); - setMessage(""); - }, [chatId, addMutation, userData]); - - const handleSend = () => { - if (message.length !== 0) { - addMutation({ - chatId, - message: message.trim(), - sender: userData.id, - }); - - setMessage(""); - - if (inputRef.current) { - inputRef.current.textArea.focus(); - inputRef.current.textArea.style.height = "auto"; - } - } - }; - const isTypingMutation = useThrottledIsTypingMutation({ - chatId, - username: userData.username, - }); - - useEffect(() => { - // update isTyping state - isTypingMutation(isFocused && message.trim().length > 0); - }, [isFocused, message, isTypingMutation]); - - useEffect(() => { - if (inputRef.current) { - inputRef.current.textArea.focus(); - } - }, []); - const [openEmoji, setOpenEmoji] = useState(false); - - const isMobile = useMediaQuery("(min-width: 426px)"); - return ( -
-
- -
-
- setIsFocused(false)} - onChange={(e: ChangeEvent) => { - setMessage(e.target.value); - }} - onFocus={() => setIsFocused(true)} - onKeyDown={(e) => { - if (e.key === "Enter") { - e.preventDefault(); - if (e.shiftKey) { - setMessage((prev) => `${prev}\n`); - } else { - handleSend(); - } - } - }} - placeholder="Aa" - ref={inputRef} - value={message} - /> - {isMobile && ( -
- - - - - - { - setMessage(message + emoji); - // if (inputRef.current) { - // inputRef.current.textArea.focus(); - // } - }} - > - - - - - -
- )} -
- -
- ); -} diff --git a/apps/infoalloggi/src/components/chat/chat-bubble.tsx b/apps/infoalloggi/src/components/chat/chat-bubble.tsx deleted file mode 100644 index 062817b..0000000 --- a/apps/infoalloggi/src/components/chat/chat-bubble.tsx +++ /dev/null @@ -1,198 +0,0 @@ -import { cva, type VariantProps } from "class-variance-authority"; -import { Check, CheckCheck } from "lucide-react"; -import * as React from "react"; -import MessageLoading from "~/components/chat/message-loading"; -import { Button, type ButtonProps } from "~/components/ui/button"; -import { cn } from "~/lib/utils"; - -// ChatBubble -const chatBubbleVariant = cva( - "flex gap-2 max-w-[60%] items-end relative group", - { - defaultVariants: { - layout: "default", - variant: "received", - }, - variants: { - layout: { - ai: "max-w-full w-full items-center", - default: "", - }, - variant: { - received: "self-start", - sent: "self-end flex-row-reverse", - }, - }, - }, -); - -interface ChatBubbleProps - extends React.HTMLAttributes, - VariantProps {} - -const ChatBubble = React.forwardRef( - ({ className, variant, layout, children, ...props }, ref) => ( -
- {React.Children.map(children, (child) => - React.isValidElement(child) && typeof child.type !== "string" - ? React.cloneElement(child, { - layout, - variant, - } as Partial>) - : child, - )} -
- ), -); -ChatBubble.displayName = "ChatBubble"; - -type ChatBubbleReadStatusProps = { - isread: boolean; -}; - -export const ChatBubbleReadStatus = ({ isread }: ChatBubbleReadStatusProps) => { - if (isread) { - return ; - } - return ; -}; - -// ChatBubbleMessage -const chatBubbleMessageVariants = cva("p-2", { - defaultVariants: { - layout: "default", - variant: "received", - }, - variants: { - layout: { - ai: "border-t w-full rounded-none bg-transparent", - default: "", - }, - variant: { - received: - "bg-secondary text-secondary-foreground rounded-r-lg rounded-tl-lg", - sent: "bg-primary text-primary-foreground rounded-l-lg rounded-tr-lg", - }, - }, -}); - -interface ChatBubbleMessageProps - extends React.HTMLAttributes, - VariantProps { - isLoading?: boolean; -} - -const ChatBubbleMessage = React.forwardRef< - HTMLDivElement, - ChatBubbleMessageProps ->( - ( - { className, variant, layout, isLoading = false, children, ...props }, - ref, - ) => ( -
- {isLoading ? ( -
- -
- ) : ( - children - )} -
- ), -); -ChatBubbleMessage.displayName = "ChatBubbleMessage"; - -// ChatBubbleTimestamp -interface ChatBubbleTimestampProps - extends React.HTMLAttributes { - timestamp: string; -} - -const ChatBubbleTimestamp: React.FC = ({ - timestamp, - className, - ...props -}) => ( -
- {timestamp} -
-); - -// ChatBubbleAction -type ChatBubbleActionProps = ButtonProps & { - icon: React.ReactNode; -}; - -const ChatBubbleAction: React.FC = ({ - icon, - onClick, - className, - variant = "ghost", - size = "icon", - ...props -}) => ( - -); - -interface ChatBubbleActionWrapperProps - extends React.HTMLAttributes { - variant?: "sent" | "received"; - className?: string; - show: boolean; -} - -const ChatBubbleActionWrapper = React.forwardRef< - HTMLDivElement, - ChatBubbleActionWrapperProps ->(({ variant, className, show, children, ...props }, ref) => ( - <> - {show && ( -
- {children} -
- )} - -)); -ChatBubbleActionWrapper.displayName = "ChatBubbleActionWrapper"; - -export { - ChatBubble, - ChatBubbleMessage, - ChatBubbleTimestamp, - ChatBubbleAction, - ChatBubbleActionWrapper, -}; diff --git a/apps/infoalloggi/src/components/chat/chat-list.tsx b/apps/infoalloggi/src/components/chat/chat-list.tsx deleted file mode 100644 index 4f72988..0000000 --- a/apps/infoalloggi/src/components/chat/chat-list.tsx +++ /dev/null @@ -1,439 +0,0 @@ -"use client"; - -import { AnimatePresence, motion } from "framer-motion"; -import { Pencil, Trash2 } from "lucide-react"; -import { - type FormEvent, - useCallback, - useEffect, - useRef, - useState, -} from "react"; -import toast from "react-hot-toast"; -import { - ChatBubble, - ChatBubbleAction, - ChatBubbleActionWrapper, - ChatBubbleMessage, - ChatBubbleReadStatus, - ChatBubbleTimestamp, -} from "~/components/chat/chat-bubble"; -import { ChatMessageList } from "~/components/chat/chat-message-list"; -import LoadingButton from "~/components/custom_ui/loading-button"; -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, -} from "~/components/ui/alert-dialog"; -import { Button } from "~/components/ui/button"; -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, -} from "~/components/ui/dialog"; -import Input from "~/components/ui/input"; -import { getUserColor, UserAvatar } from "~/components/user_avatar"; -import type { LiveChat } from "~/hooks/chatHooks"; -import { cn } from "~/lib/utils"; -import { useTranslation } from "~/providers/I18nProvider"; -import type { ChatsChatid } from "~/schemas/public/Chats"; -import type { MessagesMessageid } from "~/schemas/public/Messages"; -import type { UsersId } from "~/schemas/public/Users"; -import type { Session } from "~/server/api/trpc"; -import type { ChatMessage } from "~/server/services/messages.service"; -import type { WhoIsTyping } from "~/server/sse"; -import { api } from "~/utils/api"; - -type ChatListProps = { - chatId: ChatsChatid; - messages: ChatMessage[]; - userData: Session; - query: LiveChat["query"]; - typingStatus: WhoIsTyping[]; -}; - -export const ChatList = ({ - chatId, - messages, - userData, - query, - typingStatus, -}: ChatListProps) => { - const messagesContainerRef = useRef(null); - const [editModalOpen, setEditModalOpen] = useState(false); - const [msgSelected, setMsgSelected] = useState(null); - const [deleteModalOpen, setDeleteModalOpen] = useState(false); - - const handleEditOpen = (status: boolean) => { - setEditModalOpen(status); - }; - const handleDeleteOpen = (status: boolean) => { - setDeleteModalOpen(status); - }; - - const { mutate: deleteMutation } = api.messagesSSE.delete.useMutation({ - onError: () => { - toast.error("Error deleting message", { id: "deleteMessage" }); - }, - onMutate: () => { - toast("Deleting message...", { icon: "🗑️", id: "deleteMessage" }); - }, - onSuccess: () => { - toast("Message deleted", { icon: "🗑️", id: "deleteMessage" }); - }, - }); - const { mutate: editMutation } = api.messagesSSE.edit.useMutation({ - onError: () => { - toast.error("Error editing message", { id: "editMessage" }); - }, - onMutate: () => { - toast("Editing message...", { icon: "📝", id: "editMessage" }); - }, - onSuccess: () => { - toast("Message edited", { icon: "📝", id: "editMessage" }); - }, - }); - - const handleEditSubmit = useCallback( - (e: FormEvent) => { - e.preventDefault(); - const form = e.currentTarget; - const formData = new FormData(form); - if (!formData.get("message-edit") || !formData.get("message-id")) { - return; - } - editMutation({ - chatId, - message: formData.get("message-edit") as string, - messageId: formData.get("message-id") as MessagesMessageid, - }); - setEditModalOpen(false); - }, - [editMutation], - ); - const [locked, setLocked] = useState(false); - - useEffect(() => { - if ( - messagesContainerRef.current && - !locked && - !query.isLoading && - !query.isFetching - ) { - messagesContainerRef.current.scrollTop = - messagesContainerRef.current.scrollHeight; - } - setLocked(false); - }, [messages, typingStatus]); - - return ( -
- - - {query.hasNextPage && ( - { - setLocked(true); - await query.fetchNextPage(); - }} - variant="secondary" - > - {query.isFetchingNextPage - ? "Caricamento..." - : "Carica messaggi precedenti"} - - )} - - {messages.map((message, index) => { - const variant = getMessageVariant(message.sender, userData.id); - - const isNextSameSender = - index + 1 < messages.length && - messages[index + 1]?.sender === message.sender; - - const isPreviousSameSender = - index - 1 >= 0 && messages[index - 1]?.sender === message.sender; - - const isPrevSameDay = - index - 1 >= 0 && - // biome-ignore lint/style/noNonNullAssertion: - new Date(messages[index - 1]!.time).toDateString() === - new Date(message.time).toDateString(); - - return ( - - {!isPrevSameDay && ( - - {new Date(message.time).toLocaleDateString("it", { - day: "2-digit", - month: "2-digit", - year: "2-digit", - })} - - )} - - {isNextSameSender ? ( -
- ) : ( - - )} - -
- {!isPreviousSameSender && ( -

- {message.sender_nome} -

- )} - - {message.message} -
- {userData.id === message.sender && ( - - )} - {message.time && ( - - )} -
-
-
- - } - key={"delete"} - onClick={() => { - setMsgSelected(message); - handleDeleteOpen(true); - }} - /> - } - key={"edit"} - onClick={() => { - setMsgSelected(message); - handleEditOpen(true); - }} - /> - -
-
- ); - })} - - -
-
- - { - deleteMutation({ chatId, messageId }); - }} - msgDelete={msgSelected} - onOpenChange={handleDeleteOpen} - open={deleteModalOpen} - /> -
- ); -}; - -const Typers = ({ - currentTypers, - messageLenght, - userId, -}: { - currentTypers: WhoIsTyping[]; - messageLenght: number; - userId: UsersId; -}) => { - return ( - <> - {currentTypers.map((typer) => { - if (typer.userId === userId) return null; - const variant = "received"; - - return ( - - - - - - - - ); - })} - - ); -}; - -const EditMessageDialog = ({ - open, - onOpenChange, - msgEdit, - handleEditSubmit, -}: { - open: boolean; - onOpenChange: (status: boolean) => void; - msgEdit: ChatMessage | null; - handleEditSubmit: (e: FormEvent) => void; -}) => { - const { t } = useTranslation(); - return ( - - - - {t.modifica} - Edit - - {msgEdit && ( -
-
- - - - - -
-
- )} -
-
- ); -}; - -const DeleteMessageDialog = ({ - open, - onOpenChange, - msgDelete, - handleDeleteSubmit, -}: { - open: boolean; - onOpenChange: (status: boolean) => void; - msgDelete: ChatMessage | null; - handleDeleteSubmit: (msgId: MessagesMessageid) => void; -}) => { - const { t } = useTranslation(); - return ( - <> - {msgDelete && ( - - - - Vuoi eliminare il messaggio? - - Questa azione non può essere annullata. - - - - {t.annulla} - handleDeleteSubmit(msgDelete.messageid)} - > - {t.procedi} - - - - - )} - - ); -}; - -const getMessageVariant = (messageName: string, selectedUserName: string) => - messageName !== selectedUserName ? "received" : "sent"; diff --git a/apps/infoalloggi/src/components/chat/chat-message-list.tsx b/apps/infoalloggi/src/components/chat/chat-message-list.tsx deleted file mode 100644 index 41d30c1..0000000 --- a/apps/infoalloggi/src/components/chat/chat-message-list.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { forwardRef, type HTMLAttributes } from "react"; -import { cn } from "~/lib/utils"; - -type ChatMessageListProps = HTMLAttributes; - -const ChatMessageList = forwardRef( - ({ className, children, ...props }, ref) => ( -
- {children} -
- ), -); - -ChatMessageList.displayName = "ChatMessageList"; - -export { ChatMessageList }; diff --git a/apps/infoalloggi/src/components/chat/chat-sidebar.tsx b/apps/infoalloggi/src/components/chat/chat-sidebar.tsx deleted file mode 100644 index 86ba677..0000000 --- a/apps/infoalloggi/src/components/chat/chat-sidebar.tsx +++ /dev/null @@ -1,447 +0,0 @@ -import { 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 { ActiveChatsType } from "~/server/controllers/chat.controller"; -import type { NonNullableUser } from "~/server/controllers/user.controller"; -import { api } from "~/utils/api"; - -type LastMessage = { - message: string | null; - time: Date; - isLastSender: boolean; -}; - -export const ChatSidebar = ({ chatId }: { chatId: ChatsChatid | null }) => { - const { data: activeChats, isLoading: loadingActiveChats } = - api.chat.getActiveChats.useQuery(undefined, { - refetchInterval: 5000, // Refetch every 5 seconds, Good enough for a chat sidebar - 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 utils = api.useUtils(); - const { mutate: deletechat } = api.chat.deleteChat.useMutation({ - onSuccess: async () => { - await utils.chat.getActiveChats.invalidate(); - await utils.users.getActiveUsersWithoutChat.invalidate(); - }, - }); - - const getVariant = (lastmessage: LastMessage | null) => { - if (lastmessage) { - return lastmessage.isLastSender ? "secondary" : "grey"; - } - return "grey"; - }; - const getLastMessage = (lastmessage: LastMessage | null) => { - if (lastmessage) { - return `${lastmessage.isLastSender ? "Tu: " : ""}${lastmessage.message}`; - } - return ""; - }; - - 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.id); - }} - > - - - - - - {chat.userinfo.username} - - - - - ))} - - - - ); -}; - -const NewUserComponent = ({ - isOpen, - OpenChange, - inactiveUsers, -}: { - isOpen: boolean; - OpenChange: (status: boolean) => void; - inactiveUsers: NonNullableUser[]; -}) => { - const utils = api.useUtils(); - const { mutate: createNewChat } = api.chatSSE.create.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 - - - - - - ); -}; diff --git a/apps/infoalloggi/src/components/chat/chat-topbar.tsx b/apps/infoalloggi/src/components/chat/chat-topbar.tsx deleted file mode 100644 index 1aad0d9..0000000 --- a/apps/infoalloggi/src/components/chat/chat-topbar.tsx +++ /dev/null @@ -1,268 +0,0 @@ -"use client"; -import { - Info, - Paperclip, - ShieldUser, - ShoppingBag, - User, - UserCog, -} from "lucide-react"; -import Image from "next/image"; -import Link from "next/link"; -import { useRouter } from "next/router"; -import { useCallback } from "react"; -import toast from "react-hot-toast"; -import { EtichetteDisplayer } from "~/components/etichette"; -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, - AlertDialogTrigger, -} from "~/components/ui/alert-dialog"; -import { Button, buttonVariants } from "~/components/ui/button"; -import { - Popover, - PopoverContent, - PopoverTrigger, -} from "~/components/ui/popover"; -import { Separator } from "~/components/ui/separator"; -import { - Tooltip, - TooltipContent, - TooltipProvider, - TooltipTrigger, -} from "~/components/ui/tooltip"; -import { UserAvatar } from "~/components/user_avatar"; -import { cn } from "~/lib/utils"; -import type { ChatsChatid } from "~/schemas/public/Chats"; -import type { Session } from "~/server/api/trpc"; -import type { ChatUserInfo } from "~/server/services/chat.service"; -import type { OnlineStatus } from "~/server/sse"; -import { api } from "~/utils/api"; - -type ChatTopbarProps = { - chatId: ChatsChatid; - userData: Session; - chatUserData: ChatUserInfo; - onlineStatus: OnlineStatus[]; -}; -export default function ChatTopbar({ - chatId, - userData, - chatUserData, - onlineStatus, -}: ChatTopbarProps) { - const utils = api.useUtils(); - const { mutate: deletechat } = api.chat.deleteChat.useMutation({ - onSuccess: async () => { - await utils.chat.getActiveChats.invalidate(); - await utils.users.getActiveUsersWithoutChat.invalidate(); - await router.push("/area-riservata/admin/chats/"); - }, - }); - - const router = useRouter(); - const { mutate: swap } = api.auth.swapUser.useMutation({ - onSuccess: async () => { - toast.success("Utente cambiato con successo"); - await router.push("/area-riservata/load-page"); - }, - }); - - const handleDeleteChat = useCallback(() => { - deletechat({ chatId }); - }, [chatId, deletechat]); - - const handleSwapUser = useCallback(() => { - swap({ id: chatUserData.id }); - }, [chatUserData, swap]); - - return ( -
-
- {!userData.isAdmin ? ( - Infoalloggi logo - ) : ( - - )} -
-
- - {!userData.isAdmin ? "Chat Infoalloggi" : chatUserData.username} - - {userData.isAdmin && } -
-
- -
-
-
- -
- {userData.isAdmin && ( - - )} -
-
- ); -} - -const UserStatus = ({ - onlineStatus, - userData, -}: { - onlineStatus: OnlineStatus[]; - userData: Session; -}) => ( -
- {onlineStatus.map((user, idx) => - user.isAdmin ? ( - - - - - - - {user.nome} - {idx < onlineStatus.length - 1 && ","} - - - - -

Admin Infoalloggi

-
-
-
- ) : ( - - - {user.nome} - {!userData.isAdmin && " (Tu)"} - {idx < onlineStatus.length - 1 && ", "} - - - ), - )} -
-); - -const AdminPopover = ({ - chatUserData, - handleSwapUser, - handleDeleteChat, -}: { - chatUserData: ChatUserInfo; - handleSwapUser: () => void; - handleDeleteChat: () => void; -}) => ( - - - - - -
- - Profilo - - - - Ordini - - - Allegati - - - - - - - - - - Sei assolutamente sicuro? - - Questa azione non può essere annullata. Questo eliminerà - definitivamente la chat e rimuoverà i dati dai nostri server. - - - - Annulla - - Continua - - - - -
-
-
-); diff --git a/apps/infoalloggi/src/components/chat/chat.tsx b/apps/infoalloggi/src/components/chat/chat.tsx deleted file mode 100644 index ad88537..0000000 --- a/apps/infoalloggi/src/components/chat/chat.tsx +++ /dev/null @@ -1,53 +0,0 @@ -"use client"; - -import { memo } from "react"; -import ChatBottombar from "~/components/chat/chat-bottombar"; -import { ChatList } from "~/components/chat/chat-list"; -import ChatTopbar from "~/components/chat/chat-topbar"; -import { useLiveChat } from "~/hooks/chatHooks"; -import type { ChatsChatid } from "~/schemas/public/Chats"; -import type { Session } from "~/server/api/trpc"; -import { api } from "~/utils/api"; - -const Chat = memo( - ({ chatId, userData }: { chatId: ChatsChatid; userData: Session }) => { - const liveChat = useLiveChat(chatId, userData); - const [userinfo] = api.chat.getUserInfosByChat.useSuspenseQuery({ - chatId, - }); - - return ( -
-
- -
- - -
- -
-
- ); - }, - (prevProps, nextProps) => - prevProps.chatId === nextProps.chatId && - prevProps.userData.id === nextProps.userData.id, -); -Chat.displayName = "Chat"; - -export default Chat; diff --git a/apps/infoalloggi/src/components/chat/message-loading.tsx b/apps/infoalloggi/src/components/chat/message-loading.tsx deleted file mode 100644 index ed52f00..0000000 --- a/apps/infoalloggi/src/components/chat/message-loading.tsx +++ /dev/null @@ -1,46 +0,0 @@ -// @hidden -export default function MessageLoading() { - return ( - - Loading - - - - - - - - - - - ); -}