API data types rework

This commit is contained in:
aronmal 2023-04-25 22:27:03 +02:00
parent 207cf47c10
commit 4af85bb572
Signed by: aronmal
GPG key ID: 816B7707426FC612
16 changed files with 342 additions and 245 deletions

View file

@ -5,7 +5,7 @@ import { faEye, faLeftLong } from "@fortawesome/pro-regular-svg-icons"
import { faPlus, faUserPlus } from "@fortawesome/pro-solid-svg-icons"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import useGameState from "@lib/hooks/useGameState"
import { CreateSchema } from "@lib/zodSchemas"
import { GamePropsSchema } from "@lib/zodSchemas"
import status from "http-status"
import { GetServerSideProps } from "next"
import { useRouter } from "next/router"
@ -16,6 +16,7 @@ import { toast } from "react-toastify"
interface Props {
q: string | string[] | undefined
}
function isInputOnlyNumbers(input: string) {
return /^\d+$/.test(input)
}
@ -32,7 +33,6 @@ export function isAuthenticated(res: Response) {
type: "error",
theme: "colored",
})
return Promise.reject()
}
const handleConfirmation = () => {
@ -48,7 +48,7 @@ const handleConfirmation = () => {
)
}
export default function Home({ q }: Props) {
export default function Start({ q }: Props) {
const [otp, setOtp] = useState("")
const { gameProps, setGameProps } = useGameState()
const router = useRouter()
@ -61,7 +61,7 @@ export default function Home({ q }: Props) {
body: JSON.stringify({ pin }),
})
.then(isAuthenticated)
.then((game) => CreateSchema.parse(game))
.then((game) => GamePropsSchema.parse(game))
const res = await toast.promise(gamePromise, {
pending: {
@ -170,5 +170,5 @@ export const getServerSideProps: GetServerSideProps<Props> = async (
) => {
const { q } = context.query
return { props: { q: q ? q : "" } }
return { props: { q } }
}