Skip to content

Commit b8605e7

Browse files
committed
Meshan's suggestions
1 parent 6aa65cc commit b8605e7

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

src/components/activity/StatsGraph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const StatsGraph = (props: StatsGraphProps) => {
145145
<Legend verticalAlign="top" height={36}/>
146146
<XAxis dataKey="name" />
147147
<YAxis />
148-
<Tooltip />
148+
<Tooltip labelStyle={{ color: "#454545" }}/>
149149
{ getGraphLines() }
150150
</LineChart>
151151
</ResponsiveContainer>

src/components/activity/StatsView.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ const timeRangeOptions: { label: string, value: TimeRangeType }[] = [{
8484
}];
8585

8686
const StatsView = () => {
87-
const { data: session } = useSession();
88-
const userRole = session?.user?.role!;
89-
const userId = session?.user?.id!;
9087
const [ticketStats, setTicketStats] = useState<TicketStats[]>([]);
9188
const [personalTicketStats, setPersonalTicketStats] = useState<TicketStats[]>([]);
9289
const [globalTimeRangeOption, setGlobalTimeRangeOption] = useState(timeRangeOptions[0]);
@@ -98,7 +95,7 @@ const StatsView = () => {
9895
setTicketStats(data);
9996
}
10097
});
101-
const { isLoading: isPersonalStatsLoading } = trpc.stats.getTicketStatsHelpedByUser.useQuery({ userId: userId }, {
98+
const { isLoading: isPersonalStatsLoading } = trpc.stats.getTicketStatsHelpedByUser.useQuery(undefined, {
10299
refetchOnWindowFocus: false,
103100
onSuccess: data => {
104101
setPersonalTicketStats(data);

src/pages/activity/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import { NextPage } from 'next';
2+
import { useSession } from 'next-auth/react';
23
import dynamic from 'next/dynamic';
34
import Layout from '../../components/layout/Layout';
5+
import { UserRole } from '@prisma/client';
46

57
/**
68
* Activity page which displays the activity log
79
*/
810
const ActivityPage: NextPage = () => {
911
const ActivityView = dynamic(() => import('../../components/activity/ActivityView'));
10-
const StatsView = dynamic(() => import('../../components/activity/StatsView'))
12+
const StatsView = dynamic(() => import('../../components/activity/StatsView'));
13+
14+
const { data: session } = useSession();
15+
1116
return (
1217
<Layout>
1318
<ActivityView />
14-
<StatsView />
19+
{ session?.user?.role === UserRole.STAFF && <StatsView /> }
1520
</Layout>
1621
);
1722
};

src/server/trpc/router/stats.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { router, publicProcedure } from '../trpc';
1+
import { router, publicProcedure, protectedNotStudentProcedure } from '../trpc';
22
import { TicketStatus, TicketType } from '@prisma/client';
33
import { z } from 'zod';
44

@@ -18,28 +18,25 @@ export const statsRouter = router({
1818
},
1919
});
2020
}),
21-
getTicketStatsHelpedByUser: publicProcedure
22-
.input(z.object({
23-
userId: z.string()
24-
}))
25-
.query(async ({ input, ctx }) => {
26-
return ctx.prisma.ticket.findMany({
27-
select: {
28-
createdAt: true,
29-
helpedAt: true,
30-
resolvedAt: true,
31-
status: true,
32-
ticketType: true,
33-
description: true,
34-
isPublic: true,
35-
locationId: true,
36-
assignmentId: true,
37-
},
38-
where: {
39-
helpedByUserId: input.userId
40-
},
41-
});
42-
}),
21+
getTicketStatsHelpedByUser: protectedNotStudentProcedure
22+
.query(async ({ ctx }) => {
23+
return ctx.prisma.ticket.findMany({
24+
select: {
25+
createdAt: true,
26+
helpedAt: true,
27+
resolvedAt: true,
28+
status: true,
29+
ticketType: true,
30+
description: true,
31+
isPublic: true,
32+
locationId: true,
33+
assignmentId: true,
34+
},
35+
where: {
36+
helpedByUserId: ctx.session?.user?.id
37+
},
38+
});
39+
}),
4340
});
4441

4542
export interface TicketStats {

0 commit comments

Comments
 (0)