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}/ - - - + />