Merge pull request #2 from Openpanel-dev/feature/rename-db-columns
Feature/rename db columns
This commit is contained in:
@@ -33,10 +33,10 @@ const startServer = async () => {
|
||||
fastify.register(profileRouter, { prefix: '/profile' });
|
||||
fastify.register(liveRouter, { prefix: '/live' });
|
||||
fastify.register(miscRouter, { prefix: '/misc' });
|
||||
fastify.setErrorHandler((error, request, reply) => {
|
||||
fastify.setErrorHandler((error) => {
|
||||
fastify.log.error(error);
|
||||
});
|
||||
fastify.get('/', (request, reply) => {
|
||||
fastify.get('/', (_request, reply) => {
|
||||
reply.send({ name: 'openpanel sdk api' });
|
||||
});
|
||||
// fastify.get('/health-check', async (request, reply) => {
|
||||
|
||||
@@ -89,5 +89,5 @@ export async function validateSdkRequest(
|
||||
}
|
||||
}
|
||||
|
||||
return client.project_id;
|
||||
return client.projectId;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
"next-themes": "^0.2.1",
|
||||
"nuqs": "^1.16.1",
|
||||
"prisma-error-enum": "^0.1.3",
|
||||
"pushmodal": "^0.0.8",
|
||||
"pushmodal": "^1.0.0",
|
||||
"ramda": "^0.29.1",
|
||||
"random-animal-name": "^0.1.1",
|
||||
"react": "18.2.0",
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
|
||||
import {
|
||||
getClientsByOrganizationId,
|
||||
getProjectsByOrganizationSlug,
|
||||
} from '@openpanel/db';
|
||||
|
||||
import ListProjects from './list-projects';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationId: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({ params: { organizationId } }: PageProps) {
|
||||
const [projects, clients] = await Promise.all([
|
||||
getProjectsByOrganizationSlug(organizationId),
|
||||
getClientsByOrganizationId(organizationId),
|
||||
]);
|
||||
|
||||
return (
|
||||
<PageLayout title="Projects" organizationSlug={organizationId}>
|
||||
<ListProjects projects={projects} clients={clients} />
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationId]/[projectId]/layout-sticky-below-header';
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationSlug]/[projectId]/layout-sticky-below-header';
|
||||
import { useOverviewOptions } from '@/components/overview/useOverviewOptions';
|
||||
import { LazyChart } from '@/components/report/chart/LazyChart';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -12,10 +12,12 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { useAppParams } from '@/hooks/useAppParams';
|
||||
import { api, handleError } from '@/trpc/client';
|
||||
import { cn } from '@/utils/cn';
|
||||
import { ChevronRight, MoreHorizontal, PlusIcon, Trash } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import {
|
||||
getDefaultIntervalByDates,
|
||||
@@ -33,7 +35,13 @@ export function ListReports({ reports }: ListReportsProps) {
|
||||
const router = useRouter();
|
||||
const params = useAppParams<{ dashboardId: string }>();
|
||||
const { range, startDate, endDate } = useOverviewOptions();
|
||||
|
||||
const deletion = api.report.delete.useMutation({
|
||||
onError: handleError,
|
||||
onSuccess() {
|
||||
router.refresh();
|
||||
toast('Report deleted');
|
||||
},
|
||||
});
|
||||
return (
|
||||
<>
|
||||
<StickyBelowHeader className="flex items-center justify-between p-4">
|
||||
@@ -42,7 +50,7 @@ export function ListReports({ reports }: ListReportsProps) {
|
||||
icon={PlusIcon}
|
||||
onClick={() => {
|
||||
router.push(
|
||||
`/${params.organizationId}/${
|
||||
`/${params.organizationSlug}/${
|
||||
params.projectId
|
||||
}/reports?${new URLSearchParams({
|
||||
dashboardId: params.dashboardId,
|
||||
@@ -60,7 +68,7 @@ export function ListReports({ reports }: ListReportsProps) {
|
||||
return (
|
||||
<div className="card" key={report.id}>
|
||||
<Link
|
||||
href={`/${params.organizationId}/${params.projectId}/reports/${report.id}`}
|
||||
href={`/${params.organizationSlug}/${params.projectId}/reports/${report.id}`}
|
||||
className="flex items-center justify-between border-b border-border p-4 leading-none [&_svg]:hover:opacity-100"
|
||||
shallow
|
||||
>
|
||||
@@ -95,10 +103,10 @@ export function ListReports({ reports }: ListReportsProps) {
|
||||
<DropdownMenuItem
|
||||
className="text-destructive"
|
||||
onClick={(event) => {
|
||||
// event.stopPropagation();
|
||||
// deletion.mutate({
|
||||
// reportId: report.id,
|
||||
// });
|
||||
event.stopPropagation();
|
||||
deletion.mutate({
|
||||
reportId: report.id,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Trash size={16} className="mr-2" />
|
||||
@@ -1,4 +1,4 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
import { getDashboardById, getReportsByDashboardId } from '@openpanel/db';
|
||||
@@ -7,14 +7,14 @@ import { ListReports } from './list-reports';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
dashboardId: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({
|
||||
params: { organizationId, projectId, dashboardId },
|
||||
params: { organizationSlug, projectId, dashboardId },
|
||||
}: PageProps) {
|
||||
const [dashboard, reports] = await Promise.all([
|
||||
getDashboardById(dashboardId, projectId),
|
||||
@@ -26,7 +26,7 @@ export default async function Page({
|
||||
}
|
||||
|
||||
return (
|
||||
<PageLayout title={dashboard.name} organizationSlug={organizationId}>
|
||||
<PageLayout title={dashboard.name} organizationSlug={organizationSlug}>
|
||||
<ListReports reports={reports} />
|
||||
</PageLayout>
|
||||
);
|
||||
@@ -20,7 +20,7 @@ interface ListDashboardsProps {
|
||||
export function ListDashboards({ dashboards }: ListDashboardsProps) {
|
||||
const router = useRouter();
|
||||
const params = useAppParams();
|
||||
const { organizationId, projectId } = params;
|
||||
const { organizationSlug, projectId } = params;
|
||||
const deletion = api.dashboard.delete.useMutation({
|
||||
onError: (error, variables) => {
|
||||
return handleErrorToastOptions({
|
||||
@@ -65,8 +65,8 @@ export function ListDashboards({ dashboards }: ListDashboardsProps) {
|
||||
<Card key={item.id} hover>
|
||||
<div>
|
||||
<Link
|
||||
href={`/${organizationId}/${projectId}/dashboards/${item.id}`}
|
||||
className="block flex flex-col p-4"
|
||||
href={`/${organizationSlug}/${projectId}/dashboards/${item.id}`}
|
||||
className="flex flex-col p-4"
|
||||
>
|
||||
<span className="font-medium">{item.name}</span>
|
||||
</Link>
|
||||
@@ -1,4 +1,4 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
|
||||
import { getDashboardsByProjectId } from '@openpanel/db';
|
||||
|
||||
@@ -8,17 +8,17 @@ import { ListDashboards } from './list-dashboards';
|
||||
interface PageProps {
|
||||
params: {
|
||||
projectId: string;
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({
|
||||
params: { projectId, organizationId },
|
||||
params: { projectId, organizationSlug },
|
||||
}: PageProps) {
|
||||
const dashboards = await getDashboardsByProjectId(projectId);
|
||||
|
||||
return (
|
||||
<PageLayout title="Dashboards" organizationSlug={organizationId}>
|
||||
<PageLayout title="Dashboards" organizationSlug={organizationSlug}>
|
||||
{dashboards.length > 0 && <HeaderDashboards />}
|
||||
<ListDashboards dashboards={dashboards} />
|
||||
</PageLayout>
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Widget } from '@/components/widget';
|
||||
import { escape } from 'sqlstring';
|
||||
|
||||
import { db, getEvents } from '@openpanel/db';
|
||||
@@ -12,7 +11,7 @@ interface Props {
|
||||
export default async function EventConversionsListServer({ projectId }: Props) {
|
||||
const conversions = await db.eventMeta.findMany({
|
||||
where: {
|
||||
project_id: projectId,
|
||||
projectId,
|
||||
conversion: true,
|
||||
},
|
||||
});
|
||||
@@ -15,7 +15,7 @@ import { EventIcon } from './event-icon';
|
||||
type EventListItemProps = IServiceCreateEventPayload;
|
||||
|
||||
export function EventListItem(props: EventListItemProps) {
|
||||
const { organizationId, projectId } = useAppParams();
|
||||
const { organizationSlug, projectId } = useAppParams();
|
||||
const { createdAt, name, path, duration, meta, profile } = props;
|
||||
const [isDetailsOpen, setIsDetailsOpen] = useState(false);
|
||||
|
||||
@@ -77,7 +77,7 @@ export function EventListItem(props: EventListItemProps) {
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
href={`/${organizationId}/${projectId}/profiles/${profile?.id}`}
|
||||
href={`/${organizationSlug}/${projectId}/profiles/${profile?.id}`}
|
||||
className="max-w-[80px] overflow-hidden text-ellipsis whitespace-nowrap text-sm text-muted-foreground hover:underline"
|
||||
>
|
||||
{profile?.firstName} {profile?.lastName}
|
||||
@@ -1,4 +1,4 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
import { OverviewFiltersButtons } from '@/components/overview/filters/overview-filters-buttons';
|
||||
import { OverviewFiltersDrawer } from '@/components/overview/filters/overview-filters-drawer';
|
||||
import {
|
||||
@@ -17,7 +17,7 @@ import { EventList } from './event-list';
|
||||
interface PageProps {
|
||||
params: {
|
||||
projectId: string;
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
};
|
||||
searchParams: {
|
||||
events?: string;
|
||||
@@ -31,7 +31,7 @@ const nuqsOptions = {
|
||||
};
|
||||
|
||||
export default async function Page({
|
||||
params: { projectId, organizationId },
|
||||
params: { projectId, organizationSlug },
|
||||
searchParams,
|
||||
}: PageProps) {
|
||||
const filters =
|
||||
@@ -56,7 +56,7 @@ export default async function Page({
|
||||
]);
|
||||
|
||||
return (
|
||||
<PageLayout title="Events" organizationSlug={organizationId}>
|
||||
<PageLayout title="Events" organizationSlug={organizationSlug}>
|
||||
<StickyBelowHeader className="flex justify-between p-4">
|
||||
<OverviewFiltersDrawer
|
||||
mode="events"
|
||||
@@ -83,49 +83,49 @@ export default function LayoutMenu({ dashboards }: LayoutMenuProps) {
|
||||
<LinkWithIcon
|
||||
icon={WallpaperIcon}
|
||||
label="Overview"
|
||||
href={`/${params.organizationId}/${projectId}`}
|
||||
href={`/${params.organizationSlug}/${projectId}`}
|
||||
/>
|
||||
<LinkWithIcon
|
||||
icon={LayoutPanelTopIcon}
|
||||
label="Dashboards"
|
||||
href={`/${params.organizationId}/${projectId}/dashboards`}
|
||||
href={`/${params.organizationSlug}/${projectId}/dashboards`}
|
||||
/>
|
||||
<LinkWithIcon
|
||||
icon={GanttChartIcon}
|
||||
label="Events"
|
||||
href={`/${params.organizationId}/${projectId}/events`}
|
||||
href={`/${params.organizationSlug}/${projectId}/events`}
|
||||
/>
|
||||
<LinkWithIcon
|
||||
icon={UsersIcon}
|
||||
label="Profiles"
|
||||
href={`/${params.organizationId}/${projectId}/profiles`}
|
||||
href={`/${params.organizationSlug}/${projectId}/profiles`}
|
||||
/>
|
||||
<LinkWithIcon
|
||||
icon={CogIcon}
|
||||
label="Settings"
|
||||
href={`/${params.organizationId}/${projectId}/settings/organization`}
|
||||
href={`/${params.organizationSlug}/${projectId}/settings/organization`}
|
||||
/>
|
||||
{pathname?.includes('/settings/') && (
|
||||
<div className="flex flex-col gap-1 pl-7">
|
||||
<LinkWithIcon
|
||||
icon={BuildingIcon}
|
||||
label="Organization"
|
||||
href={`/${params.organizationId}/${projectId}/settings/organization`}
|
||||
href={`/${params.organizationSlug}/${projectId}/settings/organization`}
|
||||
/>
|
||||
<LinkWithIcon
|
||||
icon={WarehouseIcon}
|
||||
label="Projects"
|
||||
href={`/${params.organizationId}/${projectId}/settings/projects`}
|
||||
href={`/${params.organizationSlug}/${projectId}/settings/projects`}
|
||||
/>
|
||||
<LinkWithIcon
|
||||
icon={UserIcon}
|
||||
label="Profile (yours)"
|
||||
href={`/${params.organizationId}/${projectId}/settings/profile`}
|
||||
href={`/${params.organizationSlug}/${projectId}/settings/profile`}
|
||||
/>
|
||||
<LinkWithIcon
|
||||
icon={BookmarkIcon}
|
||||
label="References"
|
||||
href={`/${params.organizationId}/${projectId}/settings/references`}
|
||||
href={`/${params.organizationSlug}/${projectId}/settings/references`}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@@ -145,7 +145,7 @@ export default function LayoutMenu({ dashboards }: LayoutMenuProps) {
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
href={`/${item.organization_slug}/${item.project_id}/dashboards/${item.id}`}
|
||||
href={`/${item.organizationSlug}/${item.projectId}/dashboards/${item.id}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -18,7 +18,7 @@ export default function LayoutOrganizationSelector({
|
||||
const router = useRouter();
|
||||
|
||||
const organization = organizations.find(
|
||||
(item) => item.slug === params.organizationId
|
||||
(item) => item.slug === params.organizationSlug
|
||||
);
|
||||
|
||||
if (!organization) {
|
||||
@@ -13,7 +13,7 @@ export default function LayoutProjectSelector({
|
||||
projects,
|
||||
}: LayoutProjectSelectorProps) {
|
||||
const router = useRouter();
|
||||
const { organizationId, projectId } = useAppParams();
|
||||
const { organizationSlug, projectId } = useAppParams();
|
||||
const pathname = usePathname() || '';
|
||||
|
||||
return (
|
||||
@@ -24,12 +24,12 @@ export default function LayoutProjectSelector({
|
||||
className="w-auto min-w-0 max-sm:max-w-[100px]"
|
||||
placeholder={'Select project'}
|
||||
onChange={(value) => {
|
||||
if (organizationId && projectId) {
|
||||
if (organizationSlug && projectId) {
|
||||
const split = pathname.replace(projectId, value).split('/');
|
||||
// slicing here will remove everything after /{orgId}/{projectId}/dashboards [slice here] /xxx/xxx/xxx
|
||||
router.push(split.slice(0, 4).join('/'));
|
||||
} else {
|
||||
router.push(`/${organizationId}/${value}`);
|
||||
router.push(`/${organizationSlug}/${value}`);
|
||||
}
|
||||
}}
|
||||
value={projectId}
|
||||
@@ -17,13 +17,13 @@ import LayoutOrganizationSelector from './layout-organization-selector';
|
||||
interface LayoutSidebarProps {
|
||||
organizations: IServiceOrganization[];
|
||||
dashboards: IServiceDashboards;
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
}
|
||||
export function LayoutSidebar({
|
||||
organizations,
|
||||
dashboards,
|
||||
organizationId,
|
||||
organizationSlug,
|
||||
projectId,
|
||||
}: LayoutSidebarProps) {
|
||||
const [active, setActive] = useState(false);
|
||||
@@ -69,7 +69,7 @@ export function LayoutSidebar({
|
||||
<div className="flex flex-col gap-2 bg-background p-4 pt-0">
|
||||
<Link
|
||||
className={cn('flex gap-2', buttonVariants())}
|
||||
href={`/${organizationId}/${projectId}/reports`}
|
||||
href={`/${organizationSlug}/${projectId}/reports`}
|
||||
>
|
||||
<PlusIcon size={16} />
|
||||
Create a report
|
||||
@@ -11,22 +11,22 @@ import { LayoutSidebar } from './layout-sidebar';
|
||||
interface AppLayoutProps {
|
||||
children: React.ReactNode;
|
||||
params: {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function AppLayout({
|
||||
children,
|
||||
params: { organizationId, projectId },
|
||||
params: { organizationSlug, projectId },
|
||||
}: AppLayoutProps) {
|
||||
const [organizations, projects, dashboards] = await Promise.all([
|
||||
getCurrentOrganizations(),
|
||||
getCurrentProjects(organizationId),
|
||||
getCurrentProjects(organizationSlug),
|
||||
getDashboardsByProjectId(projectId),
|
||||
]);
|
||||
|
||||
if (!organizations.find((item) => item.slug === organizationId)) {
|
||||
if (!organizations.find((item) => item.slug === organizationSlug)) {
|
||||
return (
|
||||
<FullPageEmptyState
|
||||
title="Could not find organization"
|
||||
@@ -51,7 +51,7 @@ export default async function AppLayout({
|
||||
return (
|
||||
<div id="dashboard">
|
||||
<LayoutSidebar
|
||||
{...{ organizationId, projectId, organizations, dashboards }}
|
||||
{...{ organizationSlug, projectId, organizations, dashboards }}
|
||||
/>
|
||||
<div className="transition-all lg:pl-72">{children}</div>
|
||||
</div>
|
||||
@@ -1,4 +1,4 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
import { OverviewFiltersButtons } from '@/components/overview/filters/overview-filters-buttons';
|
||||
import { OverviewFiltersDrawer } from '@/components/overview/filters/overview-filters-drawer';
|
||||
import ServerLiveCounter from '@/components/overview/live-counter';
|
||||
@@ -10,7 +10,7 @@ import OverviewTopGeo from '@/components/overview/overview-top-geo';
|
||||
import OverviewTopPages from '@/components/overview/overview-top-pages';
|
||||
import OverviewTopSources from '@/components/overview/overview-top-sources';
|
||||
|
||||
import { db } from '@openpanel/db';
|
||||
import { getShareByProjectId } from '@openpanel/db';
|
||||
|
||||
import OverviewMetrics from '../../../../components/overview/overview-metrics';
|
||||
import { StickyBelowHeader } from './layout-sticky-below-header';
|
||||
@@ -18,22 +18,18 @@ import { OverviewReportRange } from './overview-sticky-header';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({
|
||||
params: { organizationId, projectId },
|
||||
params: { organizationSlug, projectId },
|
||||
}: PageProps) {
|
||||
const share = await db.shareOverview.findUnique({
|
||||
where: {
|
||||
project_id: projectId,
|
||||
},
|
||||
});
|
||||
const share = await getShareByProjectId(projectId);
|
||||
|
||||
return (
|
||||
<PageLayout title="Overview" organizationSlug={organizationId}>
|
||||
<PageLayout title="Overview" organizationSlug={organizationSlug}>
|
||||
<StickyBelowHeader>
|
||||
<div className="flex justify-between gap-2 p-4">
|
||||
<div className="flex gap-2">
|
||||
@@ -1,4 +1,4 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
import { OverviewFiltersButtons } from '@/components/overview/filters/overview-filters-buttons';
|
||||
import { OverviewFiltersDrawer } from '@/components/overview/filters/overview-filters-drawer';
|
||||
import { ProfileAvatar } from '@/components/profiles/profile-avatar';
|
||||
@@ -27,9 +27,9 @@ import { StickyBelowHeader } from '../../layout-sticky-below-header';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
profileId: string;
|
||||
organizationId: string;
|
||||
};
|
||||
searchParams: {
|
||||
events?: string;
|
||||
@@ -41,7 +41,7 @@ interface PageProps {
|
||||
}
|
||||
|
||||
export default async function Page({
|
||||
params: { projectId, profileId, organizationId },
|
||||
params: { projectId, profileId, organizationSlug },
|
||||
searchParams,
|
||||
}: PageProps) {
|
||||
const eventListOptions: GetEventListOptions = {
|
||||
@@ -125,7 +125,7 @@ export default async function Page({
|
||||
|
||||
return (
|
||||
<PageLayout
|
||||
organizationSlug={organizationId}
|
||||
organizationSlug={organizationSlug}
|
||||
title={
|
||||
<div className="flex items-center gap-2">
|
||||
<ProfileAvatar {...profile} size="sm" className="hidden sm:block" />
|
||||
@@ -1,4 +1,4 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
import { OverviewFiltersButtons } from '@/components/overview/filters/overview-filters-buttons';
|
||||
import { OverviewFiltersDrawer } from '@/components/overview/filters/overview-filters-drawer';
|
||||
import { eventQueryFiltersParser } from '@/hooks/useEventQueryFilters';
|
||||
@@ -11,7 +11,7 @@ import ProfileTopServer from './profile-top';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
};
|
||||
searchParams: {
|
||||
@@ -25,11 +25,11 @@ const nuqsOptions = {
|
||||
};
|
||||
|
||||
export default function Page({
|
||||
params: { organizationId, projectId },
|
||||
params: { organizationSlug, projectId },
|
||||
searchParams: { cursor, f },
|
||||
}: PageProps) {
|
||||
return (
|
||||
<PageLayout title="Profiles" organizationSlug={organizationId}>
|
||||
<PageLayout title="Profiles" organizationSlug={organizationSlug}>
|
||||
{/* <StickyBelowHeader className="flex justify-between p-4">
|
||||
<OverviewFiltersDrawer
|
||||
projectId={projectId}
|
||||
@@ -53,7 +53,7 @@ export default function Page({
|
||||
<ProfileLastSeenServer projectId={projectId} />
|
||||
<ProfileTopServer
|
||||
projectId={projectId}
|
||||
organizationId={organizationId}
|
||||
organizationSlug={organizationSlug}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -21,7 +21,7 @@ interface ProfileListProps {
|
||||
count: number;
|
||||
}
|
||||
export function ProfileList({ data, count }: ProfileListProps) {
|
||||
const { organizationId, projectId } = useAppParams();
|
||||
const { organizationSlug, projectId } = useAppParams();
|
||||
const { cursor, setCursor } = useCursor();
|
||||
return (
|
||||
<Widget>
|
||||
@@ -46,7 +46,7 @@ export function ProfileList({ data, count }: ProfileListProps) {
|
||||
render(profile) {
|
||||
return (
|
||||
<Link
|
||||
href={`/${organizationId}/${projectId}/profiles/${profile.id}`}
|
||||
href={`/${organizationSlug}/${projectId}/profiles/${profile.id}`}
|
||||
className="flex items-center gap-2 font-medium"
|
||||
>
|
||||
<ProfileAvatar size="sm" {...profile} />
|
||||
@@ -10,11 +10,11 @@ import { chQuery, getProfiles } from '@openpanel/db';
|
||||
|
||||
interface Props {
|
||||
projectId: string;
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
}
|
||||
|
||||
export default async function ProfileTopServer({
|
||||
organizationId,
|
||||
organizationSlug,
|
||||
projectId,
|
||||
}: Props) {
|
||||
// Days since last event from users
|
||||
@@ -44,7 +44,7 @@ export default async function ProfileTopServer({
|
||||
render(profile) {
|
||||
return (
|
||||
<Link
|
||||
href={`/${organizationId}/${projectId}/profiles/${profile.id}`}
|
||||
href={`/${organizationSlug}/${projectId}/profiles/${profile.id}`}
|
||||
className="flex items-center gap-2 font-medium"
|
||||
>
|
||||
<ProfileAvatar size="sm" {...profile} />
|
||||
@@ -1,4 +1,4 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
import { Pencil } from 'lucide-react';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
@@ -8,14 +8,14 @@ import ReportEditor from '../report-editor';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
reportId: string;
|
||||
organizationId: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({
|
||||
params: { reportId, organizationId },
|
||||
params: { reportId, organizationSlug },
|
||||
}: PageProps) {
|
||||
const report = await getReportById(reportId);
|
||||
|
||||
@@ -25,7 +25,7 @@ export default async function Page({
|
||||
|
||||
return (
|
||||
<PageLayout
|
||||
organizationSlug={organizationId}
|
||||
organizationSlug={organizationSlug}
|
||||
title={
|
||||
<div className="flex cursor-pointer items-center gap-2">
|
||||
{report.name}
|
||||
@@ -1,19 +1,19 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
import { Pencil } from 'lucide-react';
|
||||
|
||||
import ReportEditor from './report-editor';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default function Page({ params: { organizationId } }: PageProps) {
|
||||
export default function Page({ params: { organizationSlug } }: PageProps) {
|
||||
return (
|
||||
<PageLayout
|
||||
organizationSlug={organizationId}
|
||||
organizationSlug={organizationSlug}
|
||||
title={
|
||||
<div className="flex cursor-pointer items-center gap-2">
|
||||
Unnamed report
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationId]/[projectId]/layout-sticky-below-header';
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationSlug]/[projectId]/layout-sticky-below-header';
|
||||
import { ChartSwitch } from '@/components/report/chart';
|
||||
import { ReportChartType } from '@/components/report/ReportChartType';
|
||||
import { ReportInterval } from '@/components/report/ReportInterval';
|
||||
@@ -33,7 +33,7 @@ interface Props {
|
||||
|
||||
export default function CreateInvite({ projects }: Props) {
|
||||
const router = useRouter();
|
||||
const { organizationId: organizationSlug } = useAppParams();
|
||||
const { organizationSlug } = useAppParams();
|
||||
|
||||
const { register, handleSubmit, formState, reset, control } = useForm<IForm>({
|
||||
resolver: zodResolver(zInviteUser),
|
||||
@@ -1,7 +1,7 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
import { getInvites, getOrganizationBySlug } from '@openpanel/db';
|
||||
import { getOrganizationBySlug } from '@openpanel/db';
|
||||
|
||||
import EditOrganization from './edit-organization';
|
||||
import InvitesServer from './invites';
|
||||
@@ -9,12 +9,12 @@ import MembersServer from './members';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({
|
||||
params: { organizationId: organizationSlug },
|
||||
params: { organizationSlug },
|
||||
}: PageProps) {
|
||||
const organization = await getOrganizationBySlug(organizationSlug);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
import { auth } from '@clerk/nextjs';
|
||||
|
||||
import { getUserById } from '@openpanel/db';
|
||||
@@ -8,15 +8,17 @@ import { Logout } from './logout';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
};
|
||||
}
|
||||
export default async function Page({ params: { organizationId } }: PageProps) {
|
||||
export default async function Page({
|
||||
params: { organizationSlug },
|
||||
}: PageProps) {
|
||||
const { userId } = auth();
|
||||
const profile = await getUserById(userId!);
|
||||
|
||||
return (
|
||||
<PageLayout title={profile.lastName} organizationSlug={organizationId}>
|
||||
<PageLayout title={profile.lastName} organizationSlug={organizationSlug}>
|
||||
<div className="flex flex-col gap-4 p-4">
|
||||
<EditProfile profile={profile} />
|
||||
<Logout />
|
||||
@@ -1,9 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationId]/[projectId]/layout-sticky-below-header';
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationSlug]/[projectId]/layout-sticky-below-header';
|
||||
import { ClientActions } from '@/components/clients/client-actions';
|
||||
import { ProjectActions } from '@/components/projects/project-actions';
|
||||
// import { columns } from '@/components/projects/table';
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
@@ -13,7 +12,6 @@ import {
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Tooltiper } from '@/components/ui/tooltip';
|
||||
import { useAppParams } from '@/hooks/useAppParams';
|
||||
import { pushModal } from '@/modals';
|
||||
import { InfoIcon, PlusIcon, PlusSquareIcon } from 'lucide-react';
|
||||
|
||||
@@ -24,20 +22,12 @@ interface ListProjectsProps {
|
||||
clients: IServiceClientWithProject[];
|
||||
}
|
||||
export default function ListProjects({ projects, clients }: ListProjectsProps) {
|
||||
const organizationId = useAppParams().organizationId;
|
||||
return (
|
||||
<>
|
||||
<StickyBelowHeader>
|
||||
<div className="flex items-center justify-between p-4">
|
||||
<div />
|
||||
<Button
|
||||
icon={PlusIcon}
|
||||
onClick={() =>
|
||||
pushModal('AddProject', {
|
||||
organizationId,
|
||||
})
|
||||
}
|
||||
>
|
||||
<Button icon={PlusIcon} onClick={() => pushModal('AddProject')}>
|
||||
<span className="max-sm:hidden">Create project</span>
|
||||
<span className="sm:hidden">Project</span>
|
||||
</Button>
|
||||
@@ -57,7 +47,7 @@ export default function ListProjects({ projects, clients }: ListProjectsProps) {
|
||||
<Accordion type="single" collapsible className="-mx-4">
|
||||
{projects.map((project) => {
|
||||
const pClients = clients.filter(
|
||||
(client) => client.project_id === project.id
|
||||
(client) => client.projectId === project.id
|
||||
);
|
||||
return (
|
||||
<AccordionItem
|
||||
@@ -0,0 +1,29 @@
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
|
||||
import {
|
||||
getClientsByOrganizationSlug,
|
||||
getProjectsByOrganizationSlug,
|
||||
} from '@openpanel/db';
|
||||
|
||||
import ListProjects from './list-projects';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationSlug: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({
|
||||
params: { organizationSlug },
|
||||
}: PageProps) {
|
||||
const [projects, clients] = await Promise.all([
|
||||
getProjectsByOrganizationSlug(organizationSlug),
|
||||
getClientsByOrganizationSlug(organizationSlug),
|
||||
]);
|
||||
|
||||
return (
|
||||
<PageLayout title="Projects" organizationSlug={organizationSlug}>
|
||||
<ListProjects projects={projects} clients={clients} />
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationId]/[projectId]/layout-sticky-below-header';
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationSlug]/[projectId]/layout-sticky-below-header';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { columns } from '@/components/references/table';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -1,4 +1,4 @@
|
||||
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
|
||||
import PageLayout from '@/app/(app)/[organizationSlug]/[projectId]/page-layout';
|
||||
|
||||
import { getReferences } from '@openpanel/db';
|
||||
|
||||
@@ -6,24 +6,24 @@ import ListReferences from './list-references';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({
|
||||
params: { organizationId, projectId },
|
||||
params: { organizationSlug, projectId },
|
||||
}: PageProps) {
|
||||
const references = await getReferences({
|
||||
where: {
|
||||
project_id: projectId,
|
||||
projectId,
|
||||
},
|
||||
take: 50,
|
||||
skip: 0,
|
||||
});
|
||||
|
||||
return (
|
||||
<PageLayout title="References" organizationSlug={organizationId}>
|
||||
<PageLayout title="References" organizationSlug={organizationSlug}>
|
||||
<ListReferences data={references} />
|
||||
</PageLayout>
|
||||
);
|
||||
@@ -36,7 +36,7 @@ export function CreateProject() {
|
||||
const onSubmit: SubmitHandler<IForm> = (values) => {
|
||||
mutation.mutate({
|
||||
name: values.name,
|
||||
organizationId: params.organizationId,
|
||||
organizationSlug: params.organizationSlug,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -12,14 +12,16 @@ import { CreateProject } from './create-project';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({ params: { organizationId } }: PageProps) {
|
||||
export default async function Page({
|
||||
params: { organizationSlug },
|
||||
}: PageProps) {
|
||||
const [organization, projects] = await Promise.all([
|
||||
getOrganizationBySlug(organizationId),
|
||||
getCurrentProjects(organizationId),
|
||||
getOrganizationBySlug(organizationSlug),
|
||||
getCurrentProjects(organizationSlug),
|
||||
]);
|
||||
|
||||
if (!organization) {
|
||||
@@ -55,7 +57,7 @@ export default async function Page({ params: { organizationId } }: PageProps) {
|
||||
}
|
||||
|
||||
if (projects.length === 1 && projects[0]) {
|
||||
return redirect(`/${organizationId}/${projects[0].id}`);
|
||||
return redirect(`/${organizationSlug}/${projects[0].id}`);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -1,5 +1,5 @@
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationId]/[projectId]/layout-sticky-below-header';
|
||||
import { OverviewReportRange } from '@/app/(app)/[organizationId]/[projectId]/overview-sticky-header';
|
||||
import { StickyBelowHeader } from '@/app/(app)/[organizationSlug]/[projectId]/layout-sticky-below-header';
|
||||
import { OverviewReportRange } from '@/app/(app)/[organizationSlug]/[projectId]/overview-sticky-header';
|
||||
import { Logo } from '@/components/logo';
|
||||
import { OverviewFiltersButtons } from '@/components/overview/filters/overview-filters-buttons';
|
||||
import ServerLiveCounter from '@/components/overview/live-counter';
|
||||
@@ -28,8 +28,8 @@ export default async function Page({ params: { id } }: PageProps) {
|
||||
if (!share.public) {
|
||||
return notFound();
|
||||
}
|
||||
const projectId = share.project_id;
|
||||
const organization = await getOrganizationBySlug(share.organization_slug);
|
||||
const projectId = share.projectId;
|
||||
const organization = await getOrganizationBySlug(share.organizationSlug);
|
||||
|
||||
return (
|
||||
<div className="bg-gradient-to-tl from-blue-950 to-blue-600 p-4 md:p-16">
|
||||
|
||||
@@ -12,9 +12,9 @@ export async function POST(request: Request) {
|
||||
data: access
|
||||
.filter((a): a is string => typeof a === 'string')
|
||||
.map((projectId) => ({
|
||||
organization_slug: payload.data.organization.slug!,
|
||||
project_id: projectId,
|
||||
user_id: payload.data.public_user_data.user_id,
|
||||
organizationSlug: payload.data.organization.slug!,
|
||||
projectId: projectId,
|
||||
userId: payload.data.public_user_data.user_id,
|
||||
level: AccessLevel.read,
|
||||
})),
|
||||
});
|
||||
@@ -23,8 +23,8 @@ export async function POST(request: Request) {
|
||||
if (payload.type === 'organizationMembership.deleted') {
|
||||
await db.projectAccess.deleteMany({
|
||||
where: {
|
||||
organization_slug: payload.data.organization.slug!,
|
||||
user_id: payload.data.public_user_data.user_id,
|
||||
organizationSlug: payload.data.organization.slug!,
|
||||
userId: payload.data.public_user_data.user_id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,9 +58,8 @@ export function OverviewShare({ data }: OverviewShareProps) {
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
mutation.mutate({
|
||||
...data,
|
||||
public: false,
|
||||
projectId: data?.project_id,
|
||||
organizationId: data?.organization_slug,
|
||||
password: null,
|
||||
});
|
||||
}}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { useParams } from 'next/navigation';
|
||||
|
||||
// eslint-disable-next-line
|
||||
type AppParams = {
|
||||
organizationId: string;
|
||||
organizationSlug: string;
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
@@ -10,7 +9,7 @@ export function useAppParams<T>() {
|
||||
const params = useParams<T & AppParams>();
|
||||
return {
|
||||
...(params ?? {}),
|
||||
organizationId: params?.organizationId,
|
||||
organizationSlug: params?.organizationSlug,
|
||||
projectId: params?.projectId,
|
||||
} as T & AppParams;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ interface Props {
|
||||
projectId: string;
|
||||
}
|
||||
export default function AddClient(props: Props) {
|
||||
const { organizationId, projectId } = useAppParams();
|
||||
const { organizationSlug, projectId } = useAppParams();
|
||||
const router = useRouter();
|
||||
const form = useForm<IForm>({
|
||||
resolver: zodResolver(validation),
|
||||
@@ -62,14 +62,14 @@ export default function AddClient(props: Props) {
|
||||
},
|
||||
});
|
||||
const query = api.project.list.useQuery({
|
||||
organizationId,
|
||||
organizationSlug,
|
||||
});
|
||||
const onSubmit: SubmitHandler<IForm> = (values) => {
|
||||
mutation.mutate({
|
||||
name: values.name,
|
||||
cors: values.tab === 'website' ? values.cors : null,
|
||||
projectId: values.projectId,
|
||||
organizationId,
|
||||
organizationSlug,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ const validator = z.object({
|
||||
type IForm = z.infer<typeof validator>;
|
||||
|
||||
export default function AddDashboard() {
|
||||
const { projectId, organizationId: organizationSlug } = useAppParams();
|
||||
const { projectId, organizationSlug } = useAppParams();
|
||||
const router = useRouter();
|
||||
|
||||
const { register, handleSubmit, formState } = useForm<IForm>({
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ButtonContainer } from '@/components/button-container';
|
||||
import { InputWithLabel } from '@/components/forms/input-with-label';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useAppParams } from '@/hooks/useAppParams';
|
||||
import { api, handleError } from '@/trpc/client';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useRouter } from 'next/navigation';
|
||||
@@ -16,10 +17,9 @@ const validator = z.object({
|
||||
});
|
||||
|
||||
type IForm = z.infer<typeof validator>;
|
||||
interface AddProjectProps {
|
||||
organizationId: string;
|
||||
}
|
||||
export default function AddProject({ organizationId }: AddProjectProps) {
|
||||
|
||||
export default function AddProject() {
|
||||
const { organizationSlug } = useAppParams();
|
||||
const router = useRouter();
|
||||
const mutation = api.project.create.useMutation({
|
||||
onError: handleError,
|
||||
@@ -45,7 +45,7 @@ export default function AddProject({ organizationId }: AddProjectProps) {
|
||||
onSubmit={handleSubmit((values) => {
|
||||
mutation.mutate({
|
||||
...values,
|
||||
organizationId,
|
||||
organizationSlug,
|
||||
});
|
||||
})}
|
||||
>
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { ButtonContainer } from '@/components/button-container';
|
||||
import { InputWithLabel } from '@/components/forms/input-with-label';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Calendar } from '@/components/ui/calendar';
|
||||
import { useAppParams } from '@/hooks/useAppParams';
|
||||
import { api, handleError } from '@/trpc/client';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { Controller, useForm } from 'react-hook-form';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { toast } from 'sonner';
|
||||
import type { z } from 'zod';
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ type EditReportProps = {
|
||||
};
|
||||
|
||||
export default function EditReport({ form, onSubmit }: EditReportProps) {
|
||||
const { register, handleSubmit, reset, formState } = useForm<IForm>({
|
||||
const { register, handleSubmit, formState } = useForm<IForm>({
|
||||
resolver: zodResolver(validator),
|
||||
defaultValues: form,
|
||||
});
|
||||
|
||||
@@ -8,10 +8,11 @@ import { popModal } from '..';
|
||||
|
||||
interface ModalContentProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function ModalContent({ children }: ModalContentProps) {
|
||||
return <DialogContent>{children}</DialogContent>;
|
||||
export function ModalContent({ children, className }: ModalContentProps) {
|
||||
return <DialogContent className={className}>{children}</DialogContent>;
|
||||
}
|
||||
|
||||
interface ModalHeaderProps {
|
||||
|
||||
@@ -30,7 +30,7 @@ type IForm = z.infer<typeof validator>;
|
||||
|
||||
export default function SaveReport({ report }: SaveReportProps) {
|
||||
const router = useRouter();
|
||||
const { organizationId: organizationSlug, projectId } = useAppParams();
|
||||
const { organizationSlug, projectId } = useAppParams();
|
||||
const searchParams = useSearchParams();
|
||||
const dashboardId = searchParams?.get('dashboardId') ?? undefined;
|
||||
|
||||
|
||||
@@ -20,16 +20,16 @@ const validator = zShareOverview;
|
||||
type IForm = z.infer<typeof validator>;
|
||||
|
||||
export default function ShareOverviewModal() {
|
||||
const { projectId, organizationId: organizationSlug } = useAppParams();
|
||||
const { projectId, organizationSlug } = useAppParams();
|
||||
const router = useRouter();
|
||||
|
||||
const { register, handleSubmit, formState, control } = useForm<IForm>({
|
||||
const { register, handleSubmit, control } = useForm<IForm>({
|
||||
resolver: zodResolver(validator),
|
||||
defaultValues: {
|
||||
public: true,
|
||||
password: '',
|
||||
projectId,
|
||||
organizationId: organizationSlug,
|
||||
organizationSlug,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -5,8 +5,13 @@ import dynamic from 'next/dynamic';
|
||||
import { createPushModal } from 'pushmodal';
|
||||
|
||||
import type { ConfirmProps } from './Confirm';
|
||||
import { ModalContent } from './Modal/Container';
|
||||
|
||||
const Loading = () => <Loader className="mb-8 animate-spin" size={40} />;
|
||||
const Loading = () => (
|
||||
<ModalContent className="flex items-center justify-center p-16">
|
||||
<Loader className="animate-spin" size={40} />
|
||||
</ModalContent>
|
||||
);
|
||||
|
||||
const modals = {
|
||||
EditProject: dynamic(() => import('./EditProject'), {
|
||||
|
||||
@@ -3,38 +3,9 @@ import { createTRPCRouter, protectedProcedure } from '@/trpc/api/trpc';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
|
||||
import { db, transformClient } from '@openpanel/db';
|
||||
import { db } from '@openpanel/db';
|
||||
|
||||
export const clientRouter = createTRPCRouter({
|
||||
list: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
organizationId: z.string(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input: { organizationId } }) => {
|
||||
return db.client.findMany({
|
||||
where: {
|
||||
organization_slug: organizationId,
|
||||
},
|
||||
include: {
|
||||
project: true,
|
||||
},
|
||||
});
|
||||
}),
|
||||
get: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
})
|
||||
)
|
||||
.query(({ input }) => {
|
||||
return db.client.findUniqueOrThrow({
|
||||
where: {
|
||||
id: input.id,
|
||||
},
|
||||
});
|
||||
}),
|
||||
update: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
@@ -59,7 +30,7 @@ export const clientRouter = createTRPCRouter({
|
||||
z.object({
|
||||
name: z.string(),
|
||||
projectId: z.string(),
|
||||
organizationId: z.string(),
|
||||
organizationSlug: z.string(),
|
||||
cors: z.string().nullable(),
|
||||
})
|
||||
)
|
||||
@@ -67,8 +38,8 @@ export const clientRouter = createTRPCRouter({
|
||||
const secret = randomUUID();
|
||||
const client = await db.client.create({
|
||||
data: {
|
||||
organization_slug: input.organizationId,
|
||||
project_id: input.projectId,
|
||||
organizationSlug: input.organizationSlug,
|
||||
projectId: input.projectId,
|
||||
name: input.name,
|
||||
secret: input.cors ? null : await hashPassword(secret),
|
||||
cors: input.cors ? stripTrailingSlash(input.cors) : '*',
|
||||
@@ -76,7 +47,7 @@ export const clientRouter = createTRPCRouter({
|
||||
});
|
||||
|
||||
return {
|
||||
...transformClient(client),
|
||||
...client,
|
||||
secret: input.cors ? null : secret,
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -28,8 +28,8 @@ export const dashboardRouter = createTRPCRouter({
|
||||
return db.dashboard.create({
|
||||
data: {
|
||||
id: await getId('dashboard', name),
|
||||
project_id: projectId,
|
||||
organization_slug: organizationSlug,
|
||||
projectId: projectId,
|
||||
organizationSlug: organizationSlug,
|
||||
name,
|
||||
},
|
||||
});
|
||||
@@ -63,7 +63,7 @@ export const dashboardRouter = createTRPCRouter({
|
||||
if (forceDelete) {
|
||||
await db.report.deleteMany({
|
||||
where: {
|
||||
dashboard_id: id,
|
||||
dashboardId: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ export const eventRouter = createTRPCRouter({
|
||||
.mutation(({ input: { projectId, name, icon, color, conversion } }) => {
|
||||
return db.eventMeta.upsert({
|
||||
where: {
|
||||
name_project_id: {
|
||||
name_projectId: {
|
||||
name,
|
||||
project_id: projectId,
|
||||
projectId,
|
||||
},
|
||||
},
|
||||
create: { project_id: projectId, name, icon, color, conversion },
|
||||
create: { projectId, name, icon, color, conversion },
|
||||
update: { icon, color, conversion },
|
||||
});
|
||||
}),
|
||||
|
||||
@@ -4,12 +4,7 @@ import { clerkClient } from '@clerk/nextjs';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
|
||||
import {
|
||||
db,
|
||||
transformClient,
|
||||
transformOrganization,
|
||||
transformProject,
|
||||
} from '@openpanel/db';
|
||||
import { db, transformOrganization } from '@openpanel/db';
|
||||
|
||||
export const onboardingRouter = createTRPCRouter({
|
||||
organziation: protectedProcedure
|
||||
@@ -30,7 +25,7 @@ export const onboardingRouter = createTRPCRouter({
|
||||
const project = await db.project.create({
|
||||
data: {
|
||||
name: input.project,
|
||||
organization_slug: org.slug,
|
||||
organizationSlug: org.slug,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -38,19 +33,19 @@ export const onboardingRouter = createTRPCRouter({
|
||||
const client = await db.client.create({
|
||||
data: {
|
||||
name: `${project.name} Client`,
|
||||
organization_slug: org.slug,
|
||||
project_id: project.id,
|
||||
organizationSlug: org.slug,
|
||||
projectId: project.id,
|
||||
cors: input.cors ? stripTrailingSlash(input.cors) : '*',
|
||||
secret: input.cors ? null : await hashPassword(secret),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
client: transformClient({
|
||||
client: {
|
||||
...client,
|
||||
secret: input.cors ? null : secret,
|
||||
}),
|
||||
project: transformProject(project),
|
||||
},
|
||||
project,
|
||||
organization: transformOrganization(org),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -77,15 +77,15 @@ export const organizationRouter = createTRPCRouter({
|
||||
return db.$transaction([
|
||||
db.projectAccess.deleteMany({
|
||||
where: {
|
||||
user_id: input.userId,
|
||||
organization_slug: input.organizationSlug,
|
||||
userId: input.userId,
|
||||
organizationSlug: input.organizationSlug,
|
||||
},
|
||||
}),
|
||||
db.projectAccess.createMany({
|
||||
data: input.access.map((projectId) => ({
|
||||
user_id: input.userId,
|
||||
organization_slug: input.organizationSlug,
|
||||
project_id: projectId,
|
||||
userId: input.userId,
|
||||
organizationSlug: input.organizationSlug,
|
||||
projectId: projectId,
|
||||
level: 'read',
|
||||
})),
|
||||
}),
|
||||
|
||||
@@ -8,12 +8,12 @@ export const projectRouter = createTRPCRouter({
|
||||
list: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
organizationId: z.string().nullable(),
|
||||
organizationSlug: z.string().nullable(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input: { organizationId } }) => {
|
||||
if (organizationId === null) return [];
|
||||
return getProjectsByOrganizationSlug(organizationId);
|
||||
.query(async ({ input: { organizationSlug } }) => {
|
||||
if (organizationSlug === null) return [];
|
||||
return getProjectsByOrganizationSlug(organizationSlug);
|
||||
}),
|
||||
|
||||
update: protectedProcedure
|
||||
@@ -37,15 +37,15 @@ export const projectRouter = createTRPCRouter({
|
||||
.input(
|
||||
z.object({
|
||||
name: z.string().min(1),
|
||||
organizationId: z.string(),
|
||||
organizationSlug: z.string(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
.mutation(async ({ input: { name, organizationSlug } }) => {
|
||||
return db.project.create({
|
||||
data: {
|
||||
id: await getId('project', input.name),
|
||||
organization_slug: input.organizationId,
|
||||
name: input.name,
|
||||
id: await getId('project', name),
|
||||
organizationSlug: organizationSlug,
|
||||
name: name,
|
||||
},
|
||||
});
|
||||
}),
|
||||
|
||||
@@ -19,7 +19,7 @@ export const referenceRouter = createTRPCRouter({
|
||||
data: {
|
||||
title,
|
||||
description,
|
||||
project_id: projectId,
|
||||
projectId,
|
||||
date: new Date(datetime),
|
||||
},
|
||||
});
|
||||
@@ -47,7 +47,7 @@ export const referenceRouter = createTRPCRouter({
|
||||
const { startDate, endDate } = getChartStartEndDate(input);
|
||||
return getReferences({
|
||||
where: {
|
||||
project_id: projectId,
|
||||
projectId,
|
||||
date: {
|
||||
gte: new Date(startDate),
|
||||
lte: new Date(endDate),
|
||||
|
||||
@@ -20,14 +20,14 @@ export const reportRouter = createTRPCRouter({
|
||||
});
|
||||
return db.report.create({
|
||||
data: {
|
||||
project_id: dashboard.project_id,
|
||||
dashboard_id: dashboardId,
|
||||
projectId: dashboard.projectId,
|
||||
dashboardId,
|
||||
name: report.name,
|
||||
events: report.events,
|
||||
interval: report.interval,
|
||||
breakdowns: report.breakdowns,
|
||||
chart_type: report.chartType,
|
||||
line_type: report.lineType,
|
||||
chartType: report.chartType,
|
||||
lineType: report.lineType,
|
||||
range: report.range,
|
||||
formula: report.formula,
|
||||
},
|
||||
@@ -50,8 +50,8 @@ export const reportRouter = createTRPCRouter({
|
||||
events: report.events,
|
||||
interval: report.interval,
|
||||
breakdowns: report.breakdowns,
|
||||
chart_type: report.chartType,
|
||||
line_type: report.lineType,
|
||||
chartType: report.chartType,
|
||||
lineType: report.lineType,
|
||||
range: report.range,
|
||||
formula: report.formula,
|
||||
},
|
||||
|
||||
@@ -12,12 +12,12 @@ export const shareRouter = createTRPCRouter({
|
||||
.mutation(({ input }) => {
|
||||
return db.shareOverview.upsert({
|
||||
where: {
|
||||
project_id: input.projectId,
|
||||
projectId: input.projectId,
|
||||
},
|
||||
create: {
|
||||
id: uid.rnd(),
|
||||
organization_slug: input.organizationId,
|
||||
project_id: input.projectId,
|
||||
organizationSlug: input.organizationSlug,
|
||||
projectId: input.projectId,
|
||||
public: input.public,
|
||||
password: input.password || null,
|
||||
},
|
||||
|
||||
@@ -4,11 +4,10 @@ import Image from 'next/image';
|
||||
import Link from 'next/link';
|
||||
|
||||
import { Heading2, Lead2 } from './copy';
|
||||
import { JoinWaitlist } from './join-waitlist';
|
||||
|
||||
export default function Footer() {
|
||||
return (
|
||||
<footer className="bg-blue-darker relative relative mt-40 text-white">
|
||||
<footer className="bg-blue-darker relative mt-40 text-white">
|
||||
<div className="absolute inset-0 h-full w-full bg-[radial-gradient(circle,rgba(255,255,255,0.2)_0%,rgba(255,255,255,0)_100%)]"></div>
|
||||
<div className="container relative flex flex-col items-center text-center">
|
||||
<div className="my-24">
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
-- Project
|
||||
-- organization_slug -> organizationSlug
|
||||
ALTER TABLE
|
||||
IF EXISTS "projects" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||
|
||||
-- ProjectAccess
|
||||
-- project_id -> projectId
|
||||
-- organization_slug -> organizationSlug
|
||||
-- user_id -> userId
|
||||
ALTER TABLE
|
||||
IF EXISTS "project_access" RENAME COLUMN "project_id" TO "projectId";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "project_access" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "project_access" RENAME COLUMN "user_id" TO "userId";
|
||||
|
||||
-- Event
|
||||
-- project_id -> projectId
|
||||
-- profile_id -> profileId
|
||||
ALTER TABLE
|
||||
IF EXISTS "events" RENAME COLUMN "project_id" TO "projectId";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "events" RENAME COLUMN "profile_id" TO "profileId";
|
||||
|
||||
-- Profile
|
||||
-- external_id -> externalId
|
||||
-- first_name -> firstName
|
||||
-- last_name -> lastName
|
||||
-- project_id -> projectId
|
||||
ALTER TABLE
|
||||
IF EXISTS "profiles" RENAME COLUMN "external_id" TO "externalId";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "profiles" RENAME COLUMN "first_name" TO "firstName";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "profiles" RENAME COLUMN "last_name" TO "lastName";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "profiles" RENAME COLUMN "project_id" TO "projectId";
|
||||
|
||||
-- Client
|
||||
-- project_id -> projectId
|
||||
-- organization_slug -> organizationSlug
|
||||
ALTER TABLE
|
||||
IF EXISTS "clients" RENAME COLUMN "project_id" TO "projectId";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "clients" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||
|
||||
-- Dashboard
|
||||
-- organization_slug -> organizationSlug
|
||||
-- project_id -> projectId
|
||||
ALTER TABLE
|
||||
IF EXISTS "dashboards" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "dashboards" RENAME COLUMN "project_id" TO "projectId";
|
||||
|
||||
-- Report
|
||||
-- chart_type -> chartType
|
||||
-- line_type -> lineType
|
||||
-- project_id -> projectId
|
||||
-- dashboard_id -> dashboardId
|
||||
ALTER TABLE
|
||||
IF EXISTS "reports" RENAME COLUMN "chart_type" TO "chartType";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "reports" RENAME COLUMN "line_type" TO "lineType";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "reports" RENAME COLUMN "project_id" TO "projectId";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "reports" RENAME COLUMN "dashboard_id" TO "dashboardId";
|
||||
|
||||
-- ShareOverview
|
||||
-- project_id -> projectId
|
||||
-- organization_slug -> organizationSlug
|
||||
ALTER TABLE
|
||||
IF EXISTS "shares" RENAME COLUMN "project_id" TO "projectId";
|
||||
|
||||
ALTER TABLE
|
||||
IF EXISTS "shares" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||
|
||||
-- EventMeta (ta bort constraint)
|
||||
-- project_id -> projectId
|
||||
ALTER TABLE
|
||||
IF EXISTS "event_meta" RENAME COLUMN "project_id" TO "projectId";
|
||||
|
||||
-- Reference
|
||||
-- project_id -> projectId
|
||||
ALTER TABLE
|
||||
IF EXISTS "references" RENAME COLUMN "project_id" TO "projectId";
|
||||
@@ -0,0 +1,35 @@
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "clients" RENAME CONSTRAINT "clients_project_id_fkey" TO "clients_projectId_fkey";
|
||||
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "dashboards" RENAME CONSTRAINT "dashboards_project_id_fkey" TO "dashboards_projectId_fkey";
|
||||
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "event_meta" RENAME CONSTRAINT "event_meta_project_id_fkey" TO "event_meta_projectId_fkey";
|
||||
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "events" RENAME CONSTRAINT "events_project_id_fkey" TO "events_projectId_fkey";
|
||||
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "profiles" RENAME CONSTRAINT "profiles_project_id_fkey" TO "profiles_projectId_fkey";
|
||||
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "project_access" RENAME CONSTRAINT "project_access_project_id_fkey" TO "project_access_projectId_fkey";
|
||||
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "references" RENAME CONSTRAINT "references_project_id_fkey" TO "references_projectId_fkey";
|
||||
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "reports" RENAME CONSTRAINT "reports_dashboard_id_fkey" TO "reports_dashboardId_fkey";
|
||||
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "reports" RENAME CONSTRAINT "reports_project_id_fkey" TO "reports_projectId_fkey";
|
||||
|
||||
-- RenameForeignKey
|
||||
ALTER TABLE "shares" RENAME CONSTRAINT "shares_project_id_fkey" TO "shares_projectId_fkey";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "event_meta_name_project_id_key" RENAME TO "event_meta_name_projectId_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "shares_project_id_key" RENAME TO "shares_projectId_key";
|
||||
@@ -11,23 +11,23 @@ datasource db {
|
||||
}
|
||||
|
||||
model Project {
|
||||
id String @id @default(dbgenerated("gen_random_uuid()"))
|
||||
name String
|
||||
organization_slug String
|
||||
events Event[]
|
||||
eventsCount Int @default(0)
|
||||
profiles Profile[]
|
||||
clients Client[]
|
||||
id String @id @default(dbgenerated("gen_random_uuid()"))
|
||||
name String
|
||||
organizationSlug String
|
||||
eventsCount Int @default(0)
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
events Event[]
|
||||
profiles Profile[]
|
||||
clients Client[]
|
||||
reports Report[]
|
||||
dashboards Dashboard[]
|
||||
share ShareOverview?
|
||||
EventMeta EventMeta[]
|
||||
Reference Reference[]
|
||||
meta EventMeta[]
|
||||
references Reference[]
|
||||
access ProjectAccess[]
|
||||
|
||||
access ProjectAccess[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
@@map("projects")
|
||||
}
|
||||
@@ -39,14 +39,14 @@ enum AccessLevel {
|
||||
}
|
||||
|
||||
model ProjectAccess {
|
||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
project_id String
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
organization_slug String
|
||||
user_id String
|
||||
level AccessLevel
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
projectId String
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
organizationSlug String
|
||||
userId String
|
||||
level AccessLevel
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
@@map("project_access")
|
||||
}
|
||||
@@ -55,10 +55,10 @@ model Event {
|
||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
properties Json
|
||||
project_id String
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
projectId String
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
|
||||
profile_id String?
|
||||
profileId String?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
@@ -75,29 +75,29 @@ model Salt {
|
||||
}
|
||||
|
||||
model Profile {
|
||||
id String @id
|
||||
external_id String?
|
||||
first_name String?
|
||||
last_name String?
|
||||
email String?
|
||||
avatar String?
|
||||
properties Json
|
||||
project_id String
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
id String @id
|
||||
externalId String?
|
||||
firstName String?
|
||||
lastName String?
|
||||
email String?
|
||||
avatar String?
|
||||
properties Json
|
||||
projectId String
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
@@map("profiles")
|
||||
}
|
||||
|
||||
model Client {
|
||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
secret String?
|
||||
project_id String
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
organization_slug String
|
||||
cors String @default("*")
|
||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
secret String?
|
||||
projectId String
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
organizationSlug String
|
||||
cors String @default("*")
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
@@ -124,12 +124,12 @@ enum ChartType {
|
||||
}
|
||||
|
||||
model Dashboard {
|
||||
id String @id @default(dbgenerated("gen_random_uuid()"))
|
||||
name String
|
||||
organization_slug String
|
||||
project_id String
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
reports Report[]
|
||||
id String @id @default(dbgenerated("gen_random_uuid()"))
|
||||
name String
|
||||
organizationSlug String
|
||||
projectId String
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
reports Report[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
@@ -149,19 +149,19 @@ model Report {
|
||||
name String
|
||||
interval Interval
|
||||
range String @default("1m")
|
||||
chart_type ChartType
|
||||
line_type String @default("monotone")
|
||||
chartType ChartType
|
||||
lineType String @default("monotone")
|
||||
breakdowns Json
|
||||
events Json
|
||||
formula String?
|
||||
unit String?
|
||||
metric Metric @default(sum)
|
||||
project_id String
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
projectId String
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
previous Boolean @default(false)
|
||||
|
||||
dashboard_id String
|
||||
dashboard Dashboard @relation(fields: [dashboard_id], references: [id])
|
||||
dashboardId String
|
||||
dashboard Dashboard @relation(fields: [dashboardId], references: [id])
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
@@ -180,14 +180,14 @@ model Waitlist {
|
||||
}
|
||||
|
||||
model ShareOverview {
|
||||
id String @unique
|
||||
project_id String @unique
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
organization_slug String
|
||||
public Boolean @default(false)
|
||||
password String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
id String @unique
|
||||
projectId String @unique
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
organizationSlug String
|
||||
public Boolean @default(false)
|
||||
password String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
@@map("shares")
|
||||
}
|
||||
@@ -198,13 +198,13 @@ model EventMeta {
|
||||
conversion Boolean?
|
||||
color String?
|
||||
icon String?
|
||||
project_id String
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
projectId String
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
@@unique([name, project_id])
|
||||
@@unique([name, projectId])
|
||||
@@map("event_meta")
|
||||
}
|
||||
|
||||
@@ -213,8 +213,8 @@ model Reference {
|
||||
title String
|
||||
description String?
|
||||
date DateTime @default(now())
|
||||
project_id String
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
projectId String
|
||||
project Project @relation(fields: [projectId], references: [id])
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
@@ -1,38 +1,20 @@
|
||||
import type { Client } from '../prisma-client';
|
||||
import type { Client, Prisma } from '../prisma-client';
|
||||
import { db } from '../prisma-client';
|
||||
import { transformProject } from './project.service';
|
||||
import type { IServiceProject } from './project.service';
|
||||
|
||||
export type IServiceClient = ReturnType<typeof transformClient>;
|
||||
export type IServiceClientWithProject = IServiceClient & {
|
||||
project: Exclude<IServiceProject, null>;
|
||||
};
|
||||
|
||||
export function transformClient({ organization_slug, ...client }: Client) {
|
||||
return {
|
||||
...client,
|
||||
organizationSlug: organization_slug,
|
||||
export type IServiceClient = Client;
|
||||
export type IServiceClientWithProject = Prisma.ClientGetPayload<{
|
||||
include: {
|
||||
project: true;
|
||||
};
|
||||
}
|
||||
}>;
|
||||
|
||||
export async function getClientsByOrganizationId(organizationId: string) {
|
||||
const clients = await db.client.findMany({
|
||||
export async function getClientsByOrganizationSlug(organizationSlug: string) {
|
||||
return db.client.findMany({
|
||||
where: {
|
||||
organization_slug: organizationId,
|
||||
organizationSlug,
|
||||
},
|
||||
include: {
|
||||
project: true,
|
||||
},
|
||||
});
|
||||
|
||||
return clients
|
||||
.map((client) => {
|
||||
return {
|
||||
...transformClient(client),
|
||||
project: transformProject(client.project),
|
||||
};
|
||||
})
|
||||
.filter(
|
||||
(client): client is IServiceClientWithProject => client.project !== null
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import type { Dashboard, Prisma } from '../prisma-client';
|
||||
import { db } from '../prisma-client';
|
||||
|
||||
export type IServiceDashboard = Awaited<ReturnType<typeof getDashboardById>>;
|
||||
export type IServiceDashboards = Awaited<
|
||||
ReturnType<typeof getDashboardsByProjectId>
|
||||
>;
|
||||
export type IServiceDashboard = Dashboard;
|
||||
export type IServiceDashboards = Prisma.DashboardGetPayload<{
|
||||
include: {
|
||||
project: true;
|
||||
};
|
||||
}>[];
|
||||
|
||||
export async function getDashboardById(id: string, projectId: string) {
|
||||
const dashboard = await db.dashboard.findUnique({
|
||||
where: {
|
||||
id,
|
||||
project_id: projectId,
|
||||
projectId,
|
||||
},
|
||||
include: {
|
||||
project: true,
|
||||
@@ -26,7 +29,7 @@ export async function getDashboardById(id: string, projectId: string) {
|
||||
export function getDashboardsByProjectId(projectId: string) {
|
||||
return db.dashboard.findMany({
|
||||
where: {
|
||||
project_id: projectId,
|
||||
projectId,
|
||||
},
|
||||
include: {
|
||||
project: true,
|
||||
|
||||
@@ -144,7 +144,7 @@ export async function getEvents(
|
||||
name: {
|
||||
in: names,
|
||||
},
|
||||
project_id: events[0]?.project_id,
|
||||
projectId: events[0]?.project_id,
|
||||
},
|
||||
select: options.meta === true ? undefined : options.meta,
|
||||
});
|
||||
@@ -265,7 +265,7 @@ export async function getEventList({
|
||||
sb.where.projectId = `project_id = ${escape(projectId)}`;
|
||||
|
||||
if (profileId) {
|
||||
sb.where.deviceId = `device_id IN (SELECT device_id as did FROM openpanel.events WHERE profile_id = ${escape(profileId)} group by did)`;
|
||||
sb.where.deviceId = `device_id IN (SELECT device_id as did FROM events WHERE profile_id = ${escape(profileId)} group by did)`;
|
||||
}
|
||||
|
||||
if (events && events.length > 0) {
|
||||
@@ -357,7 +357,7 @@ export function createBotEvent({
|
||||
export function getConversionEventNames(projectId: string) {
|
||||
return db.eventMeta.findMany({
|
||||
where: {
|
||||
project_id: projectId,
|
||||
projectId,
|
||||
conversion: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ import { db } from '../prisma-client';
|
||||
export type IServiceOrganization = ReturnType<typeof transformOrganization>;
|
||||
export type IServiceInvite = ReturnType<typeof transformInvite>;
|
||||
export type IServiceMember = ReturnType<typeof transformMember>;
|
||||
export type IServiceProjectAccess = ReturnType<typeof transformAccess>;
|
||||
export type IServiceProjectAccess = ProjectAccess;
|
||||
|
||||
export function transformOrganization(org: Organization) {
|
||||
return {
|
||||
@@ -21,15 +21,6 @@ export function transformOrganization(org: Organization) {
|
||||
};
|
||||
}
|
||||
|
||||
export function transformAccess(access: ProjectAccess) {
|
||||
return {
|
||||
projectId: access.project_id,
|
||||
userId: access.user_id,
|
||||
level: access.level,
|
||||
organizationSlug: access.organization_slug,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getCurrentOrganizations() {
|
||||
const session = auth();
|
||||
const organizations = await clerkClient.users.getOrganizationMembershipList({
|
||||
@@ -53,7 +44,7 @@ export async function getOrganizationByProjectId(projectId: string) {
|
||||
});
|
||||
|
||||
return clerkClient.organizations.getOrganization({
|
||||
slug: project.organization_slug,
|
||||
slug: project.organizationSlug,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -110,7 +101,7 @@ export async function getMembers(organizationSlug: string) {
|
||||
}),
|
||||
db.projectAccess.findMany({
|
||||
where: {
|
||||
organization_slug: organizationSlug,
|
||||
organizationSlug,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
@@ -118,11 +109,11 @@ export async function getMembers(organizationSlug: string) {
|
||||
return members
|
||||
.map((member) => {
|
||||
const projectAccess = access.filter(
|
||||
(item) => item.user_id === member.publicUserData?.userId
|
||||
(item) => item.userId === member.publicUserData?.userId
|
||||
);
|
||||
return {
|
||||
...member,
|
||||
access: projectAccess.map(transformAccess),
|
||||
access: projectAccess,
|
||||
};
|
||||
})
|
||||
.map(transformMember);
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import { auth } from '@clerk/nextjs';
|
||||
import { project } from 'ramda';
|
||||
|
||||
import type { Project } from '../prisma-client';
|
||||
import { db } from '../prisma-client';
|
||||
|
||||
export type IServiceProject = ReturnType<typeof transformProject>;
|
||||
|
||||
export function transformProject({ organization_slug, ...project }: Project) {
|
||||
return {
|
||||
organizationSlug: organization_slug,
|
||||
...project,
|
||||
};
|
||||
}
|
||||
export type IServiceProject = Project;
|
||||
|
||||
export async function getProjectById(id: string) {
|
||||
const res = await db.project.findUnique({
|
||||
@@ -24,46 +16,32 @@ export async function getProjectById(id: string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return transformProject(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function getProjectsByOrganizationSlug(slug: string) {
|
||||
const res = await db.project.findMany({
|
||||
export async function getProjectsByOrganizationSlug(organizationSlug: string) {
|
||||
return db.project.findMany({
|
||||
where: {
|
||||
organization_slug: slug,
|
||||
organizationSlug,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
});
|
||||
|
||||
return res.map(transformProject);
|
||||
}
|
||||
|
||||
export async function getCurrentProjects(slug: string) {
|
||||
export async function getCurrentProjects(organizationSlug: string) {
|
||||
const session = auth();
|
||||
if (!session.userId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const access = await db.projectAccess.findMany({
|
||||
return db.project.findMany({
|
||||
where: {
|
||||
organization_slug: slug,
|
||||
user_id: session.userId,
|
||||
organizationSlug,
|
||||
},
|
||||
include: {
|
||||
access: true,
|
||||
},
|
||||
});
|
||||
|
||||
const res = await db.project.findMany({
|
||||
where: {
|
||||
organization_slug: slug,
|
||||
},
|
||||
});
|
||||
|
||||
if (access.length === 0) {
|
||||
return res.map(transformProject);
|
||||
}
|
||||
|
||||
return res
|
||||
.filter((project) => access.some((a) => a.project_id === project.id))
|
||||
.map(transformProject);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
import type { Prisma, Reference } from '../prisma-client';
|
||||
import { db } from '../prisma-client';
|
||||
|
||||
export type IServiceReference = Omit<Reference, 'project_id'> & {
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
export function transformReference({
|
||||
project_id,
|
||||
...item
|
||||
}: Reference): IServiceReference {
|
||||
return {
|
||||
...item,
|
||||
projectId: project_id,
|
||||
};
|
||||
}
|
||||
export type IServiceReference = Reference;
|
||||
|
||||
export async function getReferenceById(id: string) {
|
||||
const reference = await db.reference.findUnique({
|
||||
@@ -26,7 +14,7 @@ export async function getReferenceById(id: string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return transformReference(reference);
|
||||
return reference;
|
||||
}
|
||||
|
||||
export async function getReferences({
|
||||
@@ -38,11 +26,9 @@ export async function getReferences({
|
||||
take?: number;
|
||||
skip?: number;
|
||||
}) {
|
||||
const references = await db.reference.findMany({
|
||||
return db.reference.findMany({
|
||||
where,
|
||||
take: take ?? 50,
|
||||
skip,
|
||||
});
|
||||
|
||||
return references.map(transformReference);
|
||||
}
|
||||
|
||||
@@ -45,11 +45,11 @@ export function transformReport(
|
||||
): IChartInput & { id: string } {
|
||||
return {
|
||||
id: report.id,
|
||||
projectId: report.project_id,
|
||||
projectId: report.projectId,
|
||||
events: (report.events as IChartEvent[]).map(transformReportEvent),
|
||||
breakdowns: report.breakdowns as IChartBreakdown[],
|
||||
chartType: report.chart_type,
|
||||
lineType: (report.line_type as IChartLineType) ?? lineTypes.monotone,
|
||||
chartType: report.chartType,
|
||||
lineType: (report.lineType as IChartLineType) ?? lineTypes.monotone,
|
||||
interval: report.interval,
|
||||
name: report.name || 'Untitled',
|
||||
range: (report.range as IChartRange) ?? timeRanges['1m'],
|
||||
@@ -64,7 +64,7 @@ export function getReportsByDashboardId(dashboardId: string) {
|
||||
return db.report
|
||||
.findMany({
|
||||
where: {
|
||||
dashboard_id: dashboardId,
|
||||
dashboardId,
|
||||
},
|
||||
})
|
||||
.then((reports) => reports.map(transformReport));
|
||||
|
||||
@@ -10,3 +10,11 @@ export function getShareOverviewById(id: string) {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function getShareByProjectId(projectId: string) {
|
||||
return db.shareOverview.findUnique({
|
||||
where: {
|
||||
projectId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export const zInviteUser = z.object({
|
||||
});
|
||||
|
||||
export const zShareOverview = z.object({
|
||||
organizationId: z.string(),
|
||||
organizationSlug: z.string(),
|
||||
projectId: z.string(),
|
||||
password: z.string().nullable(),
|
||||
public: z.boolean(),
|
||||
|
||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -301,8 +301,8 @@ importers:
|
||||
specifier: ^0.1.3
|
||||
version: 0.1.3
|
||||
pushmodal:
|
||||
specifier: ^0.0.8
|
||||
version: 0.0.8(@radix-ui/react-dialog@1.0.5)(react-dom@18.2.0)(react@18.2.0)
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0(@radix-ui/react-dialog@1.0.5)(react-dom@18.2.0)(react@18.2.0)
|
||||
ramda:
|
||||
specifier: ^0.29.1
|
||||
version: 0.29.1
|
||||
@@ -14709,8 +14709,8 @@ packages:
|
||||
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
/pushmodal@0.0.8(@radix-ui/react-dialog@1.0.5)(react-dom@18.2.0)(react@18.2.0):
|
||||
resolution: {integrity: sha512-Fmsx9Fadnv51WPcXvX7x4N8BbLxMDdSStpfJ1WY4pyjqXEEht+3H51TwjZJc5PkGMURdsvi7py76SFgsmrujnw==}
|
||||
/pushmodal@1.0.0(@radix-ui/react-dialog@1.0.5)(react-dom@18.2.0)(react@18.2.0):
|
||||
resolution: {integrity: sha512-34JSZHJHGTcLqBgYk9Fyiw5vBYJZrcgoDE7GfHehKKzxBt/Ro2bSLTIGRnzQ+NRv389GxH6WXCBUH+6VJ1wvTg==}
|
||||
peerDependencies:
|
||||
'@radix-ui/react-dialog': ^1.0.0
|
||||
react: ^16.12.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0
|
||||
|
||||
Reference in New Issue
Block a user