From a8d371045b6bbd19f8aad7eaed8a31c13340af46 Mon Sep 17 00:00:00 2001 From: Prathamesh Gursal Date: Sun, 6 Oct 2024 11:40:58 +0530 Subject: [PATCH] updated the loader in settings --- frontend/src/settings/APIKeys.tsx | 78 +++++++++------- frontend/src/settings/Analytics.tsx | 14 +-- frontend/src/settings/Documents.tsx | 132 +++++++++++++++------------- 3 files changed, 124 insertions(+), 100 deletions(-) diff --git a/frontend/src/settings/APIKeys.tsx b/frontend/src/settings/APIKeys.tsx index 4517e647..e05f3a1f 100644 --- a/frontend/src/settings/APIKeys.tsx +++ b/frontend/src/settings/APIKeys.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import userService from '../api/services/userService'; @@ -6,6 +6,7 @@ import Trash from '../assets/trash.svg'; import CreateAPIKeyModal from '../modals/CreateAPIKeyModal'; import SaveAPIKeyModal from '../modals/SaveAPIKeyModal'; import { APIKeyData } from './types'; +import SkeletonLoader from '../utils/loader'; export default function APIKeys() { const { t } = useTranslation(); @@ -13,8 +14,10 @@ export default function APIKeys() { const [isSaveKeyModalOpen, setSaveKeyModal] = React.useState(false); const [newKey, setNewKey] = React.useState(''); const [apiKeys, setApiKeys] = React.useState([]); + const [loading, setLoading] = useState(true); const handleFetchKeys = async () => { + setLoading(true); try { const response = await userService.getAPIKeys(); if (!response.ok) { @@ -24,6 +27,8 @@ export default function APIKeys() { setApiKeys(apiKeys); } catch (error) { console.log(error); + } finally { + setLoading(false); } }; @@ -75,6 +80,7 @@ export default function APIKeys() { React.useEffect(() => { handleFetchKeys(); }, []); + return (
@@ -100,41 +106,45 @@ export default function APIKeys() { )}
- - - - - - - - - - - {!apiKeys?.length && ( + {loading ? ( + + ) : ( +
{t('settings.apiKeys.name')}{t('settings.apiKeys.sourceDoc')}{t('settings.apiKeys.key')}
+ - + + + + - )} - {apiKeys?.map((element, index) => ( - - - - - - - ))} - -
- {t('settings.apiKeys.noData')} - {t('settings.apiKeys.name')}{t('settings.apiKeys.sourceDoc')}{t('settings.apiKeys.key')}
{element.name}{element.source}{element.key} - Delete handleDeleteKey(element.id)} - /> -
+ + + {!apiKeys?.length && ( + + + {t('settings.apiKeys.noData')} + + + )} + {apiKeys?.map((element, index) => ( + + {element.name} + {element.source} + {element.key} + + Delete handleDeleteKey(element.id)} + /> + + + ))} + + + )}
diff --git a/frontend/src/settings/Analytics.tsx b/frontend/src/settings/Analytics.tsx index 2d22ab33..b736f6ad 100644 --- a/frontend/src/settings/Analytics.tsx +++ b/frontend/src/settings/Analytics.tsx @@ -63,9 +63,9 @@ export default function Analytics() { value: string; }>({ label: '30 Days', value: 'last_30_days' }); - const [loadingMessages, setLoadingMessages] = useState(true); // Loading state for messages - const [loadingTokens, setLoadingTokens] = useState(true); // Loading state for tokens - const [loadingFeedback, setLoadingFeedback] = useState(true); // Loading state for feedback + const [loadingMessages, setLoadingMessages] = useState(true); + const [loadingTokens, setLoadingTokens] = useState(true); + const [loadingFeedback, setLoadingFeedback] = useState(true); const fetchChatbots = async () => { try { @@ -81,7 +81,7 @@ export default function Analytics() { }; const fetchMessagesData = async (chatbot_id?: string, filter?: string) => { - setLoadingMessages(true); // Start loading + setLoadingMessages(true); try { const response = await userService.getMessageAnalytics({ api_key_id: chatbot_id, @@ -95,7 +95,7 @@ export default function Analytics() { } catch (error) { console.error(error); } finally { - setLoadingMessages(false); // Stop loading + setLoadingMessages(false); } }; @@ -114,12 +114,12 @@ export default function Analytics() { } catch (error) { console.error(error); } finally { - setLoadingTokens(false); // Stop loading + setLoadingTokens(false); } }; const fetchFeedbackData = async (chatbot_id?: string, filter?: string) => { - setLoadingFeedback(true); // Start loading + setLoadingFeedback(true); try { const response = await userService.getFeedbackAnalytics({ api_key_id: chatbot_id, diff --git a/frontend/src/settings/Documents.tsx b/frontend/src/settings/Documents.tsx index b45c968d..a5e5efb7 100644 --- a/frontend/src/settings/Documents.tsx +++ b/frontend/src/settings/Documents.tsx @@ -1,3 +1,4 @@ +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import { useDispatch } from 'react-redux'; @@ -6,6 +7,7 @@ import userService from '../api/services/userService'; import SyncIcon from '../assets/sync.svg'; import Trash from '../assets/trash.svg'; import DropdownMenu from '../components/DropdownMenu'; +import SkeletonLoader from '../utils/loader'; import { Doc, DocumentsProps } from '../models/misc'; import { getDocs } from '../preferences/preferenceApi'; import { setSourceDocs } from '../preferences/preferenceSlice'; @@ -33,6 +35,7 @@ const Documents: React.FC = ({ }) => { const { t } = useTranslation(); const dispatch = useDispatch(); + const [loading, setLoading] = useState(false); const syncOptions = [ { label: 'Never', value: 'never' }, { label: 'Daily', value: 'daily' }, @@ -41,6 +44,7 @@ const Documents: React.FC = ({ ]; const handleManageSync = (doc: Doc, sync_frequency: string) => { + setLoading(true); userService .manageSync({ source_id: doc.id, sync_frequency }) .then(() => { @@ -49,81 +53,91 @@ const Documents: React.FC = ({ .then((data) => { dispatch(setSourceDocs(data)); }) - .catch((error) => console.error(error)); + .catch((error) => console.error(error)) + .finally(() => { + setLoading(false); + }); }; + return (
- - - - - - - - - - - - {!documents?.length && ( + {loading ? ( + + ) : ( +
{t('settings.documents.name')}{t('settings.documents.date')}{t('settings.documents.tokenUsage')}{t('settings.documents.type')}
+ - + + + + + - )} - {documents && - documents.map((document, index) => ( - - - - - - + + {!documents?.length && ( + + - ))} - -
- {t('settings.documents.noData')} - {t('settings.documents.name')}{t('settings.documents.date')}{t('settings.documents.tokenUsage')}{t('settings.documents.type')}
{document.name}{document.date} - {document.tokens ? formatTokens(+document.tokens) : ''} - - {document.type === 'remote' ? 'Pre-loaded' : 'Private'} - -
- {document.type !== 'remote' && ( - Delete { - event.stopPropagation(); - handleDeleteDocument(index, document); - }} - /> - )} - {document.syncFrequency && ( -
- { - handleManageSync(document, value); - }} - defaultValue={document.syncFrequency} - icon={SyncIcon} - /> -
- )} -
+
+ {t('settings.documents.noData')}
+ )} + {documents && + documents.map((document, index) => ( + + {document.name} + {document.date} + + {document.tokens ? formatTokens(+document.tokens) : ''} + + + {document.type === 'remote' ? 'Pre-loaded' : 'Private'} + + +
+ {document.type !== 'remote' && ( + Delete { + event.stopPropagation(); + handleDeleteDocument(index, document); + }} + /> + )} + {document.syncFrequency && ( +
+ { + handleManageSync(document, value); + }} + defaultValue={document.syncFrequency} + icon={SyncIcon} + /> +
+ )} +
+ + + ))} + + + )}
); }; + Documents.propTypes = { documents: PropTypes.array.isRequired, handleDeleteDocument: PropTypes.func.isRequired, }; + export default Documents;