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
@@ -1,19 +1,31 @@
|
||||
import { Row } from '@umami/react-zen';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import { LinkButton } from '@/components/common/LinkButton';
|
||||
import { PageHeader } from '@/components/common/PageHeader';
|
||||
import { useMessages, usePixel, useSlug } from '@/components/hooks';
|
||||
import { ExternalLink, Grid2x2 } from '@/components/icons';
|
||||
import { PixelShareButton } from './PixelShareButton';
|
||||
|
||||
export function PixelHeader() {
|
||||
const { t, labels } = useMessages();
|
||||
const { getSlugUrl } = useSlug('pixel');
|
||||
export function PixelHeader({ showActions = true }: { showActions?: boolean }) {
|
||||
const pixel = usePixel();
|
||||
|
||||
return (
|
||||
<PageHeader title={pixel.name} icon={<Grid2x2 />}>
|
||||
<LinkButton href={getSlugUrl(pixel.slug)} target="_blank" prefetch={false} asAnchor>
|
||||
<IconLabel icon={<ExternalLink />} label={t(labels.view)} />
|
||||
</LinkButton>
|
||||
{showActions && pixel.id && <PixelHeaderActions pixelId={pixel.id} slug={pixel.slug} />}
|
||||
</PageHeader>
|
||||
);
|
||||
}
|
||||
|
||||
function PixelHeaderActions({ pixelId, slug }: { pixelId: string; slug: string }) {
|
||||
const { t, labels } = useMessages();
|
||||
const { getSlugUrl } = useSlug('pixel');
|
||||
|
||||
return (
|
||||
<Row alignItems="center" gap="3">
|
||||
<PixelShareButton pixelId={pixelId} />
|
||||
<LinkButton href={getSlugUrl(slug)} target="_blank" prefetch={false} asAnchor>
|
||||
<IconLabel icon={<ExternalLink />} label={t(labels.view)} />
|
||||
</LinkButton>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
@@ -12,13 +12,19 @@ import { Panel } from '@/components/common/Panel';
|
||||
|
||||
const excludedIds = ['path', 'entry', 'exit', 'title', 'language', 'screen', 'event'];
|
||||
|
||||
export function PixelPage({ pixelId }: { pixelId: string }) {
|
||||
export function PixelPage({
|
||||
pixelId,
|
||||
showHeaderActions = true,
|
||||
}: {
|
||||
pixelId: string;
|
||||
showHeaderActions?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<PixelProvider pixelId={pixelId}>
|
||||
<Grid width="100%" height="100%">
|
||||
<Column margin="2">
|
||||
<PageBody gap>
|
||||
<PixelHeader />
|
||||
<PixelHeader showActions={showHeaderActions} />
|
||||
<PixelControls pixelId={pixelId} />
|
||||
<PixelMetricsBar pixelId={pixelId} showChange={true} />
|
||||
<Panel>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { useMessages } from '@/components/hooks';
|
||||
import { Share } from '@/components/icons';
|
||||
import { DialogButton } from '@/components/input/DialogButton';
|
||||
import { PixelShareDialog } from './PixelShareDialog';
|
||||
|
||||
export function PixelShareButton({ pixelId }: { pixelId: string }) {
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<DialogButton icon={<Share />} label={t(labels.share)} title={null} width="900px">
|
||||
<PixelShareDialog pixelId={pixelId} />
|
||||
</DialogButton>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Button, Column, Heading, Row, Text } from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import { useMessages, usePixelSharesQuery } from '@/components/hooks';
|
||||
import { Plus } from '@/components/icons';
|
||||
import { SimpleShareCreateForm } from '@/components/share/SimpleShareCreateForm';
|
||||
import { SimpleSharesTable } from '@/components/share/SimpleSharesTable';
|
||||
|
||||
export function PixelShareDialog({ pixelId }: { pixelId: string }) {
|
||||
const { data, error, isLoading } = usePixelSharesQuery({ pixelId });
|
||||
const shares = data?.data || [];
|
||||
const hasShares = shares.length > 0;
|
||||
|
||||
return (
|
||||
<LoadingPanel data={data} isLoading={isLoading} error={error}>
|
||||
<PixelShareDialogContent pixelId={pixelId} hasShares={hasShares} shares={shares} />
|
||||
</LoadingPanel>
|
||||
);
|
||||
}
|
||||
|
||||
function PixelShareDialogContent({
|
||||
pixelId,
|
||||
hasShares,
|
||||
shares,
|
||||
}: {
|
||||
pixelId: string;
|
||||
hasShares: boolean;
|
||||
shares: any[];
|
||||
}) {
|
||||
const { t, labels, messages } = useMessages();
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const showCreateForm = !hasShares || isCreating;
|
||||
|
||||
return (
|
||||
<Column gap="4">
|
||||
<Row justifyContent="space-between" alignItems="center">
|
||||
<Heading>{t(labels.share)}</Heading>
|
||||
{hasShares && !isCreating && (
|
||||
<Button variant="primary" onPress={() => setIsCreating(true)}>
|
||||
<IconLabel icon={<Plus size={16} />} label={t(labels.add)} />
|
||||
</Button>
|
||||
)}
|
||||
</Row>
|
||||
{showCreateForm && (
|
||||
<SimpleShareCreateForm
|
||||
createPath={`/pixels/${pixelId}/shares`}
|
||||
onSave={() => setIsCreating(false)}
|
||||
onCancel={hasShares ? () => setIsCreating(false) : undefined}
|
||||
/>
|
||||
)}
|
||||
{hasShares ? (
|
||||
<>
|
||||
<Text>{t(messages.shareUrl)}</Text>
|
||||
<SimpleSharesTable data={shares} />
|
||||
</>
|
||||
) : (
|
||||
!showCreateForm && <Text color="muted">{t(messages.noDataAvailable)}</Text>
|
||||
)}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user