-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
800 additions
and
389 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
25 changes: 3 additions & 22 deletions
25
admin/src/pages/HomePage/components/NavigationManager/Form/hooks.ts
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 |
---|---|---|
@@ -1,29 +1,10 @@ | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { useForm } from 'react-hook-form'; | ||
import { z } from 'zod'; | ||
import { Navigation } from '../types'; | ||
|
||
const formSchema = ({ alreadyUsedNames }: { alreadyUsedNames: string[] }) => | ||
export const formSchema = ({ alreadyUsedNames }: { alreadyUsedNames: string[] }) => | ||
z.object({ | ||
name: z | ||
.string() | ||
.min(2) | ||
.and(z.string().refine((name) => !alreadyUsedNames.includes(name), 'name already used')), | ||
.min(2) // TODO: add translation | ||
.and(z.string().refine((name) => !alreadyUsedNames.includes(name), 'Name already used')), // TODO: add translation | ||
visible: z.boolean(), | ||
}); | ||
|
||
export const useNavigationForm = <T extends Partial<Navigation>>({ | ||
alreadyUsedNames, | ||
navigation: { name, visible }, | ||
}: { | ||
alreadyUsedNames: string[]; | ||
navigation: T; | ||
}) => { | ||
return useForm<z.infer<ReturnType<typeof formSchema>>>({ | ||
resolver: zodResolver(formSchema({ alreadyUsedNames })), | ||
defaultValues: { | ||
name: name ?? '', | ||
visible: visible ?? false, | ||
}, | ||
}); | ||
}; |
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
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
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
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
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
Oops, something went wrong.