Skip to content

Commit 64aaa56

Browse files
committed
feat: add button to access organisation inventory page
1 parent 88fe3c6 commit 64aaa56

File tree

4 files changed

+49
-35
lines changed

4 files changed

+49
-35
lines changed

src/components/usage/OrganisationUserUsage.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ export interface OrganisationUserUsageProps {
3737
}
3838

3939
export const OrganisationUserUsage = ({ organisationId }: OrganisationUserUsageProps) => {
40-
const { data: organisation } = useGetOrganisation(organisationId);
40+
const { data: organisation, isLoading: isOrganisationLoading } =
41+
useGetOrganisation(organisationId);
4142
const { data: units } = useGetUnits({
4243
query: { select: (data) => data.units.flatMap((org) => org.units) },
4344
});
4445
const { data, error: inventoryError } = useGetUserInventory<InventoryWithUnit[]>(
4546
{ org_id: organisationId },
4647
{
4748
query: {
49+
retry: false,
4850
select: (data) => {
4951
return data.users.map(({ projects, activity, first_seen, last_seen_date, username }) => ({
5052
username,
@@ -72,7 +74,7 @@ export const OrganisationUserUsage = ({ organisationId }: OrganisationUserUsageP
7274
);
7375
const { data: organisationMembers } = useGetOrganisationUsers(organisationId, {
7476
query: {
75-
enabled: organisation?.caller_is_member === undefined || organisation.caller_is_member,
77+
enabled: isOrganisationLoading || !organisation || organisation.caller_is_member,
7678
},
7779
});
7880

@@ -103,6 +105,10 @@ export const OrganisationUserUsage = ({ organisationId }: OrganisationUserUsageP
103105
...sharedColumns,
104106
];
105107

108+
if (inventoryError?.message === "Request failed with status code 403") {
109+
return <Alert severity="error">You do not have permission to view this inventory</Alert>;
110+
}
111+
106112
if (inventoryError) {
107113
return <Alert severity="error">{inventoryError.message}</Alert>;
108114
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { type ReactNode } from "react";
2+
3+
import { IconButton, Tooltip } from "@mui/material";
4+
5+
export interface AdornmentProps {
6+
title: string;
7+
href: string;
8+
children: ReactNode;
9+
}
10+
11+
export const Adornment = ({ title, href, children }: AdornmentProps) => (
12+
<Tooltip title={title}>
13+
<span>
14+
<IconButton
15+
href={`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}${href}`}
16+
size="small"
17+
sx={{ p: "1px" }}
18+
target="_blank"
19+
>
20+
{children}
21+
</IconButton>
22+
</span>
23+
</Tooltip>
24+
);

src/components/userContext/SelectOrganisation.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { type OrganisationDetail } from "@squonk/account-server-client";
22
import { useGetOrganisations } from "@squonk/account-server-client/organisation";
33

4+
import { DataUsage as DataUsageIcon } from "@mui/icons-material";
45
import { Autocomplete, type AutocompleteProps, Box, TextField, Typography } from "@mui/material";
56

67
import { projectPayload, useCurrentProjectId } from "../../hooks/projectHooks";
78
import { useSelectedOrganisation } from "../../state/organisationSelection";
89
import { useSelectedUnit } from "../../state/unitSelection";
910
import { PROJECT_LOCAL_STORAGE_KEY, writeToLocalStorage } from "../../utils/next/localStorage";
1011
import { getErrorMessage } from "../../utils/next/orvalError";
12+
import { Adornment } from "./Adornment";
1113
import { ItemIcons } from "./ItemIcons";
1214

1315
export interface SelectOrganisationProps
@@ -50,7 +52,19 @@ export const SelectOrganisation = (autoCompleteProps: SelectOrganisationProps) =
5052
{...params}
5153
InputProps={{
5254
...params.InputProps,
53-
startAdornment: <ItemIcons item={organisation} />,
55+
startAdornment: (
56+
<>
57+
<ItemIcons item={organisation} />
58+
{!!organisation && (
59+
<Adornment
60+
href={`/organisation/${organisation.id}/inventory`}
61+
title="User Usage"
62+
>
63+
<DataUsageIcon />
64+
</Adornment>
65+
)}
66+
</>
67+
),
5468
}}
5569
label="Organisation"
5670
/>

src/components/userContext/SelectUnit.tsx

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,18 @@
1-
import { type ReactNode } from "react";
2-
31
import { type UnitGetResponse } from "@squonk/account-server-client";
42

53
import { DataUsage as DataUsageIcon, Receipt as ReceiptIcon } from "@mui/icons-material";
6-
import {
7-
Autocomplete,
8-
type AutocompleteProps,
9-
Box,
10-
IconButton,
11-
TextField,
12-
Tooltip,
13-
Typography,
14-
} from "@mui/material";
4+
import { Autocomplete, type AutocompleteProps, Box, TextField, Typography } from "@mui/material";
155

166
import { projectPayload, useCurrentProjectId } from "../../hooks/projectHooks";
177
import { useGetVisibleUnits } from "../../hooks/useGetVisibleUnits";
188
import { useSelectedOrganisation } from "../../state/organisationSelection";
199
import { useSelectedUnit } from "../../state/unitSelection";
2010
import { PROJECT_LOCAL_STORAGE_KEY, writeToLocalStorage } from "../../utils/next/localStorage";
2111
import { getErrorMessage } from "../../utils/next/orvalError";
12+
import { Adornment } from "./Adornment";
2213
import { type PermissionLevelFilter } from "./filter";
2314
import { ItemIcons } from "./ItemIcons";
2415

25-
interface AdornmentProps {
26-
title: string;
27-
href: string;
28-
children: ReactNode;
29-
}
30-
31-
const Adornment = ({ title, href, children }: AdornmentProps) => (
32-
<Tooltip title={title}>
33-
<span>
34-
<IconButton
35-
href={`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}${href}`}
36-
size="small"
37-
sx={{ p: "1px" }}
38-
target="_blank"
39-
>
40-
{children}
41-
</IconButton>
42-
</span>
43-
</Tooltip>
44-
);
45-
4616
export interface SelectUnitProps
4717
extends Omit<AutocompleteProps<UnitGetResponse, false, false, false>, "options" | "renderInput"> {
4818
userFilter: PermissionLevelFilter;

0 commit comments

Comments
 (0)