mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 08:33:20 +00:00
(feat:prompts) delete after confirmation
This commit is contained in:
@@ -245,7 +245,8 @@
|
||||
"promptName": "Prompt Name",
|
||||
"promptText": "Prompt Text",
|
||||
"save": "Save",
|
||||
"nameExists": "Name already exists"
|
||||
"nameExists": "Name already exists",
|
||||
"deleteConfirmation": "Are you sure you want to delete the prompt '{{name}}'?"
|
||||
},
|
||||
"chunk": {
|
||||
"add": "Add Chunk",
|
||||
|
||||
@@ -245,7 +245,8 @@
|
||||
"promptName": "Nombre del Prompt",
|
||||
"promptText": "Texto del Prompt",
|
||||
"save": "Guardar",
|
||||
"nameExists": "El nombre ya existe"
|
||||
"nameExists": "El nombre ya existe",
|
||||
"deleteConfirmation": "¿Estás seguro de que deseas eliminar el prompt '{{name}}'?"
|
||||
},
|
||||
"chunk": {
|
||||
"add": "Agregar Fragmento",
|
||||
|
||||
@@ -245,7 +245,8 @@
|
||||
"promptName": "プロンプト名",
|
||||
"promptText": "プロンプトテキスト",
|
||||
"save": "保存",
|
||||
"nameExists": "名前が既に存在します"
|
||||
"nameExists": "名前が既に存在します",
|
||||
"deleteConfirmation": "プロンプト「{{name}}」を削除してもよろしいですか?"
|
||||
},
|
||||
"chunk": {
|
||||
"add": "チャンクを追加",
|
||||
|
||||
@@ -245,7 +245,8 @@
|
||||
"promptName": "Название подсказки",
|
||||
"promptText": "Текст подсказки",
|
||||
"save": "Сохранить",
|
||||
"nameExists": "Название уже существует"
|
||||
"nameExists": "Название уже существует",
|
||||
"deleteConfirmation": "Вы уверены, что хотите удалить подсказку «{{name}}»?"
|
||||
},
|
||||
"chunk": {
|
||||
"add": "Добавить фрагмент",
|
||||
|
||||
@@ -245,7 +245,8 @@
|
||||
"promptName": "提示名稱",
|
||||
"promptText": "提示文字",
|
||||
"save": "儲存",
|
||||
"nameExists": "名稱已存在"
|
||||
"nameExists": "名稱已存在",
|
||||
"deleteConfirmation": "您確定要刪除提示「{{name}}」嗎?"
|
||||
},
|
||||
"chunk": {
|
||||
"add": "新增區塊",
|
||||
|
||||
@@ -245,7 +245,8 @@
|
||||
"promptName": "提示名称",
|
||||
"promptText": "提示文本",
|
||||
"save": "保存",
|
||||
"nameExists": "名称已存在"
|
||||
"nameExists": "名称已存在",
|
||||
"deleteConfirmation": "您确定要删除提示'{{name}}'吗?"
|
||||
},
|
||||
"chunk": {
|
||||
"add": "添加块",
|
||||
|
||||
@@ -7,6 +7,7 @@ import Dropdown from '../components/Dropdown';
|
||||
import { ActiveState, PromptProps } from '../models/misc';
|
||||
import { selectToken } from '../preferences/preferenceSlice';
|
||||
import PromptsModal from '../preferences/PromptsModal';
|
||||
import ConfirmationModal from '../modals/ConfirmationModal';
|
||||
|
||||
export default function Prompts({
|
||||
prompts,
|
||||
@@ -40,6 +41,11 @@ export default function Prompts({
|
||||
const [modalState, setModalState] = React.useState<ActiveState>('INACTIVE');
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [promptToDelete, setPromptToDelete] = React.useState<{
|
||||
id: string;
|
||||
name: string;
|
||||
} | null>(null);
|
||||
|
||||
const handleAddPrompt = async () => {
|
||||
try {
|
||||
const response = await userService.createPrompt(
|
||||
@@ -69,20 +75,37 @@ export default function Prompts({
|
||||
};
|
||||
|
||||
const handleDeletePrompt = (id: string) => {
|
||||
setPrompts(prompts.filter((prompt) => prompt.id !== id));
|
||||
userService
|
||||
.deletePrompt({ id }, token)
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete prompt');
|
||||
}
|
||||
if (prompts.length > 0) {
|
||||
onSelectPrompt(prompts[0].name, prompts[0].id, prompts[0].type);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
const promptToRemove = prompts.find((prompt) => prompt.id === id);
|
||||
if (promptToRemove) {
|
||||
setPromptToDelete({ id, name: promptToRemove.name });
|
||||
}
|
||||
};
|
||||
|
||||
const confirmDeletePrompt = () => {
|
||||
if (promptToDelete) {
|
||||
setPrompts(prompts.filter((prompt) => prompt.id !== promptToDelete.id));
|
||||
userService
|
||||
.deletePrompt({ id: promptToDelete.id }, token)
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete prompt');
|
||||
}
|
||||
if (prompts.length > 0) {
|
||||
const firstPrompt = prompts.find((p) => p.id !== promptToDelete.id);
|
||||
if (firstPrompt) {
|
||||
onSelectPrompt(
|
||||
firstPrompt.name,
|
||||
firstPrompt.id,
|
||||
firstPrompt.type,
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
setPromptToDelete(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleFetchPromptContent = async (id: string) => {
|
||||
@@ -202,6 +225,19 @@ export default function Prompts({
|
||||
handleAddPrompt={handleAddPrompt}
|
||||
handleEditPrompt={handleSaveChanges}
|
||||
/>
|
||||
{promptToDelete && (
|
||||
<ConfirmationModal
|
||||
message={t('modals.prompts.deleteConfirmation', {
|
||||
name: promptToDelete.name,
|
||||
})}
|
||||
modalState="ACTIVE"
|
||||
setModalState={() => setPromptToDelete(null)}
|
||||
submitLabel={t('modals.deleteConv.delete')}
|
||||
handleSubmit={confirmDeletePrompt}
|
||||
handleCancel={() => setPromptToDelete(null)}
|
||||
variant="danger"
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user