mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Added lookup for cloud account. Added SessionModal component.
This commit is contained in:
parent
caf04015bb
commit
f733690d38
7 changed files with 79 additions and 48 deletions
|
|
@ -1,5 +1,14 @@
|
||||||
import { Text } from '@umami/react-zen';
|
import { Text } from '@umami/react-zen';
|
||||||
import { Eye, User, Clock, Ungroup, Tag, ChartPie, UserPlus, GitCompare } from '@/components/icons';
|
import {
|
||||||
|
Eye,
|
||||||
|
User,
|
||||||
|
Clock,
|
||||||
|
Sheet,
|
||||||
|
Tag,
|
||||||
|
ChartPie,
|
||||||
|
UserPlus,
|
||||||
|
AlignEndHorizontal,
|
||||||
|
} from '@/components/icons';
|
||||||
import { Lightning, Path, Money, Target, Funnel, Magnet, Network } from '@/components/svg';
|
import { Lightning, Path, Money, Target, Funnel, Magnet, Network } from '@/components/svg';
|
||||||
import { useMessages, useNavigation } from '@/components/hooks';
|
import { useMessages, useNavigation } from '@/components/hooks';
|
||||||
import { SideMenu } from '@/components/common/SideMenu';
|
import { SideMenu } from '@/components/common/SideMenu';
|
||||||
|
|
@ -47,13 +56,13 @@ export function WebsiteNav({ websiteId }: { websiteId: string }) {
|
||||||
{
|
{
|
||||||
id: 'compare',
|
id: 'compare',
|
||||||
label: formatMessage(labels.compare),
|
label: formatMessage(labels.compare),
|
||||||
icon: <GitCompare />,
|
icon: <AlignEndHorizontal />,
|
||||||
path: renderPath('/compare'),
|
path: renderPath('/compare'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'breakdown',
|
id: 'breakdown',
|
||||||
label: formatMessage(labels.breakdown),
|
label: formatMessage(labels.breakdown),
|
||||||
icon: <Ungroup />,
|
icon: <Sheet />,
|
||||||
path: renderPath('/breakdown'),
|
path: renderPath('/breakdown'),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import { useMessages } from '@/components/hooks';
|
||||||
import { EventProperties } from './EventProperties';
|
import { EventProperties } from './EventProperties';
|
||||||
import { WebsiteControls } from '@/app/(main)/websites/[websiteId]/WebsiteControls';
|
import { WebsiteControls } from '@/app/(main)/websites/[websiteId]/WebsiteControls';
|
||||||
import { getItem, setItem } from '@/lib/storage';
|
import { getItem, setItem } from '@/lib/storage';
|
||||||
|
import { SessionModal } from '@/app/(main)/websites/[websiteId]/sessions/SessionModal';
|
||||||
|
|
||||||
const KEY_NAME = 'umami.events.tab';
|
const KEY_NAME = 'umami.events.tab';
|
||||||
|
|
||||||
|
|
@ -52,6 +53,7 @@ export function EventsPage({ websiteId }) {
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
<SessionModal websiteId={websiteId} />
|
||||||
</Column>
|
</Column>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { TypeIcon } from '@/components/common/TypeIcon';
|
||||||
|
|
||||||
export function EventsTable({ data = [] }) {
|
export function EventsTable({ data = [] }) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const { renderUrl } = useNavigation();
|
const { updateParams } = useNavigation();
|
||||||
const { formatValue } = useFormat();
|
const { formatValue } = useFormat();
|
||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
|
|
@ -23,7 +23,7 @@ export function EventsTable({ data = [] }) {
|
||||||
{(row: any) => {
|
{(row: any) => {
|
||||||
return (
|
return (
|
||||||
<Row alignItems="center" gap="2">
|
<Row alignItems="center" gap="2">
|
||||||
<Link href={renderUrl(`/websites/${row.websiteId}/sessions/${row.sessionId}`)}>
|
<Link href={updateParams({ session: row.sessionId })}>
|
||||||
<Avatar seed={row.sessionId} size={32} />
|
<Avatar seed={row.sessionId} size={32} />
|
||||||
</Link>
|
</Link>
|
||||||
<Icon>{row.eventName ? <Lightning /> : <Eye />}</Icon>
|
<Icon>{row.eventName ? <Lightning /> : <Eye />}</Icon>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
import { Dialog, Modal, ModalProps } from '@umami/react-zen';
|
||||||
|
import { SessionProfile } from '@/app/(main)/websites/[websiteId]/sessions/SessionProfile';
|
||||||
|
import { useNavigation } from '@/components/hooks';
|
||||||
|
|
||||||
|
export interface SessionModalProps extends ModalProps {
|
||||||
|
websiteId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SessionModal({ websiteId, ...props }: SessionModalProps) {
|
||||||
|
const {
|
||||||
|
router,
|
||||||
|
query: { session },
|
||||||
|
updateParams,
|
||||||
|
} = useNavigation();
|
||||||
|
|
||||||
|
const handleClose = (close: () => void) => {
|
||||||
|
router.push(updateParams({ session: undefined }));
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOpenChange = (isOpen: boolean) => {
|
||||||
|
if (!isOpen) {
|
||||||
|
router.push(updateParams({ session: undefined }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal isOpen={!!session} onOpenChange={handleOpenChange} isDismissable {...props}>
|
||||||
|
<Dialog
|
||||||
|
style={{
|
||||||
|
maxWidth: 1320,
|
||||||
|
width: '100vw',
|
||||||
|
minHeight: '300px',
|
||||||
|
height: 'calc(100vh - 40px)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{({ close }) => {
|
||||||
|
return (
|
||||||
|
<SessionProfile
|
||||||
|
websiteId={websiteId}
|
||||||
|
sessionId={session}
|
||||||
|
onClose={() => handleClose(close)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Dialog>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,35 +1,19 @@
|
||||||
'use client';
|
'use client';
|
||||||
import { Key, useState } from 'react';
|
import { Key, useState } from 'react';
|
||||||
import { TabList, Tab, Tabs, TabPanel, Column, Modal, Dialog } from '@umami/react-zen';
|
import { TabList, Tab, Tabs, TabPanel, Column } from '@umami/react-zen';
|
||||||
import { SessionsDataTable } from './SessionsDataTable';
|
import { SessionsDataTable } from './SessionsDataTable';
|
||||||
import { SessionProperties } from './SessionProperties';
|
import { SessionProperties } from './SessionProperties';
|
||||||
import { useMessages, useNavigation } from '@/components/hooks';
|
import { useMessages } from '@/components/hooks';
|
||||||
import { Panel } from '@/components/common/Panel';
|
import { Panel } from '@/components/common/Panel';
|
||||||
import { WebsiteControls } from '@/app/(main)/websites/[websiteId]/WebsiteControls';
|
import { WebsiteControls } from '@/app/(main)/websites/[websiteId]/WebsiteControls';
|
||||||
import { getItem, setItem } from '@/lib/storage';
|
import { getItem, setItem } from '@/lib/storage';
|
||||||
import { SessionProfile } from '@/app/(main)/websites/[websiteId]/sessions/SessionProfile';
|
import { SessionModal } from '@/app/(main)/websites/[websiteId]/sessions/SessionModal';
|
||||||
|
|
||||||
const KEY_NAME = 'umami.sessions.tab';
|
const KEY_NAME = 'umami.sessions.tab';
|
||||||
|
|
||||||
export function SessionsPage({ websiteId }) {
|
export function SessionsPage({ websiteId }) {
|
||||||
const [tab, setTab] = useState(getItem(KEY_NAME) || 'activity');
|
const [tab, setTab] = useState(getItem(KEY_NAME) || 'activity');
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const {
|
|
||||||
router,
|
|
||||||
query: { session },
|
|
||||||
updateParams,
|
|
||||||
} = useNavigation();
|
|
||||||
|
|
||||||
const handleClose = (close: () => void) => {
|
|
||||||
router.push(updateParams({ session: undefined }));
|
|
||||||
close();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleOpenChange = (isOpen: boolean) => {
|
|
||||||
if (!isOpen) {
|
|
||||||
router.push(updateParams({ session: undefined }));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSelect = (value: Key) => {
|
const handleSelect = (value: Key) => {
|
||||||
setItem(KEY_NAME, value);
|
setItem(KEY_NAME, value);
|
||||||
|
|
@ -53,26 +37,7 @@ export function SessionsPage({ websiteId }) {
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</Panel>
|
</Panel>
|
||||||
<Modal isOpen={!!session} onOpenChange={handleOpenChange} isDismissable>
|
<SessionModal websiteId={websiteId} />
|
||||||
<Dialog
|
|
||||||
style={{
|
|
||||||
maxWidth: 1320,
|
|
||||||
width: '100vw',
|
|
||||||
minHeight: '300px',
|
|
||||||
height: 'calc(100vh - 40px)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{({ close }) => {
|
|
||||||
return (
|
|
||||||
<SessionProfile
|
|
||||||
websiteId={websiteId}
|
|
||||||
sessionId={session}
|
|
||||||
onClose={() => handleClose(close)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
</Dialog>
|
|
||||||
</Modal>
|
|
||||||
</Column>
|
</Column>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import redis from '@/lib/redis';
|
||||||
import { canCreateTeamWebsite, canCreateWebsite } from '@/permissions';
|
import { canCreateTeamWebsite, canCreateWebsite } from '@/permissions';
|
||||||
import { json, unauthorized } from '@/lib/response';
|
import { json, unauthorized } from '@/lib/response';
|
||||||
import { uuid } from '@/lib/crypto';
|
import { uuid } from '@/lib/crypto';
|
||||||
|
|
@ -50,13 +51,17 @@ export async function POST(request: Request) {
|
||||||
|
|
||||||
const { id, name, domain, shareId, teamId } = body;
|
const { id, name, domain, shareId, teamId } = body;
|
||||||
|
|
||||||
if (process.env.CLOUD_MODE && !teamId && !auth.user.hasSubscription) {
|
if (process.env.CLOUD_MODE && !teamId) {
|
||||||
|
const account = await redis.client.get(`account:${auth.user.id}`);
|
||||||
|
|
||||||
|
if (!account?.hasSubscription) {
|
||||||
const count = await getWebsiteCount(auth.user.id);
|
const count = await getWebsiteCount(auth.user.id);
|
||||||
|
|
||||||
if (count >= CLOUD_WEBSITE_LIMIT) {
|
if (count >= CLOUD_WEBSITE_LIMIT) {
|
||||||
return unauthorized({ message: 'Website limit reached.' });
|
return unauthorized({ message: 'Website limit reached.' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((teamId && !(await canCreateTeamWebsite(auth, teamId))) || !(await canCreateWebsite(auth))) {
|
if ((teamId && !(await canCreateTeamWebsite(auth, teamId))) || !(await canCreateWebsite(auth))) {
|
||||||
return unauthorized();
|
return unauthorized();
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,7 @@ export async function getWebsiteCount(userId: string) {
|
||||||
return prisma.client.website.count({
|
return prisma.client.website.count({
|
||||||
where: {
|
where: {
|
||||||
userId,
|
userId,
|
||||||
|
deletedAt: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue