Add global admin user-view preview
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { authFetch, clearToken, getApiBase, getToken } from '../../lib/auth'
|
||||
import { useUserViewPreview } from '../../lib/viewMode'
|
||||
|
||||
type ProfileInfo = {
|
||||
username: string
|
||||
@@ -97,7 +98,7 @@ export default function ProfileInvitesPage() {
|
||||
const [inviteManagedByMaster, setInviteManagedByMaster] = useState(false)
|
||||
const [masterInviteTemplate, setMasterInviteTemplate] = useState<OwnedInvitesResponse['master_invite']>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [viewAsUser, setViewAsUser] = useState(false)
|
||||
const viewAsUser = useUserViewPreview()
|
||||
|
||||
const signupBaseUrl = useMemo(() => {
|
||||
if (typeof window === 'undefined') return '/signup'
|
||||
@@ -136,7 +137,6 @@ export default function ProfileInvitesPage() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setViewAsUser(new URLSearchParams(window.location.search).get('view') === 'user')
|
||||
if (!getToken()) {
|
||||
router.push('/login')
|
||||
return
|
||||
@@ -309,11 +309,6 @@ export default function ProfileInvitesPage() {
|
||||
|
||||
const canManageInvites = profile?.role === 'admin' || inviteAccessEnabled
|
||||
|
||||
const enterUserView = () => {
|
||||
setViewAsUser(true)
|
||||
router.replace('/profile/invites?view=user')
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <main className="card">Loading invite tools...</main>
|
||||
}
|
||||
@@ -330,16 +325,6 @@ export default function ProfileInvitesPage() {
|
||||
</p>
|
||||
</div>
|
||||
<div className="admin-inline-actions">
|
||||
{profile?.role === 'admin' && !viewAsUser ? (
|
||||
<button type="button" className="ghost-button" onClick={enterUserView}>
|
||||
View as user
|
||||
</button>
|
||||
) : null}
|
||||
{profile?.role === 'admin' && viewAsUser ? (
|
||||
<button type="button" onClick={() => router.push('/admin/invites')}>
|
||||
Return to admin view
|
||||
</button>
|
||||
) : null}
|
||||
<button type="button" className="ghost-button" onClick={() => router.push('/profile')}>
|
||||
Back to profile
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user