Skip to content

Commit

Permalink
HOSTSD-227 HSB user pages (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fosol authored Jan 17, 2024
1 parent a2e1127 commit 9b3193f
Show file tree
Hide file tree
Showing 46 changed files with 617 additions and 314 deletions.
16 changes: 0 additions & 16 deletions src/dashboard/src/app/client/admin/organizations/[id]/page.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/dashboard/src/app/client/admin/organizations/page.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions src/dashboard/src/app/client/admin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
'use client';

import { useSecureRoute } from '@/hooks';

export default function Page() {
useSecureRoute((state) => state.isOrganizationAdmin, '/');

return <div>Client Admin</div>;
}
6 changes: 6 additions & 0 deletions src/dashboard/src/app/client/admin/users/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
'use client';

import { useSecureRoute } from '@/hooks';

export default function Page() {
useSecureRoute((state) => state.isOrganizationAdmin, '/');

return <div>Client User Admin</div>;
}
16 changes: 0 additions & 16 deletions src/dashboard/src/app/client/dashboard/[id]/page.tsx

This file was deleted.

28 changes: 7 additions & 21 deletions src/dashboard/src/app/client/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
import {
AllOrganizations,
AllocationByOS,
AllocationByStorageVolume,
AllocationTable,
SegmentedBarChart,
StorageTrendsChart,
TotalStorage,
} from '@/components/charts';
import { OperatingSystems } from '@/components/charts/allocationTable/constants';
'use client';

import { Dashboard } from '@/components';
import { useSecureRoute } from '@/hooks';

export default function Page() {
return (
<>
<AllOrganizations />
<StorageTrendsChart large={false} />
<AllocationByStorageVolume />
<TotalStorage />
<AllocationByOS />
<AllocationTable operatingSystem={OperatingSystems.Windows} />
<SegmentedBarChart />
</>
);
useSecureRoute((state) => state.isClient, '/');

return <Dashboard />;
}
19 changes: 19 additions & 0 deletions src/dashboard/src/app/client/servers/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use client';

import { AllocationByStorageVolume, Col } from '@/components';
import { useSecureRoute } from '@/hooks';
import { useFilteredOrganizations, useFilteredServerItems } from '@/hooks/filter';

export default function Page() {
useSecureRoute((state) => state.isClient, '/');

const { organizations } = useFilteredOrganizations();
const { serverItems } = useFilteredServerItems();

return (
<Col>
<h1></h1>All Servers
<AllocationByStorageVolume organizations={organizations} serverItems={serverItems} />
</Col>
);
}
16 changes: 0 additions & 16 deletions src/dashboard/src/app/hsb/admin/groups/[id]/page.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/dashboard/src/app/hsb/admin/groups/page.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions src/dashboard/src/app/hsb/admin/organizations/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
'use client';

import { useSecureRoute } from '@/hooks';

export default function Page() {
useSecureRoute((state) => state.isSystemAdmin, '/');

return <div>HSB Organization Admin</div>;
}
202 changes: 96 additions & 106 deletions src/dashboard/src/app/hsb/admin/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,15 @@

import styles from './Users.module.scss';

import {
Button,
Checkbox,
Info,
Overlay,
Row,
Select,
Sheet,
Spinner,
Table,
Text,
} from '@/components';
import { IUserModel } from '@/hooks';
import { Button, Checkbox, Info, Overlay, Select, Sheet, Spinner, Table, Text } from '@/components';
import { IUserModel, useSecureRoute } from '@/hooks';
import { useApiUsers } from '@/hooks/api/admin';
import { useGroups, useUsers } from '@/hooks/data';
import React from 'react';
import { IUserForm } from './IUserForm';

export default function Page() {
useSecureRoute((state) => state.isSystemAdmin, '/');
const { isReady: isReadyUsers, users } = useUsers({ includeGroups: true });
const { isReady: isReadyGroups, groups, options: groupOptions } = useGroups();
const { update: updateUser } = useApiUsers();
Expand Down Expand Up @@ -81,104 +71,104 @@ export default function Page() {
}, [updateUser, records]);

return (
<Sheet >
<Sheet>
<div className={styles.container}>
{loading && (
<Overlay>
<Spinner />
</Overlay>
)}
<div className={styles.section}>
<Info>
Find a user by name, username, or email. Click checkbox to enable user access to dashboard
for selected group(s).
</Info>
<div className={styles.search}>
<Text
name="search"
placeholder="Search"
iconType="search"
onChange={(e) => setFilter(e.target.value)}
onKeyDown={(e) => {
if (e.code === 'Enter') handleSearch();
{loading && (
<Overlay>
<Spinner />
</Overlay>
)}
<div className={styles.section}>
<Info>
Find a user by name, username, or email. Click checkbox to enable user access to
dashboard for selected group(s).
</Info>
<div className={styles.search}>
<Text
name="search"
placeholder="Search"
iconType="search"
onChange={(e) => setFilter(e.target.value)}
onKeyDown={(e) => {
if (e.code === 'Enter') handleSearch();
}}
/>
<Button variant="secondary" onClick={() => handleSearch()}>
Search
</Button>
</div>
</div>
<div className={styles.table}>
<Table
data={items}
header={
<>
<div>Username</div>
<div>Email</div>
<div>Name</div>
<div className={styles.tableHeader}>Enabled</div>
<div>Groups</div>
</>
}
>
{({ data }) => {
return (
<>
<div>{data.username}</div>
<div>{data.email}</div>
<div>{data.displayName}</div>
<div className={styles.checkbox}>
<Checkbox
checked={data.isEnabled}
onChange={(e) => {
setRecords((records) =>
records.map((r) =>
r.id === data.id
? { ...data, isEnabled: e.target.checked, isDirty: true }
: r,
),
);
}}
/>
</div>
<div className={styles.groupsSelect}>
<Select
options={groupOptions}
className={styles.multiSelect}
placeholder="Select one or more"
multiple
value={data.groups?.map((g) => g.id.toString())}
onChange={(values) => {
if (Array.isArray(values)) {
setRecords((users) =>
users.map((u) =>
u.id === data.id
? {
...u,
groups: groups.filter((g) => values?.some((v) => v == g.id)),
isDirty: true,
}
: u,
),
);
}
}}
/>
</div>
</>
);
}}
/>
<Button variant="secondary" onClick={() => handleSearch()}>
Search
</Table>
</div>
<div className={styles.footer}>
<Button
onClick={async () => await handleUpdate()}
disabled={isSubmitting || !records.some((r) => r.isDirty)}
>
Save
</Button>
</div>
</div>
<div className={styles.table}>
<Table
data={items}
header={
<>
<div>Username</div>
<div>Email</div>
<div>Name</div>
<div className={styles.tableHeader}>Enabled</div>
<div>Groups</div>
</>
}
>
{({ data }) => {
return (
<>
<div>{data.username}</div>
<div>{data.email}</div>
<div>{data.displayName}</div>
<div className={styles.checkbox}>
<Checkbox
checked={data.isEnabled}
onChange={(e) => {
setRecords((records) =>
records.map((r) =>
r.id === data.id
? { ...data, isEnabled: e.target.checked, isDirty: true }
: r,
),
);
}}
/>
</div>
<div className={styles.groupsSelect}>
<Select
options={groupOptions}
className={styles.multiSelect}
placeholder="Select one or more"
multiple
value={data.groups?.map((g) => g.id.toString())}
onChange={(values) => {
if (Array.isArray(values)) {
setRecords((users) =>
users.map((u) =>
u.id === data.id
? {
...u,
groups: groups.filter((g) => values?.some((v) => v == g.id)),
isDirty: true,
}
: u,
),
);
}
}}
/>
</div>
</>
);
}}
</Table>
</div>
<div className={styles.footer}>
<Button
onClick={async () => await handleUpdate()}
disabled={isSubmitting || !records.some((r) => r.isDirty)}
>
Save
</Button>
</div>
</div>
</Sheet>
);
}
11 changes: 0 additions & 11 deletions src/dashboard/src/app/hsb/dashboard/Page.module.scss

This file was deleted.

16 changes: 0 additions & 16 deletions src/dashboard/src/app/hsb/dashboard/[id]/page.tsx

This file was deleted.

Loading

0 comments on commit 9b3193f

Please sign in to comment.