Skip to content

Commit

Permalink
feat: fill in current preferences to the settings form
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirazad committed Jun 19, 2024
1 parent 2a08fbb commit 7c82f34
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ export async function setPaperlessToken(token: string) {
}
}

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

export async function getPaperlessDocuments(query: string) {
const user = auth();

Expand Down
6 changes: 6 additions & 0 deletions src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
setFullUserName,
setPaperlessToken,
setPaperlessURL,
getUserPreferences,
} from "../actions";
import { Toaster } from "@/components/ui/sonner";
import { toast } from "sonner";
Expand All @@ -34,6 +35,7 @@ function FullName({
}) {
const { user, isLoaded } = useUser();
const pathname = usePathname();

const formSchema = z.object({
FullName: z.string().min(1, {
message: "Required.",
Expand All @@ -54,6 +56,10 @@ function FullName({
return redirect("/sign-in?redirect=" + pathname);
}

const preferences = async () => {
return await getUserPreferences(user?.id);
};

async function onSubmit(values: z.infer<typeof formSchema>) {
setActiveTab((prevTab) => prevTab + 1); // Increment activeTab
try {
Expand Down

0 comments on commit 7c82f34

Please sign in to comment.