diff --git a/src/app/(main)/links/LinkEditForm.tsx b/src/app/(main)/links/LinkEditForm.tsx
index 78000600..2a206920 100644
--- a/src/app/(main)/links/LinkEditForm.tsx
+++ b/src/app/(main)/links/LinkEditForm.tsx
@@ -10,7 +10,7 @@ import {
Row,
TextField,
} from '@umami/react-zen';
-import { useEffect, useState } from 'react';
+import { useState } from 'react';
import { useConfig, useLinkQuery, useMessages } from '@/components/hooks';
import { useUpdateQuery } from '@/components/hooks/queries/useUpdateQuery';
import { ChevronDown, ChevronRight, RefreshCw } from '@/components/icons';
@@ -42,11 +42,15 @@ export function LinkEditForm({
const { linksUrl } = useConfig();
const hostUrl = linksUrl || LINKS_URL;
const { data, isLoading } = useLinkQuery(linkId);
- const [slug, setSlug] = useState(generateId());
+ const [initialSlug] = useState(() => generateId());
const [showAdvanced, setShowAdvanced] = useState(false);
- const handleSubmit = async (data: any) => {
- await mutateAsync(data, {
+ const handleSubmit = async (formData: any) => {
+ const { slug: formSlug, ...rest } = formData;
+ // Only include slug if creating new link or if it was modified
+ const payload = !linkId || formSlug !== data?.slug ? formData : rest;
+
+ await mutateAsync(payload, {
onSuccess: async () => {
toast(formatMessage(messages.saved));
touch('links');
@@ -56,13 +60,7 @@ export function LinkEditForm({
});
};
- const handleSlug = () => {
- const slug = generateId();
-
- setSlug(slug);
-
- return slug;
- };
+ const handleSlug = () => generateId();
const checkUrl = (url: string) => {
if (!isValidUrl(url)) {
@@ -71,12 +69,6 @@ export function LinkEditForm({
return true;
};
- useEffect(() => {
- if (data) {
- setSlug(data.slug);
- }
- }, [data]);
-
if (linkId && isLoading) {
return