Skip to content

Commit 4b7dff5

Browse files
authored
feat: update tutorial to new toasts (#57)
1 parent 7a09b32 commit 4b7dff5

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

pages/tutorials/create-your-first-crud.mdx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,8 +1578,8 @@ export default function PageAdminProjectCreate() {
15781578

15791579
Let's improve the UX of the form.
15801580

1581-
```tsx {1-2, 10-11, 16-18, 21-29, 43, 46, 50} filename="src/features/projects/PageAdminProjectCreate.tsx" showLineNumbers
1582-
import { useToastError, useToastSuccess } from "@/components/Toast";
1581+
```tsx {1-2, 13-16, 19-28, 42, 45, 49} filename="src/features/projects/PageAdminProjectCreate.tsx" showLineNumbers
1582+
import { toastCustom } from "@/components/Toast";
15831583
import { isErrorDatabaseConflict } from "@/lib/trpc/errors";
15841584

15851585
/* ... */
@@ -1588,13 +1588,11 @@ export default function PageAdminProjectCreate() {
15881588
const trpcUtils = trpc.useUtils();
15891589
const router = useRouter();
15901590

1591-
const toastError = useToastError();
1592-
const toastSuccess = useToastSuccess();
1593-
15941591
const createProject = trpc.projects.create.useMutation({
15951592
onSuccess: async () => {
15961593
await trpcUtils.projects.getAll.invalidate();
1597-
toastSuccess({
1594+
toastCustom({
1595+
status: 'success',
15981596
title: "Project created with success",
15991597
});
16001598
router.back();
@@ -1604,7 +1602,8 @@ export default function PageAdminProjectCreate() {
16041602
form.setError("name", { message: "Name already used" });
16051603
return;
16061604
}
1607-
toastError({
1605+
toastCustom({
1606+
status: 'error',
16081607
title: "Failed to create the project",
16091608
});
16101609
},
@@ -1660,7 +1659,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
16601659
import { useRouter } from "next/navigation";
16611660
import { useForm } from "react-hook-form";
16621661

1663-
import { useToastError, useToastSuccess } from "@/components/Toast";
1662+
import { toastCustom } from "@/components/Toast";
16641663
import { AdminBackButton } from "@/features/admin/AdminBackButton";
16651664
import { AdminCancelButton } from "@/features/admin/AdminCancelButton";
16661665
import {
@@ -1679,13 +1678,11 @@ export default function PageAdminProjectCreate() {
16791678
const trpcUtils = trpc.useUtils();
16801679
const router = useRouter();
16811680

1682-
const toastError = useToastError();
1683-
const toastSuccess = useToastSuccess();
1684-
16851681
const createProject = trpc.projects.create.useMutation({
16861682
onSuccess: async () => {
16871683
await trpcUtils.projects.getAll.invalidate();
1688-
toastSuccess({
1684+
toastCustom({
1685+
status: "success",
16891686
title: "Project created with success",
16901687
});
16911688
router.back();
@@ -1695,7 +1692,8 @@ export default function PageAdminProjectCreate() {
16951692
form.setError("name", { message: "Name already used" });
16961693
return;
16971694
}
1698-
toastError({
1695+
toastCustom({
1696+
status: "error",
16991697
title: "Failed to create the project",
17001698
});
17011699
},
@@ -2027,7 +2025,7 @@ import { useForm } from "react-hook-form";
20272025
import { ErrorPage } from "@/components/ErrorPage";
20282026
import { Form } from "@/components/Form";
20292027
import { LoaderFull } from "@/components/LoaderFull";
2030-
import { useToastError, useToastSuccess } from "@/components/Toast";
2028+
import { toastCustom } from "@/components/Toast";
20312029
import { AdminBackButton } from "@/features/admin/AdminBackButton";
20322030
import { AdminCancelButton } from "@/features/admin/AdminCancelButton";
20332031
import {
@@ -2059,13 +2057,11 @@ export default function PageAdminProjectUpdate() {
20592057

20602058
const isReady = !project.isFetching;
20612059

2062-
const toastSuccess = useToastSuccess();
2063-
const toastError = useToastError();
2064-
20652060
const updateProject = trpc.projects.updateById.useMutation({
20662061
onSuccess: async () => {
20672062
await trpcUtils.projects.invalidate();
2068-
toastSuccess({
2063+
toastCustom({
2064+
status: "success",
20692065
title: "Updated with success",
20702066
});
20712067
router.back();
@@ -2075,7 +2071,8 @@ export default function PageAdminProjectUpdate() {
20752071
form.setError("name", { message: "Name already used" });
20762072
return;
20772073
}
2078-
toastError({
2074+
toastCustom({
2075+
status: "error",
20792076
title: "Update failed",
20802077
});
20812078
},
@@ -2272,7 +2269,7 @@ Now, let's implement the delete button with a confirm modal in the `PageAdminPro
22722269
**`useRouter` is imported from `next/navigation`** and not `next/router`
22732270
</Callout>
22742271

2275-
```tsx {3, 6-9, 13-15, 20-31, 38, 46-65} filename="src/features/projects/PageAdminProject.tsx" showLineNumbers
2272+
```tsx {3, 6-9, 13-14, 19-31, 38, 46-65} filename="src/features/projects/PageAdminProject.tsx" showLineNumbers
22762273
import {
22772274
/* ... */
22782275
IconButton,
@@ -2281,13 +2278,12 @@ import {
22812278
import { /* ... */, useRouter } from "next/navigation";
22822279
import { /* ... */, LuTrash2 } from "react-icons/lu";
22832280
import { ConfirmModal } from "@/components/ConfirmModal";
2284-
import { useToastError } from "@/components/Toast";
2281+
import { toastCustom } from "@/components/Toast";
22852282
/* ... */
22862283

22872284
export default function PageAdminProject() {
22882285
const router = useRouter();
22892286
const trpcUtils = trpc.useUtils();
2290-
const toastError = useToastError();
22912287

22922288
const params = /* ... */;
22932289
const project = /* ... */;
@@ -2298,7 +2294,8 @@ export default function PageAdminProject() {
22982294
router.replace(ROUTES_PROJECTS.admin.root());
22992295
},
23002296
onError: () => {
2301-
toastError({
2297+
toastCustom({
2298+
status: "error",
23022299
title: "Deletion failed",
23032300
description: "Failed to delete the project",
23042301
});

0 commit comments

Comments
 (0)