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

@@ -0,0 +1,14 @@
import { useMessages } from '@/components/hooks';
import { Edit } from '@/components/icons';
import { DialogButton } from '@/components/input/DialogButton';
import { SimpleShareEditForm } from './SimpleShareEditForm';
export function SimpleShareEditButton({ shareId }: { shareId: string }) {
const { t, labels } = useMessages();
return (
<DialogButton icon={<Edit />} title={t(labels.share)} variant="quiet" width="600px">
{({ close }) => <SimpleShareEditForm shareId={shareId} onClose={close} />}
</DialogButton>
);
}
@@ -0,0 +1,104 @@
import {
Button,
Column,
Form,
FormField,
FormSubmitButton,
Label,
Loading,
Row,
TextField,
} from '@umami/react-zen';
import { useEffect, useState } from 'react';
import { useApi, useConfig, useMessages, useModified } from '@/components/hooks';
export function SimpleShareEditForm({
shareId,
onSave,
onClose,
}: {
shareId: string;
onSave?: () => void;
onClose?: () => void;
}) {
const { t, labels, getErrorMessage } = useMessages();
const config = useConfig();
const { get, post } = useApi();
const { touch } = useModified();
const { modified } = useModified('shares');
const [share, setShare] = useState<any>(null);
const [isLoading, setIsLoading] = useState(true);
const [isPending, setIsPending] = useState(false);
const [error, setError] = useState<any>(null);
const getUrl = (slug: string) => {
return `${config?.cloudMode ? process.env.cloudUrl : window?.location.origin}${process.env.basePath || ''}/share/${slug}`;
};
useEffect(() => {
const loadShare = async () => {
setIsLoading(true);
try {
const data = await get(`/share/id/${shareId}`);
setShare(data);
} finally {
setIsLoading(false);
}
};
loadShare();
}, [get, modified, shareId]);
const handleSubmit = async (data: { name: string }) => {
setIsPending(true);
setError(null);
try {
await post(`/share/id/${shareId}`, {
name: data.name,
slug: share.slug,
parameters: share.parameters || {},
});
touch('shares');
onSave?.();
onClose?.();
} catch (e) {
setError(e);
} finally {
setIsPending(false);
}
};
if (isLoading) {
return <Loading placement="absolute" />;
}
return (
<Form
onSubmit={handleSubmit}
error={getErrorMessage(error)}
defaultValues={{ name: share?.name || '' }}
>
<Column gap="6">
<Column>
<Label>{t(labels.shareUrl)}</Label>
<TextField value={getUrl(share?.slug || '')} isReadOnly allowCopy />
</Column>
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
<TextField autoComplete="off" autoFocus />
</FormField>
<Row justifyContent="flex-end" paddingTop="3" gap="3">
{onClose && (
<Button isDisabled={isPending} onPress={onClose}>
{t(labels.cancel)}
</Button>
)}
<FormSubmitButton variant="primary" isDisabled={isPending}>
{t(labels.save)}
</FormSubmitButton>
</Row>
</Column>
</Form>
);
}
+5 -2
View File
@@ -4,10 +4,12 @@ import { CopyButton } from '@/components/common/CopyButton';
import { DateDistance } from '@/components/common/DateDistance';
import { ExternalLink } from '@/components/common/ExternalLink';
import { useConfig, useMessages, useMobile } from '@/components/hooks';
import { SimpleShareEditButton } from './SimpleShareEditButton';
export function SimpleSharesTable(props: DataTableProps) {
const { t, labels } = useMessages();
const { cloudMode } = useConfig();
const config = useConfig();
const cloudMode = config?.cloudMode;
const { isMobile } = useMobile();
const getUrl = (slug: string) => {
@@ -40,9 +42,10 @@ export function SimpleSharesTable(props: DataTableProps) {
<DataColumn id="created" label={t(labels.created)}>
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
</DataColumn>
<DataColumn id="action" align="end" width="60px">
<DataColumn id="action" align="end" width="100px">
{({ id, slug }: any) => (
<Row>
<SimpleShareEditButton shareId={id} />
<ShareDeleteButton shareId={id} slug={slug} />
</Row>
)}