diff --git a/frontend/src/components/settings/SettingsPage.jsx b/frontend/src/components/settings/SettingsPage.jsx
index 90fa550..905504e 100644
--- a/frontend/src/components/settings/SettingsPage.jsx
+++ b/frontend/src/components/settings/SettingsPage.jsx
@@ -10,7 +10,6 @@ import {
unlinkRepo,
checkDevMode
} from '../../api/api';
-import UnlinkModal from './UnlinkModal';
import SettingsBranchModal from './SettingsBranchModal';
import {
FileText,
@@ -35,7 +34,6 @@ import Alert from '../ui/Alert';
import CommitSection from './CommitSection';
import Tooltip from '../ui/Tooltip';
import DiffModal from './DiffModal';
-import LinkRepoModal from './LinkRepoModal';
import ArrContainer from './arrs/ArrContainer';
import RepoContainer from './git/RepoContainer';
@@ -56,8 +54,6 @@ const SettingsPage = () => {
const [loadingDiff, setLoadingDiff] = useState(false);
const [selectionType, setSelectionType] = useState(null);
const [funMessage, setFunMessage] = useState('');
- const [showLinkModal, setShowLinkModal] = useState(false);
- const [showUnlinkModal, setShowUnlinkModal] = useState(false);
const [sortConfig, setSortConfig] = useState({
key: 'type',
direction: 'descending'
@@ -562,34 +558,6 @@ const SettingsPage = () => {
}
};
- const handleLinkRepo = async () => {
- setLoadingAction('');
- setShowLinkModal(false);
- await fetchSettings();
- };
-
- const handleUnlinkRepo = async removeFiles => {
- setLoadingAction('unlink_repo');
- try {
- const response = await unlinkRepo(removeFiles);
- if (response.success) {
- setSettings(null);
- setStatus(null);
- Alert.success('Repository unlinked successfully');
- setShowUnlinkModal(false); // Close the modal after unlinking
- } 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 (
@@ -601,9 +569,8 @@ const SettingsPage = () => {
{settings && (
@@ -847,16 +814,6 @@ const SettingsPage = () => {
isDevMode={isDevMode}
/>
)}
- setShowLinkModal(false)}
- onSubmit={handleLinkRepo}
- />
- setShowUnlinkModal(false)}
- onSubmit={handleUnlinkRepo}
- />
);
};
diff --git a/frontend/src/components/settings/UnlinkModal.jsx b/frontend/src/components/settings/UnlinkModal.jsx
deleted file mode 100644
index b74b528..0000000
--- a/frontend/src/components/settings/UnlinkModal.jsx
+++ /dev/null
@@ -1,57 +0,0 @@
-// UnlinkModal.js
-import React, { useState } from 'react';
-import PropTypes from 'prop-types';
-import Modal from '../ui/Modal';
-
-const UnlinkRepoModal = ({ isOpen, onClose, onSubmit }) => {
- const [removeFiles, setRemoveFiles] = useState(false);
-
- const handleUnlink = () => {
- onSubmit(removeFiles); // Pass removeFiles correctly
- onClose(); // Close the modal after unlinking
-};
-
- return (
-
-
-
- Are you sure you want to unlink the repository?
-
-
- setRemoveFiles(!removeFiles)}
- className="form-checkbox h-4 w-4 text-red-600 transition duration-150 ease-in-out"
- />
-
-
-
-
-
-
-
-
- );
-};
-
-UnlinkRepoModal.propTypes = {
- isOpen: PropTypes.bool.isRequired,
- onClose: PropTypes.func.isRequired,
- onSubmit: PropTypes.func.isRequired,
-};
-
-export default UnlinkRepoModal;
diff --git a/frontend/src/components/settings/git/RepoContainer.jsx b/frontend/src/components/settings/git/RepoContainer.jsx
index e9b1894..8b5253f 100644
--- a/frontend/src/components/settings/git/RepoContainer.jsx
+++ b/frontend/src/components/settings/git/RepoContainer.jsx
@@ -1,49 +1,109 @@
-import React from 'react';
-import {Loader, Unlink} from 'lucide-react';
+import React, {useState} from 'react';
+import {Loader, Unlink, Link} from 'lucide-react';
import Tooltip from '../../ui/Tooltip';
+import {unlinkRepo, getSettings} from '../../../api/api';
+import Alert from '../../ui/Alert';
+import LinkRepo from './modal/LinkRepo';
+import UnlinkRepo from './modal/UnlinkRepo';
+
+const RepoContainer = ({settings, setSettings, fetchGitStatus}) => {
+ const [loadingAction, setLoadingAction] = useState('');
+ const [showLinkModal, setShowLinkModal] = useState(false);
+ const [showUnlinkRepo, setShowUnlinkRepo] = useState(false);
+
+ const handleLinkRepo = async () => {
+ setLoadingAction('link_repo');
+ setShowLinkModal(true);
+ };
+
+ const handleUnlinkRepo = async removeFiles => {
+ setLoadingAction('unlink_repo');
+ try {
+ const response = await unlinkRepo(removeFiles);
+ if (response.success) {
+ setSettings(null);
+ Alert.success('Repository unlinked successfully');
+ setShowUnlinkRepo(false);
+ } 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('');
+ }
+ };
+
+ const onLinkSubmit = async () => {
+ setLoadingAction('');
+ setShowLinkModal(false);
+ const fetchedSettings = await getSettings();
+ setSettings(fetchedSettings);
+ if (fetchedSettings) {
+ await fetchGitStatus();
+ }
+ };
-const RepoContainer = ({settings, loadingAction, onLinkRepo, onUnlinkRepo}) => {
if (!settings) {
return (
-
+ <>
+
+ setShowLinkModal(false)}
+ onSubmit={onLinkSubmit}
+ />
+ >
);
}
return (
-
-
-
-
+
+
+
+ setShowUnlinkRepo(false)}
+ onSubmit={handleUnlinkRepo}
+ />
);
};
diff --git a/frontend/src/components/settings/LinkRepoModal.jsx b/frontend/src/components/settings/git/modal/LinkRepo.jsx
similarity index 92%
rename from frontend/src/components/settings/LinkRepoModal.jsx
rename to frontend/src/components/settings/git/modal/LinkRepo.jsx
index fd86606..f663a70 100644
--- a/frontend/src/components/settings/LinkRepoModal.jsx
+++ b/frontend/src/components/settings/git/modal/LinkRepo.jsx
@@ -1,10 +1,10 @@
import React, {useState} from 'react';
-import Modal from '../ui/Modal';
+import Modal from '../../ui/Modal';
import {Loader} from 'lucide-react';
-import {cloneRepo} from '../../api/api';
-import Alert from '../ui/Alert';
+import {cloneRepo} from '../../../api/api';
+import Alert from '../../ui/Alert';
-const LinkRepoModal = ({isOpen, onClose, onSubmit}) => {
+const LinkRepo = ({isOpen, onClose, onSubmit}) => {
const [gitRepo, setGitRepo] = useState('');
const [loading, setLoading] = useState(false);
@@ -68,4 +68,4 @@ const LinkRepoModal = ({isOpen, onClose, onSubmit}) => {
);
};
-export default LinkRepoModal;
+export default LinkRepo;
diff --git a/frontend/src/components/settings/git/modal/UnlinkRepo.jsx b/frontend/src/components/settings/git/modal/UnlinkRepo.jsx
new file mode 100644
index 0000000..011d42e
--- /dev/null
+++ b/frontend/src/components/settings/git/modal/UnlinkRepo.jsx
@@ -0,0 +1,57 @@
+// UnlinkModal.js
+import React, {useState} from 'react';
+import PropTypes from 'prop-types';
+import Modal from '../../../ui/Modal';
+
+const UnlinkRepo = ({isOpen, onClose, onSubmit}) => {
+ const [removeFiles, setRemoveFiles] = useState(false);
+
+ const handleUnlink = () => {
+ onSubmit(removeFiles); // Pass removeFiles correctly
+ onClose(); // Close the modal after unlinking
+ };
+
+ return (
+
+
+
+ Are you sure you want to unlink the repository?
+
+
+ setRemoveFiles(!removeFiles)}
+ className='form-checkbox h-4 w-4 text-red-600 transition duration-150 ease-in-out'
+ />
+
+
+
+
+
+
+
+
+ );
+};
+
+UnlinkRepo.propTypes = {
+ isOpen: PropTypes.bool.isRequired,
+ onClose: PropTypes.func.isRequired,
+ onSubmit: PropTypes.func.isRequired
+};
+
+export default UnlinkRepo;