feat: add danger zone to settings

This commit is contained in:
Vasily Zubarev
2025-04-24 21:33:39 +02:00
parent 088d596480
commit 1fe0cc25a7
5 changed files with 120 additions and 6 deletions

View File

@@ -0,0 +1,59 @@
"use server"
import { prisma } from "@/lib/db"
import { DEFAULT_CATEGORIES, DEFAULT_CURRENCIES, DEFAULT_FIELDS, DEFAULT_SETTINGS } from "@/models/defaults"
import { User } from "@prisma/client"
import { redirect } from "next/navigation"
export async function resetLLMSettings(user: User) {
const llmSettings = DEFAULT_SETTINGS.filter((setting) => setting.code === "prompt_analyse_new_file")
for (const setting of llmSettings) {
await prisma.setting.upsert({
where: { userId_code: { code: setting.code, userId: user.id } },
update: { value: setting.value },
create: { ...setting, userId: user.id },
})
}
redirect("/settings/llm")
}
export async function resetFieldsAndCategories(user: User) {
// Reset categories
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 },
})
}
// Reset currencies
for (const currency of DEFAULT_CURRENCIES) {
await prisma.currency.upsert({
where: { userId_code: { code: currency.code, userId: user.id } },
update: { name: currency.name },
create: { ...currency, userId: user.id },
})
}
// Reset fields
for (const field of DEFAULT_FIELDS) {
await prisma.field.upsert({
where: { userId_code: { code: field.code, userId: user.id } },
update: {
name: field.name,
type: field.type,
llm_prompt: field.llm_prompt,
isVisibleInList: field.isVisibleInList,
isVisibleInAnalysis: field.isVisibleInAnalysis,
isRequired: field.isRequired,
isExtra: field.isExtra,
},
create: { ...field, userId: user.id },
})
}
redirect("/settings/fields")
}

View File

@@ -0,0 +1,51 @@
import { Button } from "@/components/ui/button"
import { getCurrentUser } from "@/lib/auth"
import { resetFieldsAndCategories, resetLLMSettings } from "./actions"
export default async function DangerSettingsPage() {
const user = await getCurrentUser()
return (
<div className="container">
<h1 className="text-2xl font-bold mb-2 text-red-500">The Danger Zone</h1>
<p className="text-sm text-red-400 mb-8 max-w-prose">
The settings here will overwrite your existing fields, categories and prompts. Use them only if something is
broken.
</p>
<div className="space-y-10">
<div className="space-y-2">
<h3 className="text-lg font-bold">LLM settings</h3>
<p className="text-sm text-gray-500 mb-6 max-w-prose">
This will reset the system prompt and other LLM settings to their default values
</p>
<form
action={async () => {
"use server"
await resetLLMSettings(user)
}}
>
<Button variant="destructive" type="submit">
Reset main LLM prompt
</Button>
</form>
</div>
<div className="space-y-2">
<h3 className="text-lg font-bold">Fields, currencies and categories</h3>
<p className="text-sm text-gray-500 mb-6 max-w-prose">
This will reset all fields, currencies and categories to their default values
</p>
<form
action={async () => {
"use server"
await resetFieldsAndCategories(user)
}}
>
<Button variant="destructive" type="submit">
Reset fields, currencies and categories
</Button>
</form>
</div>
</div>
</div>
)
}

View File

@@ -40,6 +40,10 @@ const settingsCategories = [
title: "Backups",
href: "/settings/backups",
},
{
title: "Danger Zone",
href: "/settings/danger",
},
]
export default function SettingsLayout({ children }: { children: React.ReactNode }) {

View File

@@ -19,7 +19,7 @@ export default async function ChoosePlanPage() {
<ColoredText>TaxHacker Cloud Edition</ColoredText>
<h2 className="mt-3 text-2xl font-semibold text-muted-foreground">Choose your plan</h2>
</CardTitle>
<CardContent className="w-full">
<CardContent className="p-0 w-full">
{config.auth.disableSignup ? (
<div className="text-center text-md text-muted-foreground">
Creating new account is disabled for now. Please use the self-hosted version.

View File

@@ -7,22 +7,22 @@ import Link from "next/link"
export default function LandingPage() {
return (
<div className="min-h-screen flex flex-col bg-[#FAFAFA]">
<header className="py-6 px-8 bg-white/80 backdrop-blur-md shadow-sm fixed w-full z-10">
<header className="py-6 px-4 md:px-8 bg-white/80 backdrop-blur-md shadow-sm fixed w-full z-10">
<div className="max-w-7xl mx-auto flex justify-between items-center">
<Link href="/" className="flex items-center gap-2">
<Image src="/logo/256.png" alt="Logo" width={32} height={32} className="h-8" />
<ColoredText className="text-2xl font-bold">TaxHacker</ColoredText>
</Link>
<div className="flex gap-4">
<div className="flex gap-1 md:gap-4 text-xs md:text-sm">
<Link
href="/enter"
className="text-sm font-medium px-4 py-2 rounded-full border border-gray-200 hover:bg-gray-50 transition-all"
className="font-medium px-4 py-2 rounded-full border border-gray-200 hover:bg-gray-50 transition-all"
>
Log In
</Link>
<Link
href="/cloud"
className="text-sm font-medium bg-gradient-to-r from-blue-600 to-indigo-600 text-white px-4 py-2 rounded-full hover:opacity-90 transition-all"
className="font-medium bg-gradient-to-r from-blue-600 to-indigo-600 text-white px-4 py-2 rounded-full hover:opacity-90 transition-all"
>
Sign Up
</Link>
@@ -43,7 +43,7 @@ export default function LandingPage() {
<p className="text-xl text-gray-600 mb-8 max-w-2xl mx-auto">
A self-hosted accounting app crafted with love for freelancers and small businesses
</p>
<div className="flex gap-4 justify-center">
<div className="flex gap-4 justify-center text-sm md:text-lg">
<Link
href="#start"
className="px-8 py-3 bg-gradient-to-r from-blue-600 to-indigo-600 text-white font-medium rounded-full hover:opacity-90 transition-all shadow-lg shadow-blue-500/20"