import { SidebarCreateItem } from "@/components/sidebar/items/all/sidebar-create-item" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { ChatbotUIContext } from "@/context/context" import { COLLECTION_DESCRIPTION_MAX, COLLECTION_NAME_MAX } from "@/db/limits" import { TablesInsert } from "@/supabase/types" import { CollectionFile } from "@/types" import { FC, useContext, useState } from "react" import { CollectionFileSelect } from "./collection-file-select" interface CreateCollectionProps { isOpen: boolean onOpenChange: (isOpen: boolean) => void } export const CreateCollection: FC = ({ isOpen, onOpenChange }) => { const { profile, selectedWorkspace } = useContext(ChatbotUIContext) const [name, setName] = useState("") const [isTyping, setIsTyping] = useState(false) const [description, setDescription] = useState("") const [selectedCollectionFiles, setSelectedCollectionFiles] = useState< CollectionFile[] >([]) const handleFileSelect = (file: CollectionFile) => { setSelectedCollectionFiles(prevState => { const isFileAlreadySelected = prevState.find( selectedFile => selectedFile.id === file.id ) if (isFileAlreadySelected) { return prevState.filter(selectedFile => selectedFile.id !== file.id) } else { return [...prevState, file] } }) } if (!profile) return null if (!selectedWorkspace) return null return ( ({ user_id: profile.user_id, collection_id: "", file_id: file.id })), user_id: profile.user_id, name, description } as TablesInsert<"collections"> } isOpen={isOpen} isTyping={isTyping} onOpenChange={onOpenChange} renderInputs={() => ( <>
setName(e.target.value)} maxLength={COLLECTION_NAME_MAX} />
setDescription(e.target.value)} maxLength={COLLECTION_DESCRIPTION_MAX} />
)} /> ) }