1
1
import { BadgeCheckIcon } from "@heroicons/react/solid" ;
2
+ import { GetStaticPaths , GetStaticProps } from "next" ;
2
3
import { useRouter } from "next/router" ;
3
4
import { useState } from "react" ;
4
5
import { Controller , useForm } from "react-hook-form" ;
6
+ import { z } from "zod" ;
5
7
6
- import { DEFAULT_SCHEDULE , availabilityAsString } from "@calcom/lib/availability" ;
8
+ import { availabilityAsString , DEFAULT_SCHEDULE } from "@calcom/lib/availability" ;
7
9
import { useLocale } from "@calcom/lib/hooks/useLocale" ;
8
10
import showToast from "@calcom/lib/notification" ;
11
+ import { stringOrNumber } from "@calcom/prisma/zod-utils" ;
9
12
import { inferQueryOutput , trpc } from "@calcom/trpc/react" ;
10
13
import Button from "@calcom/ui/Button" ;
11
14
import Switch from "@calcom/ui/Switch" ;
@@ -124,15 +127,15 @@ export function AvailabilityForm(props: inferQueryOutput<"viewer.availability.sc
124
127
) ;
125
128
}
126
129
130
+ const querySchema = z . object ( {
131
+ schedule : stringOrNumber ,
132
+ } ) ;
133
+
127
134
export default function Availability ( ) {
128
135
const router = useRouter ( ) ;
129
136
const { i18n } = useLocale ( ) ;
130
- const query = trpc . useQuery ( [
131
- "viewer.availability.schedule" ,
132
- {
133
- scheduleId : parseInt ( router . query . schedule as string ) ,
134
- } ,
135
- ] ) ;
137
+ const { schedule : scheduleId } = router . isReady ? querySchema . parse ( router . query ) : { schedule : - 1 } ;
138
+ const query = trpc . useQuery ( [ "viewer.availability.schedule" , { scheduleId } ] , { enabled : router . isReady } ) ;
136
139
const [ name , setName ] = useState < string > ( ) ;
137
140
return (
138
141
< div >
@@ -158,3 +161,23 @@ export default function Availability() {
158
161
</ div >
159
162
) ;
160
163
}
164
+
165
+ export const getStaticProps : GetStaticProps = ( ctx ) => {
166
+ const params = querySchema . safeParse ( ctx . params ) ;
167
+
168
+ if ( ! params . success ) return { notFound : true } ;
169
+
170
+ return {
171
+ props : {
172
+ schedule : params . data . schedule ,
173
+ } ,
174
+ revalidate : 10 , // seconds
175
+ } ;
176
+ } ;
177
+
178
+ export const getStaticPaths : GetStaticPaths = ( ) => {
179
+ return {
180
+ paths : [ ] ,
181
+ fallback : "blocking" ,
182
+ } ;
183
+ } ;
0 commit comments