feat(v2): add website overview
This commit is contained in:
parent
539f24244a
commit
6a5de70fdb
@ -19,6 +19,7 @@ import { Route as MonitorImport } from './routes/monitor'
|
|||||||
import { Route as LoginImport } from './routes/login'
|
import { Route as LoginImport } from './routes/login'
|
||||||
import { Route as DashboardImport } from './routes/dashboard'
|
import { Route as DashboardImport } from './routes/dashboard'
|
||||||
import { Route as IndexImport } from './routes/index'
|
import { Route as IndexImport } from './routes/index'
|
||||||
|
import { Route as WebsiteOverviewImport } from './routes/website/overview'
|
||||||
import { Route as WebsiteAddImport } from './routes/website/add'
|
import { Route as WebsiteAddImport } from './routes/website/add'
|
||||||
import { Route as WebsiteWebsiteIdImport } from './routes/website/$websiteId'
|
import { Route as WebsiteWebsiteIdImport } from './routes/website/$websiteId'
|
||||||
import { Route as TelemetryAddImport } from './routes/telemetry/add'
|
import { Route as TelemetryAddImport } from './routes/telemetry/add'
|
||||||
@ -70,6 +71,11 @@ const IndexRoute = IndexImport.update({
|
|||||||
getParentRoute: () => rootRoute,
|
getParentRoute: () => rootRoute,
|
||||||
} as any)
|
} as any)
|
||||||
|
|
||||||
|
const WebsiteOverviewRoute = WebsiteOverviewImport.update({
|
||||||
|
path: '/overview',
|
||||||
|
getParentRoute: () => WebsiteRoute,
|
||||||
|
} as any)
|
||||||
|
|
||||||
const WebsiteAddRoute = WebsiteAddImport.update({
|
const WebsiteAddRoute = WebsiteAddImport.update({
|
||||||
path: '/add',
|
path: '/add',
|
||||||
getParentRoute: () => WebsiteRoute,
|
getParentRoute: () => WebsiteRoute,
|
||||||
@ -178,6 +184,10 @@ declare module '@tanstack/react-router' {
|
|||||||
preLoaderRoute: typeof WebsiteAddImport
|
preLoaderRoute: typeof WebsiteAddImport
|
||||||
parentRoute: typeof WebsiteImport
|
parentRoute: typeof WebsiteImport
|
||||||
}
|
}
|
||||||
|
'/website/overview': {
|
||||||
|
preLoaderRoute: typeof WebsiteOverviewImport
|
||||||
|
parentRoute: typeof WebsiteImport
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +201,11 @@ export const routeTree = rootRoute.addChildren([
|
|||||||
PageRoute.addChildren([PageSlugRoute, PageAddRoute]),
|
PageRoute.addChildren([PageSlugRoute, PageAddRoute]),
|
||||||
RegisterRoute,
|
RegisterRoute,
|
||||||
TelemetryRoute.addChildren([TelemetryTelemetryIdRoute, TelemetryAddRoute]),
|
TelemetryRoute.addChildren([TelemetryTelemetryIdRoute, TelemetryAddRoute]),
|
||||||
WebsiteRoute.addChildren([WebsiteWebsiteIdRoute, WebsiteAddRoute]),
|
WebsiteRoute.addChildren([
|
||||||
|
WebsiteWebsiteIdRoute,
|
||||||
|
WebsiteAddRoute,
|
||||||
|
WebsiteOverviewRoute,
|
||||||
|
]),
|
||||||
])
|
])
|
||||||
|
|
||||||
/* prettier-ignore-end */
|
/* prettier-ignore-end */
|
||||||
|
@ -14,7 +14,8 @@ import {
|
|||||||
useNavigate,
|
useNavigate,
|
||||||
useRouterState,
|
useRouterState,
|
||||||
} from '@tanstack/react-router';
|
} from '@tanstack/react-router';
|
||||||
import { LuPlus } from 'react-icons/lu';
|
import { useEffect } from 'react';
|
||||||
|
import { LuEye, LuPlus } from 'react-icons/lu';
|
||||||
|
|
||||||
export const Route = createFileRoute('/website')({
|
export const Route = createFileRoute('/website')({
|
||||||
beforeLoad: routeAuthBeforeLoad,
|
beforeLoad: routeAuthBeforeLoad,
|
||||||
@ -39,19 +40,19 @@ function WebsiteComponent() {
|
|||||||
href: `/website/${item.id}`,
|
href: `/website/${item.id}`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
useDataReady(
|
useEffect(() => {
|
||||||
() => data.length > 0,
|
if (pathname === Route.fullPath) {
|
||||||
() => {
|
navigate({
|
||||||
if (pathname === Route.fullPath) {
|
to: '/website/overview',
|
||||||
navigate({
|
});
|
||||||
to: '/website/$websiteId',
|
|
||||||
params: {
|
|
||||||
websiteId: data[0].id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
}, []);
|
||||||
|
|
||||||
|
const handleClickOverview = useEvent(() => {
|
||||||
|
navigate({
|
||||||
|
to: '/website/overview',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const handleClickAdd = useEvent(() => {
|
const handleClickAdd = useEvent(() => {
|
||||||
navigate({
|
navigate({
|
||||||
@ -67,13 +68,22 @@ function WebsiteComponent() {
|
|||||||
<CommonHeader
|
<CommonHeader
|
||||||
title={t('Website')}
|
title={t('Website')}
|
||||||
actions={
|
actions={
|
||||||
<Button
|
<div className="space-x-2">
|
||||||
variant="outline"
|
<Button
|
||||||
Icon={LuPlus}
|
variant="outline"
|
||||||
onClick={handleClickAdd}
|
Icon={LuEye}
|
||||||
>
|
onClick={handleClickOverview}
|
||||||
{t('Add')}
|
>
|
||||||
</Button>
|
{t('Overview')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
Icon={LuPlus}
|
||||||
|
onClick={handleClickAdd}
|
||||||
|
>
|
||||||
|
{t('Add')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
77
src/client/routes/website/overview.tsx
Normal file
77
src/client/routes/website/overview.tsx
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import { routeAuthBeforeLoad } from '@/utils/route';
|
||||||
|
import { createFileRoute, useNavigate } from '@tanstack/react-router';
|
||||||
|
import { z } from 'zod';
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { useTranslation } from '@i18next-toolkit/react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormDescription,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from '@/components/ui/form';
|
||||||
|
import { useEvent } from '@/hooks/useEvent';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { useCurrentWorkspaceId } from '@/store/user';
|
||||||
|
import { trpc } from '@/api/trpc';
|
||||||
|
import { hostnameRegex } from '@tianji/shared';
|
||||||
|
import { Card, CardContent, CardFooter } from '@/components/ui/card';
|
||||||
|
import { CommonWrapper } from '@/components/CommonWrapper';
|
||||||
|
import { WebsiteOverview } from '@/components/website/WebsiteOverview';
|
||||||
|
import { Empty } from 'antd';
|
||||||
|
import { LuPlus } from 'react-icons/lu';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
|
||||||
|
export const Route = createFileRoute('/website/overview')({
|
||||||
|
beforeLoad: routeAuthBeforeLoad,
|
||||||
|
component: WebsiteOverviewComponent,
|
||||||
|
});
|
||||||
|
|
||||||
|
function WebsiteOverviewComponent() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const workspaceId = useCurrentWorkspaceId();
|
||||||
|
const { data: websites = [], isLoading } = trpc.website.all.useQuery({
|
||||||
|
workspaceId,
|
||||||
|
});
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CommonWrapper
|
||||||
|
header={<h1 className="text-xl font-bold">{t('Add Website')}</h1>}
|
||||||
|
>
|
||||||
|
<ScrollArea className="h-full overflow-hidden p-4">
|
||||||
|
{websites.length === 0 && isLoading === false && (
|
||||||
|
<Empty
|
||||||
|
description={
|
||||||
|
<div className="py-2">
|
||||||
|
<div className="mb-1">
|
||||||
|
{t('Not any website has been exist')}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
Icon={LuPlus}
|
||||||
|
onClick={() =>
|
||||||
|
navigate({
|
||||||
|
to: '/website/add',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t('Add Website Now')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="space-y-10 p-4">
|
||||||
|
{websites.map((website) => (
|
||||||
|
<WebsiteOverview website={website} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
</CommonWrapper>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user