diff --git a/.gitignore b/.gitignore index 90a4241..c5b735c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ node_modules /public/build /prisma/dev.db +/prisma/dev.db-journal .env /app/tailwind.css diff --git a/app/routes/account.tsx b/app/routes/account.tsx index e69de29..d0dc13b 100644 --- a/app/routes/account.tsx +++ b/app/routes/account.tsx @@ -0,0 +1,195 @@ +import type { User, Team } from "@prisma/client"; +import { useEffect, useState } from "react"; +import type { LinksFunction, LoaderFunction } from "remix"; +import { useLoaderData, Form, redirect, useCatch } from "remix"; +import { getUser } from "~/utils/session.server"; +import Header from "../components/Header"; + +export const links: LinksFunction = () => { + return []; +}; + +type LoaderData = { + user: (User & { team: Team & { members: User[] } }) | null; +}; + +export const loader: LoaderFunction = async ({ request }) => { + const user = await getUser(request); + if (!user?.id) { + return redirect("/login"); + } + + const data: LoaderData = { + user, + }; + return data; +}; + +const themes = [ + "light", + "dark", + "cupcake", + "bumblebee", + "emerald", + "corporate", + "synthwave", + "retro", + "cyberpunk", + "valentine", +]; + +export default function ExpensesRoute() { + const data = useLoaderData(); + const [activeTab, setActiveTab] = useState<"preferences" | "manage">( + "preferences" + ); + const [activeTheme, setActiveTheme] = useState(data.user?.theme || "dark"); + useEffect(() => { + document?.querySelector("html")?.setAttribute("data-theme", activeTheme); + }, [activeTheme]); + + return ( + <> +
+
+
+

Account

+
+ + +
+ +
+
+
+

+ Theme +

+ {themes.map((theme) => ( +
+ +
+ ))} +
+
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+ +
+
+
+
+ + ); +} + +export function CatchBoundary() { + const caught = useCatch(); + + if (caught.status === 401) { + return redirect("/login"); + } + if (caught.status === 404) { + return ( +
There are no expenses to display.
+ ); + } + throw new Error(`Unexpected caught response with status: ${caught.status}`); +} + +export function ErrorBoundary() { + return
I did a whoopsies.
; +} diff --git a/prisma/migrations/20220214095543_theme/migration.sql b/prisma/migrations/20220214095543_theme/migration.sql new file mode 100644 index 0000000..bac37a6 --- /dev/null +++ b/prisma/migrations/20220214095543_theme/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "theme" TEXT; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0556679..dc54bd2 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -27,6 +27,7 @@ model User { teamId String team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) expenses Expense[] + theme String? } model Expense { diff --git a/prisma/seed.ts b/prisma/seed.ts index 964ae91..cd3e8f6 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -16,6 +16,7 @@ async function seed() { "$2b$10$K7L1OJ45/4Y2nIvhRVpCe.FSmhDdWoXehVzJptJ/op0lSsvqNu/1u", teamId: famiglia.id, icon: "🧑‍💻", + theme: "dark", }, }); const shahra = await db.user.create({ @@ -25,6 +26,7 @@ async function seed() { "$2b$10$K7L1OJ45/4Y2nIvhRVpCe.FSmhDdWoXehVzJptJ/op0lSsvqNu/1u", teamId: famiglia.id, icon: "💃", + theme: "emerald", }, });