diff --git a/src/app/(main)/SideNav.tsx b/src/app/(main)/SideNav.tsx index aadf8670f..55ff27cd1 100644 --- a/src/app/(main)/SideNav.tsx +++ b/src/app/(main)/SideNav.tsx @@ -10,6 +10,7 @@ import { TooltipTrigger, } from '@umami/react-zen'; import Link from 'next/link'; +import { AdminNav } from '@/app/(main)/admin/AdminNav'; import { SettingsNav } from '@/app/(main)/settings/SettingsNav'; import { WebsiteNav } from '@/app/(main)/websites/[websiteId]/WebsiteNav'; import { IconLabel } from '@/components/common/IconLabel'; @@ -103,6 +104,8 @@ export function SideNav(props: any) { ) : pathname.includes('/settings') ? ( + ) : pathname.includes('/admin') ? ( + ) : ( {links.map(({ id, path, label, icon }) => { diff --git a/src/app/(main)/admin/AdminLayout.tsx b/src/app/(main)/admin/AdminLayout.tsx index 681ba3f03..92d316ac5 100644 --- a/src/app/(main)/admin/AdminLayout.tsx +++ b/src/app/(main)/admin/AdminLayout.tsx @@ -1,9 +1,7 @@ 'use client'; -import { Column, Grid } from '@umami/react-zen'; import type { ReactNode } from 'react'; import { PageBody } from '@/components/common/PageBody'; import { useLoginQuery } from '@/components/hooks'; -import { AdminNav } from './AdminNav'; export function AdminLayout({ children }: { children: ReactNode }) { const { user } = useLoginQuery(); @@ -12,21 +10,5 @@ export function AdminLayout({ children }: { children: ReactNode }) { return null; } - return ( - - - - - - {children} - - - ); + return {children}; } diff --git a/src/app/(main)/admin/AdminNav.tsx b/src/app/(main)/admin/AdminNav.tsx index edcfb4c62..064305cfa 100644 --- a/src/app/(main)/admin/AdminNav.tsx +++ b/src/app/(main)/admin/AdminNav.tsx @@ -1,9 +1,9 @@ -import { Column, Focusable, Row, Tooltip, TooltipTrigger } from '@umami/react-zen'; -import Link from 'next/link'; import { IconLabel } from '@/components/common/IconLabel'; import { NavMenu } from '@/components/common/NavMenu'; import { useMessages, useNavigation } from '@/components/hooks'; import { ArrowLeft, Globe, User, Users } from '@/components/icons'; +import { Column, Focusable, Row, Tooltip, TooltipTrigger } from '@umami/react-zen'; +import Link from 'next/link'; export function AdminNav({ onItemClick }: { onItemClick?: () => void }) { const { t, labels } = useMessages(); @@ -41,7 +41,7 @@ export function AdminNav({ onItemClick }: { onItemClick?: () => void }) { return ( - + void }) { - {type === 'pixel' ? : type === 'link' ? : } + {type === 'pixel' ? ( + + ) : type === 'link' ? ( + + ) : ( + + )} {name} diff --git a/src/app/(main)/boards/[boardId]/BoardComponentRenderer.tsx b/src/app/(main)/boards/[boardId]/BoardComponentRenderer.tsx index f6449fbd4..ec2a30df1 100644 --- a/src/app/(main)/boards/[boardId]/BoardComponentRenderer.tsx +++ b/src/app/(main)/boards/[boardId]/BoardComponentRenderer.tsx @@ -6,9 +6,11 @@ import { getComponentDefinition } from '../boardComponentRegistry'; function BoardComponentRendererComponent({ config, websiteId, + entityType, }: { config: BoardComponentConfig; websiteId?: string; + entityType?: string; }) { const definition = getComponentDefinition(config.type); @@ -20,7 +22,8 @@ function BoardComponentRendererComponent({ ); } - const Component = definition.component; + const Component = + (entityType && definition.componentByEntityType?.[entityType]) || definition.component; if (!websiteId && definition.requiresWebsite !== false) { return ( @@ -36,7 +39,9 @@ function BoardComponentRendererComponent({ export const BoardComponentRenderer = memo( BoardComponentRendererComponent, (prevProps, nextProps) => - prevProps.websiteId === nextProps.websiteId && prevProps.config === nextProps.config, + prevProps.websiteId === nextProps.websiteId && + prevProps.entityType === nextProps.entityType && + prevProps.config === nextProps.config, ); BoardComponentRenderer.displayName = 'BoardComponentRenderer'; diff --git a/src/app/(main)/boards/[boardId]/BoardComponentSelect.tsx b/src/app/(main)/boards/[boardId]/BoardComponentSelect.tsx index 16c77d269..3a03ffea0 100644 --- a/src/app/(main)/boards/[boardId]/BoardComponentSelect.tsx +++ b/src/app/(main)/boards/[boardId]/BoardComponentSelect.tsx @@ -177,14 +177,16 @@ export function BoardComponentSelect({ onSelect(config); }; - const previewConfig: BoardComponentConfig | null = selectedDef - ? { - type: selectedDef.type, - title, - description, - props: { ...selectedDef.defaultProps, ...configValues }, - } - : null; + const previewConfig: BoardComponentConfig | null = useMemo( + () => + selectedDef + ? { + type: selectedDef.type, + props: { ...selectedDef.defaultProps, ...configValues }, + } + : null, + [selectedDef, configValues], + ); const canSave = !!selectedDef && isSelectedDefSupported && (!needsWebsite || !!resolvedEntityId); const availableDefinitions = useMemo( @@ -274,12 +276,16 @@ export function BoardComponentSelect({ )} @@ -364,7 +370,7 @@ export function BoardComponentSelect({ Preview {hasSelectedEntity && previewConfig && (!needsWebsite || resolvedEntityId) ? ( - + ) : ( diff --git a/src/app/(main)/boards/[boardId]/BoardEditColumn.tsx b/src/app/(main)/boards/[boardId]/BoardEditColumn.tsx index e0d3395da..0a89ea25c 100644 --- a/src/app/(main)/boards/[boardId]/BoardEditColumn.tsx +++ b/src/app/(main)/boards/[boardId]/BoardEditColumn.tsx @@ -1,3 +1,8 @@ +import { Panel } from '@/components/common/Panel'; +import { useBoard, useMessages, useNavigation } from '@/components/hooks'; +import { Pencil, Plus, X } from '@/components/icons'; +import { getBoardEntity, getBoardType, getResolvedComponentEntity } from '@/lib/boards'; +import type { BoardComponentConfig } from '@/lib/types'; import { Box, Button, @@ -10,11 +15,6 @@ import { TooltipTrigger, } from '@umami/react-zen'; import { useMemo, useState } from 'react'; -import { Panel } from '@/components/common/Panel'; -import { useBoard, useMessages, useNavigation } from '@/components/hooks'; -import { Pencil, Plus, X } from '@/components/icons'; -import { getBoardEntity, getBoardType, getResolvedComponentEntity } from '@/lib/boards'; -import type { BoardComponentConfig } from '@/lib/types'; import { getComponentDefinition } from '../boardComponentRegistry'; import { BoardComponentRenderer } from './BoardComponentRenderer'; import { BoardComponentSelect } from './BoardComponentSelect'; @@ -42,14 +42,14 @@ export function BoardEditColumn({ const boardType = getBoardType(board); const { entityType: boardEntityType, entityId: boardEntityId } = getBoardEntity(board); const definition = component ? getComponentDefinition(component.type) : undefined; - const { entityId } = getResolvedComponentEntity(board, component); + const { entityType, entityId } = getResolvedComponentEntity(board, component); const renderedComponent = useMemo(() => { if (!component || (!entityId && definition?.requiresWebsite !== false)) { return null; } - return ; - }, [component, definition?.requiresWebsite, entityId]); + return ; + }, [component, definition?.requiresWebsite, entityId, entityType]); const handleSelect = (config: BoardComponentConfig) => { onSetComponent(id, config); @@ -79,7 +79,7 @@ export function BoardEditColumn({ onMouseEnter={() => setShowActions(true)} onMouseLeave={() => setShowActions(false)} > - {canEdit && canRemoveAction && showActions && ( + {canEdit && (showActions || !hasComponent) && ( - - {hasComponent && ( - - - {t(labels.edit)} - - )} + - - {t(labels.remove)} + {t(hasComponent ? labels.edit : labels.selectComponent)} + {canRemoveAction && ( + + + {t(labels.remove)} + + )} )} - {renderedComponent ? ( + {renderedComponent && ( {renderedComponent} - ) : ( - canEdit && ( - - - - ) )} - {showEntityBadge && isOpenBoardType(boardType) && entityBadge && ( - + + {showBadge ? ( + + {title && {title}} - + + ) : ( + title && {title} )} + {description && {description}} - - - + + + ); diff --git a/src/app/(main)/boards/boardComponentRegistry.tsx b/src/app/(main)/boards/boardComponentRegistry.tsx index 31d2f2c81..2af1c7006 100644 --- a/src/app/(main)/boards/boardComponentRegistry.tsx +++ b/src/app/(main)/boards/boardComponentRegistry.tsx @@ -1,5 +1,6 @@ -import type { ComponentType } from 'react'; import { TextBlock } from '@/app/(main)/boards/TextBlock'; +import { LinkMetricsBar } from '@/app/(main)/links/[linkId]/LinkMetricsBar'; +import { PixelMetricsBar } from '@/app/(main)/pixels/[pixelId]/PixelMetricsBar'; import { WebsiteChart } from '@/app/(main)/websites/[websiteId]/WebsiteChart'; import { WebsiteMetricsBar } from '@/app/(main)/websites/[websiteId]/WebsiteMetricsBar'; import { @@ -15,12 +16,14 @@ import { EventsChart } from '@/components/metrics/EventsChart'; import { MetricsTable } from '@/components/metrics/MetricsTable'; import { WeeklyTraffic } from '@/components/metrics/WeeklyTraffic'; import { WorldMap } from '@/components/metrics/WorldMap'; +import type { ComponentType } from 'react'; export interface ConfigField { name: string; label: string; type: 'select' | 'number' | 'text' | 'textarea'; options?: { label: string; value: string }[]; + optionsByEntityType?: Record; defaultValue?: any; } @@ -31,6 +34,7 @@ export interface ComponentDefinition { category: string; icon: ComponentType; component: ComponentType; + componentByEntityType?: Record>; defaultProps?: Record; configFields?: ConfigField[]; requiresWebsite?: boolean; @@ -44,31 +48,60 @@ export const CATEGORIES = [ ] as const; const METRIC_TYPES = [ - { label: 'Pages', value: 'path' }, - { label: 'Entry pages', value: 'entry' }, - { label: 'Exit pages', value: 'exit' }, - { label: 'Referrers', value: 'referrer' }, - { label: 'Channels', value: 'channel' }, - { label: 'Browsers', value: 'browser' }, + { label: 'Path', value: 'path' }, + { label: 'Entry page', value: 'entry' }, + { label: 'Exit page', value: 'exit' }, + { label: 'Title', value: 'title' }, + { label: 'Query', value: 'query' }, + { label: 'Referrer', value: 'referrer' }, + { label: 'Channel', value: 'channel' }, + { label: 'Country', value: 'country' }, + { label: 'Region', value: 'region' }, + { label: 'City', value: 'city' }, + { label: 'Browser', value: 'browser' }, { label: 'OS', value: 'os' }, - { label: 'Devices', value: 'device' }, - { label: 'Countries', value: 'country' }, - { label: 'Regions', value: 'region' }, - { label: 'Cities', value: 'city' }, - { label: 'Languages', value: 'language' }, - { label: 'Screens', value: 'screen' }, - { label: 'Query parameters', value: 'query' }, - { label: 'Page titles', value: 'title' }, - { label: 'Hosts', value: 'host' }, - { label: 'Events', value: 'event' }, + { label: 'Device', value: 'device' }, + { label: 'Language', value: 'language' }, + { label: 'Screen', value: 'screen' }, + { label: 'UTM Source', value: 'utmSource' }, + { label: 'UTM Medium', value: 'utmMedium' }, + { label: 'UTM Campaign', value: 'utmCampaign' }, + { label: 'UTM Content', value: 'utmContent' }, + { label: 'UTM Term', value: 'utmTerm' }, + { label: 'Event', value: 'event' }, + { label: 'Hostname', value: 'hostname' }, ]; +const PIXEL_LINK_METRIC_TYPES = METRIC_TYPES.filter(({ value }) => + [ + 'referrer', + 'country', + 'region', + 'city', + 'browser', + 'os', + 'device', + 'query', + 'utmSource', + 'utmMedium', + 'utmCampaign', + 'utmContent', + 'utmTerm', + ].includes(value), +); + const LIMIT_OPTIONS = [ { label: '5', value: '5' }, { label: '10', value: '10' }, { label: '20', value: '20' }, ]; +const PixelMetricsBarAdapter = ({ websiteId }: { websiteId?: string }) => + websiteId ? : null; + +const LinkMetricsBarAdapter = ({ websiteId }: { websiteId?: string }) => + websiteId ? : null; + const componentDefinitions: ComponentDefinition[] = [ // Overview { @@ -78,6 +111,10 @@ const componentDefinitions: ComponentDefinition[] = [ category: 'overview', icon: PanelTop, component: WebsiteMetricsBar, + componentByEntityType: { + pixel: PixelMetricsBarAdapter, + link: LinkMetricsBarAdapter, + }, }, { type: 'WebsiteChart', @@ -103,6 +140,10 @@ const componentDefinitions: ComponentDefinition[] = [ label: 'Metric type', type: 'select', options: METRIC_TYPES, + optionsByEntityType: { + pixel: PIXEL_LINK_METRIC_TYPES, + link: PIXEL_LINK_METRIC_TYPES, + }, defaultValue: 'path', }, { diff --git a/src/app/(main)/boards/useBoardEntityBadgeProps.ts b/src/app/(main)/boards/useBoardEntityBadgeProps.ts index cbb55025f..42958352e 100644 --- a/src/app/(main)/boards/useBoardEntityBadgeProps.ts +++ b/src/app/(main)/boards/useBoardEntityBadgeProps.ts @@ -13,7 +13,7 @@ export function useBoardEntityBadgeProps( const { data: link } = useLinkQuery(enabled && entityType === 'link' ? entityId : undefined); if (entityType === 'website' && website?.name) { - return { type: entityType, name: website.name }; + return { type: entityType, name: website.name, domain: website.domain ?? undefined }; } if (entityType === 'pixel' && pixel?.name) { diff --git a/src/app/(main)/links/[linkId]/LinkMetricsBar.tsx b/src/app/(main)/links/[linkId]/LinkMetricsBar.tsx index ec07962c6..e8c946bfe 100644 --- a/src/app/(main)/links/[linkId]/LinkMetricsBar.tsx +++ b/src/app/(main)/links/[linkId]/LinkMetricsBar.tsx @@ -14,7 +14,7 @@ export function LinkMetricsBar({ }) { const { isAllTime } = useDateRange(); const { t, labels } = useMessages(); - const { data, isLoading, isFetching, error } = useWebsiteStatsQuery(linkId); + const { data, isLoading, isFetching, error } = useWebsiteStatsQuery({ websiteId: linkId }); const { pageviews, visitors, visits, comparison } = data || {}; diff --git a/src/app/(main)/pixels/[pixelId]/PixelMetricsBar.tsx b/src/app/(main)/pixels/[pixelId]/PixelMetricsBar.tsx index 3a46291e1..d17bc78c6 100644 --- a/src/app/(main)/pixels/[pixelId]/PixelMetricsBar.tsx +++ b/src/app/(main)/pixels/[pixelId]/PixelMetricsBar.tsx @@ -14,7 +14,7 @@ export function PixelMetricsBar({ }) { const { isAllTime } = useDateRange(); const { t, labels } = useMessages(); - const { data, isLoading, isFetching, error } = useWebsiteStatsQuery(pixelId); + const { data, isLoading, isFetching, error } = useWebsiteStatsQuery({ websiteId: pixelId }); const { pageviews, visitors, visits, comparison } = data || {}; diff --git a/src/app/(main)/settings/SettingsNav.tsx b/src/app/(main)/settings/SettingsNav.tsx index 113978381..47cdb9cb5 100644 --- a/src/app/(main)/settings/SettingsNav.tsx +++ b/src/app/(main)/settings/SettingsNav.tsx @@ -51,7 +51,7 @@ export function SettingsNav({ return ( - + { @@ -53,57 +53,35 @@ export async function GET(_request: Request, { params }: { params: Promise<{ slu return notFound(); } - if (share.shareType === ENTITY_TYPE.board) { - const board = await getBoard(share.entityId); - - if (!board) { - return notFound(); - } - - const data: Record = { - shareId: share.id, - shareType: share.shareType, - boardId: share.entityId, - parameters: share.parameters, - websiteIds: getBoardWebsiteIds(board), - }; - - data.token = createToken(data, secret()); - - return json(data); - } - - let entity: { userId?: string; teamId?: string } | null = null; const data: Record = { shareId: share.id, shareType: share.shareType, parameters: share.parameters, }; - if (share.shareType === ENTITY_TYPE.website) { + let entity: { userId?: string; teamId?: string } | null = null; + + if (share.shareType === ENTITY_TYPE.board) { + const board = await getBoard(share.entityId); + if (!board) return notFound(); + entity = board; + data.boardId = share.entityId; + data.websiteIds = getBoardWebsiteIds({ + type: board.type, + parameters: share.parameters as BoardParameters, + }); + } else if (share.shareType === ENTITY_TYPE.website) { entity = await getWebsite(share.entityId); - - if (!entity) { - return notFound(); - } - + if (!entity) return notFound(); data.websiteId = share.entityId; } else if (share.shareType === ENTITY_TYPE.pixel) { entity = await getPixel(share.entityId); - - if (!entity) { - return notFound(); - } - + if (!entity) return notFound(); data.websiteId = share.entityId; data.pixelId = share.entityId; } else if (share.shareType === ENTITY_TYPE.link) { entity = await getLink(share.entityId); - - if (!entity) { - return notFound(); - } - + if (!entity) return notFound(); data.websiteId = share.entityId; data.linkId = share.entityId; } else { @@ -116,7 +94,6 @@ export async function GET(_request: Request, { params }: { params: Promise<{ slu if (accountId) { const whiteLabel = await getWhiteLabel(accountId); - if (whiteLabel) { data.whiteLabel = whiteLabel; } diff --git a/src/app/share/[slug]/[[...path]]/ShareBranding.tsx b/src/app/share/[slug]/[[...path]]/ShareBranding.tsx new file mode 100644 index 000000000..89573b288 --- /dev/null +++ b/src/app/share/[slug]/[[...path]]/ShareBranding.tsx @@ -0,0 +1,32 @@ +'use client'; +import { useShare } from '@/components/hooks'; +import { Logo } from '@/components/svg'; +import { Icon, Row, Text } from '@umami/react-zen'; + +const LOGO_SIZE = { sm: 24, md: 32, lg: 40 }; +const TEXT_SIZE = { sm: 'sm', md: 'base', lg: 'lg' } as const; + +export function ShareBranding({ size = 'md' }: { size?: 'sm' | 'md' | 'lg' }) { + const share = useShare(); + const logoDomain = share?.whiteLabel?.domainName || 'https://umami.is'; + const logoName = share?.whiteLabel?.displayName || 'umami'; + const logoImage = share?.whiteLabel?.logoUrl; + const height = LOGO_SIZE[size]; + + return ( + + + {logoImage ? ( + {logoName} + ) : ( + + + + )} + + {logoName} + + + + ); +} diff --git a/src/app/share/[slug]/[[...path]]/ShareFooter.tsx b/src/app/share/[slug]/[[...path]]/ShareFooter.tsx new file mode 100644 index 000000000..69177b34c --- /dev/null +++ b/src/app/share/[slug]/[[...path]]/ShareFooter.tsx @@ -0,0 +1,25 @@ +'use client'; +import { useShare } from '@/components/hooks'; +import { Column, Row } from '@umami/react-zen'; +import { ShareBranding } from './ShareBranding'; + +export function ShareFooter() { + const share = useShare(); + + if (!share?.whiteLabel) { + return null; + } + + return ( + + + + + + ); +} diff --git a/src/app/share/[slug]/[[...path]]/ShareNav.tsx b/src/app/share/[slug]/[[...path]]/ShareNav.tsx index 103e9733f..1c49fe16b 100644 --- a/src/app/share/[slug]/[[...path]]/ShareNav.tsx +++ b/src/app/share/[slug]/[[...path]]/ShareNav.tsx @@ -1,10 +1,11 @@ -import { Button, Column, Icon, Row, Text, ThemeButton } from '@umami/react-zen'; +import { Button, Column, Icon, Row, ThemeButton } from '@umami/react-zen'; import { NavMenu } from '@/components/common/NavMenu'; import { useMessages, useNavigation, useShare } from '@/components/hooks'; import { AlignEndHorizontal, Clock, Eye, PanelLeft, Sheet, Tag, User } from '@/components/icons'; import { LanguageButton } from '@/components/input/LanguageButton'; import { PreferencesButton } from '@/components/input/PreferencesButton'; -import { Funnel, Lightning, Logo, Magnet, Money, Network, Path, Target } from '@/components/svg'; +import { Funnel, Lightning, Magnet, Money, Network, Path, Target } from '@/components/svg'; +import { ShareBranding } from './ShareBranding'; export function ShareNav({ collapsed, @@ -18,11 +19,7 @@ export function ShareNav({ const share = useShare(); const { t, labels } = useMessages(); const { pathname } = useNavigation(); - const { slug, parameters, whiteLabel } = share; - - const logoDomain = whiteLabel?.domainName || 'https://umami.is'; - const logoName = whiteLabel?.displayName || 'umami'; - const logoImage = whiteLabel?.logoUrl; + const { slug, parameters } = share; const renderPath = (path: string) => `/share/${slug}${path}`; @@ -149,20 +146,7 @@ export function ShareNav({ border={isMobile ? undefined : 'right'} > - {!collapsed && ( - - - {logoImage ? ( - {logoName} - ) : ( - - - - )} - {logoName} - - - )} + {!collapsed && } {!onItemClick && (