From 2c2d05fd0a2c3c26d765f8a6beb88d907a097c1d Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 11 Feb 2024 14:54:52 +0000 Subject: refactor: Migrating to trpc instead of next's route handers --- packages/web/app/dashboard/bookmarks/components/AddLink.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'packages/web/app/dashboard/bookmarks/components/AddLink.tsx') diff --git a/packages/web/app/dashboard/bookmarks/components/AddLink.tsx b/packages/web/app/dashboard/bookmarks/components/AddLink.tsx index f99c1655..e8ecec35 100644 --- a/packages/web/app/dashboard/bookmarks/components/AddLink.tsx +++ b/packages/web/app/dashboard/bookmarks/components/AddLink.tsx @@ -3,13 +3,13 @@ import { Button } from "@/components/ui/button"; import { Form, FormControl, FormField, FormItem } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; -import APIClient from "@/lib/api"; import { Plus } from "lucide-react"; import { useRouter } from "next/navigation"; import { useForm, SubmitErrorHandler } from "react-hook-form"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { toast } from "@/components/ui/use-toast"; +import { api } from "@/lib/trpc"; const formSchema = z.object({ url: z.string().url({ message: "The link must be a valid URL" }), @@ -23,9 +23,10 @@ export default function AddLink() { }); async function onSubmit(value: z.infer) { - const [_resp, error] = await APIClient.bookmarkLink(value.url); - if (error) { - toast({ description: error.message, variant: "destructive" }); + try { + await api.bookmarks.bookmarkLink.mutate({ url: value.url, type: "link" }); + } catch (e) { + toast({ description: "Something went wrong", variant: "destructive" }); return; } router.refresh(); -- cgit v1.2.3-70-g09d2