Skip to content

Commit

Permalink
Fix SSH key error bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattia013 committed Nov 15, 2024
1 parent 46049e2 commit a5db35e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions frontend/src/components/accountPage/SSHKeysTable/SSHKeysTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export interface ISSHKeysTableProps {

const SSHKeysTable: FC<ISSHKeysTableProps> = props => {
const { sshKeys, onDeleteKey } = props;
const [showDeleteModalConfirm, setShowDeleteModalConfirm] = useState(false);
const [recordToDelete, setRecordToDelete] = useState<{
name: string;
key: string;
} | null>(null);
return (
<Table
dataSource={sshKeys}
Expand Down Expand Up @@ -47,7 +50,7 @@ const SSHKeysTable: FC<ISSHKeysTableProps> = props => {
sshKeys?.length && (
<>
<ModalAlert
headTitle={record.name}
headTitle={recordToDelete?.name}
message="Delete ssh key"
description="Do you really want to delete this key?"
type="warning"
Expand All @@ -57,7 +60,7 @@ const SSHKeysTable: FC<ISSHKeysTableProps> = props => {
shape="round"
className="mr-2 w-24"
type="primary"
onClick={() => setShowDeleteModalConfirm(false)}
onClick={() => setRecordToDelete(null)} // Close the modal without deleting
>
Close
</Button>,
Expand All @@ -66,21 +69,23 @@ const SSHKeysTable: FC<ISSHKeysTableProps> = props => {
shape="round"
className="ml-2 w-24"
type="danger"
onClick={() =>
onDeleteKey(record)
.then(() => setShowDeleteModalConfirm(false))
.catch(err => null)
}
onClick={() => {
if (recordToDelete) {
onDeleteKey(recordToDelete) // Safe to call because recordToDelete is not null
.then(() => setRecordToDelete(null)) // Close modal on success
.catch(err => null); // Handle error gracefully
}
}}
>
Delete
</Button>,
]}
show={showDeleteModalConfirm}
setShow={setShowDeleteModalConfirm}
show={!!recordToDelete} // Show the modal only when recordToDelete is not null
setShow={() => setRecordToDelete(null)} // Close the modal on outside click or Close button
/>

<DeleteOutlined
onClick={() => setShowDeleteModalConfirm(true)}
onClick={() => setRecordToDelete(record)}
style={{ color: 'red' }}
/>
</>
Expand Down

0 comments on commit a5db35e

Please sign in to comment.