(props: Props)
| 15 | } |
| 16 | |
| 17 | const UpdateConversationModal = (props: Props) => { |
| 18 | const { close, conversation } = props; |
| 19 | const { t } = useTranslation(); |
| 20 | const conversationStore = useConversationStore(); |
| 21 | const [title, setTitle] = useState(conversation.title); |
| 22 | const [assistantId, setAssistantId] = useState(conversation.assistantId); |
| 23 | const allowSave = title !== ""; |
| 24 | const assistantItems = assistantList.map((assistant) => { |
| 25 | return { |
| 26 | value: assistant.id, |
| 27 | label: assistant.name, |
| 28 | }; |
| 29 | }); |
| 30 | const currentAssistant = assistantList.find((assistant) => assistant.id === assistantId); |
| 31 | |
| 32 | const handleSaveEdit = () => { |
| 33 | const formatedTitle = title.trim(); |
| 34 | if (formatedTitle === "") { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | conversationStore.updateConversation(conversation.id, { |
| 39 | title: formatedTitle, |
| 40 | assistantId: assistantId, |
| 41 | }); |
| 42 | toast.success("Conversation updated"); |
| 43 | close(); |
| 44 | }; |
| 45 | |
| 46 | return ( |
| 47 | <Modal title={t("conversation.update")} onClose={close}> |
| 48 | <div className="w-full flex flex-col justify-start items-start mt-2"> |
| 49 | <label className="block text-sm font-medium text-gray-700 mb-1">{t("conversation.title")}</label> |
| 50 | <TextField placeholder={t("conversation.conversation-title") || ""} value={title} onChange={(value) => setTitle(value)} /> |
| 51 | </div> |
| 52 | <div className="w-full flex flex-col justify-start items-start mt-2"> |
| 53 | <label className="text-sm font-medium text-gray-700 mb-1 flex flex-row justify-start items-center"> |
| 54 | {t("assistant.self")} <BetaBadge /> |
| 55 | </label> |
| 56 | <Select className="w-full" value={assistantId} itemList={assistantItems} onValueChange={(value) => setAssistantId(value)} /> |
| 57 | {currentAssistant && ( |
| 58 | <div className="w-full flex flex-col justify-start items-start"> |
| 59 | <p className="block text-sm text-gray-700 mt-2 mx-3">{currentAssistant.description}</p> |
| 60 | </div> |
| 61 | )} |
| 62 | <a |
| 63 | className="mt-1 mx-3 text-sm text-blue-600 underline hover:opacity-80" |
| 64 | href="https://github.com/sqlchat/sqlchat/tree/main/assistants" |
| 65 | target="_blank" |
| 66 | > |
| 67 | {t("assistant.create-your-bot")} <Icon.FiExternalLink className="inline-block -mt-0.5" /> |
| 68 | </a> |
| 69 | </div> |
| 70 | <div className="w-full flex flex-row justify-end items-center mt-4 space-x-2"> |
| 71 | <button className="btn btn-outline" onClick={close}> |
| 72 | {t("common.close")} |
| 73 | </button> |
| 74 | <button className="btn" disabled={!allowSave} onClick={handleSaveEdit}> |
nothing calls this directly
no outgoing calls
no test coverage detected