From b6c3f3a545571d3362eb4f3af7172d66583e6c2a Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Tue, 3 Sep 2024 19:02:12 +0930 Subject: [PATCH] feat: add unlink button to frontend --- .../src/components/settings/SettingsPage.jsx | 55 ++++++++++++++++--- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/settings/SettingsPage.jsx b/frontend/src/components/settings/SettingsPage.jsx index 79b5d21..9d1160b 100644 --- a/frontend/src/components/settings/SettingsPage.jsx +++ b/frontend/src/components/settings/SettingsPage.jsx @@ -8,6 +8,7 @@ import { revertFile, pullBranch, getDiff, + unlinkRepo, } from "../../api/api"; import SettingsModal from "./SettingsModal"; import SettingsBranchModal from "./SettingsBranchModal"; @@ -28,6 +29,7 @@ import { CheckCircle, File, Settings, + Unlink, } from "lucide-react"; import Alert from "../ui/Alert"; import CommitSection from "./CommitSection"; @@ -502,6 +504,27 @@ const SettingsPage = () => { } }; + const handleUnlinkRepo = async () => { + if (window.confirm("Are you sure you want to unlink this repository? This action cannot be undone.")) { + setLoadingAction("unlink_repo"); + try { + const response = await unlinkRepo(); + if (response.success) { + setSettings(null); + setStatus(null); + Alert.success("Repository unlinked successfully"); + } else { + Alert.error(response.error || "Failed to unlink repository"); + } + } catch (error) { + Alert.error("An unexpected error occurred while unlinking the repository"); + console.error("Error unlinking repository:", error); + } finally { + setLoadingAction(""); + } + } + }; + return (

@@ -513,14 +536,30 @@ const SettingsPage = () => {

Connected Repository

- - {settings.gitRepo} - +
+ + {settings.gitRepo} + + + + +