Skip to content

Commit

Permalink
Added deletion modal in account page
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Mar 9, 2022
1 parent ac46e24 commit 8206bd9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import { ModalAlert } from '../../common/ModalAlert';

export interface ISSHKeysTableProps {
sshKeys?: { name: string; key: string }[];
onDeleteKey?: (key: {
name: string;
key: string;
}) => Promise<Boolean | undefined>;
onDeleteKey: (key: { name: string; key: string }) => Promise<boolean>;
}

const SSHKeysTable: FC<ISSHKeysTableProps> = props => {
const { sshKeys } = props;
const { sshKeys, onDeleteKey } = props;
const [showDeleteModalConfirm, setShowDeleteModalConfirm] = useState(false);
return (
<Table
Expand Down Expand Up @@ -70,8 +67,7 @@ const SSHKeysTable: FC<ISSHKeysTableProps> = props => {
className="ml-2 w-24"
type="danger"
onClick={() =>
props
.onDeleteKey?.(record)
onDeleteKey(record)
.then(() => setShowDeleteModalConfirm(false))
.catch(err => null)
}
Expand Down
14 changes: 4 additions & 10 deletions frontend/src/components/accountPage/UserPanel/UserPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@ export interface IUserPanelProps {
username: string;
email: string;
sshKeys?: { name: string; key: string }[];
onDeleteKey?: (key: {
name: string;
key: string;
}) => boolean | Promise<boolean>;
onAddKey?: (key: { name: string; key: string }) => boolean | Promise<boolean>;
onDeleteKey: (key: { name: string; key: string }) => Promise<boolean>;
onAddKey: (key: { name: string; key: string }) => boolean | Promise<boolean>;
}

const UserPanel: FC<IUserPanelProps> = props => {
const { sshKeys, ...otherInfo } = props;
const { sshKeys, onDeleteKey, ...otherInfo } = props;
const [showSSHModal, setShowSSHModal] = useState(false);

const closeModal = () => setShowSSHModal(false);

const deleteKey = async (targetKey: { name: string; key: string }) => {
return props.onDeleteKey?.(targetKey);
};
const addKey = async (newKey: { name: string; key: string }) => {
if (await props.onAddKey?.(newKey)) {
closeModal();
Expand All @@ -56,7 +50,7 @@ const UserPanel: FC<IUserPanelProps> = props => {
<UserInfo {...otherInfo} />
</TabPane>
<TabPane tab="SSH Keys" key="2">
<SSHKeysTable sshKeys={sshKeys} onDeleteKey={deleteKey} />
<SSHKeysTable sshKeys={sshKeys} onDeleteKey={onDeleteKey} />
<Button className="mt-3" onClick={() => setShowSSHModal(true)}>
Add SSH key
</Button>
Expand Down

0 comments on commit 8206bd9

Please sign in to comment.