Skip to content

Commit 4fc3a1d

Browse files
authored
Merge pull request #982 from trycompai/main
[comp] Production Deploy
2 parents 7e472af + 90d0801 commit 4fc3a1d

File tree

5 files changed

+82
-44
lines changed

5 files changed

+82
-44
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
·
2121
<a href="https://github.com/trycompai/comp/issues">Issues</a>
2222
·
23-
<a href="https://github.com/orgs/trycompai/projects/1">Roadmap</a>
23+
<a href="https://roadmap.trycomp.ai/roadmap">Roadmap</a>
2424
</p>
2525
</p>
2626

apps/app/src/app/(app)/[orgId]/people/devices/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import { DeviceComplianceChart } from './components/DeviceComplianceChart';
22
import { EmployeeDevicesList } from './components/EmployeeDevicesList';
33
import { getEmployeeDevices } from './data';
4+
import type { Host } from './types';
45

56
export default async function EmployeeDevicesPage() {
6-
const devices = (await getEmployeeDevices()) || [];
7+
let devices: Host[] = [];
8+
9+
try {
10+
const fetchedDevices = await getEmployeeDevices();
11+
devices = fetchedDevices || [];
12+
} catch (error) {
13+
console.error('Error fetching employee devices:', error);
14+
// Return empty array on error to render empty state
15+
devices = [];
16+
}
717

818
return (
919
<div>

apps/portal/src/app/(app)/(home)/[orgId]/components/EmployeeTasksList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface EmployeeTasksListProps {
1717
trainingVideos: EmployeeTrainingVideoCompletion[];
1818
member: Member;
1919
fleetPolicies: FleetPolicy[];
20-
host: Host;
20+
host: Host | null;
2121
isFleetEnabled: boolean;
2222
}
2323

@@ -65,7 +65,7 @@ export const EmployeeTasksList = ({
6565
}
6666
};
6767

68-
const hasPolicies = fleetPolicies.length;
68+
const hasPolicies = fleetPolicies.length > 0;
6969

7070
return (
7171
<Tabs defaultValue="policies">
@@ -81,7 +81,7 @@ export const EmployeeTasksList = ({
8181
<VideoCarousel videos={trainingVideos} member={member} />
8282
</TabsContent>
8383
<TabsContent value="device" className="py-2">
84-
{isFleetEnabled && hasPolicies ? (
84+
{isFleetEnabled && hasPolicies && host ? (
8585
<Card>
8686
<CardHeader>
8787
<CardTitle>{host.computer_name}'s Policies</CardTitle>

apps/portal/src/app/(app)/(home)/[orgId]/components/OrganizationDashboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface OrganizationDashboardProps {
1414
organizationId: string;
1515
member: MemberWithUserOrg; // Pass the full member object for user info etc.
1616
fleetPolicies: FleetPolicy[];
17-
host: Host;
17+
host: Host | null;
1818
isFleetEnabled: boolean;
1919
}
2020

apps/portal/src/app/(app)/(home)/[orgId]/page.tsx

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,88 @@ import type { Member } from '@comp/db/types';
66
import { headers } from 'next/headers';
77
import { redirect } from 'next/navigation';
88
import { OrganizationDashboard } from './components/OrganizationDashboard';
9+
import type { FleetPolicy, Host } from './types';
910

1011
export default async function OrganizationPage({ params }: { params: Promise<{ orgId: string }> }) {
11-
const { orgId } = await params;
12+
try {
13+
const { orgId } = await params;
1214

13-
const session = await auth.api.getSession({
14-
headers: await headers(),
15-
});
15+
const session = await auth.api.getSession({
16+
headers: await headers(),
17+
});
1618

17-
if (!session?.user) {
18-
redirect('/login'); // Or appropriate login/auth route
19-
}
19+
if (!session?.user) {
20+
redirect('/login'); // Or appropriate login/auth route
21+
}
2022

21-
const member = await db.member.findFirst({
22-
where: {
23-
userId: session.user.id,
24-
organizationId: orgId,
25-
},
26-
include: {
27-
user: true,
28-
organization: true, // Include organization details
29-
},
30-
});
23+
let member = null;
3124

32-
if (!member) {
33-
redirect('/'); // Or appropriate login/auth route
34-
}
25+
try {
26+
member = await db.member.findFirst({
27+
where: {
28+
userId: session.user.id,
29+
organizationId: orgId,
30+
},
31+
include: {
32+
user: true,
33+
organization: true, // Include organization details
34+
},
35+
});
36+
} catch (error) {
37+
console.error('Error fetching member:', error);
38+
// Return a fallback UI or redirect to error page
39+
redirect('/');
40+
}
41+
42+
if (!member) {
43+
redirect('/'); // Or appropriate login/auth route
44+
}
45+
46+
const { fleetPolicies, device } = await getFleetPolicies(member);
3547

36-
const { fleetPolicies, device } = await getFleetPolicies(member);
37-
const isFleetEnabled = await getPostHogClient()?.isFeatureEnabled(
38-
'is-fleet-enabled',
39-
session?.user.id,
40-
);
48+
let isFleetEnabled = false;
49+
try {
50+
const postHogClient = await getPostHogClient();
51+
isFleetEnabled =
52+
(await postHogClient?.isFeatureEnabled('is-fleet-enabled', session?.user.id)) ?? false;
53+
} catch (error) {
54+
console.error('Error checking fleet feature flag:', error);
55+
// Default to false if there's an error
56+
}
4157

42-
return (
43-
<OrganizationDashboard
44-
key={orgId} // Use organizationId as key
45-
organizationId={orgId}
46-
member={member}
47-
fleetPolicies={fleetPolicies}
48-
host={device}
49-
isFleetEnabled={isFleetEnabled ?? false}
50-
/>
51-
);
58+
return (
59+
<OrganizationDashboard
60+
key={orgId} // Use organizationId as key
61+
organizationId={orgId}
62+
member={member}
63+
fleetPolicies={fleetPolicies}
64+
host={device}
65+
isFleetEnabled={isFleetEnabled}
66+
/>
67+
);
68+
} catch (error) {
69+
console.error('Error in OrganizationPage:', error);
70+
// Redirect to a safe page if there's an unexpected error
71+
redirect('/');
72+
}
5273
}
5374

54-
const getFleetPolicies = async (member: Member) => {
75+
const getFleetPolicies = async (
76+
member: Member,
77+
): Promise<{ fleetPolicies: FleetPolicy[]; device: Host | null }> => {
5578
const deviceLabelId = member.fleetDmLabelId;
5679
const fleet = await getFleetInstance();
5780

5881
try {
5982
const deviceResponse = await fleet.get(`/labels/${deviceLabelId}/hosts`);
60-
const device = deviceResponse.data.hosts[0]; // There should only be one device per label.
83+
const device: Host | undefined = deviceResponse.data.hosts[0]; // There should only be one device per label.
84+
85+
if (!device) {
86+
return { fleetPolicies: [], device: null };
87+
}
88+
6189
const deviceWithPolicies = await fleet.get(`/hosts/${device.id}`);
62-
const fleetPolicies = deviceWithPolicies.data.host.policies;
90+
const fleetPolicies: FleetPolicy[] = deviceWithPolicies.data.host.policies;
6391
return { fleetPolicies, device };
6492
} catch (error) {
6593
console.error(error);

0 commit comments

Comments
 (0)