From 4f5fc2b577fbe8eaecaf9b1641fe0c9f9a2633bb Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Sat, 7 Sep 2024 16:12:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Use=20profile=20image=20from=20oaut?= =?UTF-8?q?h=20provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/declarations/next-auth.d.ts | 4 +- apps/web/src/app/[locale]/(admin)/sidebar.tsx | 2 +- .../src/components/current-user-avatar.tsx | 14 ++++++ .../components/settings/profile-settings.tsx | 8 ++- apps/web/src/components/user-dropdown.tsx | 4 +- apps/web/src/components/user-provider.tsx | 4 +- apps/web/src/components/user.tsx | 16 ------ apps/web/src/utils/auth.ts | 4 ++ packages/ui/package.json | 1 + packages/ui/src/avatar.tsx | 50 +++++++++++++++++++ packages/ui/src/command.tsx | 2 +- packages/ui/tsconfig.json | 5 ++ yarn.lock | 10 ++++ 13 files changed, 95 insertions(+), 29 deletions(-) create mode 100644 apps/web/src/components/current-user-avatar.tsx create mode 100644 packages/ui/src/avatar.tsx diff --git a/apps/web/declarations/next-auth.d.ts b/apps/web/declarations/next-auth.d.ts index 42e5183c45b..eb7f8cb8989 100644 --- a/apps/web/declarations/next-auth.d.ts +++ b/apps/web/declarations/next-auth.d.ts @@ -11,13 +11,11 @@ declare module "next-auth" { interface Session { user: { id: string; - name?: string | null; - email?: string | null; timeZone?: string | null; timeFormat?: TimeFormat | null; locale?: string | null; weekStart?: number | null; - }; + } & DefaultSession["user"]; } interface User extends DefaultUser { diff --git a/apps/web/src/app/[locale]/(admin)/sidebar.tsx b/apps/web/src/app/[locale]/(admin)/sidebar.tsx index 056362422dc..35647c8302e 100644 --- a/apps/web/src/app/[locale]/(admin)/sidebar.tsx +++ b/apps/web/src/app/[locale]/(admin)/sidebar.tsx @@ -18,9 +18,9 @@ import { import Link from "next/link"; import { usePathname } from "next/navigation"; +import { CurrentUserAvatar } from "@/components/current-user-avatar"; import { ProBadge } from "@/components/pro-badge"; import { Trans } from "@/components/trans"; -import { CurrentUserAvatar } from "@/components/user"; import { IfGuest, useUser } from "@/components/user-provider"; import { IfFreeUser } from "@/contexts/plan"; import { IconComponent } from "@/types"; diff --git a/apps/web/src/components/current-user-avatar.tsx b/apps/web/src/components/current-user-avatar.tsx new file mode 100644 index 00000000000..ed8c9902a96 --- /dev/null +++ b/apps/web/src/components/current-user-avatar.tsx @@ -0,0 +1,14 @@ +"use client"; +import { Avatar, AvatarFallback, AvatarImage } from "@rallly/ui/avatar"; + +import { useUser } from "@/components/user-provider"; + +export const CurrentUserAvatar = ({ className }: { className?: string }) => { + const { user } = useUser(); + return ( + + + {user.name[0]} + + ); +}; diff --git a/apps/web/src/components/settings/profile-settings.tsx b/apps/web/src/components/settings/profile-settings.tsx index 428603b0db8..3148082a21d 100644 --- a/apps/web/src/components/settings/profile-settings.tsx +++ b/apps/web/src/components/settings/profile-settings.tsx @@ -9,8 +9,8 @@ import { import { Input } from "@rallly/ui/input"; import { useForm } from "react-hook-form"; +import { CurrentUserAvatar } from "@/components/current-user-avatar"; import { Trans } from "@/components/trans"; -import { UserAvatar } from "@/components/user"; import { useUser } from "@/components/user-provider"; export const ProfileSettings = () => { @@ -26,9 +26,7 @@ export const ProfileSettings = () => { }, }); - const { control, watch, handleSubmit, formState, reset } = form; - - const watchName = watch("name"); + const { control, handleSubmit, formState, reset } = form; return (
@@ -41,7 +39,7 @@ export const ProfileSettings = () => { >
- +
{ className={cn("group min-w-0", className)} >