From 013c929cd10653314468c0085457afaea57fb1f2 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Thu, 12 Mar 2026 11:28:19 -0700 Subject: [PATCH 1/9] Test favicon, fix remove/add overlap bug, fix badge overlapping component bug --- src/app/(main)/boards/BoardEntityBadge.tsx | 30 +++++++++- .../boards/[boardId]/BoardEditColumn.tsx | 57 +++++++++---------- .../boards/[boardId]/BoardViewColumn.tsx | 18 ++++-- .../(main)/boards/useBoardEntityBadgeProps.ts | 2 +- 4 files changed, 68 insertions(+), 39 deletions(-) diff --git a/src/app/(main)/boards/BoardEntityBadge.tsx b/src/app/(main)/boards/BoardEntityBadge.tsx index 70fc3604e..c5b476ff9 100644 --- a/src/app/(main)/boards/BoardEntityBadge.tsx +++ b/src/app/(main)/boards/BoardEntityBadge.tsx @@ -1,12 +1,38 @@ import { Icon, Row, Text } from '@umami/react-zen'; +import { useState } from 'react'; +import { Favicon } from '@/components/common/Favicon'; import { Globe, Grid2x2, Link } from '@/components/icons'; import type { BoardEntityType } from '@/lib/boards'; -export function BoardEntityBadge({ type, name }: { type: BoardEntityType; name: string }) { +function WebsiteIcon({ domain }: { domain?: string }) { + const [failed, setFailed] = useState(false); + + if (domain && !failed) { + return setFailed(true)} />; + } + + return ; +} + +export function BoardEntityBadge({ + type, + name, + domain, +}: { + type: BoardEntityType; + name: string; + domain?: string; +}) { return ( - {type === 'pixel' ? : type === 'link' ? : } + {type === 'pixel' ? ( + + ) : type === 'link' ? ( + + ) : ( + + )} {name} diff --git a/src/app/(main)/boards/[boardId]/BoardEditColumn.tsx b/src/app/(main)/boards/[boardId]/BoardEditColumn.tsx index e0d3395da..32cfc7c26 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'; @@ -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 ? ( + + + + ) : ( + + + + ) )} 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) { From 00a31c63664bee41f2291e947c1cc92cf91dc260 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Thu, 12 Mar 2026 11:51:20 -0700 Subject: [PATCH 2/9] fix globe fallback, fix freeform bug --- src/app/(main)/boards/BoardEntityBadge.tsx | 20 +++++++++++--- .../boards/[boardId]/BoardViewColumn.tsx | 26 +++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/app/(main)/boards/BoardEntityBadge.tsx b/src/app/(main)/boards/BoardEntityBadge.tsx index c5b476ff9..3a3e1d554 100644 --- a/src/app/(main)/boards/BoardEntityBadge.tsx +++ b/src/app/(main)/boards/BoardEntityBadge.tsx @@ -1,17 +1,31 @@ import { Icon, Row, Text } from '@umami/react-zen'; import { useState } from 'react'; -import { Favicon } from '@/components/common/Favicon'; import { Globe, Grid2x2, Link } from '@/components/icons'; import type { BoardEntityType } from '@/lib/boards'; +const HOSTNAME_REGEX = /^(?:https?:\/\/)?(?:[^@\n]+@)?([^:/\n?=]+)/im; + function WebsiteIcon({ domain }: { domain?: string }) { const [failed, setFailed] = useState(false); if (domain && !failed) { - return setFailed(true)} />; + const match = domain.match(HOSTNAME_REGEX); + const hostname = match?.[1]; + + if (hostname) { + return ( + setFailed(true)} + /> + ); + } } - return ; + return ; } export function BoardEntityBadge({ diff --git a/src/app/(main)/boards/[boardId]/BoardViewColumn.tsx b/src/app/(main)/boards/[boardId]/BoardViewColumn.tsx index 572fe9d2e..580209442 100644 --- a/src/app/(main)/boards/[boardId]/BoardViewColumn.tsx +++ b/src/app/(main)/boards/[boardId]/BoardViewColumn.tsx @@ -1,4 +1,4 @@ -import { Box, Column, Row } from '@umami/react-zen'; +import { Column, Heading, Row, Text } from '@umami/react-zen'; import { Panel } from '@/components/common/Panel'; import { useBoard } from '@/components/hooks'; import { getBoardType, getResolvedComponentEntity, isOpenBoardType } from '@/lib/boards'; @@ -31,22 +31,20 @@ export function BoardViewColumn({ const showBadge = showEntityBadge && isOpenBoardType(boardType) && !!entityBadge; return ( - - {showBadge && ( - title ? ( - - - - ) : ( - - - - ) + + {showBadge ? ( + + {title && {title}} + + + ) : ( + title && {title} )} + {description && {description}} - + - + ); From 7e54e7de312e40e654d44d28a545b118c4a2c63d Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Thu, 12 Mar 2026 14:39:26 -0700 Subject: [PATCH 3/9] remove fallback logic, use service instead of direct URL --- src/app/(main)/boards/BoardEntityBadge.tsx | 31 +++------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/src/app/(main)/boards/BoardEntityBadge.tsx b/src/app/(main)/boards/BoardEntityBadge.tsx index 3a3e1d554..31d7081ab 100644 --- a/src/app/(main)/boards/BoardEntityBadge.tsx +++ b/src/app/(main)/boards/BoardEntityBadge.tsx @@ -1,33 +1,8 @@ import { Icon, Row, Text } from '@umami/react-zen'; -import { useState } from 'react'; -import { Globe, Grid2x2, Link } from '@/components/icons'; +import { Favicon } from '@/components/common/Favicon'; +import { Grid2x2, Link } from '@/components/icons'; import type { BoardEntityType } from '@/lib/boards'; -const HOSTNAME_REGEX = /^(?:https?:\/\/)?(?:[^@\n]+@)?([^:/\n?=]+)/im; - -function WebsiteIcon({ domain }: { domain?: string }) { - const [failed, setFailed] = useState(false); - - if (domain && !failed) { - const match = domain.match(HOSTNAME_REGEX); - const hostname = match?.[1]; - - if (hostname) { - return ( - setFailed(true)} - /> - ); - } - } - - return ; -} - export function BoardEntityBadge({ type, name, @@ -45,7 +20,7 @@ export function BoardEntityBadge({ ) : type === 'link' ? ( ) : ( - + )} {name} From d2d14f6de0393a9adfb2dd782e3dd6f3ecbb228a Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Thu, 12 Mar 2026 16:18:52 -0700 Subject: [PATCH 4/9] choose correct Metricsbar based on component type, fix metric types list based on component type, fix chart previews reanimating. fix hostname broken query on channel query --- .../[boardId]/BoardComponentRenderer.tsx | 9 ++- .../boards/[boardId]/BoardComponentSelect.tsx | 34 +++++---- .../boards/[boardId]/BoardEditColumn.tsx | 6 +- .../boards/[boardId]/BoardViewColumn.tsx | 2 +- .../(main)/boards/boardComponentRegistry.tsx | 75 ++++++++++++++----- .../(main)/links/[linkId]/LinkMetricsBar.tsx | 2 +- .../pixels/[pixelId]/PixelMetricsBar.tsx | 2 +- src/queries/sql/getChannelExpandedMetrics.ts | 4 +- src/queries/sql/getChannelMetrics.ts | 5 +- 9 files changed, 97 insertions(+), 42 deletions(-) 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 32cfc7c26..0a89ea25c 100644 --- a/src/app/(main)/boards/[boardId]/BoardEditColumn.tsx +++ b/src/app/(main)/boards/[boardId]/BoardEditColumn.tsx @@ -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); diff --git a/src/app/(main)/boards/[boardId]/BoardViewColumn.tsx b/src/app/(main)/boards/[boardId]/BoardViewColumn.tsx index 580209442..5bb2f8b65 100644 --- a/src/app/(main)/boards/[boardId]/BoardViewColumn.tsx +++ b/src/app/(main)/boards/[boardId]/BoardViewColumn.tsx @@ -43,7 +43,7 @@ export function BoardViewColumn({ {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)/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/queries/sql/getChannelExpandedMetrics.ts b/src/queries/sql/getChannelExpandedMetrics.ts index c3201dfa6..c43e2544b 100644 --- a/src/queries/sql/getChannelExpandedMetrics.ts +++ b/src/queries/sql/getChannelExpandedMetrics.ts @@ -60,6 +60,7 @@ async function relationalQuery( website_event.utm_source, website_event.session_id, website_event.visit_id, + website_event.hostname, count(*) c, min(website_event.created_at) min_time, max(website_event.created_at) max_time @@ -77,7 +78,8 @@ async function relationalQuery( website_event.utm_medium, website_event.utm_source, website_event.session_id, - website_event.visit_id), + website_event.visit_id, + website_event.hostname), channels as ( select case diff --git a/src/queries/sql/getChannelMetrics.ts b/src/queries/sql/getChannelMetrics.ts index 487c5dd74..da28c0492 100644 --- a/src/queries/sql/getChannelMetrics.ts +++ b/src/queries/sql/getChannelMetrics.ts @@ -39,7 +39,8 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) { website_event.url_query, website_event.utm_medium, website_event.utm_source, - website_event.session_id + website_event.session_id, + website_event.hostname from website_event ${cohortQuery} ${excludeBounceQuery} @@ -61,7 +62,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) { when ${toPostgresLikeClause('referrer_domain', EMAIL_DOMAINS)} or utm_medium ilike '%mail%' then 'email' when ${toPostgresLikeClause('referrer_domain', SHOPPING_DOMAINS)} or utm_medium ilike '%shop%' then concat(prefix, 'Shopping') when ${toPostgresLikeClause('referrer_domain', VIDEO_DOMAINS)} or utm_medium ilike '%video%' then concat(prefix, 'Video') - wwhen referrer_domain != regexp_replace(hostname, '^www.', '') and referrer_domain != '' then 'referral' + when referrer_domain != regexp_replace(hostname, '^www.', '') and referrer_domain != '' then 'referral' else '' end AS x, count(distinct session_id) y from prefix From 5a7b651f3dad52c593942e123a3f36c0adda01e2 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Thu, 12 Mar 2026 16:23:06 -0700 Subject: [PATCH 5/9] fix dashboard save --- src/app/api/dashboard/route.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app/api/dashboard/route.ts b/src/app/api/dashboard/route.ts index 92c8e4c14..880057181 100644 --- a/src/app/api/dashboard/route.ts +++ b/src/app/api/dashboard/route.ts @@ -1,8 +1,7 @@ -import { z } from 'zod'; -import { uuid } from '@/lib/crypto'; import { parseRequest } from '@/lib/request'; import { json, unauthorized } from '@/lib/response'; import { createBoard, getBoard, updateBoard } from '@/queries/prisma'; +import { z } from 'zod'; export async function GET(request: Request) { const { auth, error } = await parseRequest(request); @@ -55,7 +54,6 @@ export async function POST(request: Request) { const result = await createBoard({ id: userId, type: 'dashboard', - slug: uuid(), userId, ...data, }); From b823a6ca3e5277296a00ed4e55ed25a4f2fbc8c2 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Fri, 13 Mar 2026 14:46:10 -0700 Subject: [PATCH 6/9] apply white-labeling to all share pages --- src/app/api/share/[slug]/route.ts | 57 ++++++------------- .../[slug]/[[...path]]/ShareBranding.tsx | 32 +++++++++++ .../share/[slug]/[[...path]]/ShareFooter.tsx | 25 ++++++++ src/app/share/[slug]/[[...path]]/ShareNav.tsx | 26 ++------- .../share/[slug]/[[...path]]/SharePage.tsx | 38 ++++++------- 5 files changed, 98 insertions(+), 80 deletions(-) create mode 100644 src/app/share/[slug]/[[...path]]/ShareBranding.tsx create mode 100644 src/app/share/[slug]/[[...path]]/ShareFooter.tsx diff --git a/src/app/api/share/[slug]/route.ts b/src/app/api/share/[slug]/route.ts index a237a8f17..f110ae936 100644 --- a/src/app/api/share/[slug]/route.ts +++ b/src/app/api/share/[slug]/route.ts @@ -1,11 +1,11 @@ +import { getBoardWebsiteIds } from '@/lib/boards'; import { ENTITY_TYPE, ROLES } from '@/lib/constants'; import { secret } from '@/lib/crypto'; import { createToken } from '@/lib/jwt'; -import { getBoardWebsiteIds } from '@/lib/boards'; import prisma from '@/lib/prisma'; import redis from '@/lib/redis'; import { json, notFound } from '@/lib/response'; -import type { WhiteLabel } from '@/lib/types'; +import type { BoardParameters, WhiteLabel } from '@/lib/types'; import { getBoard, getLink, getPixel, getShareByCode, getWebsite } from '@/queries/prisma'; async function getAccountId(entity: { userId?: string; teamId?: string }): Promise { @@ -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 && (