2024-04-19 05:16:11 -05:00
|
|
|
import useLocalSettingsStore from "@/store/localSettings";
|
|
|
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
|
|
|
import ProfilePhoto from "./ProfilePhoto";
|
|
|
|
import Link from "next/link";
|
|
|
|
import { signOut } from "next-auth/react";
|
2024-06-09 08:27:16 -05:00
|
|
|
import { useTranslation } from "next-i18next";
|
2024-07-31 13:15:50 -05:00
|
|
|
import { useUser } from "@/hooks/store/user";
|
2024-04-19 05:16:11 -05:00
|
|
|
|
|
|
|
export default function ProfileDropdown() {
|
2024-06-09 08:27:16 -05:00
|
|
|
const { t } = useTranslation();
|
2024-04-19 05:16:11 -05:00
|
|
|
const { settings, updateSettings } = useLocalSettingsStore();
|
2024-08-01 17:40:08 -05:00
|
|
|
const { data: user } = useUser();
|
2024-04-19 05:16:11 -05:00
|
|
|
|
2024-07-30 22:19:29 -05:00
|
|
|
const isAdmin = user.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1);
|
2024-07-03 16:29:33 -05:00
|
|
|
|
2024-04-19 05:16:11 -05:00
|
|
|
const handleToggle = () => {
|
2024-06-09 08:27:16 -05:00
|
|
|
const newTheme = settings.theme === "dark" ? "light" : "dark";
|
|
|
|
updateSettings({ theme: newTheme });
|
2024-04-19 05:16:11 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="dropdown dropdown-end">
|
|
|
|
<div
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
onMouseDown={dropdownTriggerer}
|
|
|
|
className="btn btn-circle btn-ghost"
|
|
|
|
>
|
|
|
|
<ProfilePhoto
|
2024-07-30 22:19:29 -05:00
|
|
|
src={user.image ? user.image : undefined}
|
2024-04-19 05:16:11 -05:00
|
|
|
priority={true}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-07-03 16:29:33 -05:00
|
|
|
<ul
|
|
|
|
className={`dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box ${
|
|
|
|
isAdmin ? "w-48" : "w-40"
|
|
|
|
} mt-1`}
|
|
|
|
>
|
2024-04-19 05:16:11 -05:00
|
|
|
<li>
|
|
|
|
<Link
|
|
|
|
href="/settings/account"
|
|
|
|
onClick={() => (document?.activeElement as HTMLElement)?.blur()}
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
2024-06-09 08:27:16 -05:00
|
|
|
{t("settings")}
|
2024-04-19 05:16:11 -05:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
<li className="block sm:hidden">
|
|
|
|
<div
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
handleToggle();
|
|
|
|
}}
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
2024-06-09 08:27:16 -05:00
|
|
|
{t("switch_to", {
|
|
|
|
theme: settings.theme === "light" ? t("dark") : t("light"),
|
|
|
|
})}
|
2024-04-19 05:16:11 -05:00
|
|
|
</div>
|
|
|
|
</li>
|
2024-07-03 16:29:33 -05:00
|
|
|
{isAdmin ? (
|
|
|
|
<li>
|
|
|
|
<Link
|
|
|
|
href="/admin"
|
|
|
|
onClick={() => (document?.activeElement as HTMLElement)?.blur()}
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
|
|
|
{t("server_administration")}
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
) : null}
|
2024-04-19 05:16:11 -05:00
|
|
|
<li>
|
|
|
|
<div
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
signOut();
|
|
|
|
}}
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
2024-06-09 08:27:16 -05:00
|
|
|
{t("logout")}
|
2024-04-19 05:16:11 -05:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|