Skip to content

Commit

Permalink
260 feature tabs on banking (#261)
Browse files Browse the repository at this point in the history
* working tabs

* working Table review BIG

* working table with cat search and input search

* working table with filter, category etc

* working multiple review OK

* working update labels, but x10000 calls

* working new usestate, but table update goes to bottom

* complete review table
  • Loading branch information
Codehagen authored Jul 25, 2024
1 parent d4042e3 commit 7de4bdc
Show file tree
Hide file tree
Showing 27 changed files with 1,357 additions and 471 deletions.
2 changes: 1 addition & 1 deletion apps/www/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default [
"@typescript-eslint/require-await": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-empty-function": "warn",
Expand Down
3 changes: 3 additions & 0 deletions apps/www/src/actions/get-transactions-to-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export async function getTransactionsToReview() {
const transactions = await prisma.transaction.findMany({
where: {
review: false,
bankAccount: {
userId: user.id,
},
},
include: {
category: true,
Expand Down
34 changes: 34 additions & 0 deletions apps/www/src/actions/update-category-review-table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// actions/update-category.ts
"use server";

import { revalidatePath } from "next/cache";

import { prisma } from "@/lib/db";
import { getCurrentUser } from "@/lib/session";

export async function updateCategoryReviewTable(
transactionId: string,
categoryId: string,
) {
try {
const category = await prisma.category.findUnique({
where: { id: categoryId },
});

if (!category) {
return { success: false, error: "Category not found" };
}

const updatedTransaction = await prisma.transaction.update({
where: { id: transactionId },
data: { categoryId: categoryId },
});

revalidatePath("/dashboard/banking");

return { success: true, data: updatedTransaction };
} catch (error) {
console.error("Error updating category:", error);
return { success: false, error: "Failed to update category" };
}
}
29 changes: 29 additions & 0 deletions apps/www/src/actions/update-multiple-transactions-review.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use server";

import { revalidatePath } from "next/cache";

import { prisma } from "@/lib/db";
import { getCurrentUser } from "@/lib/session";

export async function updateMultipleTransactionReviews(
transactionIds: string[],
) {
const user = await getCurrentUser();
if (!user) {
throw new Error("User not authenticated");
}

try {
await prisma.transaction.updateMany({
where: { id: { in: transactionIds } },
data: { review: true },
});

revalidatePath("/dashboard");

return { success: true };
} catch (error) {
console.error("Error updating multiple transaction reviews:", error);
return { success: false, error: error.message };
}
}
52 changes: 52 additions & 0 deletions apps/www/src/actions/update-transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use server";

import { revalidatePath } from "next/cache";

import { prisma } from "@/lib/db";
import { getCurrentUser } from "@/lib/session";

interface UpdateTransactionData {
id: string;
accountId?: string;
assetId?: string;
currencyIso?: string;
categoryId?: string;
amount?: number;
date?: Date;
description?: string;
review?: boolean;
}

export async function updateTransaction(data: UpdateTransactionData) {
const user = await getCurrentUser();
const userId = user?.id;

if (!userId) {
console.error("No user is currently logged in.");
return { success: false, error: "User not authenticated" };
}

try {
const updatedTransaction = await prisma.transaction.update({
where: { id: data.id },
data: {
accountId: data.accountId,
assetId: data.assetId,
currencyIso: data.currencyIso,
categoryId: data.categoryId,
date: data.date,
description: data.description,
review: data.review,
},
});

revalidatePath("/dashboard");

console.log(`Updated transaction with ID: ${updatedTransaction.id}`);

return { success: true, transaction: updatedTransaction };
} catch (error) {
console.error(`Error updating transaction: ${error.message}`);
return { success: false, error: error.message };
}
}
7 changes: 6 additions & 1 deletion apps/www/src/app/(dashboard)/dashboard/banking/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { getBankAccountDetails } from "@/actions/get-bank-account-details";
import { getBankAccountTransactions } from "@/actions/get-bank-account-transactions";

import { AccountDropdownMenu } from "@/components/banking/AccountDropdownMenu";
import BankingDashboard from "@/components/banking/BankingDashboard";
import BankingDashboardDetails from "@/components/banking/BankingDashboardDetails";
import { BankingDropdownMenu } from "@/components/banking/BankingDropdownMenu";
import { AddTransactionsButton } from "@/components/buttons/AddTransactionsButton";
import { DashboardHeader } from "@/components/dashboard/header";
import { DashboardShell } from "@/components/dashboard/shell";
Expand Down Expand Up @@ -49,8 +51,11 @@ export default async function BankAccountPage({
heading={bankAccountDetails.name}
text="Here are your recent transactions"
>
<CSVUploader bankAccountId={bankAccountId} />
{/* <CSVUploader bankAccountId={bankAccountId} /> */}
</DashboardHeader>
<div className=" -mb-4 flex justify-end space-x-2">
<AccountDropdownMenu bankAccountId={bankAccountId} />
</div>
<div>
{transactions.length === 0 ? (
<EmptyPlaceholder>
Expand Down
130 changes: 103 additions & 27 deletions apps/www/src/app/(dashboard)/dashboard/banking/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import { redirect } from "next/navigation";
import { getUserBankAccounts } from "@/actions/get-bankaccounts"; // Adjust the import path as needed

import { getTransactionsToReview } from "@/actions/get-transactions-to-review";

import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from "@dingify/ui/components/tabs";

import { authOptions } from "@/lib/auth";
import { getCurrentUser } from "@/lib/session";
import BankAccountsTable from "@/components/banking/BankAccountsTable";
import { BankingDropdownMenu } from "@/components/banking/BankingDropdownMenu";
import { AddAccountSheet } from "@/components/buttons/AddAccountSheeet";
import { AddButton } from "@/components/buttons/AddButton";
import { AreaChartBanking } from "@/components/charts/AreaChart";
import { OverallUseageChart } from "@/components/charts/OverallUseageChart";
import { DashboardHeader } from "@/components/dashboard/header";
import { DashboardShell } from "@/components/dashboard/shell";
import { CSVUploader } from "@/components/import/CsvImporter";
import { EmptyPlaceholder } from "@/components/shared/empty-placeholder";
import { columns } from "@/components/tables/transactions/components/columns-review-transactions-table";
import { ReviewTransactionsTable } from "@/components/tables/transactions/components/review-transactions-table";

export const metadata = {
title: "Banking",
Expand All @@ -26,36 +36,102 @@ export default async function BankingPage() {
}

const bankAccounts = await getUserBankAccounts();
console.log(bankAccounts);
const reviewTransactions = await getTransactionsToReview();

return (
<DashboardShell>
<DashboardHeader heading="Banking" text="Overview off all your accounts ">
<AddAccountSheet currentPath="/banking" />
<DashboardHeader heading="Banking" text="Overview off all your accounts">
<AddAccountSheet currentPath="/banking" children={undefined} />
</DashboardHeader>
<div>
{bankAccounts.length === 0 ? (
<EmptyPlaceholder>
<EmptyPlaceholder.Icon name="post" />
<EmptyPlaceholder.Title>
You have no bank accounts
</EmptyPlaceholder.Title>
<EmptyPlaceholder.Description>
Add a bank account to start tracking your finances.
</EmptyPlaceholder.Description>
<AddAccountSheet currentPath="/banking" />
</EmptyPlaceholder>
) : (
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<AreaChartBanking />
<OverallUseageChart />

<div className="col-span-1 md:col-span-2">
<BankAccountsTable bankAccounts={bankAccounts} />
</div>
<Tabs defaultValue="overview" className="-mt-4 w-full">
<div className="flex items-center justify-between">
<TabsList>
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="accounts">Accounts</TabsTrigger>
<TabsTrigger value="review">Review</TabsTrigger>
<TabsTrigger value="transactions" disabled>
Transactions
</TabsTrigger>
</TabsList>
<BankingDropdownMenu />
</div>
<TabsContent value="overview">
<div>
{bankAccounts.length === 0 ? (
<EmptyPlaceholder>
<EmptyPlaceholder.Icon name="post" />
<EmptyPlaceholder.Title>
You have no bank accounts
</EmptyPlaceholder.Title>
<EmptyPlaceholder.Description>
Add a bank account to start tracking your finances.
</EmptyPlaceholder.Description>
<AddAccountSheet currentPath="/banking" children={undefined} />
</EmptyPlaceholder>
) : (
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
<AreaChartBanking />
<OverallUseageChart />
</div>
)}
</div>
)}
</div>
</TabsContent>
<TabsContent value="accounts">
{bankAccounts.length === 0 ? (
<EmptyPlaceholder>
<EmptyPlaceholder.Icon name="post" />
<EmptyPlaceholder.Title>
You have no bank accounts
</EmptyPlaceholder.Title>
<EmptyPlaceholder.Description>
Add a bank account to start tracking your finances.
</EmptyPlaceholder.Description>
<AddAccountSheet currentPath="/banking" children={undefined} />
</EmptyPlaceholder>
) : (
<BankAccountsTable bankAccounts={bankAccounts} />
)}
</TabsContent>
<TabsContent value="review">
{bankAccounts.length === 0 ? (
<EmptyPlaceholder>
<EmptyPlaceholder.Icon name="post" />
<EmptyPlaceholder.Title>
No accounts to review
</EmptyPlaceholder.Title>
<EmptyPlaceholder.Description>
Add a bank account to start reviewing your finances.
</EmptyPlaceholder.Description>
<AddAccountSheet currentPath="/banking" children={undefined} />
</EmptyPlaceholder>
) : (
<div>
<ReviewTransactionsTable
data={reviewTransactions}
columns={columns}
/>
</div>
)}
</TabsContent>
<TabsContent value="transactions">
{bankAccounts.length === 0 ? (
<EmptyPlaceholder>
<EmptyPlaceholder.Icon name="post" />
<EmptyPlaceholder.Title>
No transactions to display
</EmptyPlaceholder.Title>
<EmptyPlaceholder.Description>
Add a bank account to start tracking your transactions.
</EmptyPlaceholder.Description>
<AddAccountSheet currentPath="/banking" children={undefined} />
</EmptyPlaceholder>
) : (
<div>
<p>Transactions content goes here</p>
</div>
)}
</TabsContent>
</Tabs>
</DashboardShell>
);
}
6 changes: 3 additions & 3 deletions apps/www/src/app/(dashboard)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default async function DashboardPage() {
return (
<DashboardShell>
<DashboardHeader heading="Dashboard" text="Your analytics dashboard">
<AddAccountSheet currentPath="/dashboard" />
<AddAccountSheet currentPath="/dashboard" children={undefined} />
</DashboardHeader>
<div>
{transactions.length === 0 ? (
Expand All @@ -47,15 +47,15 @@ export default async function DashboardPage() {
<EmptyPlaceholder.Description>
Let's start with adding some accounts
</EmptyPlaceholder.Description>
<AddAccountSheet currentPath="/dashboard" />
<AddAccountSheet currentPath="/dashboard" children={undefined} />
</EmptyPlaceholder>
) : (
// Render TransactionsTable if there are transactions
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
<BudgetVsCostChart />
<AssetVsDebt />

<div className="col-span-1 lg:col-span-2">
<div className="col-span-full lg:col-span-2">
<TransactionsToReview transactions={reviewTransactions} />
</div>
</div>
Expand Down
Loading

0 comments on commit 7de4bdc

Please sign in to comment.