diff --git a/app/(app)/settings/backups/page.tsx b/app/(app)/settings/backups/page.tsx
index b5b26de..d6708fe 100644
--- a/app/(app)/settings/backups/page.tsx
+++ b/app/(app)/settings/backups/page.tsx
@@ -44,7 +44,7 @@ export default function BackupSettingsPage() {
progress?.current ? (
`Archiving ${progress.current}/${progress.total} files`
) : (
- "Preparing backup..."
+ "Preparing backup. Don't close the page..."
)
) : isDownloading ? (
"Archive is created. Downloading..."
diff --git a/app/(app)/settings/danger/actions.ts b/app/(app)/settings/danger/actions.ts
index 9c19fef..3261e81 100644
--- a/app/(app)/settings/danger/actions.ts
+++ b/app/(app)/settings/danger/actions.ts
@@ -24,10 +24,13 @@ export async function resetFieldsAndCategories(user: User) {
for (const category of DEFAULT_CATEGORIES) {
await prisma.category.upsert({
where: { userId_code: { code: category.code, userId: user.id } },
- update: { name: category.name, color: category.color, llm_prompt: category.llm_prompt },
- create: { ...category, userId: user.id },
+ update: { name: category.name, color: category.color, llm_prompt: category.llm_prompt, createdAt: new Date() },
+ create: { ...category, userId: user.id, createdAt: new Date() },
})
}
+ await prisma.category.deleteMany({
+ where: { userId: user.id, code: { notIn: DEFAULT_CATEGORIES.map((category) => category.code) } },
+ })
// Reset currencies
for (const currency of DEFAULT_CURRENCIES) {
@@ -37,6 +40,9 @@ export async function resetFieldsAndCategories(user: User) {
create: { ...currency, userId: user.id },
})
}
+ await prisma.currency.deleteMany({
+ where: { userId: user.id, code: { notIn: DEFAULT_CURRENCIES.map((currency) => currency.code) } },
+ })
// Reset fields
for (const field of DEFAULT_FIELDS) {
@@ -46,14 +52,18 @@ export async function resetFieldsAndCategories(user: User) {
name: field.name,
type: field.type,
llm_prompt: field.llm_prompt,
+ createdAt: new Date(),
isVisibleInList: field.isVisibleInList,
isVisibleInAnalysis: field.isVisibleInAnalysis,
isRequired: field.isRequired,
isExtra: field.isExtra,
},
- create: { ...field, userId: user.id },
+ create: { ...field, userId: user.id, createdAt: new Date() },
})
}
+ await prisma.field.deleteMany({
+ where: { userId: user.id, code: { notIn: DEFAULT_FIELDS.map((field) => field.code) } },
+ })
redirect("/settings/fields")
}
diff --git a/app/(app)/transactions/[transactionId]/page.tsx b/app/(app)/transactions/[transactionId]/page.tsx
index a761673..32f67de 100644
--- a/app/(app)/transactions/[transactionId]/page.tsx
+++ b/app/(app)/transactions/[transactionId]/page.tsx
@@ -3,6 +3,7 @@ import TransactionEditForm from "@/components/transactions/edit"
import TransactionFiles from "@/components/transactions/transaction-files"
import { Card } from "@/components/ui/card"
import { getCurrentUser } from "@/lib/auth"
+import { incompleteTransactionFields } from "@/lib/stats"
import { getCategories } from "@/models/categories"
import { getCurrencies } from "@/models/currencies"
import { getFields } from "@/models/fields"
@@ -11,6 +12,7 @@ import { getProjects } from "@/models/projects"
import { getSettings } from "@/models/settings"
import { getTransactionById } from "@/models/transactions"
import { notFound } from "next/navigation"
+import Link from "next/link"
export default async function TransactionPage({ params }: { params: Promise<{ transactionId: string }> }) {
const { transactionId } = await params
@@ -26,11 +28,26 @@ export default async function TransactionPage({ params }: { params: Promise<{ tr
const settings = await getSettings(user.id)
const fields = await getFields(user.id)
const projects = await getProjects(user.id)
+ const incompleteFields = incompleteTransactionFields(fields, transaction)
return (
-
-
+
+ {incompleteFields.length > 0 && (
+
+
+ Some fields are incomplete: {incompleteFields.map((field) => field.name).join(", ")}
+
+
+ You can decide which fields are required for you in{" "}
+
+ Fields settings
+
+ .
+
+
+ )}
+
Transactions
-
+
diff --git a/app/(app)/transactions/page.tsx b/app/(app)/transactions/page.tsx
index 2b469a3..e2f324f 100644
--- a/app/(app)/transactions/page.tsx
+++ b/app/(app)/transactions/page.tsx
@@ -19,7 +19,7 @@ export const metadata: Metadata = {
description: "Manage your transactions",
}
-const TRANSACTIONS_PER_PAGE = 1000
+const TRANSACTIONS_PER_PAGE = 500
export default async function TransactionsPage({ searchParams }: { searchParams: Promise }) {
const { page, ...filters } = await searchParams
diff --git a/app/(app)/unsorted/layout.tsx b/app/(app)/unsorted/layout.tsx
deleted file mode 100644
index 24a7502..0000000
--- a/app/(app)/unsorted/layout.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-export default function UnsortedLayout({ children }: { children: React.ReactNode }) {
- return {children}
-}
diff --git a/app/(app)/unsorted/loading.tsx b/app/(app)/unsorted/loading.tsx
index 5366594..a317f48 100644
--- a/app/(app)/unsorted/loading.tsx
+++ b/app/(app)/unsorted/loading.tsx
@@ -3,10 +3,11 @@ import { Loader2 } from "lucide-react"
export default function Loading() {
return (
-
+
- Loading unsorted files...
+ Loading unsorted files...
+
diff --git a/app/(app)/unsorted/page.tsx b/app/(app)/unsorted/page.tsx
index b796733..e98b06a 100644
--- a/app/(app)/unsorted/page.tsx
+++ b/app/(app)/unsorted/page.tsx
@@ -31,7 +31,7 @@ export default async function UnsortedPage() {
const settings = await getSettings(user.id)
return (
- <>
+
You have {files.length} unsorted files
@@ -101,6 +101,6 @@ export default async function UnsortedPage() {
)}
- >
+
)
}
diff --git a/app/globals.css b/app/globals.css
index 620b66b..b93217a 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -82,10 +82,13 @@
body {
@apply bg-background text-foreground;
}
- input[type="number"]::-webkit-inner-spin-button,
- input[type="number"]::-webkit-outer-spin-button {
+ input::-webkit-outer-spin-button,
+ input::-webkit-inner-spin-button {
-webkit-appearance: none;
appearance: none;
margin: 0;
}
+ input[type="number"] {
+ -moz-appearance: textfield;
+ }
}
diff --git a/components/agents/agent-window.tsx b/components/agents/tool-window.tsx
similarity index 79%
rename from components/agents/agent-window.tsx
rename to components/agents/tool-window.tsx
index 10f9df4..41ef5ad 100644
--- a/components/agents/agent-window.tsx
+++ b/components/agents/tool-window.tsx
@@ -1,6 +1,6 @@
import { Bot } from "lucide-react"
-export default function AgentWindow({ title, children }: { title: string; children: React.ReactNode }) {
+export default function ToolWindow({ title, children }: { title: string; children: React.ReactNode }) {
return (
diff --git a/components/forms/convert-currency.tsx b/components/forms/convert-currency.tsx
index 4736486..f391fe8 100644
--- a/components/forms/convert-currency.tsx
+++ b/components/forms/convert-currency.tsx
@@ -3,6 +3,22 @@ import { formatCurrency } from "@/lib/utils"
import { format, startOfDay } from "date-fns"
import { Loader2 } from "lucide-react"
import { useEffect, useState } from "react"
+import { Button } from "../ui/button"
+
+async function getCurrencyRate(currencyCodeFrom: string, currencyCodeTo: string, date: Date): Promise
{
+ const formattedDate = format(date, "yyyy-MM-dd")
+ const response = await fetch(`/api/currency?from=${currencyCodeFrom}&to=${currencyCodeTo}&date=${formattedDate}`)
+
+ if (!response.ok) {
+ const errorData = await response.json()
+ console.log("Currency API error:", errorData.error)
+ throw new Error(errorData.error || "Failed to fetch currency rate")
+ }
+
+ const data = await response.json()
+ return data.rate
+}
+
export const FormConvertCurrency = ({
originalTotal,
originalCurrencyCode,
@@ -23,27 +39,31 @@ export const FormConvertCurrency = ({
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState(null)
- useEffect(() => {
- const fetchData = async () => {
- try {
- setIsLoading(true)
- setError(null)
+ const fetchAndUpdateRates = async () => {
+ try {
+ setIsLoading(true)
+ setError(null)
- const exchangeRate = await getCurrencyRate(originalCurrencyCode, targetCurrencyCode, normalizedDate)
-
- setExchangeRate(exchangeRate)
- setConvertedTotal(Math.round(originalTotal * exchangeRate * 100) / 100)
- } catch (error) {
- console.error("Error fetching currency rates:", error)
- setExchangeRate(0)
- setConvertedTotal(0)
- setError(error instanceof Error ? error.message : "Failed to fetch currency rate")
- } finally {
- setIsLoading(false)
- }
+ const rate = await getCurrencyRate(originalCurrencyCode, targetCurrencyCode, normalizedDate)
+ setExchangeRate(rate)
+ setConvertedTotal(Math.round(originalTotal * rate * 100) / 100)
+ } catch (error) {
+ console.error("Error fetching currency rates:", error)
+ setExchangeRate(0)
+ setConvertedTotal(0)
+ setError(error instanceof Error ? error.message : "Failed to fetch currency rate")
+ } finally {
+ setIsLoading(false)
}
+ }
- fetchData()
+ const handleRestart = () => {
+ setError(null)
+ fetchAndUpdateRates()
+ }
+
+ useEffect(() => {
+ fetchAndUpdateRates()
}, [originalCurrencyCode, targetCurrencyCode, normalizedDateString, originalTotal])
useEffect(() => {
@@ -82,23 +102,16 @@ export const FormConvertCurrency = ({
{!error && (
The exchange rate will be added to the transaction
)}
- {error && {error} }
+ {error && (
+
+ {error}
+
+ Retry
+
+
+ )}
)}
)
}
-
-async function getCurrencyRate(currencyCodeFrom: string, currencyCodeTo: string, date: Date): Promise
{
- const formattedDate = format(date, "yyyy-MM-dd")
- const response = await fetch(`/api/currency?from=${currencyCodeFrom}&to=${currencyCodeTo}&date=${formattedDate}`)
-
- if (!response.ok) {
- const errorData = await response.json()
- console.log("Currency API error:", errorData.error)
- throw new Error(errorData.error || "Failed to fetch currency rate")
- }
-
- const data = await response.json()
- return data.rate
-}
diff --git a/components/forms/simple.tsx b/components/forms/simple.tsx
index 4556e78..b6a402b 100644
--- a/components/forms/simple.tsx
+++ b/components/forms/simple.tsx
@@ -29,7 +29,11 @@ export function FormInput({ title, hideIfEmpty = false, isRequired = false, ...p
return (
{title && {title} }
-
+
)
}
@@ -70,6 +74,7 @@ export function FormTextarea({ title, hideIfEmpty = false, isRequired = false, .
ref={textareaRef}
{...props}
className={cn("bg-background", isRequired && isEmpty && "bg-yellow-50", props.className)}
+ data-1p-ignore
/>
)
diff --git a/components/transactions/edit.tsx b/components/transactions/edit.tsx
index 8e40d75..c169031 100644
--- a/components/transactions/edit.tsx
+++ b/components/transactions/edit.tsx
@@ -136,30 +136,6 @@ export default function TransactionEditForm({
/>
- {formData.currencyCode !== settings.default_currency || formData.convertedTotal !== 0 ? (
-
-
- {(!formData.convertedCurrencyCode || formData.convertedCurrencyCode !== settings.default_currency) && (
-
- )}
-
- ) : (
- <>>
- )}
-
+ {formData.currencyCode !== settings.default_currency || formData.convertedTotal !== 0 ? (
+ <>
+
+ {(!formData.convertedCurrencyCode || formData.convertedCurrencyCode !== settings.default_currency) && (
+
+ )}
+ >
+ ) : (
+ <>>
+ )}
@@ -195,16 +195,20 @@ export default function TransactionEditForm({
className="h-24"
isRequired={fieldMap.note.isRequired}
/>
- {extraFields.map((field) => (
-
- ))}
+
+
+ {extraFields.map((field) => (
+
+ ))}
+
diff --git a/components/transactions/fields-selector.tsx b/components/transactions/fields-selector.tsx
index 97e12ef..fe6edd2 100644
--- a/components/transactions/fields-selector.tsx
+++ b/components/transactions/fields-selector.tsx
@@ -11,16 +11,16 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Field } from "@/prisma/client"
-import { ColumnsIcon } from "lucide-react"
+import { ColumnsIcon, Loader2 } from "lucide-react"
import { useRouter } from "next/navigation"
import { useState } from "react"
export function ColumnSelector({ fields, onChange }: { fields: Field[]; onChange?: () => void }) {
const router = useRouter()
- const [isLoading, setIsLoading] = useState<{ [key: string]: boolean }>({})
+ const [isLoading, setIsLoading] = useState(false)
const handleToggle = async (fieldCode: string, isCurrentlyVisible: boolean) => {
- setIsLoading((prev) => ({ ...prev, [fieldCode]: true }))
+ setIsLoading(true)
try {
await updateFieldVisibilityAction(fieldCode, !isCurrentlyVisible)
@@ -34,7 +34,7 @@ export function ColumnSelector({ fields, onChange }: { fields: Field[]; onChange
} catch (error) {
console.error("Failed to toggle column visibility:", error)
} finally {
- setIsLoading((prev) => ({ ...prev, [fieldCode]: false }))
+ setIsLoading(false)
}
}
@@ -42,7 +42,7 @@ export function ColumnSelector({ fields, onChange }: { fields: Field[]; onChange
-
+ {isLoading ? : }
@@ -53,10 +53,9 @@ export function ColumnSelector({ fields, onChange }: { fields: Field[]; onChange
key={field.code}
checked={field.isVisibleInList}
onCheckedChange={() => handleToggle(field.code, field.isVisibleInList)}
- disabled={isLoading[field.code]}
+ disabled={isLoading}
>
{field.name}
- {isLoading[field.code] && Saving... }
))}
diff --git a/components/transactions/list.tsx b/components/transactions/list.tsx
index f558271..584e955 100644
--- a/components/transactions/list.tsx
+++ b/components/transactions/list.tsx
@@ -4,7 +4,7 @@ import { BulkActionsMenu } from "@/components/transactions/bulk-actions"
import { Badge } from "@/components/ui/badge"
import { Checkbox } from "@/components/ui/checkbox"
import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "@/components/ui/table"
-import { calcTotalPerCurrency } from "@/lib/stats"
+import { calcTotalPerCurrency, isTransactionIncomplete } from "@/lib/stats"
import { cn, formatCurrency } from "@/lib/utils"
import { Category, Field, Project, Transaction } from "@/prisma/client"
import { formatDate } from "date-fns"
@@ -230,19 +230,6 @@ export function TransactionList({ transactions, fields = [] }: { transactions: T
) : null
}
- // Function to check if a transaction is incomplete
- const isTransactionIncomplete = (transaction: Transaction): boolean => {
- const requiredFields = fields.filter((field) => field.isRequired)
-
- return requiredFields.some((field) => {
- const value = field.isExtra
- ? (transaction.extra as Record)?.[field.code]
- : transaction[field.code as keyof Transaction]
-
- return value === undefined || value === null || value === "" || value === 0
- })
- }
-
return (
@@ -271,7 +258,7 @@ export function TransactionList({ transactions, fields = [] }: { transactions: T
{formData.total != 0 && formData.currencyCode && formData.currencyCode !== settings.default_currency && (
-
+
setFormData((prev) => ({ ...prev, convertedTotal: value }))}
/>
-
+
)}
diff --git a/lib/stats.ts b/lib/stats.ts
index fa0062b..74ed6d6 100644
--- a/lib/stats.ts
+++ b/lib/stats.ts
@@ -1,4 +1,4 @@
-import { Transaction } from "@/prisma/client"
+import { Field, Transaction } from "@/prisma/client"
export function calcTotalPerCurrency(transactions: Transaction[]): Record {
return transactions.reduce(
@@ -15,3 +15,21 @@ export function calcTotalPerCurrency(transactions: Transaction[]): Record
)
}
+
+export const isTransactionIncomplete = (fields: Field[], transaction: Transaction): boolean => {
+ const incompleteFields = incompleteTransactionFields(fields, transaction)
+
+ return incompleteFields.length > 0
+}
+
+export const incompleteTransactionFields = (fields: Field[], transaction: Transaction): Field[] => {
+ const requiredFields = fields.filter((field) => field.isRequired)
+
+ return requiredFields.filter((field) => {
+ const value = field.isExtra
+ ? (transaction.extra as Record)?.[field.code]
+ : transaction[field.code as keyof Transaction]
+
+ return value === undefined || value === null || value === ""
+ })
+}
diff --git a/models/transactions.ts b/models/transactions.ts
index 6e2f72c..f57d8f2 100644
--- a/models/transactions.ts
+++ b/models/transactions.ts
@@ -38,11 +38,11 @@ export const getTransactions = cache(
if (filters) {
if (filters.search) {
where.OR = [
- { name: { contains: filters.search } },
- { merchant: { contains: filters.search } },
- { description: { contains: filters.search } },
- { note: { contains: filters.search } },
- { text: { contains: filters.search } },
+ { name: { contains: filters.search, mode: 'insensitive' } },
+ { merchant: { contains: filters.search, mode: 'insensitive' } },
+ { description: { contains: filters.search, mode: 'insensitive' } },
+ { note: { contains: filters.search, mode: 'insensitive' } },
+ { text: { contains: filters.search, mode: 'insensitive' } },
]
}