diff --git a/app/(app)/settings/danger/actions.ts b/app/(app)/settings/danger/actions.ts new file mode 100644 index 0000000..62fd5f5 --- /dev/null +++ b/app/(app)/settings/danger/actions.ts @@ -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") +} diff --git a/app/(app)/settings/danger/page.tsx b/app/(app)/settings/danger/page.tsx new file mode 100644 index 0000000..81964cc --- /dev/null +++ b/app/(app)/settings/danger/page.tsx @@ -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 ( +
+

The Danger Zone

+

+ The settings here will overwrite your existing fields, categories and prompts. Use them only if something is + broken. +

+
+
+

LLM settings

+

+ This will reset the system prompt and other LLM settings to their default values +

+
{ + "use server" + await resetLLMSettings(user) + }} + > + +
+
+
+

Fields, currencies and categories

+

+ This will reset all fields, currencies and categories to their default values +

+
{ + "use server" + await resetFieldsAndCategories(user) + }} + > + +
+
+
+
+ ) +} diff --git a/app/(app)/settings/layout.tsx b/app/(app)/settings/layout.tsx index 6245d62..2f8f996 100644 --- a/app/(app)/settings/layout.tsx +++ b/app/(app)/settings/layout.tsx @@ -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 }) { diff --git a/app/(auth)/cloud/page.tsx b/app/(auth)/cloud/page.tsx index 8c13393..a4c9350 100644 --- a/app/(auth)/cloud/page.tsx +++ b/app/(auth)/cloud/page.tsx @@ -19,7 +19,7 @@ export default async function ChoosePlanPage() { TaxHacker Cloud Edition

Choose your plan

- + {config.auth.disableSignup ? (
Creating new account is disabled for now. Please use the self-hosted version. diff --git a/app/landing/landing.tsx b/app/landing/landing.tsx index bb34ec1..80422fd 100644 --- a/app/landing/landing.tsx +++ b/app/landing/landing.tsx @@ -7,22 +7,22 @@ import Link from "next/link" export default function LandingPage() { return (
-
+
Logo TaxHacker -
+
Log In Sign Up @@ -43,7 +43,7 @@ export default function LandingPage() {

A self-hosted accounting app crafted with love for freelancers and small businesses

-
+