From 83e4023c19455f88577ec23d5d1815c791cd132d Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Tue, 28 Jan 2025 04:50:28 +0530 Subject: [PATCH] (feat:settings/docs) confirm on delete --- frontend/src/locale/en.json | 3 +- frontend/src/locale/es.json | 3 +- frontend/src/locale/jp.json | 3 +- frontend/src/locale/ru.json | 3 +- frontend/src/locale/zh-TW.json | 3 +- frontend/src/locale/zh.json | 3 +- frontend/src/settings/Documents.tsx | 57 ++++++++++++++++++++++++----- frontend/src/upload/Upload.tsx | 6 +-- 8 files changed, 62 insertions(+), 19 deletions(-) diff --git a/frontend/src/locale/en.json b/frontend/src/locale/en.json index 2f6d2617..35058be0 100644 --- a/frontend/src/locale/en.json +++ b/frontend/src/locale/en.json @@ -71,7 +71,8 @@ "weekly": "Weekly", "monthly": "Monthly" }, - "actions": "Actions" + "actions": "Actions", + "deleteWarning": "Are you sure you want to delete \"{{name}}\"?" }, "apiKeys": { "label": "Chatbots", diff --git a/frontend/src/locale/es.json b/frontend/src/locale/es.json index 6437dead..d0b47874 100644 --- a/frontend/src/locale/es.json +++ b/frontend/src/locale/es.json @@ -71,7 +71,8 @@ "weekly": "Semanal", "monthly": "Mensual" }, - "actions": "Acciones" + "actions": "Acciones", + "deleteWarning": "¿Estás seguro de que deseas eliminar \"{{name}}\"?" }, "apiKeys": { "label": "Chatbots", diff --git a/frontend/src/locale/jp.json b/frontend/src/locale/jp.json index 199f83e8..2fdc2c61 100644 --- a/frontend/src/locale/jp.json +++ b/frontend/src/locale/jp.json @@ -70,7 +70,8 @@ "weekly": "毎週", "monthly": "毎月" }, - "actions": "アクション" + "actions": "アクション", + "deleteWarning": "\"{{name}}\"を削除してもよろしいですか?" }, "apiKeys": { "label": "チャットボット", diff --git a/frontend/src/locale/ru.json b/frontend/src/locale/ru.json index 3621aafc..087b8dfd 100644 --- a/frontend/src/locale/ru.json +++ b/frontend/src/locale/ru.json @@ -71,7 +71,8 @@ "weekly": "Еженедельно", "monthly": "Ежемесячно" }, - "actions": "Действия" + "actions": "Действия", + "deleteWarning": "Вы уверены, что хотите удалить \"{{name}}\"?" }, "apiKeys": { "label": "API ключи", diff --git a/frontend/src/locale/zh-TW.json b/frontend/src/locale/zh-TW.json index 8dbd550d..f2abf1e5 100644 --- a/frontend/src/locale/zh-TW.json +++ b/frontend/src/locale/zh-TW.json @@ -71,7 +71,8 @@ "weekly": "每週", "monthly": "每月" }, - "actions": "操作" + "actions": "操作", + "deleteWarning": "您確定要刪除 \"{{name}}\" 嗎?" }, "apiKeys": { "label": "聊天機器人", diff --git a/frontend/src/locale/zh.json b/frontend/src/locale/zh.json index 0e53a257..56c8fbb1 100644 --- a/frontend/src/locale/zh.json +++ b/frontend/src/locale/zh.json @@ -71,7 +71,8 @@ "weekly": "每周", "monthly": "每月" }, - "actions": "操作" + "actions": "操作", + "deleteWarning": "您确定要删除 \"{{name}}\" 吗?" }, "apiKeys": { "label": "聊天机器人", diff --git a/frontend/src/settings/Documents.tsx b/frontend/src/settings/Documents.tsx index a11b125f..88590165 100644 --- a/frontend/src/settings/Documents.tsx +++ b/frontend/src/settings/Documents.tsx @@ -16,6 +16,7 @@ import { getDocs, getDocsWithPagination } from '../preferences/preferenceApi'; import { setSourceDocs } from '../preferences/preferenceSlice'; import { setPaginatedDocuments } from '../preferences/preferenceSlice'; import { formatDate } from '../utils/dateTimeUtils'; +import ConfirmationModal from '../modals/ConfirmationModal'; // Utility function to format numbers const formatTokens = (tokens: number): string => { @@ -134,6 +135,26 @@ const Documents: React.FC = ({ }); }; + const [documentToDelete, setDocumentToDelete] = useState<{ + index: number; + document: Doc; + } | null>(null); + const [deleteModalState, setDeleteModalState] = + useState('INACTIVE'); + + const handleDeleteConfirmation = (index: number, document: Doc) => { + setDocumentToDelete({ index, document }); + setDeleteModalState('ACTIVE'); + }; + + const handleConfirmedDelete = () => { + if (documentToDelete) { + handleDeleteDocument(documentToDelete.index, documentToDelete.document); + setDeleteModalState('INACTIVE'); + setDocumentToDelete(null); + } + }; + useEffect(() => { refreshDocs(undefined, 1, rowsPerPage); }, [searchTerm]); @@ -182,10 +203,10 @@ const Documents: React.FC = ({
{' '} {/* Removed overflow-auto */} -
+
- + @@ -223,34 +244,34 @@ const Documents: React.FC = ({ - + {!currentDocuments?.length ? ( ) : ( currentDocuments.map((document, index) => ( - + - - -
{t('settings.documents.name')}
{t('settings.documents.noData')}
{document.name} + {document.date ? formatDate(document.date) : ''} + {document.tokens ? formatTokens(+document.tokens) : ''} +
{!document.syncFrequency && (
@@ -269,7 +290,7 @@ const Documents: React.FC = ({
); }; diff --git a/frontend/src/upload/Upload.tsx b/frontend/src/upload/Upload.tsx index 02aa2318..b1c45156 100644 --- a/frontend/src/upload/Upload.tsx +++ b/frontend/src/upload/Upload.tsx @@ -23,14 +23,14 @@ function Upload({ isOnboarding, renderTab = null, close, - onSuccessfulUpload, + onSuccessfulUpload = () => undefined, }: { receivedFile: File[]; setModalState: (state: ActiveState) => void; isOnboarding: boolean; renderTab: string | null; close: () => void; - onSuccessfulUpload: () => void; + onSuccessfulUpload?: () => void; }) { const [docName, setDocName] = useState(receivedFile[0]?.name); const [urlName, setUrlName] = useState(''); @@ -220,7 +220,7 @@ function Upload({ setfiles([]); setProgress(undefined); setModalState('INACTIVE'); - onSuccessfulUpload(); + onSuccessfulUpload?.(); } } else if (data.status == 'PROGRESS') { setProgress(