forked from sqlchat/sqlchat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateConversationModal.tsx
More file actions
98 lines (92 loc) · 3.19 KB
/
UpdateConversationModal.tsx
File metadata and controls
98 lines (92 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { useState } from "react";
import { toast } from "react-hot-toast";
import { useTranslation } from "react-i18next";
import { assistantList, useConversationStore } from "@/store";
import { Conversation } from "@/types";
import TextField from "./kit/TextField";
import Modal from "./kit/Modal";
import Select from "./kit/Select";
import Icon from "./Icon";
import BetaBadge from "./BetaBadge";
interface Props {
conversation: Conversation;
close: () => void;
}
const UpdateConversationModal = (props: Props) => {
const { close, conversation } = props;
const { t } = useTranslation();
const conversationStore = useConversationStore();
const [title, setTitle] = useState(conversation.title);
const [assistantId, setAssistantId] = useState(conversation.assistantId);
const allowSave = title !== "";
const assistantItems = assistantList.map((assistant) => {
return {
value: assistant.id,
label: assistant.name,
};
});
const currentAssistant = assistantList.find(
(assistant) => assistant.id === assistantId
);
const handleSaveEdit = () => {
const formatedTitle = title.trim();
if (formatedTitle === "") {
return;
}
conversationStore.updateConversation(conversation.id, {
title: formatedTitle,
assistantId: assistantId,
});
toast.success("Conversation updated");
close();
};
return (
<Modal title={t("conversation.update")} onClose={close}>
<div className="w-full flex flex-col justify-start items-start mt-2">
<label className="block text-sm font-medium text-gray-700 mb-1">
{t("conversation.title")}
</label>
<TextField
placeholder={t("conversation.conversation-title") || ""}
value={title}
onChange={(value) => setTitle(value)}
/>
</div>
<div className="w-full flex flex-col justify-start items-start mt-2">
<label className="text-sm font-medium text-gray-700 mb-1 flex flex-row justify-start items-center">
{t("assistant.self")} <BetaBadge />
</label>
<Select
className="w-full"
value={assistantId}
itemList={assistantItems}
onValueChange={(value) => setAssistantId(value)}
/>
{currentAssistant && (
<div className="w-full flex flex-col justify-start items-start">
<p className="block text-sm text-gray-700 mt-2 mx-3">
{currentAssistant.description}
</p>
</div>
)}
<a
className="mt-1 mx-3 text-sm text-blue-600 underline hover:opacity-80"
href="https://github.com/sqlchat/sqlchat/tree/main/assistants"
target="_blank"
>
{t("assistant.create-your-bot")}{" "}
<Icon.FiExternalLink className="inline-block -mt-0.5" />
</a>
</div>
<div className="w-full flex flex-row justify-end items-center mt-4 space-x-2">
<button className="btn btn-outline" onClick={close}>
{t("common.close")}
</button>
<button className="btn" disabled={!allowSave} onClick={handleSaveEdit}>
{t("common.save")}
</button>
</div>
</Modal>
);
};
export default UpdateConversationModal;