From 8f00885d7066cb8eae2caee49b32face16218ccc Mon Sep 17 00:00:00 2001 From: Aamir Azad Date: Tue, 18 Jun 2024 18:02:28 +0530 Subject: [PATCH] feat: fill in current preferences to the settings form --- src/app/actions.ts | 10 ++++++++++ src/app/settings/page.tsx | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/app/actions.ts b/src/app/actions.ts index 6a31c59..e8073c2 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -39,3 +39,13 @@ export async function setPaperlessToken(token: string, userId: string) { throw new Error("Database error"); } } + +export async function getUserPreferences(userId: string) { + try { + await db.query.users.findFirst({ + where: (model, { eq }) => eq(model.userId, userId), + }); + } catch { + throw new Error("Database error"); + } +} diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx index c8c7f17..4395c7d 100644 --- a/src/app/settings/page.tsx +++ b/src/app/settings/page.tsx @@ -22,6 +22,7 @@ import { setFullUserName, setPaperlessToken, setPaperlessURL, + getUserPreferences, } from "../actions"; import { Toaster } from "@/components/ui/sonner"; import { toast } from "sonner"; @@ -33,6 +34,7 @@ function FullName({ }) { const { user, isLoaded } = useUser(); const pathname = usePathname(); + const formSchema = z.object({ FullName: z.string().min(1, { message: "Required.", @@ -53,6 +55,10 @@ function FullName({ return redirect("/sign-in?redirect=" + pathname); } + const preferences = async () => { + return await getUserPreferences(user?.id); + }; + async function onSubmit(values: z.infer) { setActiveTab((prevTab) => prevTab + 1); // Increment activeTab try {