Add sharing to pixel and link detail pages
This commit is contained in:
1 parent
c4226bc63d
commit
64bf4c378c
23 files changed
+582
-43
No files matched your search
@@ -22,9 +22,11 @@ export * from './queries/useEventDataPropertiesQuery';
|
||||
export * from './queries/useEventDataQuery';
|
||||
export * from './queries/useEventDataValuesQuery';
|
||||
export * from './queries/useLinkQuery';
|
||||
export * from './queries/useLinkSharesQuery';
|
||||
export * from './queries/useLinksQuery';
|
||||
export * from './queries/useLoginQuery';
|
||||
export * from './queries/usePixelQuery';
|
||||
export * from './queries/usePixelSharesQuery';
|
||||
export * from './queries/usePixelsQuery';
|
||||
export * from './queries/useRealtimeQuery';
|
||||
export * from './queries/useReplayQuery';
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function useLinkSharesQuery(
|
||||
{ linkId }: { linkId: string },
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
const { modified } = useModified('shares');
|
||||
const { get } = useApi();
|
||||
|
||||
return usePagedQuery({
|
||||
queryKey: ['linkShares', { linkId, modified }],
|
||||
queryFn: pageParams => {
|
||||
return get(`/links/${linkId}/shares`, pageParams);
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function usePixelSharesQuery(
|
||||
{ pixelId }: { pixelId: string },
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
const { modified } = useModified('shares');
|
||||
const { get } = useApi();
|
||||
|
||||
return usePagedQuery({
|
||||
queryKey: ['pixelShares', { pixelId, modified }],
|
||||
queryFn: pageParams => {
|
||||
return get(`/pixels/${pixelId}/shares`, pageParams);
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -2,7 +2,9 @@ import { useConfig } from '@/components/hooks/useConfig';
|
||||
import { LINKS_URL, PIXELS_URL } from '@/lib/constants';
|
||||
|
||||
export function useSlug(type: 'link' | 'pixel') {
|
||||
const { linksUrl, pixelsUrl } = useConfig();
|
||||
const config = useConfig();
|
||||
const linksUrl = config?.linksUrl;
|
||||
const pixelsUrl = config?.pixelsUrl;
|
||||
|
||||
const hostUrl = type === 'link' ? linksUrl || LINKS_URL : pixelsUrl || PIXELS_URL;
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Button, Column, Form, FormField, FormSubmitButton, Row, TextField } from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { useApi, useMessages, useModified } from '@/components/hooks';
|
||||
|
||||
export function SimpleShareCreateForm({
|
||||
createPath,
|
||||
onSave,
|
||||
onCancel,
|
||||
}: {
|
||||
createPath: string;
|
||||
onSave?: () => void;
|
||||
onCancel?: () => void;
|
||||
}) {
|
||||
const { post } = useApi();
|
||||
const { touch } = useModified();
|
||||
const { t, labels, getErrorMessage } = useMessages();
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [error, setError] = useState<unknown>(null);
|
||||
|
||||
const handleSubmit = async (data: { name: string }) => {
|
||||
setIsPending(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await post(createPath, {
|
||||
name: data.name,
|
||||
});
|
||||
|
||||
touch('shares');
|
||||
onSave?.();
|
||||
} catch (e) {
|
||||
setError(e);
|
||||
} finally {
|
||||
setIsPending(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit} error={getErrorMessage(error)} defaultValues={{ name: '' }}>
|
||||
<Column gap="4">
|
||||
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
|
||||
<TextField autoComplete="off" autoFocus />
|
||||
</FormField>
|
||||
<Row justifyContent="flex-end" gap="3">
|
||||
{onCancel && (
|
||||
<Button isDisabled={isPending} onPress={onCancel}>
|
||||
{t(labels.cancel)}
|
||||
</Button>
|
||||
)}
|
||||
<FormSubmitButton variant="primary" isDisabled={isPending}>
|
||||
{t(labels.add)}
|
||||
</FormSubmitButton>
|
||||
</Row>
|
||||
</Column>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { DataColumn, DataTable, type DataTableProps, Row } from '@umami/react-zen';
|
||||
import { ShareDeleteButton } from '@/app/(main)/websites/[websiteId]/settings/ShareDeleteButton';
|
||||
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';
|
||||
|
||||
export function SimpleSharesTable(props: DataTableProps) {
|
||||
const { t, labels } = useMessages();
|
||||
const { cloudMode } = useConfig();
|
||||
const { isMobile } = useMobile();
|
||||
|
||||
const getUrl = (slug: string) => {
|
||||
if (cloudMode) {
|
||||
return `${process.env.cloudUrl}/share/${slug}`;
|
||||
}
|
||||
|
||||
return `${window?.location.origin}${process.env.basePath || ''}/share/${slug}`;
|
||||
};
|
||||
|
||||
return (
|
||||
<DataTable {...props} displayMode={isMobile ? 'cards' : 'table'}>
|
||||
<DataColumn id="name" label={t(labels.name)}>
|
||||
{({ name }: any) => name}
|
||||
</DataColumn>
|
||||
<DataColumn id="slug" label={t(labels.shareUrl)} width="2fr">
|
||||
{({ slug }: any) => {
|
||||
const url = getUrl(slug);
|
||||
|
||||
return (
|
||||
<Row alignItems="center" gap="1" overflow="hidden">
|
||||
<ExternalLink href={url} prefetch={false}>
|
||||
{isMobile ? slug : url}
|
||||
</ExternalLink>
|
||||
<CopyButton value={url} label="Copy URL" />
|
||||
</Row>
|
||||
);
|
||||
}}
|
||||
</DataColumn>
|
||||
<DataColumn id="created" label={t(labels.created)}>
|
||||
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
|
||||
</DataColumn>
|
||||
<DataColumn id="action" align="end" width="60px">
|
||||
{({ id, slug }: any) => (
|
||||
<Row>
|
||||
<ShareDeleteButton shareId={id} slug={slug} />
|
||||
</Row>
|
||||
)}
|
||||
</DataColumn>
|
||||
</DataTable>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user