File tree Expand file tree Collapse file tree 5 files changed +64
-6
lines changed Expand file tree Collapse file tree 5 files changed +64
-6
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ const CoolDownTimer = () => {
55
55
max = { 180 }
56
56
width = "100%"
57
57
onChange = { ( val ) => setCooldownTime ( parseInt ( val ) ) }
58
+ mr = { 1 }
58
59
>
59
60
< NumberInputField />
60
61
< NumberInputStepper >
Original file line number Diff line number Diff line change 6
6
} from "@prisma/client" ;
7
7
import { useRef } from "react" ;
8
8
import { MutableRefObject } from "react" ;
9
+ import { trpc } from "../../utils/trpc" ;
10
+ import Countdown from "../ticket-page/Countdown" ;
9
11
import CreateTicketForm from "./CreateTicketForm" ;
10
12
11
13
interface CreateTicketProps {
@@ -20,9 +22,11 @@ const CreateTicket = (props: CreateTicketProps) => {
20
22
const { siteSettings, personalQueue } = props ;
21
23
const endOfForm = useRef ( ) as MutableRefObject < HTMLSpanElement > ;
22
24
25
+ const { data : userCooldown } = trpc . ticket . getUserCooldownTime . useQuery ( ) ;
26
+
23
27
return (
24
28
< Flex width = "full" align = "left" flexDir = "column" p = { 4 } >
25
- < Text fontSize = "2xl" mb = { 5 } >
29
+ < Text fontSize = "2xl" >
26
30
Welcome back. Create a ticket to get started or{ " " }
27
31
< span
28
32
style = { { cursor : "pointer" , textDecoration : "underline" } }
@@ -32,6 +36,14 @@ const CreateTicket = (props: CreateTicketProps) => {
32
36
view the queue
33
37
</ span >
34
38
</ Text >
39
+ { userCooldown && (
40
+ < Flex >
41
+ < Text mt = "0.5" fontSize = "lg" >
42
+ Cooldown until you can make another ticket:
43
+ </ Text >
44
+ < Countdown initialTimeInMs = { userCooldown } />
45
+ </ Flex >
46
+ ) }
35
47
< CreateTicketForm
36
48
personalQueue = { personalQueue }
37
49
arePublicTicketsEnabled = {
Original file line number Diff line number Diff line change @@ -151,9 +151,12 @@ const CreateTicketForm = (props: CreateTicketFormProps) => {
151
151
} ,
152
152
} ) ;
153
153
154
- const cooldownPeriod = trpc . admin . getCoolDownTime . useQuery ( undefined , {
155
- refetchOnWindowFocus : false ,
156
- } ) . data ;
154
+ const { data : cooldownPeriod } = trpc . admin . getCoolDownTime . useQuery (
155
+ undefined ,
156
+ {
157
+ refetchOnWindowFocus : false ,
158
+ } ,
159
+ ) ;
157
160
158
161
const handleTicketTypeChange = ( newVal : TicketType ) => {
159
162
setTicketType ( newVal ) ;
@@ -266,6 +269,7 @@ const CreateTicketForm = (props: CreateTicketFormProps) => {
266
269
borderWidth = { 1 }
267
270
borderRadius = { 8 }
268
271
boxShadow = "lg"
272
+ mt = { 5 }
269
273
>
270
274
< Box my = { 4 } textAlign = "left" >
271
275
< form onSubmit = { onSubmit } >
Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ const QueueLayout = (props: QueueLayoutProps) => {
38
38
39
39
const [ isQueueOpen , setIsQueueOpen ] = useState < boolean > ( ) ;
40
40
const [ isPendingStageEnabled , setIsPendingStageEnabled ] = useState < boolean > ( ) ;
41
- const [ arePublicTicketsEnabled , setArePublicTicketsEnabled ] = useState < boolean > ( ) ;
41
+ const [ arePublicTicketsEnabled , setArePublicTicketsEnabled ] =
42
+ useState < boolean > ( ) ;
42
43
const changeUserRoleMutation = trpc . user . updateUserRole . useMutation ( ) ;
43
44
const { siteSettings } = useSiteSettings ( ) ;
44
45
@@ -95,7 +96,11 @@ const QueueLayout = (props: QueueLayoutProps) => {
95
96
}
96
97
} ) ;
97
98
98
- if ( isQueueOpen === undefined || isPendingStageEnabled === undefined || arePublicTicketsEnabled === undefined ) {
99
+ if (
100
+ isQueueOpen === undefined ||
101
+ isPendingStageEnabled === undefined ||
102
+ arePublicTicketsEnabled === undefined
103
+ ) {
99
104
return < Spinner /> ;
100
105
}
101
106
Original file line number Diff line number Diff line change @@ -736,6 +736,42 @@ export const ticketRouter = router({
736
736
return ticketsWithNames [ 0 ] ;
737
737
} ) ,
738
738
739
+ getUserCooldownTime : protectedProcedure . query ( async ( { ctx } ) => {
740
+ // If there is a cooldown timer and the user is a student, return how long the student
741
+ // has to wait before making another ticket. The wait time is returned in milliseconds and is
742
+ // calculated by (lastTicketResolvedAt + cooldownTime) - Date.now()
743
+ if ( ctx . session . user . role !== UserRole . STUDENT ) {
744
+ return null ;
745
+ }
746
+
747
+ const cooldownTimeResult = await ctx . prisma . variableSettings . findUnique ( {
748
+ where : { setting : VariableSiteSettings . COOLDOWN_TIME } ,
749
+ } ) ;
750
+
751
+ const cooldownTime = parseInt ( cooldownTimeResult ?. value ?? "0" ) ;
752
+
753
+ if ( ! cooldownTime ) {
754
+ return null ;
755
+ }
756
+
757
+ const lastTicket = await ctx . prisma . ticket . findFirst ( {
758
+ where : {
759
+ createdByUserId : ctx . session . user . id ,
760
+ resolvedAt : {
761
+ gte : new Date ( Date . now ( ) - cooldownTime * 60 * 1000 ) ,
762
+ } ,
763
+ } ,
764
+ } ) ;
765
+
766
+ if ( ! lastTicket || ! lastTicket . resolvedAt ) {
767
+ return null ;
768
+ }
769
+
770
+ return (
771
+ lastTicket . resolvedAt . getTime ( ) + cooldownTime * 60 * 1000 - Date . now ( )
772
+ ) ;
773
+ } ) ,
774
+
739
775
getTicketsWithStatus : protectedProcedure
740
776
. input (
741
777
z . object ( {
You can’t perform that action at this time.
0 commit comments