add share page options enable filtering and enforce theme
This commit is contained in:
1 parent
5ccfb6d0a5
commit
9b099408c2
75 files changed
+450
-172
No files matched your search
@@ -1,6 +1,16 @@
|
||||
import { Button, Column, Form, FormField, FormSubmitButton, Row, TextField } from '@umami/react-zen';
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Column,
|
||||
Form,
|
||||
FormField,
|
||||
FormSubmitButton,
|
||||
Row,
|
||||
TextField,
|
||||
} from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { useApi, useMessages, useModified } from '@/components/hooks';
|
||||
import { ThemeModeSelector } from '@/components/input/ThemeModeSelector';
|
||||
|
||||
export function BoardShareCreateForm({
|
||||
boardId,
|
||||
@@ -15,15 +25,19 @@ export function BoardShareCreateForm({
|
||||
const { touch } = useModified();
|
||||
const { t, labels, getErrorMessage } = useMessages();
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [error, setError] = useState<unknown>(null);
|
||||
const [error, setError] = useState<any>(null);
|
||||
|
||||
const handleSubmit = async (data: { name: string }) => {
|
||||
const handleSubmit = async (data: { name: string; allowFilter?: boolean; theme?: string }) => {
|
||||
setIsPending(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await post(`/boards/${boardId}/shares`, {
|
||||
name: data.name,
|
||||
parameters: {
|
||||
allowFilter: data.allowFilter ?? true,
|
||||
theme: data.theme === 'system' ? undefined : data.theme,
|
||||
},
|
||||
});
|
||||
|
||||
touch('shares');
|
||||
@@ -36,22 +50,38 @@ export function BoardShareCreateForm({
|
||||
};
|
||||
|
||||
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
|
||||
onSubmit={handleSubmit}
|
||||
error={getErrorMessage(error)}
|
||||
defaultValues={{ name: '', allowFilter: true, theme: 'system' }}
|
||||
>
|
||||
{({ watch, setValue }) => (
|
||||
<Column gap="4">
|
||||
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
|
||||
<TextField autoComplete="off" autoFocus />
|
||||
</FormField>
|
||||
<FormField name="allowFilter">
|
||||
<Checkbox>{t(labels.filters)}</Checkbox>
|
||||
</FormField>
|
||||
<FormField label={t(labels.theme)} name="theme">
|
||||
<ThemeModeSelector
|
||||
value={watch('theme')}
|
||||
includeSystem
|
||||
onChange={value => setValue('theme', value, { shouldDirty: true })}
|
||||
/>
|
||||
</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>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { CopyButton } from '@/components/common/CopyButton';
|
||||
import { ExternalLink } from '@/components/common/ExternalLink';
|
||||
import { useConfig, useMessages, useMobile } from '@/components/hooks';
|
||||
import { DataColumn, DataTable, type DataTableProps, Row } from '@umami/react-zen';
|
||||
import { SimpleShareEditButton } from '@/components/share/SimpleShareEditButton';
|
||||
|
||||
export function BoardSharesTable(props: DataTableProps) {
|
||||
const { t, labels } = useMessages();
|
||||
@@ -36,9 +37,10 @@ export function BoardSharesTable(props: DataTableProps) {
|
||||
);
|
||||
}}
|
||||
</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>
|
||||
)}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Column, Row } from '@umami/react-zen';
|
||||
import { useShare } from '@/components/hooks';
|
||||
import { ExportButton } from '@/components/input/ExportButton';
|
||||
import { FilterBar } from '@/components/input/FilterBar';
|
||||
import { MonthFilter } from '@/components/input/MonthFilter';
|
||||
import { WebsiteDateFilter } from '@/components/input/WebsiteDateFilter';
|
||||
import { WebsiteFilterButton } from '@/components/input/WebsiteFilterButton';
|
||||
import { allowShareFilter } from '@/lib/share';
|
||||
|
||||
export function LinkControls({
|
||||
linkId: websiteId,
|
||||
@@ -18,15 +20,18 @@ export function LinkControls({
|
||||
allowMonthFilter?: boolean;
|
||||
allowDownload?: boolean;
|
||||
}) {
|
||||
const share = useShare();
|
||||
const showFilter = allowFilter && allowShareFilter(share?.parameters);
|
||||
|
||||
return (
|
||||
<Column gap>
|
||||
<Row alignItems="center" justifyContent="space-between" gap="3">
|
||||
{allowFilter ? <WebsiteFilterButton websiteId={websiteId} /> : <div />}
|
||||
{showFilter ? <WebsiteFilterButton websiteId={websiteId} /> : <div />}
|
||||
{allowDateFilter && <WebsiteDateFilter websiteId={websiteId} showAllTime={false} />}
|
||||
{allowDownload && <ExportButton websiteId={websiteId} />}
|
||||
{allowMonthFilter && <MonthFilter />}
|
||||
</Row>
|
||||
{allowFilter && <FilterBar websiteId={websiteId} />}
|
||||
{showFilter && <FilterBar websiteId={websiteId} />}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Column, Row } from '@umami/react-zen';
|
||||
import { useShare } from '@/components/hooks';
|
||||
import { ExportButton } from '@/components/input/ExportButton';
|
||||
import { FilterBar } from '@/components/input/FilterBar';
|
||||
import { MonthFilter } from '@/components/input/MonthFilter';
|
||||
import { WebsiteDateFilter } from '@/components/input/WebsiteDateFilter';
|
||||
import { WebsiteFilterButton } from '@/components/input/WebsiteFilterButton';
|
||||
import { allowShareFilter } from '@/lib/share';
|
||||
|
||||
export function PixelControls({
|
||||
pixelId: websiteId,
|
||||
@@ -18,15 +20,18 @@ export function PixelControls({
|
||||
allowMonthFilter?: boolean;
|
||||
allowDownload?: boolean;
|
||||
}) {
|
||||
const share = useShare();
|
||||
const showFilter = allowFilter && allowShareFilter(share?.parameters);
|
||||
|
||||
return (
|
||||
<Column gap>
|
||||
<Row alignItems="center" justifyContent="space-between" gap="3">
|
||||
{allowFilter ? <WebsiteFilterButton websiteId={websiteId} /> : <div />}
|
||||
{showFilter ? <WebsiteFilterButton websiteId={websiteId} /> : <div />}
|
||||
{allowDateFilter && <WebsiteDateFilter websiteId={websiteId} showAllTime={false} />}
|
||||
{allowDownload && <ExportButton websiteId={websiteId} />}
|
||||
{allowMonthFilter && <MonthFilter />}
|
||||
</Row>
|
||||
{allowFilter && <FilterBar websiteId={websiteId} />}
|
||||
{showFilter && <FilterBar websiteId={websiteId} />}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
@@ -1,21 +1,8 @@
|
||||
import { Button, Icon, Row, useTheme } from '@umami/react-zen';
|
||||
import { Moon, Sun } from '@/components/icons';
|
||||
import { useTheme } from '@umami/react-zen';
|
||||
import { ThemeModeSelector } from '@/components/input/ThemeModeSelector';
|
||||
|
||||
export function ThemeSetting() {
|
||||
const { theme, setTheme } = useTheme();
|
||||
|
||||
return (
|
||||
<Row gap>
|
||||
<Button variant={theme === 'light' ? 'primary' : undefined} onPress={() => setTheme('light')}>
|
||||
<Icon>
|
||||
<Sun />
|
||||
</Icon>
|
||||
</Button>
|
||||
<Button variant={theme === 'dark' ? 'primary' : undefined} onPress={() => setTheme('dark')}>
|
||||
<Icon>
|
||||
<Moon />
|
||||
</Icon>
|
||||
</Button>
|
||||
</Row>
|
||||
);
|
||||
return <ThemeModeSelector value={theme} onChange={value => setTheme(value as 'light' | 'dark')} />;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { DataColumn, DataTable, type DataTableProps, Icon } from '@umami/react-zen';
|
||||
import type { ReactNode } from 'react';
|
||||
import { DateDistance } from '@/components/common/DateDistance';
|
||||
import { LinkButton } from '@/components/common/LinkButton';
|
||||
import { SortableLabel } from '@/components/common/SortableLabel';
|
||||
import { useMessages, useNavigation } from '@/components/hooks';
|
||||
@@ -22,6 +23,13 @@ export function WebsitesTable({ showActions, renderLink, ...props }: WebsitesTab
|
||||
{renderLink}
|
||||
</DataColumn>
|
||||
<DataColumn id="domain" label={<SortableLabel label={t(labels.domain)} sortKey="domain" />} />
|
||||
<DataColumn
|
||||
id="created"
|
||||
label={<SortableLabel label={t(labels.created)} sortKey="createdAt" defaultDirection="desc" />}
|
||||
width="200px"
|
||||
>
|
||||
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
|
||||
</DataColumn>
|
||||
{showActions && (
|
||||
<DataColumn id="action" label=" " align="end">
|
||||
{(row: any) => {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Column, Grid, Row } from '@umami/react-zen';
|
||||
import { useShare } from '@/components/hooks';
|
||||
import { ExportButton } from '@/components/input/ExportButton';
|
||||
import { FilterBar } from '@/components/input/FilterBar';
|
||||
import { MonthFilter } from '@/components/input/MonthFilter';
|
||||
import { WebsiteDateFilter } from '@/components/input/WebsiteDateFilter';
|
||||
import { WebsiteFilterButton } from '@/components/input/WebsiteFilterButton';
|
||||
import { allowShareFilter } from '@/lib/share';
|
||||
|
||||
export function WebsiteControls({
|
||||
websiteId,
|
||||
@@ -22,11 +24,16 @@ export function WebsiteControls({
|
||||
allowDownload?: boolean;
|
||||
allowCompare?: boolean;
|
||||
}) {
|
||||
const share = useShare();
|
||||
const showFilter = allowFilter && allowShareFilter(share?.parameters);
|
||||
|
||||
return (
|
||||
<Column gap>
|
||||
<Grid columns={{ base: '1fr', md: 'auto 1fr' }} gap>
|
||||
<Row alignItems="center" justifyContent="flex-start" gap="4">
|
||||
{allowFilter && <WebsiteFilterButton websiteId={websiteId} allowBounceFilter={allowBounceFilter} />}
|
||||
{showFilter && (
|
||||
<WebsiteFilterButton websiteId={websiteId} allowBounceFilter={allowBounceFilter} />
|
||||
)}
|
||||
</Row>
|
||||
<Row alignItems="center" justifyContent={{ base: 'flex-start', md: 'flex-end' }}>
|
||||
{allowDateFilter && (
|
||||
@@ -36,7 +43,7 @@ export function WebsiteControls({
|
||||
{allowMonthFilter && <MonthFilter />}
|
||||
</Row>
|
||||
</Grid>
|
||||
{allowFilter && <FilterBar websiteId={websiteId} />}
|
||||
{showFilter && <FilterBar websiteId={websiteId} />}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
@@ -7,13 +7,16 @@ import {
|
||||
FormSubmitButton,
|
||||
Grid,
|
||||
Label,
|
||||
ListSeparator,
|
||||
Loading,
|
||||
Row,
|
||||
Switch,
|
||||
Text,
|
||||
TextField,
|
||||
} from '@umami/react-zen';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useApi, useConfig, useMessages, useModified } from '@/components/hooks';
|
||||
import { ThemeModeSelector } from '@/components/input/ThemeModeSelector';
|
||||
import { SHARE_NAV_ITEMS } from './constants';
|
||||
|
||||
export function ShareEditForm({
|
||||
@@ -59,12 +62,14 @@ export function ShareEditForm({
|
||||
}, [shareId, modified]);
|
||||
|
||||
const handleSubmit = async (data: any) => {
|
||||
const parameters: Record<string, boolean> = {};
|
||||
const parameters: Record<string, boolean | string | undefined> = {};
|
||||
SHARE_NAV_ITEMS.forEach(section => {
|
||||
section.items.forEach(item => {
|
||||
parameters[item.id] = data[item.id] ?? false;
|
||||
});
|
||||
});
|
||||
parameters.allowFilter = data.allowFilter ?? true;
|
||||
parameters.theme = data.theme === 'system' ? undefined : data.theme;
|
||||
|
||||
setIsPending(true);
|
||||
setError(null);
|
||||
@@ -101,6 +106,8 @@ export function ShareEditForm({
|
||||
// Build default values from share parameters
|
||||
const defaultValues: Record<string, any> = {
|
||||
name: share?.name || '',
|
||||
allowFilter: share?.parameters?.allowFilter ?? true,
|
||||
theme: share?.parameters?.theme || 'system',
|
||||
};
|
||||
SHARE_NAV_ITEMS.forEach(section => {
|
||||
section.items.forEach(item => {
|
||||
@@ -114,7 +121,7 @@ export function ShareEditForm({
|
||||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit} error={getErrorMessage(error)} defaultValues={defaultValues}>
|
||||
{({ watch }) => {
|
||||
{({ watch, setValue }) => {
|
||||
const values = watch();
|
||||
const hasSelection = allItemIds.some(id => values[id]);
|
||||
|
||||
@@ -129,7 +136,25 @@ export function ShareEditForm({
|
||||
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
|
||||
<TextField autoComplete="off" autoFocus={!isEditing} />
|
||||
</FormField>
|
||||
<Grid columns="repeat(auto-fit, minmax(150px, 1fr))" gap="3">
|
||||
<Grid columns={{ base: 'repeat(2, 1fr)', lg: 'repeat(3, 1fr)' }} gap="3">
|
||||
<FormField label={t(labels.filters)} name="allowFilter">
|
||||
<Switch
|
||||
isSelected={watch('allowFilter')}
|
||||
onChange={value => setValue('allowFilter', value, { shouldDirty: true })}
|
||||
>
|
||||
{t(labels.filtersEnabled)}
|
||||
</Switch>
|
||||
</FormField>
|
||||
<FormField label={t(labels.theme)} name="theme">
|
||||
<ThemeModeSelector
|
||||
value={watch('theme')}
|
||||
includeSystem
|
||||
onChange={value => setValue('theme', value, { shouldDirty: true })}
|
||||
/>
|
||||
</FormField>
|
||||
</Grid>
|
||||
<ListSeparator />
|
||||
<Grid columns={{ base: 'repeat(2, 1fr)', lg: 'repeat(3, 1fr)' }} gap="3">
|
||||
{SHARE_NAV_ITEMS.map(section => (
|
||||
<Column key={section.section} gap="3">
|
||||
<Text weight="bold">{t((labels as any)[section.section])}</Text>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { uuid } from '@/lib/crypto';
|
||||
import { getRandomChars } from '@/lib/generate';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { filterParams, pagingParams } from '@/lib/schema';
|
||||
import { anyObjectParam, filterParams, pagingParams } from '@/lib/schema';
|
||||
import { canUpdateBoard, canViewBoard } from '@/permissions';
|
||||
import { createShare, getSharesByEntityId } from '@/queries/prisma';
|
||||
|
||||
@@ -45,6 +45,7 @@ export async function POST(
|
||||
) {
|
||||
const schema = z.object({
|
||||
name: z.string().max(200),
|
||||
parameters: anyObjectParam.optional(),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
@@ -54,7 +55,8 @@ export async function POST(
|
||||
}
|
||||
|
||||
const { boardId } = await params;
|
||||
const { name } = body;
|
||||
const { name, parameters } = body;
|
||||
const shareParameters = parameters ?? {};
|
||||
|
||||
if (!(await canUpdateBoard(auth, boardId))) {
|
||||
return unauthorized();
|
||||
@@ -66,7 +68,7 @@ export async function POST(
|
||||
shareType: ENTITY_TYPE.board,
|
||||
name,
|
||||
slug: getRandomChars(16),
|
||||
parameters: {},
|
||||
parameters: shareParameters,
|
||||
});
|
||||
|
||||
return json(share);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { uuid } from '@/lib/crypto';
|
||||
import { getRandomChars } from '@/lib/generate';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { filterParams, pagingParams } from '@/lib/schema';
|
||||
import { anyObjectParam, filterParams, pagingParams } from '@/lib/schema';
|
||||
import { canUpdateLink, canViewLink } from '@/permissions';
|
||||
import { createShare, getSharesByEntityId } from '@/queries/prisma';
|
||||
|
||||
@@ -45,6 +45,7 @@ export async function POST(
|
||||
) {
|
||||
const schema = z.object({
|
||||
name: z.string().max(200),
|
||||
parameters: anyObjectParam.optional(),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
@@ -54,7 +55,8 @@ export async function POST(
|
||||
}
|
||||
|
||||
const { linkId } = await params;
|
||||
const { name } = body;
|
||||
const { name, parameters } = body;
|
||||
const shareParameters = parameters ?? {};
|
||||
|
||||
if (!(await canUpdateLink(auth, linkId))) {
|
||||
return unauthorized();
|
||||
@@ -66,7 +68,7 @@ export async function POST(
|
||||
shareType: ENTITY_TYPE.link,
|
||||
name,
|
||||
slug: getRandomChars(16),
|
||||
parameters: {},
|
||||
parameters: shareParameters,
|
||||
});
|
||||
|
||||
return json(share);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { uuid } from '@/lib/crypto';
|
||||
import { getRandomChars } from '@/lib/generate';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { filterParams, pagingParams } from '@/lib/schema';
|
||||
import { anyObjectParam, filterParams, pagingParams } from '@/lib/schema';
|
||||
import { canUpdatePixel, canViewPixel } from '@/permissions';
|
||||
import { createShare, getSharesByEntityId } from '@/queries/prisma';
|
||||
|
||||
@@ -45,6 +45,7 @@ export async function POST(
|
||||
) {
|
||||
const schema = z.object({
|
||||
name: z.string().max(200),
|
||||
parameters: anyObjectParam.optional(),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
@@ -54,7 +55,8 @@ export async function POST(
|
||||
}
|
||||
|
||||
const { pixelId } = await params;
|
||||
const { name } = body;
|
||||
const { name, parameters } = body;
|
||||
const shareParameters = parameters ?? {};
|
||||
|
||||
if (!(await canUpdatePixel(auth, pixelId))) {
|
||||
return unauthorized();
|
||||
@@ -66,7 +68,7 @@ export async function POST(
|
||||
shareType: ENTITY_TYPE.pixel,
|
||||
name,
|
||||
slug: getRandomChars(16),
|
||||
parameters: {},
|
||||
parameters: shareParameters,
|
||||
});
|
||||
|
||||
return json(share);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
import { useShareTokenQuery } from '@/components/hooks';
|
||||
import { ENTITY_TYPE } from '@/lib/constants';
|
||||
import type { WhiteLabel } from '@/lib/types';
|
||||
import type { ShareParameters, WhiteLabel } from '@/lib/types';
|
||||
import { Loading } from '@umami/react-zen';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { createContext, type ReactNode, useEffect } from 'react';
|
||||
@@ -15,7 +15,7 @@ export interface ShareData {
|
||||
boardId?: string;
|
||||
pixelId?: string;
|
||||
linkId?: string;
|
||||
parameters: any;
|
||||
parameters: ShareParameters;
|
||||
token: string;
|
||||
whiteLabel?: WhiteLabel;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useMessages, useNavigation, useShare } from '@/components/hooks';
|
||||
import { AlignEndHorizontal, Clock, Eye, PanelLeft, Sheet, Tag, User } from '@/components/icons';
|
||||
import { LanguageButton } from '@/components/input/LanguageButton';
|
||||
import { PreferencesButton } from '@/components/input/PreferencesButton';
|
||||
import { allowShareFilter, excludeShareFilterParam, getShareTheme } from '@/lib/share';
|
||||
import { Funnel, Gauge, Lightning, Magnet, Money, Network, Path, Target } from '@/components/svg';
|
||||
import { buildPath } from '@/lib/url';
|
||||
import {
|
||||
@@ -32,12 +33,19 @@ export function ShareNav({
|
||||
const { t, labels } = useMessages();
|
||||
const { pathname, query } = useNavigation();
|
||||
const { slug, parameters } = share;
|
||||
const allowFilter = allowShareFilter(parameters);
|
||||
const shareTheme = getShareTheme(parameters);
|
||||
|
||||
const renderPath = (path: string) =>
|
||||
buildPath(`/share/${slug}${path}`, {
|
||||
...query,
|
||||
...Object.fromEntries(
|
||||
Object.entries(query).filter(([key]) => {
|
||||
return allowFilter || !excludeShareFilterParam(key);
|
||||
}),
|
||||
),
|
||||
event: undefined,
|
||||
compare: undefined,
|
||||
theme: undefined,
|
||||
view: undefined,
|
||||
unit: undefined,
|
||||
excludeBounce: undefined,
|
||||
@@ -202,13 +210,13 @@ export function ShareNav({
|
||||
>
|
||||
{collapsed ? (
|
||||
<Column gap="2" alignItems="center">
|
||||
<ThemeButton />
|
||||
{!shareTheme && <ThemeButton />}
|
||||
<LanguageButton />
|
||||
<PreferencesButton />
|
||||
</Column>
|
||||
) : (
|
||||
<Row>
|
||||
<ThemeButton />
|
||||
{!shareTheme && <ThemeButton />}
|
||||
<LanguageButton />
|
||||
<PreferencesButton />
|
||||
</Row>
|
||||
|
||||
@@ -22,6 +22,7 @@ import { PageBody } from '@/components/common/PageBody';
|
||||
import { useShare } from '@/components/hooks';
|
||||
import { MobileMenuButton } from '@/components/input/MobileMenuButton';
|
||||
import { ENTITY_TYPE } from '@/lib/constants';
|
||||
import { getShareTheme } from '@/lib/share';
|
||||
import { Column, Grid, Row, useTheme } from '@umami/react-zen';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
@@ -68,20 +69,20 @@ export function SharePage() {
|
||||
setNavCollapsed(value);
|
||||
};
|
||||
const share = useShare();
|
||||
const { setTheme } = useTheme();
|
||||
const { initTheme } = useTheme();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const path = getSharePath(pathname);
|
||||
const { slug, websiteId, boardId, pixelId, linkId, parameters = {}, shareType } = share;
|
||||
const shareTheme = getShareTheme(parameters);
|
||||
|
||||
useEffect(() => {
|
||||
const url = new URL(window?.location?.href);
|
||||
const theme = url.searchParams.get('theme');
|
||||
initTheme(shareTheme, 'system');
|
||||
|
||||
if (theme === 'light' || theme === 'dark') {
|
||||
setTheme(theme);
|
||||
}
|
||||
}, [setTheme]);
|
||||
return () => {
|
||||
initTheme(undefined, 'system');
|
||||
};
|
||||
}, [shareTheme, initTheme]);
|
||||
|
||||
// Check if the requested path is allowed
|
||||
const pageKey = path || '';
|
||||
|
||||
Reference in new issue
Block a user