Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

add change password

Bill Yang6ed067f0d18f
diff --git a/client/src/app/globals.css b/client/src/app/globals.css
index 70ddfea47..2802e5175 100644
--- a/client/src/app/globals.css
+++ b/client/src/app/globals.css
@@ -28,11 +28,6 @@ body {
--input: 240 5.9% 90%;
--ring: 240 5.9% 10%;
--radius: 0.3rem;
- --chart-1: 12 76% 61%;
- --chart-2: 173 58% 39%;
- --chart-3: 197 37% 24%;
- --chart-4: 43 74% 66%;
- --chart-5: 27 87% 67%;
/* Slate */
--slate-50: 210 40% 98%;
diff --git a/client/src/app/settings/account/Account.tsx b/client/src/app/settings/account/Account.tsx
new file mode 100644
index 000000000..63651092f
--- /dev/null
+++ b/client/src/app/settings/account/Account.tsx
@@ -0,0 +1,70 @@
+import { authClient } from "@/lib/auth";
+import {
+ Card,
+ CardContent,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+} from "../../../components/ui/card";
+import { Input } from "../../../components/ui/input";
+import { Label } from "../../../components/ui/label";
+import { useState } from "react";
+import { Button } from "../../../components/ui/button";
+import { ChangePassword } from "./ChangePassword";
+
+export function Account({
+ session,
+}: {
+ session: ReturnType<typeof authClient.useSession>;
+}) {
+ const [username, setUsername] = useState(session.data?.user.username ?? "");
+ const [email, setEmail] = useState(session.data?.user.email ?? "");
+
+ const hasChanges =
+ username !== session.data?.user.username ||
+ email !== session.data?.user.email;
+
+ return (
+ <div className="flex flex-col gap-4">
+ <Card className="p-2">
+ <CardHeader>
+ <CardTitle className="text-xl">Account</CardTitle>
+ </CardHeader>
+ <CardContent className="flex flex-col gap-4">
+ <div className="grid w-full items-center gap-1.5">
+ <Label htmlFor="username">Username</Label>
+ <Input
+ className="w-60"
+ id="username"
+ value={username}
+ onChange={({ target }) => setUsername(target.value)}
+ />
+ </div>
+ <div className="grid w-full items-center gap-1.5">
+ <Label htmlFor="email">Email</Label>
+ <Input
+ className="w-60"
+ id="email"
+ type="email"
+ value={email}
+ onChange={({ target }) => setEmail(target.value)}
+ />
+ </div>
+ </CardContent>
+ <CardFooter className="flex justify-end">
+ <Button variant={"accent"} disabled={!hasChanges}>
+ Save Changes
+ </Button>
+ </CardFooter>
+ </Card>
+ <Card className="p-2 pt-6">
+ <CardContent className="flex flex-col gap-4">
+ <ChangePassword />
+ <Button variant={"destructive"} className="w-60">
+ Delete Account
+ </Button>
+ </CardContent>
+ </Card>
+ </div>
+ );
+}
diff --git a/client/src/app/settings/account/ChangePassword.tsx b/client/src/app/settings/account/ChangePassword.tsx
new file mode 100644
index 000000000..44070cce5
--- /dev/null
+++ b/client/src/app/settings/account/ChangePassword.tsx
@@ -0,0 +1,130 @@
+import { useState } from "react";
+import { Button } from "../../../components/ui/button";
+import { authClient } from "../../../lib/auth";
+import {
+ Dialog,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "../../../components/ui/dialog";
+import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
+} from "../../../components/ui/alert";
+import { AlertCircle } from "lucide-react";
+import { Label } from "../../../components/ui/label";
+import { Input } from "../../../components/ui/input";
+
+export function ChangePassword() {
+ const [open, setOpen] = useState(false);
+ const [currentPassword, setCurrentPassword] = useState("");
+ const [newPassword, setNewPassword] = useState("");
+ const [confirmPassword, setConfirmPassword] = useState("");
+ const [error, setError] = useState("");
+
+ const passwordsMatch = newPassword === confirmPassword;
+
+ const handleSubmit = async () => {
+ setError("");
+
+ if (newPassword !== confirmPassword) {
+ setError("New password and confirm password do not match");
+ return;
+ }
+ try {
+ const response = await authClient.changePassword({
+ currentPassword,
+ newPassword,
+ });
+
+ if (response.error) {
+ setError(String(response.error.message));
+ return;
+ }
+
+ setOpen(false);
+ } catch (error) {
+ setError(String(error));
+ }
+ };
+
+ return (
+ <div>
+ <Dialog
+ open={open}
+ onOpenChange={(isOpen) => {
+ setOpen(isOpen);
+ setCurrentPassword("");
+ setNewPassword("");
+ setConfirmPassword("");
+ setError("");
+ }}
+ >
+ <DialogTrigger asChild>
+ <Button>Change Password</Button>
+ </DialogTrigger>
+ <DialogContent className="max-w-lg">
+ <DialogHeader>
+ <DialogTitle>Change Password</DialogTitle>
+ </DialogHeader>
+ <div className="grid w-full items-center gap-1.5">
+ <Label htmlFor="currentPassword">Current Password</Label>
+ <Input
+ value={currentPassword}
+ onChange={(e) => setCurrentPassword(e.target.value)}
+ type="password"
+ />
+ </div>
+ <div className="grid w-full items-center gap-1.5">
+ <Label htmlFor="newPassword">New Password</Label>
+ <Input
+ value={newPassword}
+ onChange={(e) => setNewPassword(e.target.value)}
+ type="password"
+ />
+ </div>
+ <div className="grid w-full items-center gap-1.5">
+ <Label htmlFor="confirmPassword">Confirm Password</Label>
+ <Input
+ value={confirmPassword}
+ onChange={(e) => setConfirmPassword(e.target.value)}
+ type="password"
+ />
+ </div>
+ {error && (
+ <Alert variant="destructive">
+ <AlertCircle className="h-4 w-4" />
+ <AlertTitle>Error Changing Password</AlertTitle>
+ <AlertDescription>{error}</AlertDescription>
+ </Alert>
+ )}
+ <DialogFooter>
+ <Button
+ type="submit"
+ onClick={() => setOpen(false)}
+ variant={"ghost"}
+ >
+ Cancel
+ </Button>
+ <Button
+ type="submit"
+ onClick={handleSubmit}
+ disabled={
+ !currentPassword ||
+ !newPassword ||
+ !confirmPassword ||
+ !passwordsMatch
+ }
+ variant={"warning"}
+ >
+ Change
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </div>
+ );
+}
diff --git a/client/src/app/settings/page.tsx b/client/src/app/settings/page.tsx
index 1312e2c6d..adb22fcd0 100644
--- a/client/src/app/settings/page.tsx
+++ b/client/src/app/settings/page.tsx
@@ -3,14 +3,45 @@
import { Button } from "@/components/ui/button";
import { authClient } from "../../lib/auth";
import { useRouter } from "next/navigation";
+import { useState } from "react";
+import { GearSix, User } from "@phosphor-icons/react";
+
+import { Input } from "../../components/ui/input";
+import { Account } from "./account/Account";
export default function SettingsPage() {
const session = authClient.useSession();
const router = useRouter();
+ const [selectedTab, setSelectedTab] = useState<
+ "account" | "settings" | "users"
+ >("account");
return (
<div className="max-w-6xl">
- <div className="space-y-6">
+ <div className="grid grid-cols-[200px_1fr] gap-6">
+ <div className="flex flex-col gap-2">
+ <Button
+ variant={selectedTab === "account" ? "default" : "ghost"}
+ onClick={() => setSelectedTab("account")}
+ className="justify-start"
+ >
+ <User size={16} weight="bold" />
+ Account
+ </Button>
+ <Button
+ variant={selectedTab === "settings" ? "default" : "ghost"}
+ onClick={() => setSelectedTab("settings")}
+ className="justify-start"
+ >
+ <GearSix size={16} weight="bold" />
+ Settings
+ </Button>
+ </div>
+ {selectedTab === "account" && session.data?.user && (
+ <Account session={session} />
+ )}
+ </div>
+ {/* <div className="space-y-6">
<div>
<h3 className="text-lg font-medium">Settings</h3>
<p className="text-sm text-muted-foreground">
@@ -25,7 +56,18 @@ export default function SettingsPage() {
>
Signout
</Button>
- </div>
+
+ <div className="flex gap-2 flex-col">
+ <Button>Test</Button>
+ <Button variant={"destructive"}>Test</Button>
+ <Button variant={"accent"}>Test</Button>
+ <Button variant={"warning"}>Test</Button>
+ <Button variant={"ghost"}>Test</Button>
+ <Button variant={"link"}>Test</Button>
+ <Button variant={"outline"}>Test</Button>
+ <Button variant={"secondary"}>Test</Button>
+ </div>
+ </div> */}
</div>
);
}
diff --git a/client/src/components/TopBar.tsx b/client/src/components/TopBar.tsx
index dcd1f615b..d86818fcd 100644
--- a/client/src/components/TopBar.tsx
+++ b/client/src/components/TopBar.tsx
@@ -19,7 +19,7 @@ export function TopBar() {
href="/settings"
className="text-neutral-100 flex items-center gap-1"
>
- <GearSix size={18} />
+ <GearSix size={18} weight="bold" />
Settings
</Link>
<ThemeToggle />
diff --git a/client/src/components/ui/button.tsx b/client/src/components/ui/button.tsx
index f328bf4e7..880eddcc8 100644
--- a/client/src/components/ui/button.tsx
+++ b/client/src/components/ui/button.tsx
@@ -5,18 +5,22 @@ import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const buttonVariants = cva(
- "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 dark:focus-visible:ring-neutral-300",
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 dark:focus-visible:ring-neutral-300",
{
variants: {
variant: {
default:
"bg-neutral-50 text-neutral-950 shadow hover:bg-neutral-900/90 dark:bg-neutral-850 dark:text-neutral-50 dark:hover:bg-neutral-700",
+ secondary:
+ "bg-neutral-100 text-neutral-900 shadow-sm hover:bg-neutral-100/80 dark:bg-neutral-50 dark:text-neutral-800 dark:hover:bg-neutral-50/90",
+ accent:
+ "bg-neutral-500 text-neutral-900 shadow-sm hover:bg-neutral-500/80 dark:bg-fuchsia-600 dark:text-neutral-50 dark:hover:bg-fuchsia-600/90",
destructive:
"bg-red-500 text-neutral-50 shadow-sm hover:bg-red-500/90 dark:bg-red-900 dark:text-neutral-50 dark:hover:bg-red-900/90",
+ warning:
+ "bg-yellow-500 text-neutral-900 shadow-sm hover:bg-yellow-500/90 dark:bg-yellow-600 dark:text-neutral-50 dark:hover:bg-yellow-600/90",
outline:
"border border-neutral-200 bg-white shadow-sm hover:bg-neutral-100 hover:text-neutral-900 dark:border-neutral-650 dark:bg-neutral-900 dark:hover:bg-neutral-800 dark:hover:text-neutral-50",
- secondary:
- "bg-neutral-100 text-neutral-900 shadow-sm hover:bg-neutral-100/80 dark:bg-neutral-800 dark:text-neutral-50 dark:hover:bg-neutral-800/80",
ghost:
"hover:bg-neutral-100 hover:text-neutral-900 dark:hover:bg-neutral-800 dark:hover:text-neutral-50",
link: "text-neutral-900 underline-offset-4 hover:underline dark:text-neutral-50",
diff --git a/client/src/components/ui/label.tsx b/client/src/components/ui/label.tsx
index 534182176..0df6941a1 100644
--- a/client/src/components/ui/label.tsx
+++ b/client/src/components/ui/label.tsx
@@ -1,14 +1,14 @@
-"use client"
+"use client";
-import * as React from "react"
-import * as LabelPrimitive from "@radix-ui/react-label"
-import { cva, type VariantProps } from "class-variance-authority"
+import * as React from "react";
+import * as LabelPrimitive from "@radix-ui/react-label";
+import { cva, type VariantProps } from "class-variance-authority";
-import { cn } from "@/lib/utils"
+import { cn } from "@/lib/utils";
const labelVariants = cva(
- "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
-)
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 text-muted-foreground"
+);
const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
@@ -20,7 +20,7 @@ const Label = React.forwardRef<
className={cn(labelVariants(), className)}
{...props}
/>
-))
-Label.displayName = LabelPrimitive.Root.displayName
+));
+Label.displayName = LabelPrimitive.Root.displayName;
-export { Label }
+export { Label };