Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to restore deleted account #189

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading