-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
frontend/src/component/admin/users/UsersHeader/LicensedUsersChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { FC } from 'react'; | ||
import 'chartjs-adapter-date-fns'; | ||
import type { LicensedUsersSchema } from 'openapi'; | ||
import { LineChart } from 'component/insights/components/LineChart/LineChart'; | ||
import { useTheme } from '@mui/material'; | ||
|
||
interface ILicensedUsersChartProps { | ||
licensedUsers: LicensedUsersSchema['licensedUsers']['history']; | ||
} | ||
|
||
export const LicensedUsersChart: FC<ILicensedUsersChartProps> = ({ | ||
licensedUsers, | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
const data = { | ||
datasets: [ | ||
{ | ||
label: 'Licensed users', | ||
data: licensedUsers, | ||
borderColor: theme.palette.primary.main, | ||
backgroundColor: theme.palette.primary.main, | ||
fill: false, | ||
}, | ||
], | ||
}; | ||
return ( | ||
<LineChart | ||
data={data} | ||
overrideOptions={{ | ||
parsing: { | ||
yAxisKey: 'count', | ||
xAxisKey: 'date', | ||
}, | ||
scales: { | ||
y: { | ||
beginAtZero: true, | ||
type: 'linear', | ||
grid: { | ||
color: theme.palette.divider, | ||
borderColor: theme.palette.divider, | ||
}, | ||
ticks: { | ||
color: theme.palette.text.secondary, | ||
display: true, | ||
precision: 0, | ||
}, | ||
}, | ||
x: { | ||
type: 'time', | ||
time: { | ||
unit: 'month', | ||
tooltipFormat: 'MMM yyyy', | ||
displayFormats: { | ||
month: 'MMM', | ||
}, | ||
}, | ||
grid: { | ||
color: 'transparent', | ||
borderColor: 'transparent', | ||
}, | ||
ticks: { | ||
color: theme.palette.text.secondary, | ||
display: true, | ||
source: 'data', | ||
maxRotation: 90, | ||
minRotation: 23.5, | ||
}, | ||
}, | ||
}, | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { LicensedUsersSchema } from '../openapi'; | ||
import { useApiGetter, fetcher } from './api/getters/useApiGetter/useApiGetter'; | ||
import { formatApiPath } from '../utils/formatPath'; | ||
|
||
const path = `api/admin/licensed-users`; | ||
|
||
const placeholderData: LicensedUsersSchema = { | ||
seatCount: 0, | ||
licensedUsers: { | ||
current: 0, | ||
history: [], | ||
}, | ||
}; | ||
|
||
export const useLicensedUsers = () => { | ||
const { data, refetch, loading, error } = useApiGetter<LicensedUsersSchema>( | ||
formatApiPath(path), | ||
() => fetcher(formatApiPath(path), 'Licensed users'), | ||
); | ||
|
||
return { data: data || placeholderData, refetch, loading, error }; | ||
}; |