Files
payloadcms/packages/ui/src/graphics/Account/index.tsx
Jarrod Flesch 56dec13820 fix: format admin url inside forgot pw email (#11509)
### What?
Supersedes https://github.com/payloadcms/payload/pull/11490.

Refactors imports of `formatAdminURL` to import from `payload/shared`
instead of `@payloadcms/ui/shared`. The ui package now imports and
re-exports the function to prevent this from being a breaking change.

### Why?
This makes it easier for other packages/plugins to consume the
`formatAdminURL` function instead of needing to implement their own or
rely on the ui package for the utility.
2025-03-04 11:55:36 -05:00

34 lines
981 B
TypeScript

'use client'
import { usePathname } from 'next/navigation.js'
import { formatAdminURL } from 'payload/shared'
import React from 'react'
// import { RenderComponent } from '../../elements/RenderComponent/client.js'
import { useAuth } from '../../providers/Auth/index.js'
import { useConfig } from '../../providers/Config/index.js'
import { DefaultAccountIcon } from './Default/index.js'
import { GravatarAccountIcon } from './Gravatar/index.js'
export const Account = () => {
const {
config: {
admin: {
avatar,
routes: { account: accountRoute },
},
routes: { admin: adminRoute },
},
} = useConfig()
const { user } = useAuth()
const pathname = usePathname()
const isOnAccountPage = pathname === formatAdminURL({ adminRoute, path: accountRoute })
if (!user?.email || avatar === 'default') {
return <DefaultAccountIcon active={isOnAccountPage} />
}
if (avatar === 'gravatar') {
return <GravatarAccountIcon />
}
}