Skip to content

Commit

Permalink
chore: add licensed user data to the licensed users box (#8868)
Browse files Browse the repository at this point in the history
This change adds actual data from the server to the licensed users box
in the users header.

It also extracts the open sidebar button into its own component so
that we don't re-fetch the data when we open the sidebar. That's the
same issue we've had with project status and project creation screens,
etc.
  • Loading branch information
thomasheartman authored Nov 27, 2024
1 parent 679e9d1 commit eaca09b
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions frontend/src/component/admin/users/UsersHeader/LicensedUsersBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Box, styled } from '@mui/material';
import { HelpIcon } from 'component/common/HelpIcon/HelpIcon';
import { useState } from 'react';
import { LicensedUsersSidebar } from './LicensedUsersSidebar';
import { useLicensedUsers } from 'hooks/useLicensedUsers';
import useLoading from 'hooks/useLoading';

const StyledButton = styled('button')(({ theme }) => ({
background: 'none',
Expand Down Expand Up @@ -40,12 +42,35 @@ const MainMetric = styled('span')(({ theme }) => ({
fontWeight: 'bold',
}));

export const LicensedUsersBox = () => {
const OpenSidebarButton = () => {
const [licensedUsersChartOpen, setLicensedUsersChartOpen] = useState(false);

return (
<Figure>
<>
<StyledButton
onClick={() => {
setLicensedUsersChartOpen(true);
}}
>
View graph over time
</StyledButton>
<LicensedUsersSidebar
open={licensedUsersChartOpen}
close={() => setLicensedUsersChartOpen(false)}
/>
</>
);
};

export const LicensedUsersBox = () => {
const { data, loading } = useLicensedUsers();
const ref = useLoading(loading, '[data-loading-licensed-users=true]');
return (
<Figure ref={ref}>
<TopRow>
<MainMetric>11/25</MainMetric>
<MainMetric data-loading-licensed-users>
{data.licensedUsers.current}/{data.seatCount}
</MainMetric>
<HelpIcon
htmlTooltip
tooltip={
Expand All @@ -60,18 +85,8 @@ export const LicensedUsersBox = () => {

<StyledCaption>
<span>Seats used in the last 30 days</span>
<StyledButton
onClick={() => {
setLicensedUsersChartOpen(true);
}}
>
View graph over time
</StyledButton>
<OpenSidebarButton />
</StyledCaption>
<LicensedUsersSidebar
open={licensedUsersChartOpen}
close={() => setLicensedUsersChartOpen(false)}
/>
</Figure>
);
};

0 comments on commit eaca09b

Please sign in to comment.