@@ -1654,25 +1654,27 @@ You can test the form at [localhost:3000/admin/projects](http://localhost:3000/a
16541654And the final code of ` PageAdminProjectCreate.tsx ` file should look like this.
16551655
16561656``` tsx filename="src/features/projects/PageAdminProjectCreate.tsx" showLineNumbers
1657- import { Button , Heading } from " @chakra-ui/react" ;
1658- import { zodResolver } from " @hookform/resolvers/zod" ;
1659- import { useRouter } from " next/navigation" ;
1660- import { useForm } from " react-hook-form" ;
1657+ import { Button , Heading } from ' @chakra-ui/react' ;
1658+ import { zodResolver } from ' @hookform/resolvers/zod' ;
1659+ import { useRouter } from ' next/navigation' ;
1660+ import { useForm } from ' react-hook-form' ;
16611661
1662- import { toastCustom } from " @/components/Toast" ;
1663- import { AdminBackButton } from " @/features/admin/AdminBackButton" ;
1664- import { AdminCancelButton } from " @/features/admin/AdminCancelButton" ;
1662+ import { Form } from ' @/components/Form' ;
1663+ import { toastCustom } from ' @/components/Toast' ;
1664+ import { AdminBackButton } from ' @/features/admin/AdminBackButton' ;
1665+ import { AdminCancelButton } from ' @/features/admin/AdminCancelButton' ;
16651666import {
16661667 AdminLayoutPage ,
16671668 AdminLayoutPageContent ,
16681669 AdminLayoutPageTopBar ,
1669- } from " @/features/admin/AdminLayoutPage" ;
1670+ } from ' @/features/admin/AdminLayoutPage' ;
1671+ import { ProjectForm } from ' @/features/projects/ProjectForm' ;
16701672import {
1671- ProjectForm ,
1672- ProjectFormFields ,
1673- } from " @/features/projects/ProjectForm " ;
1674- import { trpc } from " @/lib/trpc/client" ;
1675- import { isErrorDatabaseConflict } from " @/lib/trpc/errors" ;
1673+ FormFieldsProject ,
1674+ zFormFieldsProject ,
1675+ } from ' @/features/projects/schemas ' ;
1676+ import { trpc } from ' @/lib/trpc/client' ;
1677+ import { isErrorDatabaseConflict } from ' @/lib/trpc/errors' ;
16761678
16771679export default function PageAdminProjectCreate() {
16781680 const trpcUtils = trpc .useUtils ();
@@ -1682,28 +1684,28 @@ export default function PageAdminProjectCreate() {
16821684 onSuccess : async () => {
16831685 await trpcUtils .projects .getAll .invalidate ();
16841686 toastCustom ({
1685- status: " success" ,
1686- title: " Project created with success" ,
1687+ status: ' success' ,
1688+ title: ' Project created with success' ,
16871689 });
16881690 router .back ();
16891691 },
16901692 onError : (error ) => {
1691- if (isErrorDatabaseConflict (error , " name" )) {
1692- form .setError (" name" , { message: " Name already used" });
1693+ if (isErrorDatabaseConflict (error , ' name' )) {
1694+ form .setError (' name' , { message: ' Name already used' });
16931695 return ;
16941696 }
16951697 toastCustom ({
1696- status: " error" ,
1697- title: " Failed to create the project" ,
1698+ status: ' error' ,
1699+ title: ' Failed to create the project' ,
16981700 });
16991701 },
17001702 });
17011703
17021704 const form = useForm <FormFieldsProject >({
17031705 resolver: zodResolver (zFormFieldsProject ()),
17041706 defaultValues: {
1705- name: " " ,
1706- description: " " ,
1707+ name: ' ' ,
1708+ description: ' ' ,
17071709 },
17081710 });
17091711
0 commit comments