fix: restore from backup, restart button for tools, loader for fields

This commit is contained in:
vas3k
2025-05-20 20:37:26 +02:00
parent 4b3c62c9eb
commit c352f5eadd
18 changed files with 172 additions and 118 deletions

View File

@@ -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..."

View File

@@ -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")
}

View File

@@ -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 (
<div className="flex flex-wrap flex-row items-start justify-center gap-4 max-w-6xl">
<Card className="w-full flex-1 flex flex-col flex-wrap justify-center items-start gap-10 p-5 bg-accent">
<div className="w-full">
<Card className="w-full flex-1 flex flex-col flex-wrap justify-center items-start overflow-hidden">
{incompleteFields.length > 0 && (
<div className="w-full flex flex-col gap-1 rounded-md bg-yellow-50 p-5">
<span>
Some fields are incomplete: <strong>{incompleteFields.map((field) => field.name).join(", ")}</strong>
</span>
<span className="text-xs text-muted-foreground">
You can decide which fields are required for you in{" "}
<Link href="/settings/fields" className="underline">
Fields settings
</Link>
.
</span>
</div>
)}
<div className="w-full p-5 bg-accent">
<TransactionEditForm
transaction={transaction}
categories={categories}

View File

@@ -1,6 +1,6 @@
import { Button } from "@/components/ui/button"
import { Skeleton } from "@/components/ui/skeleton"
import { Download, Plus } from "lucide-react"
import { Download, Loader2, Plus } from "lucide-react"
export default function Loading() {
return (
@@ -8,7 +8,7 @@ export default function Loading() {
<header className="flex items-center justify-between mb-12">
<h2 className="flex flex-row gap-3 md:gap-5">
<span className="text-3xl font-bold tracking-tight">Transactions</span>
<Skeleton className="h-10 w-16" />
<Loader2 className="h-10 w-10 animate-spin" />
</h2>
<div className="flex gap-2">
<Button variant="outline">

View File

@@ -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<TransactionFilters> }) {
const { page, ...filters } = await searchParams

View File

@@ -1,3 +0,0 @@
export default function UnsortedLayout({ children }: { children: React.ReactNode }) {
return <div className="flex flex-col gap-4 p-4 max-w-6xl">{children}</div>
}

View File

@@ -3,10 +3,11 @@ import { Loader2 } from "lucide-react"
export default function Loading() {
return (
<div className="flex flex-col gap-4">
<div className="flex flex-col gap-4 p-4 w-full max-w-6xl">
<header className="flex items-center justify-between">
<h2 className="text-3xl font-bold tracking-tight flex flex-row gap-2">
<Loader2 className="h-10 w-10 animate-spin" /> <span>Loading unsorted files...</span>
<span>Loading unsorted files...</span>
<Loader2 className="h-10 w-10 animate-spin" />
</h2>
</header>

View File

@@ -31,7 +31,7 @@ export default async function UnsortedPage() {
const settings = await getSettings(user.id)
return (
<>
<div className="flex flex-col gap-4 p-4 w-full max-w-6xl">
<header className="flex items-center justify-between">
<h2 className="text-3xl font-bold tracking-tight">You have {files.length} unsorted files</h2>
</header>
@@ -101,6 +101,6 @@ export default async function UnsortedPage() {
</div>
)}
</main>
</>
</div>
)
}