Files
sign/apps/web/components/settings.tsx

197 lines
7.1 KiB
TypeScript
Raw Normal View History

2023-01-25 13:24:40 +01:00
import { ChangeEvent, useEffect, useState } from "react";
2023-01-04 16:28:32 +01:00
import Head from "next/head";
2023-04-04 22:02:32 +00:00
import Link from "next/link";
import { useRouter } from "next/router";
2023-01-25 13:22:47 +01:00
import { updateUser } from "@documenso/features";
2023-03-01 15:11:08 +01:00
import { getUser } from "@documenso/lib/api";
2023-04-04 22:02:32 +00:00
import { Button } from "@documenso/ui";
import { KeyIcon, UserCircleIcon } from "@heroicons/react/24/outline";
import { useSession } from "next-auth/react";
2022-12-06 18:49:38 +01:00
const subNavigation = [
2023-01-04 15:04:28 +01:00
{
name: "Profile",
href: "/settings/profile",
icon: UserCircleIcon,
current: true,
},
{
name: "Password",
href: "/settings/password",
icon: KeyIcon,
current: false,
},
2022-12-06 18:49:38 +01:00
];
function classNames(...classes: any) {
return classes.filter(Boolean).join(" ");
}
export default function Setttings() {
2023-01-19 14:13:21 +01:00
const session = useSession();
2023-01-25 13:22:47 +01:00
const [user, setUser] = useState({
email: "",
name: "",
});
useEffect(() => {
2023-03-01 15:11:08 +01:00
getUser().then((res: any) => {
res.json().then((j: any) => {
2023-01-25 13:22:47 +01:00
setUser(j);
});
});
}, [session]);
2022-12-06 18:49:38 +01:00
2023-01-04 15:04:28 +01:00
const router = useRouter();
subNavigation.forEach((element) => {
element.current = element.href == router.route;
});
2023-01-25 13:22:47 +01:00
const [savingTimeout, setSavingTimeout] = useState<any>();
function handleNameChange(e: ChangeEvent<HTMLInputElement>): void {
let u = { ...user };
u.name = e.target.value;
setUser(u);
clearTimeout(savingTimeout);
const t = setTimeout(() => {
updateUser(u);
}, 1000);
setSavingTimeout(t);
}
const handleKeyPress = (event: any) => {
if (event.key === "Enter") {
clearTimeout(savingTimeout);
updateUser(user);
}
};
2022-12-06 18:49:38 +01:00
return (
<div>
2023-01-04 16:28:32 +01:00
<Head>
<title>Settings | Documenso</title>
</Head>
2022-12-06 19:45:18 +01:00
<header className="py-10">
<div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
2023-04-04 22:02:32 +00:00
<h1 className="text-brown text-3xl font-bold leading-tight tracking-tight">Settings</h1>
2022-12-06 19:45:18 +01:00
</div>
</header>
2023-04-04 22:10:30 +00:00
<div
className="mx-auto max-w-screen-xl px-4 pb-6 sm:px-6 lg:px-8 lg:pb-16"
hidden={!user.email}>
2022-12-06 18:49:38 +01:00
<div className="overflow-hidden rounded-lg bg-white shadow">
<div className="divide-y divide-gray-200 lg:grid lg:grid-cols-12 lg:divide-y-0 lg:divide-x">
<aside className="py-6 lg:col-span-3">
<nav className="space-y-1">
{subNavigation.map((item) => (
2023-01-04 15:04:28 +01:00
<Link
2022-12-06 18:49:38 +01:00
key={item.name}
href={item.href}
className={classNames(
item.current
2023-04-04 22:02:32 +00:00
? "border-neon-dark bg-teal-50 text-teal-700 hover:bg-teal-50 hover:text-teal-700"
2022-12-06 18:49:38 +01:00
: "border-transparent text-gray-900 hover:bg-gray-50 hover:text-gray-900",
2023-04-04 22:02:32 +00:00
"group flex items-center border-l-4 px-3 py-2 text-sm font-medium"
2022-12-06 18:49:38 +01:00
)}
2023-04-04 22:02:32 +00:00
aria-current={item.current ? "page" : undefined}>
2022-12-06 18:49:38 +01:00
<item.icon
className={classNames(
item.current
? "text-teal-500 group-hover:text-teal-500"
: "text-gray-400 group-hover:text-gray-500",
2023-04-04 22:02:32 +00:00
"-ml-1 mr-3 h-6 w-6 flex-shrink-0"
2022-12-06 18:49:38 +01:00
)}
aria-hidden="true"
/>
<span className="truncate">{item.name}</span>
2023-01-04 15:04:28 +01:00
</Link>
2022-12-06 18:49:38 +01:00
))}
</nav>
</aside>
<form
2023-04-04 22:02:32 +00:00
className="min-h-[251px] divide-y divide-gray-200 lg:col-span-9"
2022-12-06 18:49:38 +01:00
action="#"
method="POST"
2023-04-04 22:02:32 +00:00
hidden={subNavigation.filter((e) => e.current)[0]?.name !== subNavigation[0].name}>
2022-12-06 18:49:38 +01:00
{/* Profile section */}
<div className="py-6 px-4 sm:p-6 lg:pb-8">
<div>
2023-04-04 22:02:32 +00:00
<h2 className="text-lg font-medium leading-6 text-gray-900">Profile</h2>
2022-12-06 18:49:38 +01:00
<p className="mt-1 text-sm text-gray-500">
2023-01-04 14:41:10 +01:00
Let people know who they are dealing with builds trust.
2022-12-06 18:49:38 +01:00
</p>
</div>
2023-02-02 15:04:22 +01:00
<div className="my-6 grid grid-cols-12 gap-6">
2022-12-06 18:49:38 +01:00
<div className="col-span-12 sm:col-span-6">
2023-04-04 22:02:32 +00:00
<label htmlFor="first-name" className="block text-sm font-medium text-gray-700">
2023-01-12 13:21:32 +01:00
Full Name
2022-12-06 18:49:38 +01:00
</label>
<input
type="text"
name="first-name"
id="first-name"
2023-01-19 14:13:21 +01:00
value={user?.name || ""}
2023-01-25 13:22:47 +01:00
onChange={(e) => handleNameChange(e)}
onKeyDown={handleKeyPress}
2022-12-06 18:49:38 +01:00
autoComplete="given-name"
2023-04-04 22:02:32 +00:00
className="focus:border-neon focus:ring-neon mt-1 block w-full rounded-md border border-gray-300 py-2 px-3 shadow-sm focus:outline-none sm:text-sm"
2022-12-06 18:49:38 +01:00
/>
</div>
<div className="col-span-12 sm:col-span-6">
2023-04-04 22:02:32 +00:00
<label htmlFor="first-name" className="block text-sm font-medium text-gray-700">
2023-01-12 13:21:32 +01:00
Email
2022-12-06 18:49:38 +01:00
</label>
<input
2023-01-12 13:21:32 +01:00
disabled
2023-01-19 14:18:04 +01:00
value={user?.email!}
2022-12-06 18:49:38 +01:00
type="text"
2023-01-12 13:21:32 +01:00
name="first-name"
id="first-name"
autoComplete="given-name"
2023-04-04 22:02:32 +00:00
className="focus:border-neon focus:ring-neon mt-1 block w-full rounded-md border border-gray-300 py-2 px-3 shadow-sm focus:outline-none disabled:bg-neutral-100 sm:text-sm"
2022-12-06 18:49:38 +01:00
/>
</div>
</div>
2023-02-02 15:04:22 +01:00
<Button onClick={() => updateUser(user)}>Save</Button>
2022-12-06 18:49:38 +01:00
</div>
</form>
2023-03-19 12:31:54 +01:00
<div
2023-04-04 22:02:32 +00:00
hidden={subNavigation.filter((e) => e.current)[0]?.name !== subNavigation[1].name}
className="min-h-[251px] divide-y divide-gray-200 lg:col-span-9">
2023-03-19 12:31:54 +01:00
{/* Passwords section */}
<div className="py-6 px-4 sm:p-6 lg:pb-8">
<div>
2023-04-04 22:02:32 +00:00
<h2 className="text-lg font-medium leading-6 text-gray-900">Password</h2>
2023-03-19 12:31:54 +01:00
<p className="mt-1 text-sm text-gray-500">
2023-04-04 22:02:32 +00:00
Forgot your passwort? Email <b>hi@documenso.com</b> to reset it.
2023-03-19 12:31:54 +01:00
</p>
</div>
</div>
</div>
2022-12-06 18:49:38 +01:00
</div>
</div>
</div>
2023-01-25 13:24:40 +01:00
<div className="mt-10 max-w-[1100px]" hidden={!!user.email}>
<div className="ph-item">
<div className="ph-col-12">
<div className="ph-picture"></div>
<div className="ph-row">
<div className="ph-col-6 big"></div>
<div className="ph-col-4 empty big"></div>
<div className="ph-col-2 big"></div>
<div className="ph-col-4"></div>
<div className="ph-col-8 empty"></div>
<div className="ph-col-6"></div>
<div className="ph-col-6 empty"></div>
<div className="ph-col-12"></div>
</div>
</div>
</div>
</div>
2022-12-06 18:49:38 +01:00
</div>
);
}