Move pixel and link editing to dedicated pages

This commit is contained in:
Mike Cao committed 2026-03-09 22:09:54 -07:00
1 parent 48f8cd0ece
commit 9941181697
17 files changed
+285 -60

No files matched your search

+6 -7
View File
@@ -1,16 +1,15 @@
import { LinkButton } from '@/components/common/LinkButton';
import { useNavigation } from '@/components/hooks';
import { useMessages } from '@/components/hooks';
import { Edit } from '@/components/icons';
import { DialogButton } from '@/components/input/DialogButton';
import { PixelEditForm } from './PixelEditForm';
export function PixelEditButton({ pixelId }: { pixelId: string }) {
const { t, labels } = useMessages();
const { renderUrl } = useNavigation();
return (
<DialogButton icon={<Edit />} title={t(labels.addPixel)} variant="quiet" width="600px">
{({ close }) => {
return <PixelEditForm pixelId={pixelId} onClose={close} />;
}}
</DialogButton>
<LinkButton href={renderUrl(`/pixels/${pixelId}/edit`, false)} variant="quiet" aria-label={t(labels.edit)}>
<Edit />
</LinkButton>
);
}
+2 -1
View File
@@ -38,7 +38,8 @@ export function PixelEditForm({
teamId,
},
);
const { pixelsUrl } = useConfig();
const config = useConfig();
const pixelsUrl = config?.pixelsUrl;
const hostUrl = pixelsUrl || PIXELS_URL;
const { data, isLoading } = usePixelQuery(pixelId);
const [slug, setSlug] = useState(generateId());
@@ -2,9 +2,8 @@ import { Row } from '@umami/react-zen';
import { IconLabel } from '@/components/common/IconLabel';
import { LinkButton } from '@/components/common/LinkButton';
import { PageHeader } from '@/components/common/PageHeader';
import { useMessages, usePixel, useSlug } from '@/components/hooks';
import { ExternalLink, Grid2x2 } from '@/components/icons';
import { PixelShareButton } from './PixelShareButton';
import { useMessages, useNavigation, usePixel, useSlug } from '@/components/hooks';
import { Edit, ExternalLink, Grid2x2 } from '@/components/icons';
export function PixelHeader({ showActions = true }: { showActions?: boolean }) {
const pixel = usePixel();
@@ -18,11 +17,14 @@ export function PixelHeader({ showActions = true }: { showActions?: boolean }) {
function PixelHeaderActions({ pixelId, slug }: { pixelId: string; slug: string }) {
const { t, labels } = useMessages();
const { renderUrl } = useNavigation();
const { getSlugUrl } = useSlug('pixel');
return (
<Row alignItems="center" gap="3">
<PixelShareButton pixelId={pixelId} />
<LinkButton href={renderUrl(`/pixels/${pixelId}/edit`, false)}>
<IconLabel icon={<Edit />} label={t(labels.edit)} />
</LinkButton>
<LinkButton href={getSlugUrl(slug)} target="_blank" prefetch={false} asAnchor>
<IconLabel icon={<ExternalLink />} label={t(labels.view)} />
</LinkButton>
@@ -1,14 +0,0 @@
import { useMessages } from '@/components/hooks';
import { Share } from '@/components/icons';
import { DialogButton } from '@/components/input/DialogButton';
import { PixelShareDialog } from './PixelShareDialog';
export function PixelShareButton({ pixelId }: { pixelId: string }) {
const { t, labels } = useMessages();
return (
<DialogButton icon={<Share />} label={t(labels.share)} title={null} width="900px">
<PixelShareDialog pixelId={pixelId} />
</DialogButton>
);
}
@@ -7,19 +7,19 @@ import { Plus } from '@/components/icons';
import { SimpleShareCreateForm } from '@/components/share/SimpleShareCreateForm';
import { SimpleSharesTable } from '@/components/share/SimpleSharesTable';
export function PixelShareDialog({ pixelId }: { pixelId: string }) {
export function PixelShareForm({ pixelId }: { pixelId: string }) {
const { data, error, isLoading } = usePixelSharesQuery({ pixelId });
const shares = data?.data || [];
const hasShares = shares.length > 0;
return (
<LoadingPanel data={data} isLoading={isLoading} error={error}>
<PixelShareDialogContent pixelId={pixelId} hasShares={hasShares} shares={shares} />
<PixelShareFormContent pixelId={pixelId} hasShares={hasShares} shares={shares} />
</LoadingPanel>
);
}
function PixelShareDialogContent({
function PixelShareFormContent({
pixelId,
hasShares,
shares,
@@ -0,0 +1,46 @@
'use client';
import { Column } from '@umami/react-zen';
import Link from 'next/link';
import { PixelEditForm } from '@/app/(main)/pixels/PixelEditForm';
import { PixelProvider } from '@/app/(main)/pixels/PixelProvider';
import { PixelShareForm } from '@/app/(main)/pixels/[pixelId]/PixelShareForm';
import { Panel } from '@/components/common/Panel';
import { IconLabel } from '@/components/common/IconLabel';
import { PageHeader } from '@/components/common/PageHeader';
import { useMessages, useNavigation, usePixel } from '@/components/hooks';
import { ArrowLeft, Grid2x2 } from '@/components/icons';
export function PixelEditPage({ pixelId }: { pixelId: string }) {
return (
<PixelProvider pixelId={pixelId}>
<Column margin="2">
<PixelEditHeader />
<Column gap="6">
<Panel>
<PixelEditForm pixelId={pixelId} />
</Panel>
<Panel>
<PixelShareForm pixelId={pixelId} />
</Panel>
</Column>
</Column>
</PixelProvider>
);
}
function PixelEditHeader() {
const pixel = usePixel();
const { t, labels } = useMessages();
const { renderUrl } = useNavigation();
return (
<>
<Column marginTop="6">
<Link href={renderUrl(`/pixels/${pixel.id}`)}>
<IconLabel icon={<ArrowLeft />} label={t(labels.pixel)} />
</Link>
</Column>
<PageHeader title={pixel.name} icon={<Grid2x2 />} />
</>
);
}
@@ -0,0 +1,18 @@
import type { Metadata } from 'next';
import { getPixel } from '@/queries/prisma';
import { PixelEditPage } from './PixelEditPage';
export default async function ({ params }: { params: Promise<{ pixelId: string }> }) {
const { pixelId } = await params;
const pixel = await getPixel(pixelId);
if (!pixel || pixel.deletedAt) {
return null;
}
return <PixelEditPage pixelId={pixelId} />;
}
export const metadata: Metadata = {
title: 'Edit Pixel',
};