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

[Typescript migration] Migrate AccountSyncCheck to ts #3757

Merged
merged 3 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useState } from 'react';
import React, { useCallback, useRef, useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding more TypeScript type definitions

While the migration adds some type safety, there are opportunities for more comprehensive typing.

Consider adding these type definitions:

interface Account {
  id: string;
  account_id: string;
  // ... other properties
}

interface FailedAccount {
  type: string;
  code: string;
}

interface AccountSyncCheckProps {
  // if any props are needed in the future
}

import { Trans } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';
Expand All @@ -16,7 +16,7 @@
import { Popover } from '../common/Popover';
import { View } from '../common/View';

function getErrorMessage(type, code) {
function getErrorMessage(type: string, code: string) {
switch (type.toUpperCase()) {
case 'ITEM_ERROR':
switch (code.toUpperCase()) {
Expand Down Expand Up @@ -81,7 +81,7 @@
const [open, setOpen] = useState(false);
const triggerRef = useRef(null);

if (!failedAccounts) {
if (!failedAccounts || !id) {
return null;
}

Expand All @@ -91,21 +91,30 @@
}

const account = accounts.find(account => account.id === id);
if (!account) {
return null;
}

const { type, code } = error;
const showAuth =
(type === 'ITEM_ERROR' && code === 'ITEM_LOGIN_REQUIRED') ||
(type === 'INVALID_INPUT' && code === 'INVALID_ACCESS_TOKEN');

function reauth() {
const reauth = useCallback(() => {

Check failure on line 103 in packages/desktop-client/src/components/accounts/AccountSyncCheck.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook "useCallback" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?
setOpen(false);

authorizeBank(dispatch, { upgradingAccountId: account.account_id });
}
if (account?.account_id) {
authorizeBank(dispatch, { upgradingAccountId: account.account_id });
}
}, [dispatch, account?.account_id]);

const unlink = useCallback(async () => {

Check failure on line 111 in packages/desktop-client/src/components/accounts/AccountSyncCheck.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook "useCallback" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?
if (account?.id) {
dispatch(unlinkAccount(account.id));
}

async function unlink() {
dispatch(unlinkAccount(account.id));
setOpen(false);
}
}, [dispatch, account?.id]);

return (
<View>
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/budget/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function separateGroups(categoryGroups: CategoryGroupEntity[]) {
return [
categoryGroups.filter(g => !g.is_income),
categoryGroups.find(g => g.is_income),
];
] as const;
}

export function makeAmountGrey(value: number | string): CSSProperties {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3757.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [joel-jeremy]
---

Migrate AccountSyncCheck.jsx file to typescript
Loading