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

Fix link to contributions from transactions drawer inside dashboard #10424

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
27 changes: 22 additions & 5 deletions components/dashboard/sections/transactions/TransactionDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ const transactionQuery = gql`
toAccount {
id
slug
... on AccountWithHost {
host {
id
slug
}
}
}
fromAccount {
id
Expand Down Expand Up @@ -241,6 +247,17 @@ const getExpenseUrl = (dashboardAccount, expense) => {
return `/${expense.account.slug}/expenses/${expense.legacyId}`;
};

const getContributionUrl = (dashboardAccount, order) => {
if (dashboardAccount?.isHost && order.toAccount.host?.id === dashboardAccount.id) {
return getDashboardRoute(order.toAccount.host, `orders?orderId=${order.legacyId}`);
} else if (dashboardAccount?.id === order.toAccount.id) {
return getDashboardRoute(order.toAccount, `incoming-contributions?orderId=${order.legacyId}`);
} else if (dashboardAccount?.id === order.fromAccount.id) {
return getDashboardRoute(order.fromAccount, `outgoing-contributions?orderId=${order.legacyId}`);
}
return `/${order.toAccount.slug}/contributions/${order.legacyId}`;
};

function TransactionDetails({ transactionId, getActions }: TransactionDetailsProps) {
const intl = useIntl();
const prevTransactionId = usePrevious(transactionId);
Expand All @@ -255,11 +272,14 @@ function TransactionDetails({ transactionId, getActions }: TransactionDetailsPro
const actions = getActions(transaction, dropdownTriggerRef, refetch);
const accountingCategory = transaction?.expense?.accountingCategory || transaction?.order?.accountingCategory;

let expenseUrl;
let expenseUrl, contributionUrl;

if (transaction?.expense) {
expenseUrl = getExpenseUrl(account, transaction.expense);
}
if (transaction?.order) {
contributionUrl = getContributionUrl(account, transaction.order);
}
return (
<React.Fragment>
<DrawerHeader
Expand Down Expand Up @@ -639,10 +659,7 @@ function TransactionDetails({ transactionId, getActions }: TransactionDetailsPro
value={
<HoverCard>
<HoverCardTrigger asChild>
<Link
href={`/${transaction?.order.toAccount.slug}/contributions/${transaction?.order.legacyId}`}
className="underline hover:text-primary"
>
<Link href={contributionUrl} className="underline hover:text-primary">
{transaction?.order.description}
</Link>
</HoverCardTrigger>
Expand Down
Loading