mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(console): add date picker in dashboard (#1085)
This commit is contained in:
parent
bcc05e521d
commit
5a073ceb60
3 changed files with 27 additions and 4 deletions
|
@ -29,7 +29,7 @@ const Block = ({ varient = 'default', count, delta, title }: Props) => {
|
||||||
<div className={styles.number}>{formatNumberWithComma(count)}</div>
|
<div className={styles.number}>{formatNumberWithComma(count)}</div>
|
||||||
{delta !== undefined && (
|
{delta !== undefined && (
|
||||||
<div className={classNames(styles.delta, delta < 0 && styles.down)}>
|
<div className={classNames(styles.delta, delta < 0 && styles.down)}>
|
||||||
<span>(${deltaLable})</span>
|
<span>({deltaLable})</span>
|
||||||
{delta > 0 && <ArrowUp />}
|
{delta > 0 && <ArrowUp />}
|
||||||
{delta < 0 && <ArrowDown />}
|
{delta < 0 && <ArrowDown />}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,6 +28,17 @@
|
||||||
margin-bottom: _.unit(4);
|
margin-bottom: _.unit(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.activeCard {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.datePicker {
|
||||||
|
position: absolute;
|
||||||
|
right: _.unit(6);
|
||||||
|
top: _.unit(6);
|
||||||
|
width: 160px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.curve {
|
.curve {
|
||||||
margin: _.unit(10) 0 _.unit(6);
|
margin: _.unit(10) 0 _.unit(6);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React from 'react';
|
import dayjs from 'dayjs';
|
||||||
|
import React, { ChangeEventHandler, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
Area,
|
Area,
|
||||||
|
@ -12,6 +13,7 @@ import {
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
import Card from '@/components/Card';
|
import Card from '@/components/Card';
|
||||||
|
import TextInput from '@/components/TextInput';
|
||||||
|
|
||||||
import Block from './components/Block';
|
import Block from './components/Block';
|
||||||
import Skeleton from './components/Skeleton';
|
import Skeleton from './components/Skeleton';
|
||||||
|
@ -19,13 +21,20 @@ import * as styles from './index.module.scss';
|
||||||
import { ActiveUsersResponse, NewUsersResponse, TotalUsersResponse } from './types';
|
import { ActiveUsersResponse, NewUsersResponse, TotalUsersResponse } from './types';
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
|
const [date, setDate] = useState<string>(dayjs().format('YYYY-MM-DD'));
|
||||||
const { data: totalData } = useSWR<TotalUsersResponse>('/api/dashboard/users/total');
|
const { data: totalData } = useSWR<TotalUsersResponse>('/api/dashboard/users/total');
|
||||||
const { data: newData } = useSWR<NewUsersResponse>('/api/dashboard/users/new');
|
const { data: newData } = useSWR<NewUsersResponse>('/api/dashboard/users/new');
|
||||||
const { data: activeData } = useSWR<ActiveUsersResponse>('/api/dashboard/users/active');
|
const { data: activeData } = useSWR<ActiveUsersResponse>(
|
||||||
|
`/api/dashboard/users/active?date=${date}`
|
||||||
|
);
|
||||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
|
|
||||||
const isLoading = !totalData || !newData || !activeData;
|
const isLoading = !totalData || !newData || !activeData;
|
||||||
|
|
||||||
|
const handleDateChange: ChangeEventHandler<HTMLInputElement> = (event) => {
|
||||||
|
setDate(event.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<div className={styles.header}>
|
<div className={styles.header}>
|
||||||
|
@ -48,13 +57,16 @@ const Dashboard = () => {
|
||||||
delta={newData.last7Days.delta}
|
delta={newData.last7Days.delta}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Card>
|
<Card className={styles.activeCard}>
|
||||||
<Block
|
<Block
|
||||||
title="dashboard.daily_active_users"
|
title="dashboard.daily_active_users"
|
||||||
count={activeData.dau.count}
|
count={activeData.dau.count}
|
||||||
delta={activeData.dau.delta}
|
delta={activeData.dau.delta}
|
||||||
varient="plain"
|
varient="plain"
|
||||||
/>
|
/>
|
||||||
|
<div className={styles.datePicker}>
|
||||||
|
<TextInput type="date" value={date} onChange={handleDateChange} />
|
||||||
|
</div>
|
||||||
<div className={styles.curve}>
|
<div className={styles.curve}>
|
||||||
<ResponsiveContainer>
|
<ResponsiveContainer>
|
||||||
<AreaChart
|
<AreaChart
|
||||||
|
|
Loading…
Reference in a new issue