aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web/app/dashboard/bookmarks/components/AddLink.tsx
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-02-16 20:33:00 +0000
committerMohamedBassem <me@mbassem.com>2024-02-16 20:33:00 +0000
commit6febe13b3f4ad4eff3f205ece445b3577255bf41 (patch)
tree776e5dd7337ce21eaf6f4b7efc71cd587c21bf9d /packages/web/app/dashboard/bookmarks/components/AddLink.tsx
parente4f4270790936db81364bab057d3cdb4bbdaa31e (diff)
downloadkarakeep-6febe13b3f4ad4eff3f205ece445b3577255bf41.tar.zst
Migrating to react query for client side queries
Diffstat (limited to 'packages/web/app/dashboard/bookmarks/components/AddLink.tsx')
-rw-r--r--packages/web/app/dashboard/bookmarks/components/AddLink.tsx26
1 files changed, 15 insertions, 11 deletions
diff --git a/packages/web/app/dashboard/bookmarks/components/AddLink.tsx b/packages/web/app/dashboard/bookmarks/components/AddLink.tsx
index e8ecec35..34f043e7 100644
--- a/packages/web/app/dashboard/bookmarks/components/AddLink.tsx
+++ b/packages/web/app/dashboard/bookmarks/components/AddLink.tsx
@@ -17,21 +17,19 @@ const formSchema = z.object({
export default function AddLink() {
const router = useRouter();
+ const bookmarkLinkMutator = api.bookmarks.bookmarkLink.useMutation({
+ onSuccess: () => {
+ router.refresh();
+ },
+ onError: () => {
+ toast({ description: "Something went wrong", variant: "destructive" });
+ },
+ });
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
});
- async function onSubmit(value: z.infer<typeof formSchema>) {
- try {
- await api.bookmarks.bookmarkLink.mutate({ url: value.url, type: "link" });
- } catch (e) {
- toast({ description: "Something went wrong", variant: "destructive" });
- return;
- }
- router.refresh();
- }
-
const onError: SubmitErrorHandler<z.infer<typeof formSchema>> = (errors) => {
toast({
description: Object.values(errors)
@@ -43,7 +41,13 @@ export default function AddLink() {
return (
<Form {...form}>
- <form onSubmit={form.handleSubmit(onSubmit, onError)}>
+ <form
+ onSubmit={form.handleSubmit(
+ (value) =>
+ bookmarkLinkMutator.mutate({ url: value.url, type: "link" }),
+ onError,
+ )}
+ >
<div className="container flex w-full items-center space-x-2 py-4">
<FormField
control={form.control}