From d130242a0a90980141d3bdf94827819e46a16e6a Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Fri, 15 Aug 2025 13:04:13 -0700 Subject: [PATCH] Pixel editing. --- src/app/(main)/links/[linkId]/route.ts | 0 src/app/(main)/pixels/PixelDeleteButton.tsx | 4 +- src/app/(main)/pixels/PixelEditButton.tsx | 2 +- src/app/(main)/pixels/PixelEditForm.tsx | 67 +++++++++++++------ src/app/(main)/pixels/PixelsTable.tsx | 9 ++- src/app/(main)/pixels/[pixelId]/route.ts | 0 .../websites/[websiteId]/WebsiteProvider.tsx | 2 +- src/app/api/pixels/[pixelId]/route.ts | 5 +- src/app/api/pixels/route.ts | 4 +- src/components/common/ExternalLink.tsx | 2 +- src/components/hooks/queries/usePixelQuery.ts | 2 +- src/lib/load.ts | 2 +- src/queries/prisma/link.ts | 2 +- src/queries/prisma/pixel.ts | 2 +- src/queries/prisma/report.ts | 2 +- src/queries/prisma/segment.ts | 2 +- src/queries/prisma/team.ts | 2 +- src/queries/prisma/teamUser.ts | 2 +- src/queries/prisma/user.ts | 2 +- src/queries/prisma/website.ts | 2 +- src/queries/sql/events/getEventData.ts | 2 +- src/queries/sql/sessions/createSession.ts | 2 +- src/validations/report.ts | 2 +- 23 files changed, 72 insertions(+), 49 deletions(-) delete mode 100644 src/app/(main)/links/[linkId]/route.ts delete mode 100644 src/app/(main)/pixels/[pixelId]/route.ts diff --git a/src/app/(main)/links/[linkId]/route.ts b/src/app/(main)/links/[linkId]/route.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/app/(main)/pixels/PixelDeleteButton.tsx b/src/app/(main)/pixels/PixelDeleteButton.tsx index 3e5bf7fc..70e2b1f6 100644 --- a/src/app/(main)/pixels/PixelDeleteButton.tsx +++ b/src/app/(main)/pixels/PixelDeleteButton.tsx @@ -7,19 +7,17 @@ import { useApi, useMessages, useModified } from '@/components/hooks'; export function PixelDeleteButton({ pixelId, - websiteId, name, onSave, }: { pixelId: string; - websiteId: string; name: string; onSave?: () => void; }) { const { formatMessage, labels } = useMessages(); const { del, useMutation } = useApi(); const { mutate, isPending, error } = useMutation({ - mutationFn: () => del(`/websites/${websiteId}/pixels/${pixelId}`), + mutationFn: () => del(`/pixels/${pixelId}`), }); const { touch } = useModified(); diff --git a/src/app/(main)/pixels/PixelEditButton.tsx b/src/app/(main)/pixels/PixelEditButton.tsx index 289e4a90..a1310d44 100644 --- a/src/app/(main)/pixels/PixelEditButton.tsx +++ b/src/app/(main)/pixels/PixelEditButton.tsx @@ -9,7 +9,7 @@ export function PixelEditButton({ pixelId }: { pixelId: string }) { return ( }> - + {({ close }) => { return ; }} diff --git a/src/app/(main)/pixels/PixelEditForm.tsx b/src/app/(main)/pixels/PixelEditForm.tsx index a622d018..8026c76a 100644 --- a/src/app/(main)/pixels/PixelEditForm.tsx +++ b/src/app/(main)/pixels/PixelEditForm.tsx @@ -5,7 +5,6 @@ import { Row, TextField, Button, - Text, Label, Column, Icon, @@ -16,6 +15,8 @@ import { useMessages } from '@/components/hooks'; import { Refresh } from '@/components/icons'; import { getRandomChars } from '@/lib/crypto'; import { useUpdateQuery } from '@/components/hooks/queries/useUpdateQuery'; +import { useEffect, useState } from 'react'; +import { PIXELS_URL } from '@/lib/constants'; const generateId = () => getRandomChars(9); @@ -31,29 +32,48 @@ export function PixelEditForm({ onClose?: () => void; }) { const { formatMessage, labels } = useMessages(); - const { mutate, error, isPending } = useUpdateQuery('/pixels', { id: pixelId, teamId }); - const { pixelDomain } = useConfig(); + const { mutate, error, isPending, touch } = useUpdateQuery( + pixelId ? `/pixels/${pixelId}` : '/pixels', + { + id: pixelId, + teamId, + }, + ); + const { pixelsUrl } = useConfig(); + const hostUrl = pixelsUrl || PIXELS_URL; const { data, isLoading } = usePixelQuery(pixelId); + const [slug, setSlug] = useState(generateId()); const handleSubmit = async (data: any) => { mutate(data, { onSuccess: async () => { + touch('pixels'); onSave?.(); onClose?.(); }, }); }; - if (pixelId && !isLoading) { + const handleSlug = () => { + const slug = generateId(); + + setSlug(slug); + + return slug; + }; + + useEffect(() => { + if (data) { + setSlug(data.slug); + } + }, [data]); + + if (pixelId && isLoading) { return ; } return ( -
+ {({ setValue }) => { return ( <> @@ -65,22 +85,29 @@ export function PixelEditForm({ + + + + - + - {pixelDomain || window.location.origin}/ - - - + />