mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Work on brewery page, refactors
Refactor query types to explicitly use z.infer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
|
||||
import useSWR from 'swr';
|
||||
import { beerPostQueryResultArraySchema } from '@/services/BeerPost/schema/BeerPostQueryResult';
|
||||
import { z } from 'zod';
|
||||
|
||||
const useBeerPostSearch = (query: string | undefined) => {
|
||||
const { data, isLoading, error } = useSWR(
|
||||
@@ -13,7 +14,7 @@ const useBeerPostSearch = (query: string | undefined) => {
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
const result = beerPostQueryResultArraySchema.parse(json);
|
||||
const result = z.array(beerPostQueryResult).parse(json);
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
import UserContext from '@/contexts/userContext';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useContext, useEffect } from 'react';
|
||||
import { useContext } from 'react';
|
||||
|
||||
const useRedirectWhenLoggedIn = () => {
|
||||
const { user } = useContext(UserContext);
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
router.push('/');
|
||||
}, [user, router]);
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
export default useRedirectWhenLoggedIn;
|
||||
|
||||
Reference in New Issue
Block a user