Skip to content
Snippets Groups Projects
Commit ce8f65ff authored by timothycarambat's avatar timothycarambat
Browse files

add back delete workspace button

parent e8662d79
No related branches found
No related tags found
No related merge requests found
import { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import Workspace from "@/models/workspace";
import paths from "@/utils/paths";
import System from "@/models/system";
export default function DeleteWorkspace({ workspace }) {
const { slug } = useParams();
const [deleting, setDeleting] = useState(false);
const [canDelete, setCanDelete] = useState(false);
useEffect(() => {
async function fetchKeys() {
const canDelete = await System.getCanDeleteWorkspaces();
setCanDelete(canDelete);
}
fetchKeys();
}, [workspace?.slug]);
const deleteWorkspace = async () => {
if (
!window.confirm(
`You are about to delete your entire ${workspace.name} workspace. This will remove all vector embeddings on your vector database.\n\nThe original source files will remain untouched. This action is irreversible.`
)
)
return false;
setDeleting(true);
const success = await Workspace.delete(workspace.slug);
if (!success) {
showToast("Workspace could not be deleted!", "error", { clear: true });
setDeleting(false);
return;
}
workspace.slug === slug
? (window.location = paths.home())
: window.location.reload();
};
if (!canDelete) return null;
return (
<button
disabled={deleting}
onClick={deleteWorkspace}
type="button"
className="w-60 mt-[40px] transition-all duration-300 border border-transparent rounded-lg whitespace-nowrap text-sm px-5 py-2.5 focus:z-10 bg-red-500/25 text-red-200 hover:text-white hover:bg-red-600 disabled:bg-red-600 disabled:text-red-200 disabled:animate-pulse"
>
{deleting ? "Deleting Workspace..." : "Delete Workspace"}
</button>
);
}
...@@ -5,6 +5,7 @@ import { useEffect, useRef, useState } from "react"; ...@@ -5,6 +5,7 @@ import { useEffect, useRef, useState } from "react";
import VectorCount from "./VectorCount"; import VectorCount from "./VectorCount";
import WorkspaceName from "./WorkspaceName"; import WorkspaceName from "./WorkspaceName";
import SuggestedChatMessages from "./SuggestedChatMessages"; import SuggestedChatMessages from "./SuggestedChatMessages";
import DeleteWorkspace from "./DeleteWorkspace";
export default function GeneralInfo({ slug }) { export default function GeneralInfo({ slug }) {
const [workspace, setWorkspace] = useState(null); const [workspace, setWorkspace] = useState(null);
...@@ -56,7 +57,6 @@ export default function GeneralInfo({ slug }) { ...@@ -56,7 +57,6 @@ export default function GeneralInfo({ slug }) {
workspace={workspace} workspace={workspace}
setHasChanges={setHasChanges} setHasChanges={setHasChanges}
/> />
{hasChanges && ( {hasChanges && (
<button <button
type="submit" type="submit"
...@@ -69,6 +69,7 @@ export default function GeneralInfo({ slug }) { ...@@ -69,6 +69,7 @@ export default function GeneralInfo({ slug }) {
<div className="mt-6"> <div className="mt-6">
<SuggestedChatMessages slug={workspace.slug} /> <SuggestedChatMessages slug={workspace.slug} />
</div> </div>
<DeleteWorkspace workspace={workspace} />
</> </>
); );
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment