Skip to content

Commit c0dcb6a

Browse files
committed
Fix public tickets toggle
2 parents 632e12e + 9ac4dca commit c0dcb6a

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

src/components/queue/CreateTicketForm.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ const CreateTicketForm = (props: CreateTicketFormProps) => {
8080
setIsPublic(false);
8181
} else {
8282
setDescription(STARTER_CONCEPTUAL_TICKET_DESCRIPTION);
83-
setIsPublic(true);
83+
if (arePublicTicketsEnabled) {
84+
setIsPublic(true);
85+
}
8486
}
8587
};
8688

@@ -220,8 +222,8 @@ const CreateTicketForm = (props: CreateTicketFormProps) => {
220222
<Tooltip
221223
hasArrow
222224
label='Public tickets can be joined by other students. This is great for group work
223-
or conceptual questions! If your ticket is public, we are more likely to
224-
help you for a longer time.'
225+
or conceptual questions! If your ticket is public, we are more likely to
226+
help you for a longer time.'
225227
bg='gray.300'
226228
color='black'
227229
>

src/components/queue/TicketQueue.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const TicketQueue = (props: TicketQueueProps) => {
171171
const isGetTicketsLoading =
172172
isGetOpenTicketsLoading || isGetAssignedTicketsLoading || isGetPendingTicketsLoading || isGetAbsentTicketsLoading;
173173

174-
/** Don't show priority tickets on the Open tab since they are in the */
174+
/** Don't show priority tickets on the Open tab */
175175
const removePriorityTickets = (tickets: TicketWithNames[]) => {
176176
return tickets.filter(ticket => !ticket.isPriority);
177177
};

src/components/ticket-page/TicketButtons.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Button, Flex, Spinner } from '@chakra-ui/react';
33
import { TicketStatus, TicketType, UserRole } from '@prisma/client';
44
import { TicketWithNames } from '../../server/trpc/router/ticket';
55
import { trpc } from '../../utils/trpc';
6+
import useSiteSettings from '../../utils/hooks/useSiteSettings';
7+
import { SiteSettings, SiteSettingsValues } from '@prisma/client';
68

79
interface TicketCardProps {
810
ticket: TicketWithNames;
@@ -25,6 +27,8 @@ const TicketButtons = (props: TicketCardProps) => {
2527

2628
const [areButtonsLoading, setAreButtonsLoading] = useState(false);
2729
const [areButtonsDisabled, setAreButtonsDisabled] = useState(false);
30+
const { siteSettings } = useSiteSettings();
31+
2832
const approveTicketsMutation = trpc.ticket.approveTickets.useMutation();
2933
const resolveTicketsMutation = trpc.ticket.resolveTickets.useMutation();
3034
const requeueTicketsMutation = trpc.ticket.requeueTickets.useMutation();
@@ -155,6 +159,10 @@ const TicketButtons = (props: TicketCardProps) => {
155159
)();
156160
};
157161

162+
if (siteSettings === undefined) {
163+
return <></>;
164+
}
165+
158166
return (
159167
<Flex justifyContent='center' flexDirection={['column', 'column', 'column', 'row']}>
160168
<Button
@@ -249,6 +257,7 @@ const TicketButtons = (props: TicketCardProps) => {
249257
onClick={handleToggleIsPublic}
250258
colorScheme='teal'
251259
hidden={
260+
siteSettings?.get(SiteSettings.ARE_PUBLIC_TICKETS_ENABLED) === SiteSettingsValues.FALSE ||
252261
isAbsent ||
253262
isResolved ||
254263
isClosed ||

src/components/ticket-page/TicketView.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useState, useEffect } from 'react';
22
import { useToast } from '@chakra-ui/react';
33
import Router, { useRouter } from 'next/router';
44
import { trpc } from '../../utils/trpc';
5-
import { TicketWithNames } from '../../server/trpc/router/ticket';
65
import { useSession } from 'next-auth/react';
76
import { UserRole } from '@prisma/client';
87
import InnerTicket from './InnerTicket';

src/server/trpc/router/ticket.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,25 @@ export const ticketRouter = router({
8282
return;
8383
}
8484

85+
const publicTicketsEnabled = await ctx.prisma.settings.findUnique({
86+
where: {
87+
setting: SiteSettings.ARE_PUBLIC_TICKETS_ENABLED,
88+
},
89+
});
90+
91+
// Ensure that public tickets are enabled if the ticket is public. This is necessary because
92+
// the client might have a stale value for the setting.
93+
const isPublic = publicTicketsEnabled?.value === SiteSettingsValues.TRUE ? input.isPublic : false;
94+
8595
// If a ticket is made with a priority assigment, it's a priority ticket
8696
const isPriority = assignment?.isPriority;
8797

8898
const ticket = await ctx.prisma.ticket.create({
8999
data: {
90100
description: input.description,
91-
isPublic: input.isPublic ?? false,
101+
isPublic: isPublic,
92102
locationDescription: input.locationDescription,
93-
usersInGroup: input.isPublic ? { connect: [{ id: ctx.session.user.id }] } : undefined,
103+
usersInGroup: isPublic ? { connect: [{ id: ctx.session.user.id }] } : undefined,
94104
isPriority: isPriority,
95105
ticketType: input.ticketType,
96106
assignment: {
@@ -122,7 +132,7 @@ export const ticketRouter = router({
122132
});
123133

124134
// Add the ticket to User.ticketsJoined if it is public
125-
if (input.isPublic) {
135+
if (isPublic) {
126136
await ctx.prisma.user.update({
127137
where: { id: ctx.session.user.id },
128138
data: {

0 commit comments

Comments
 (0)