Skip to content

πŸ“ˆ Open source, privacy-first web analytics β€” a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Admin panel - add an ability to view feedback attachments

Blue Mouse2220694888ca
diff --git a/backend/apps/cloud/src/admin/admin.controller.ts b/backend/apps/cloud/src/admin/admin.controller.ts
index 9ca7bffa5..e128fc7a6 100644
--- a/backend/apps/cloud/src/admin/admin.controller.ts
+++ b/backend/apps/cloud/src/admin/admin.controller.ts
@@ -25,6 +25,8 @@ const USERS_FILTERS: UsersFilter[] = [
'paid',
'trial',
'free',
+ 'cancelling',
+ 'suspended',
'blocked',
]
diff --git a/backend/apps/cloud/src/admin/admin.service.ts b/backend/apps/cloud/src/admin/admin.service.ts
index ea03a44c7..14d98fdcc 100644
--- a/backend/apps/cloud/src/admin/admin.service.ts
+++ b/backend/apps/cloud/src/admin/admin.service.ts
@@ -225,6 +225,8 @@ export type UsersFilter =
| 'paid'
| 'trial'
| 'free'
+ | 'cancelling'
+ | 'suspended'
| 'blocked'
export type ProjectsFilter =
@@ -1310,6 +1312,10 @@ export class AdminService {
query = query.andWhere('user.planCode IN (:...freePlans)', {
freePlans: [PlanCode.free, PlanCode.none],
})
+ } else if (filter === 'cancelling') {
+ query = query.andWhere('user.cancellationEffectiveDate IS NOT NULL')
+ } else if (filter === 'suspended') {
+ query = query.andWhere('user.isAccountBillingSuspended = true')
} else if (filter === 'blocked') {
query = query.andWhere(
'(user.dashboardBlockReason IS NOT NULL OR user.isAccountBillingSuspended = true)',
diff --git a/web/app/pages/Admin/FeedbackTab.tsx b/web/app/pages/Admin/FeedbackTab.tsx
index 1ab8dd8e4..e202f4041 100644
--- a/web/app/pages/Admin/FeedbackTab.tsx
+++ b/web/app/pages/Admin/FeedbackTab.tsx
@@ -1,10 +1,16 @@
+import { Dialog, DialogBackdrop, DialogPanel } from '@headlessui/react'
import {
ArrowSquareOutIcon,
+ CaretLeftIcon,
+ CaretRightIcon,
FileIcon,
MagnifyingGlassIcon,
+ MagnifyingGlassPlusIcon,
+ XIcon,
} from '@phosphor-icons/react'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
+import { useEffect, useState } from 'react'
import { Link } from 'react-router'
import { Badge } from '~/ui/Badge'
@@ -51,21 +57,165 @@ const attachmentName = (url: string): string => {
}
}
+const ImageLightbox = ({
+ images,
+ index,
+ onClose,
+ onNavigate,
+}: {
+ images: string[]
+ index: number | null
+ onClose: () => void
+ onNavigate: (index: number) => void
+}) => {
+ const [isZoomed, setIsZoomed] = useState(false)
+
+ const isOpened = index !== null
+ const url = isOpened ? images[index] : null
+
+ useEffect(() => {
+ setIsZoomed(false)
+ }, [index])
+
+ useEffect(() => {
+ if (!isOpened) {
+ return undefined
+ }
+
+ const onKeyDown = (event: KeyboardEvent) => {
+ if (event.key === 'ArrowLeft' && index > 0) {
+ onNavigate(index - 1)
+ } else if (event.key === 'ArrowRight' && index < images.length - 1) {
+ onNavigate(index + 1)
+ }
+ }
+
+ window.addEventListener('keydown', onKeyDown)
+ return () => window.removeEventListener('keydown', onKeyDown)
+ }, [isOpened, index, images.length, onNavigate])
+
+ return (
+ <Dialog className='relative z-40' open={isOpened} onClose={onClose}>
+ <DialogBackdrop
+ transition
+ className='fixed inset-0 bg-black/85 backdrop-blur-[2px] transition-opacity duration-200 ease-out-quint data-closed:opacity-0 data-leave:duration-150'
+ />
+
+ <div className='fixed inset-0 z-10 flex flex-col'>
+ <DialogPanel
+ transition
+ className='flex min-h-0 flex-1 flex-col transition-[opacity,transform] duration-200 ease-out-quint data-closed:scale-[0.98] data-closed:opacity-0 data-leave:duration-150'
+ >
+ {index !== null && url ? (
+ <>
+ <div className='flex shrink-0 items-center justify-between gap-4 px-4 py-3'>
+ <span className='truncate text-sm text-gray-300'>
+ {attachmentName(url)}
+ {images.length > 1 ? (
+ <span className='ml-2 text-gray-500 tabular-nums'>
+ {index + 1} / {images.length}
+ </span>
+ ) : null}
+ </span>
+ <div className='flex shrink-0 items-center gap-1'>
+ <a
+ href={url}
+ target='_blank'
+ rel='noopener noreferrer'
+ aria-label='Open original in a new tab'
+ className='rounded-md p-2 text-gray-300 transition-colors hover:bg-white/10 hover:text-white'
+ >
+ <ArrowSquareOutIcon className='size-5' />
+ </a>
+ <button
+ type='button'
+ onClick={onClose}
+ aria-label='Close'
+ className='rounded-md p-2 text-gray-300 transition-colors hover:bg-white/10 hover:text-white'
+ >
+ <XIcon className='size-5' />
+ </button>
+ </div>
+ </div>
+
+ <div
+ role='presentation'
+ className={cn(
+ 'min-h-0 flex-1 overflow-auto',
+ !isZoomed && 'flex items-center justify-center p-4 pt-0',
+ )}
+ onClick={(event) => {
+ if (event.target === event.currentTarget) {
+ onClose()
+ }
+ }}
+ >
+ <button
+ type='button'
+ aria-label={isZoomed ? 'Zoom out' : 'Zoom in'}
+ onClick={() => setIsZoomed((prev) => !prev)}
+ className='group contents'
+ >
+ <img
+ src={url}
+ alt={attachmentName(url)}
+ className={cn(
+ 'group-focus-visible:outline-2 group-focus-visible:outline-indigo-500',
+ isZoomed
+ ? 'mx-auto max-w-none cursor-zoom-out'
+ : 'max-h-full max-w-full cursor-zoom-in object-contain',
+ )}
+ />
+ </button>
+ </div>
+
+ {index > 0 ? (
+ <button
+ type='button'
+ onClick={() => onNavigate(index - 1)}
+ aria-label='Previous image'
+ className='absolute top-1/2 left-3 -translate-y-1/2 rounded-full bg-black/50 p-2.5 text-gray-200 transition-colors hover:bg-black/70 hover:text-white'
+ >
+ <CaretLeftIcon className='size-6' />
+ </button>
+ ) : null}
+ {index < images.length - 1 ? (
+ <button
+ type='button'
+ onClick={() => onNavigate(index + 1)}
+ aria-label='Next image'
+ className='absolute top-1/2 right-3 -translate-y-1/2 rounded-full bg-black/50 p-2.5 text-gray-200 transition-colors hover:bg-black/70 hover:text-white'
+ >
+ <CaretRightIcon className='size-6' />
+ </button>
+ ) : null}
+ </>
+ ) : null}
+ </DialogPanel>
+ </div>
+ </Dialog>
+ )
+}
+
const Attachments = ({ urls }: { urls: string[] }) => {
+ const [lightboxIndex, setLightboxIndex] = useState<number | null>(null)
+
if (urls.length === 0) {
return null
}
+ const imageUrls = urls.filter((url) => IMAGE_EXTENSIONS.test(url))
+
return (
<div className='mt-3 flex flex-wrap gap-2'>
{urls.map((url) =>
IMAGE_EXTENSIONS.test(url) ? (
- <a
+ <button
key={url}
- href={url}
- target='_blank'
- rel='noopener noreferrer'
- className='group relative block overflow-hidden rounded-md ring-1 ring-gray-200 transition-shadow hover:ring-2 hover:ring-indigo-400 dark:ring-slate-700/80'
+ type='button'
+ onClick={() => setLightboxIndex(imageUrls.indexOf(url))}
+ aria-label={`View ${attachmentName(url)}`}
+ className='group relative block cursor-pointer overflow-hidden rounded-md ring-1 ring-gray-200 transition-shadow hover:ring-2 hover:ring-indigo-400 dark:ring-slate-700/80'
>
<img
src={url}
@@ -74,9 +224,9 @@ const Attachments = ({ urls }: { urls: string[] }) => {
className='h-24 w-auto max-w-48 object-cover'
/>
<span className='absolute inset-0 hidden items-center justify-center bg-black/40 group-hover:flex'>
- <ArrowSquareOutIcon className='size-5 text-white' />
+ <MagnifyingGlassPlusIcon className='size-5 text-white' />
</span>
- </a>
+ </button>
) : (
<a
key={url}
@@ -90,6 +240,12 @@ const Attachments = ({ urls }: { urls: string[] }) => {
</a>
),
)}
+ <ImageLightbox
+ images={imageUrls}
+ index={lightboxIndex}
+ onClose={() => setLightboxIndex(null)}
+ onNavigate={setLightboxIndex}
+ />
</div>
)
}
diff --git a/web/app/pages/Admin/OverviewTab.tsx b/web/app/pages/Admin/OverviewTab.tsx
index 6b8588a8c..a15b13431 100644
--- a/web/app/pages/Admin/OverviewTab.tsx
+++ b/web/app/pages/Admin/OverviewTab.tsx
@@ -1,5 +1,6 @@
import dayjs from 'dayjs'
import { motion } from 'motion/react'
+import { Link } from 'react-router'
import {
MetricCard,
@@ -8,7 +9,7 @@ import {
import { Badge } from '~/ui/Badge'
import Select from '~/ui/Select'
import { Text } from '~/ui/Text'
-import { nFormatter, nLocaleFormatter } from '~/utils/generic'
+import { cn, nFormatter, nLocaleFormatter } from '~/utils/generic'
import { AdminChart, ADMIN_CHART_COLORS } from './AdminChart'
import { ChangeBadge, StatCard } from './components'
@@ -107,7 +108,8 @@ const FUNNEL_STAGES: {
]
// Cohort funnel: everyone who signed up in the selected window and how far
-// they got (current state)
+// they got (current state). Layout per stage: label + drop-off note on the
+// left, bar in the middle, count and share on fixed-width no-wrap columns.
const ActivationFunnel = ({
funnel,
chartDays,
@@ -122,55 +124,82 @@ const ActivationFunnel = ({
<Text as='p' size='sm' colour='secondary' className='mt-0.5'>
Users who signed up in the last {chartDays} days, by how far they got
</Text>
- <div className='mt-4 flex flex-col gap-2.5'>
+ <div className='mt-4 flex flex-col'>
{FUNNEL_STAGES.map(({ key, label }, index) => {
const count = funnel[key]
const pctOfSignups =
funnel.signups > 0 ? (count / funnel.signups) * 100 : 0
const prevCount =
index === 0 ? null : funnel[FUNNEL_STAGES[index - 1].key]
- const stepPct =
- prevCount === null
- ? null
- : prevCount > 0
- ? Math.round((count / prevCount) * 100)
- : 0
+ const lost = prevCount === null ? 0 : prevCount - count
+ // "Paying now" is current state, not a strict subset of "sent data",
+ // so it can exceed the previous stage - don't render a negative loss
+ const lostPct =
+ prevCount && lost > 0 ? Math.round((lost / prevCount) * 100) : 0
return (
- <div key={key} className='flex items-center gap-3'>
- <Text as='span' size='sm' className='w-36 shrink-0' truncate>
- {label}
- </Text>
- <div className='h-5 flex-1 overflow-hidden rounded-sm bg-gray-100 dark:bg-slate-800/60'>
- <div
- className='h-full rounded-sm bg-indigo-500 transition-[width] duration-300'
- style={{ width: `${pctOfSignups}%` }}
- />
+ <div key={key}>
+ {index > 0 ? (
+ <div className='py-1 pl-3'>
+ <Text
+ as='span'
+ size='xs'
+ className={cn(
+ 'tabular-nums',
+ lost > 0
+ ? 'text-red-500 dark:text-red-400'
+ : 'text-gray-400 dark:text-gray-500',
+ )}
+ >
+ {lost > 0
+ ? `↓ lost ${nLocaleFormatter(lost)} (${lostPct}%)`
+ : '↓ everyone continued'}
+ </Text>
+ </div>
+ ) : null}
+ <div className='flex items-center gap-4'>
+ <Text
+ as='span'
+ size='sm'
+ weight='medium'
+ className='w-40 shrink-0 whitespace-nowrap'
+ truncate
+ >
+ {label}
+ </Text>
+ <div className='h-7 flex-1 overflow-hidden rounded-md bg-gray-100 dark:bg-slate-800/60'>
+ <div
+ className='flex h-full items-center rounded-md bg-indigo-500 transition-[width] duration-300'
+ style={{ width: `${Math.min(pctOfSignups, 100)}%` }}
+ >
+ {pctOfSignups >= 20 ? (
+ <span className='px-2.5 text-xs font-semibold whitespace-nowrap text-white tabular-nums'>
+ {Math.round(pctOfSignups)}%
+ </span>
+ ) : null}
+ </div>
+ </div>
+ <div className='flex w-28 shrink-0 items-baseline justify-end gap-1.5 whitespace-nowrap'>
+ <Text
+ as='span'
+ size='base'
+ weight='semibold'
+ className='tabular-nums'
+ >
+ {nLocaleFormatter(count)}
+ </Text>
+ {pctOfSignups < 20 ? (
+ <Text
+ as='span'
+ size='xs'
+ colour='secondary'
+ className='tabular-nums'
+ >
+ ({Math.round(pctOfSignups)}%)
+ </Text>
+ ) : null}
+ </div>
</div>
- <Text
- as='span'
- size='sm'
- weight='semibold'
- className='w-14 shrink-0 text-right tabular-nums'
- >
- {nLocaleFormatter(count)}
- </Text>
- <Text
- as='span'
- size='xs'
- colour='secondary'
- className='w-24 shrink-0 text-right tabular-nums'
- >
- {Math.round(pctOfSignups)}% of signups
- </Text>
- <Text
- as='span'
- size='xs'
- colour='secondary'
- className='hidden w-20 shrink-0 text-right tabular-nums sm:block'
- >
- {stepPct === null ? '' : `${stepPct}% of prev`}
- </Text>
</div>
)
})}
@@ -385,23 +414,39 @@ export const OverviewTab = ({
{
label: 'Verified users',
value: nLocaleFormatter(overview.users.active),
+ to: '/admin?tab=users&filter=active',
},
{
label: 'Projects',
value: nLocaleFormatter(overview.projects.total),
+ to: '/admin?tab=projects',
},
{
label: 'Live projects',
value: nLocaleFormatter(overview.projects.live),
+ to: '/admin?tab=projects&filter=active',
},
{
label: 'Organisations',
value: nLocaleFormatter(overview.organisations.total),
+ to: '/admin?tab=organisations',
},
{
label: 'Events (7d)',
value: nFormatter(overview.events.last7d, 1),
},
+ {
+ label: 'Cancelling',
+ value: (
+ <span className='inline-flex items-center gap-2'>
+ {nLocaleFormatter(overview.users.cancelling)}
+ {overview.users.cancelling > 0 ? (
+ <Badge colour='yellow' label='review' />
+ ) : null}
+ </span>
+ ),
+ to: '/admin?tab=users&filter=cancelling',
+ },
{
label: 'Billing suspended',
value: (
@@ -412,26 +457,44 @@ export const OverviewTab = ({
) : null}
</span>
),
+ to: '/admin?tab=users&filter=suspended',
},
- ].map(({ label, value }) => (
- <div key={label}>
- <dt>
- <Text as='span' size='xs' colour='secondary'>
- {label}
- </Text>
- </dt>
- <dd>
- <Text
- as='span'
- size='base'
- weight='semibold'
- className='tabular-nums'
+ ].map(({ label, value, to }) => {
+ const content = (
+ <>
+ <dt>
+ <Text as='span' size='xs' colour='secondary'>
+ {label}
+ </Text>
+ </dt>
+ <dd>
+ <Text
+ as='span'
+ size='base'
+ weight='semibold'
+ className='tabular-nums'
+ >
+ {value}
+ </Text>
+ </dd>
+ </>
+ )
+
+ if (to) {
+ return (
+ <Link
+ key={label}
+ to={to}
+ className='group -m-1.5 rounded-md p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-slate-800/60'
>
- {value}
- </Text>
- </dd>
- </div>
- ))}
+ {content}
+ <span className='sr-only'>View {label}</span>
+ </Link>
+ )
+ }
+
+ return <div key={label}>{content}</div>
+ })}
</dl>
</div>
</div>
diff --git a/web/app/pages/Admin/UsersTab.tsx b/web/app/pages/Admin/UsersTab.tsx
index 7c648e470..c962fd800 100644
--- a/web/app/pages/Admin/UsersTab.tsx
+++ b/web/app/pages/Admin/UsersTab.tsx
@@ -36,6 +36,8 @@ const USER_FILTERS = [
{ key: 'paid', label: 'Paying' },
{ key: 'trial', label: 'Trial' },
{ key: 'free', label: 'Free / none' },
+ { key: 'cancelling', label: 'Cancelling' },
+ { key: 'suspended', label: 'Billing suspended' },
{ key: 'blocked', label: 'Blocked / suspended' },
]
diff --git a/web/app/routes/admin.tsx b/web/app/routes/admin.tsx
index 91b1db216..acdda5a71 100644
--- a/web/app/routes/admin.tsx
+++ b/web/app/routes/admin.tsx
@@ -1,6 +1,7 @@
import { useTranslation } from 'react-i18next'
import type {
ActionFunctionArgs,
+ LinksFunction,
LoaderFunctionArgs,
MetaFunction,
} from 'react-router'
@@ -11,6 +12,10 @@ import { serverFetch } from '~/api/api.server'
import { isSelfhosted } from '~/lib/constants'
import AdminPage from '~/pages/Admin'
import NotFound from '~/pages/NotFound'
+// The billboard.js theming (line widths, axis fonts, dark-mode grid colours)
+// lives in this stylesheet - without it the admin charts render with
+// billboard defaults
+import ProjectViewStyle from '~/styles/ProjectViewStyle.css?url'
import type {
AdminActionData,
AdminBilling,
@@ -33,6 +38,10 @@ import type {
import { getDescription, getTitle } from '~/utils/seo'
import { createHeadersWithCookies, hasAuthTokens } from '~/utils/session.server'
+export const links: LinksFunction = () => [
+ { rel: 'stylesheet', href: ProjectViewStyle },
+]
+
export const meta: MetaFunction<typeof loader> = ({ loaderData: data }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const { t } = useTranslation('common')