♻️ refactor(core): Restructure project for better module separation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@shadcn/ui/avatar';
|
||||
import { Card, CardDescription, CardHeader, CardTitle } from '@shadcn/ui/card';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@workspace/ui/components/avatar';
|
||||
import { Card, CardDescription, CardHeader, CardTitle } from '@workspace/ui/components/card';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
import Link from 'next/link';
|
||||
|
||||
@@ -25,11 +25,12 @@ export default async function Billing({ type }: BillingProps) {
|
||||
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
||||
const data = await response.json();
|
||||
const now = new Date().getTime();
|
||||
list = data[type].filter((item) => {
|
||||
list = data[type].filter((item: { expiryDate: string }) => {
|
||||
const expiryDate = Date.parse(item.expiryDate);
|
||||
return !isNaN(expiryDate) && expiryDate > now;
|
||||
});
|
||||
} catch (error) {
|
||||
console.log('Error fetching billing data:', error);
|
||||
return null;
|
||||
}
|
||||
if (list && list.length === 0) return null;
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
'use client';
|
||||
|
||||
import { queryRevenueStatistics } from '@/services/admin/console';
|
||||
import { unitConversion } from '@repo/ui/utils';
|
||||
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@shadcn/ui/card';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@workspace/ui/components/card';
|
||||
import {
|
||||
ChartContainer,
|
||||
ChartLegend,
|
||||
ChartLegendContent,
|
||||
ChartTooltip,
|
||||
ChartTooltipContent,
|
||||
} from '@shadcn/ui/chart';
|
||||
} from '@workspace/ui/components/chart';
|
||||
import { Separator } from '@workspace/ui/components/separator';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@workspace/ui/components/tabs';
|
||||
import { unitConversion } from '@workspace/ui/utils';
|
||||
import { useLocale, useTranslations } from 'next-intl';
|
||||
import {
|
||||
Area,
|
||||
AreaChart,
|
||||
@@ -20,11 +30,7 @@ import {
|
||||
Pie,
|
||||
PieChart,
|
||||
XAxis,
|
||||
} from '@shadcn/ui/lib/recharts';
|
||||
import { Separator } from '@shadcn/ui/separator';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@shadcn/ui/tabs';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useLocale, useTranslations } from 'next-intl';
|
||||
} from 'recharts';
|
||||
import { Display } from '../display';
|
||||
import { Empty } from '../empty';
|
||||
|
||||
|
||||
@@ -2,16 +2,22 @@
|
||||
|
||||
import { queryServerTotalData, queryTicketWaitReply } from '@/services/admin/console';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { formatBytes } from '@repo/ui/utils';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@shadcn/ui/card';
|
||||
import { ChartContainer, ChartTooltip, ChartTooltipContent } from '@shadcn/ui/chart';
|
||||
import { Bar, BarChart, CartesianGrid, LabelList, XAxis, YAxis } from '@shadcn/ui/lib/recharts';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@shadcn/ui/select';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@shadcn/ui/tabs';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@workspace/ui/components/card';
|
||||
import { ChartContainer, ChartTooltip, ChartTooltipContent } from '@workspace/ui/components/chart';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@workspace/ui/components/select';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@workspace/ui/components/tabs';
|
||||
import { formatBytes } from '@workspace/ui/utils';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import Link from 'next/link';
|
||||
import { useState } from 'react';
|
||||
import { Bar, BarChart, CartesianGrid, LabelList, XAxis, YAxis } from 'recharts';
|
||||
import { Empty } from '../empty';
|
||||
import { RevenueStatisticsCard } from './revenue-statistics-card';
|
||||
import { UserStatisticsCard } from './user-statistics-card';
|
||||
@@ -65,8 +71,8 @@ export default function Statistics() {
|
||||
})) || [],
|
||||
},
|
||||
};
|
||||
|
||||
const currentData = trafficData[dataType][timeFrame];
|
||||
const currentData =
|
||||
trafficData[dataType as 'nodes' | 'users'][timeFrame as 'today' | 'yesterday'];
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
'use client';
|
||||
|
||||
import { queryUserStatistics } from '@/services/admin/console';
|
||||
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '@shadcn/ui/card';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from '@workspace/ui/components/card';
|
||||
import {
|
||||
ChartContainer,
|
||||
ChartLegend,
|
||||
ChartLegendContent,
|
||||
ChartTooltip,
|
||||
ChartTooltipContent,
|
||||
} from '@shadcn/ui/chart';
|
||||
} from '@workspace/ui/components/chart';
|
||||
import { Separator } from '@workspace/ui/components/separator';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@workspace/ui/components/tabs';
|
||||
import { useLocale, useTranslations } from 'next-intl';
|
||||
import {
|
||||
Area,
|
||||
AreaChart,
|
||||
@@ -19,28 +29,9 @@ import {
|
||||
Pie,
|
||||
PieChart,
|
||||
XAxis,
|
||||
} from '@shadcn/ui/lib/recharts';
|
||||
import { Separator } from '@shadcn/ui/separator';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@shadcn/ui/tabs';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useLocale, useTranslations } from 'next-intl';
|
||||
} from 'recharts';
|
||||
import { Empty } from '../empty';
|
||||
|
||||
const UserStatisticsConfig = {
|
||||
register: {
|
||||
label: '注册',
|
||||
color: 'hsl(var(--chart-1))',
|
||||
},
|
||||
new_purchase: {
|
||||
label: '新购',
|
||||
color: 'hsl(var(--chart-2))',
|
||||
},
|
||||
repurchase: {
|
||||
label: '复购',
|
||||
color: 'hsl(var(--chart-3))',
|
||||
},
|
||||
};
|
||||
|
||||
export function UserStatisticsCard() {
|
||||
const t = useTranslations('index');
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import useGlobalStore from '@/config/use-global';
|
||||
import { formatBytes, unitConversion } from '@repo/ui/utils';
|
||||
import { formatBytes, unitConversion } from '@workspace/ui/utils';
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
type DisplayType = 'currency' | 'traffic' | 'number';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { default as _Empty } from '@repo/ui/empty';
|
||||
import { default as _Empty } from '@workspace/ui/custom-components/empty';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ import {
|
||||
BreadcrumbList,
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
} from '@shadcn/ui/breadcrumb';
|
||||
import { Separator } from '@shadcn/ui/separator';
|
||||
import { SidebarTrigger } from '@shadcn/ui/sidebar';
|
||||
} from '@workspace/ui/components/breadcrumb';
|
||||
import { Separator } from '@workspace/ui/components/separator';
|
||||
import { SidebarTrigger } from '@workspace/ui/components/sidebar';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { Fragment, useMemo } from 'react';
|
||||
|
||||
@@ -3,8 +3,14 @@
|
||||
import { locales } from '@/config/constants';
|
||||
import { setLocale } from '@/utils/common';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { getCountry } from '@repo/ui/utils';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@shadcn/ui/select';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@workspace/ui/components/select';
|
||||
import { getCountry } from '@workspace/ui/utils';
|
||||
import { useLocale, useTranslations } from 'next-intl';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
@@ -21,7 +27,7 @@ export default function LanguageSwitch() {
|
||||
|
||||
return (
|
||||
<Select defaultValue={locale} onValueChange={handleLanguageChange}>
|
||||
<SelectTrigger className='hover:bg-accent hover:text-accent-foreground w-auto border-none bg-transparent p-2 focus:ring-0 [&>svg]:hidden'>
|
||||
<SelectTrigger className='hover:bg-accent hover:text-accent-foreground w-auto border-none bg-transparent p-2 shadow-none focus:ring-0 [&>svg]:hidden'>
|
||||
<SelectValue>
|
||||
<div className='flex items-center'>
|
||||
<Icon icon={`flagpack:${country?.alpha2.toLowerCase()}`} className='!size-5' />
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { ProTable as _ProTable, ProTableProps } from '@repo/ui/pro-table';
|
||||
import { ProTable as _ProTable, ProTableProps } from '@workspace/ui/custom-components/pro-table';
|
||||
import { useTranslations } from 'next-intl';
|
||||
export { type ProTableActions } from '@repo/ui/pro-table';
|
||||
export { type ProTableActions } from '@workspace/ui/custom-components/pro-table';
|
||||
|
||||
export function ProTable<
|
||||
TData extends Record<string, unknown>,
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
} from '@shadcn/ui/sidebar';
|
||||
} from '@workspace/ui/components/sidebar';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import Image from 'next/legacy/image';
|
||||
import Link from 'next/link';
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
'use client';
|
||||
|
||||
import { MoonIcon, SunIcon } from '@repo/ui/lotties';
|
||||
import { Button } from '@shadcn/ui/button';
|
||||
import { DotLottieReact } from '@lottiefiles/dotlottie-react';
|
||||
import { Button } from '@workspace/ui/components/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@shadcn/ui/dropdown-menu';
|
||||
} from '@workspace/ui/components/dropdown-menu';
|
||||
import MoonLottie from '@workspace/ui/lotties/moon.json';
|
||||
import SunLottie from '@workspace/ui/lotties/sun.json';
|
||||
import { useTheme } from 'next-themes';
|
||||
|
||||
export default function ThemeSwitch() {
|
||||
const { setTheme } = useTheme();
|
||||
const { setTheme, resolvedTheme } = useTheme();
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size='icon'>
|
||||
<MoonIcon className='size-8 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0' />
|
||||
<SunIcon className='roate-90 absolute size-8 scale-0 transition-all dark:rotate-0 dark:scale-100' />
|
||||
<DotLottieReact data={resolvedTheme === 'dark' ? MoonLottie : SunLottie} autoplay loop />
|
||||
<span className='sr-only'>Toggle theme</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
import useGlobalStore from '@/config/use-global';
|
||||
import { Logout } from '@/utils/common';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@shadcn/ui/avatar';
|
||||
import { Button } from '@shadcn/ui/button';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@workspace/ui/components/avatar';
|
||||
import { Button } from '@workspace/ui/components/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuTrigger,
|
||||
} from '@shadcn/ui/dropdown-menu';
|
||||
} from '@workspace/ui/components/dropdown-menu';
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
export function UserNav() {
|
||||
|
||||
Reference in New Issue
Block a user