Skip to content

Commit

Permalink
Add button to restore deleted account (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig authored Sep 9, 2024
1 parent d6c4cfa commit 5983d60
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/renderer/components/account-list.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { AccountInfo } from '../types';
import { AccountInfo, AppReduxState } from '../types';
import { useDispatch } from 'react-redux';
import { selectAccount } from '../lib/reducer';
import { selectAccount, setAccounts } from '../lib/reducer';
import { useSelector } from 'react-redux';

export default function AccountList({
accounts,
Expand All @@ -11,11 +12,30 @@ export default function AccountList({
showAccountEdit: () => void;
}) {
const dispatch = useDispatch();
const selectedAccount = useSelector((state: AppReduxState) => state.selectedAccount)
const hasSelectedAccountBeenDeleted = (() => {
if (selectedAccount) {
if (accounts.some(account => account.id === selectedAccount.id)) {
return false
}
return true;
}
return false;
})()

return (
<div className="config-page">
<div className="account-page-header">
<h2 className="config-page__title">Accounts</h2>
<div className="account-page-actions">
{hasSelectedAccountBeenDeleted && selectedAccount && <button
className="add-account-button btn"
onClick={() => {
dispatch(setAccounts([selectedAccount, ...accounts]));
}}
>
Restore '{selectedAccount.name}'
</button>}
<button
className="add-account-button btn"
onClick={() => {
Expand Down

0 comments on commit 5983d60

Please sign in to comment.