-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adds mode and status filter to test screen Closes #89
- Loading branch information
Showing
3 changed files
with
149 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
libs/react/containers/src/tests/test-search/test-search-config-schema.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useEffect } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { z } from "zod"; | ||
import { createUsePersistenceHook } from "../../hooks/use-persistence"; | ||
import type { QuestionBankName } from "@chair-flight/base/types"; | ||
import type { UseFormReturn } from "react-hook-form"; | ||
|
||
const searchConfigSchema = z.object({ | ||
mode: z.enum(["all", "study", "exam"]), | ||
status: z.enum(["all", "created", "started", "finished"]), | ||
}); | ||
|
||
type SearchConfig = z.infer<typeof searchConfigSchema>; | ||
|
||
const defaultSearchConfig: z.infer<typeof searchConfigSchema> = { | ||
mode: "all", | ||
status: "all", | ||
}; | ||
|
||
const searchPersistence = { | ||
"cf-test-search-atpl": createUsePersistenceHook<SearchConfig>( | ||
"cf-test-search-atpl", | ||
), | ||
"cf-test-search-type": createUsePersistenceHook<SearchConfig>( | ||
"cf-test-search-type", | ||
), | ||
"cf-test-search-prep": createUsePersistenceHook<SearchConfig>( | ||
"cf-test-search-prep", | ||
), | ||
}; | ||
|
||
const resolver = zodResolver(searchConfigSchema); | ||
|
||
export const useSearchConfig = ( | ||
questionBank: QuestionBankName, | ||
): [SearchConfig, UseFormReturn<SearchConfig>] => { | ||
const key = `cf-test-search-${questionBank}` as const; | ||
const useSearchPersistence = searchPersistence[key]; | ||
const { persistedData, setPersistedData } = useSearchPersistence(); | ||
const defaultValues = persistedData ?? defaultSearchConfig; | ||
const form = useForm({ defaultValues, resolver }); | ||
const mode = form.watch("mode"); | ||
const status = form.watch("status"); | ||
|
||
useEffect(() => { | ||
setPersistedData({ mode, status }); | ||
}, [mode, status, setPersistedData]); | ||
|
||
return [{ mode, status }, form]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d5691de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
chair-flight – ./
chair-flight.vercel.app
chair-flight-git-main-chair-flight-team.vercel.app
chair-flight-chair-flight-team.vercel.app
www.chair-flight.com
chair-flight.com