Skip to content

Commit

Permalink
Update create-your-first-crud.mdx
Browse files Browse the repository at this point in the history
Dans cette étape de fin : https://docs.web.start-ui.com/tutorials/create-your-first-crud#result-1
Le code final mentionné ne correspond pas à celui qu'on obtient si on suit les étapes une à une, de plus copier/coller ce code à la place de celui qu'on compose soi-même en suivant le tuto crée des erreurs sur beaucoup de variables.
J'ai donc corrigé juste le final code avec celui que j'ai obtenu en suivant le tuto pas à pas
  • Loading branch information
Duriel7 authored Dec 27, 2024
1 parent ddfb2e8 commit 1e1960e
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions pages/tutorials/create-your-first-crud.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1654,25 +1654,27 @@ You can test the form at [localhost:3000/admin/projects](http://localhost:3000/a
And the final code of `PageAdminProjectCreate.tsx` file should look like this.

```tsx filename="src/features/projects/PageAdminProjectCreate.tsx" showLineNumbers
import { Button, Heading } from "@chakra-ui/react";
import { zodResolver } from "@hookform/resolvers/zod";
import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { Button, Heading } from '@chakra-ui/react';
import { zodResolver } from '@hookform/resolvers/zod';
import { useRouter } from 'next/navigation';
import { useForm } from 'react-hook-form';

import { toastCustom } from "@/components/Toast";
import { AdminBackButton } from "@/features/admin/AdminBackButton";
import { AdminCancelButton } from "@/features/admin/AdminCancelButton";
import { Form } from '@/components/Form';
import { toastCustom } from '@/components/Toast';
import { AdminBackButton } from '@/features/admin/AdminBackButton';
import { AdminCancelButton } from '@/features/admin/AdminCancelButton';
import {
AdminLayoutPage,
AdminLayoutPageContent,
AdminLayoutPageTopBar,
} from "@/features/admin/AdminLayoutPage";
} from '@/features/admin/AdminLayoutPage';
import { ProjectForm } from '@/features/projects/ProjectForm';
import {
ProjectForm,
ProjectFormFields,
} from "@/features/projects/ProjectForm";
import { trpc } from "@/lib/trpc/client";
import { isErrorDatabaseConflict } from "@/lib/trpc/errors";
FormFieldsProject,
zFormFieldsProject,
} from '@/features/projects/schemas';
import { trpc } from '@/lib/trpc/client';
import { isErrorDatabaseConflict } from '@/lib/trpc/errors';

export default function PageAdminProjectCreate() {
const trpcUtils = trpc.useUtils();
Expand All @@ -1682,28 +1684,28 @@ export default function PageAdminProjectCreate() {
onSuccess: async () => {
await trpcUtils.projects.getAll.invalidate();
toastCustom({
status: "success",
title: "Project created with success",
status: 'success',
title: 'Project created with success',
});
router.back();
},
onError: (error) => {
if (isErrorDatabaseConflict(error, "name")) {
form.setError("name", { message: "Name already used" });
if (isErrorDatabaseConflict(error, 'name')) {
form.setError('name', { message: 'Name already used' });
return;
}
toastCustom({
status: "error",
title: "Failed to create the project",
status: 'error',
title: 'Failed to create the project',
});
},
});

const form = useForm<FormFieldsProject>({
resolver: zodResolver(zFormFieldsProject()),
defaultValues: {
name: "",
description: "",
name: '',
description: '',
},
});

Expand Down

0 comments on commit 1e1960e

Please sign in to comment.