Skip to content

Commit

Permalink
bug fixed + ui fix + improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel31x13 committed Dec 5, 2023
1 parent 54d0073 commit 51cd832
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
16 changes: 12 additions & 4 deletions src/@/components/BookmarkForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ const BookmarkForm = () => {
return;
},
onError: (error) => {
if ((error as AxiosError)?.response?.status === 401) {
if (error as AxiosError) {
toast({
title: 'Error',
description: 'You are not logged in. Please try again.',
description:
(error as any).response.data.response ||
'There was an error while trying to save the link. Please try again.',
variant: 'destructive',
});
} else {
Expand Down Expand Up @@ -278,7 +280,7 @@ const BookmarkForm = () => {
</PopoverTrigger>
<PopoverContent
className={`min-w-full p-0 overflow-y-auto ${
!openOptions ? 'max-h-[100px]' : ''
!openOptions ? 'max-h-[100px]' : 'max-h-[200px]'
}`}
>
<Command className="flex-grow min-w-full dropdown-content">
Expand All @@ -304,12 +306,18 @@ const BookmarkForm = () => {
</CommandItem>
) : (
collections.response?.map(
(collection: { name: string; id: number }) => (
(collection: {
name: string;
id: number;
ownerId: number;
}) => (
<CommandItem
value={collection.name}
key={collection.id}
onSelect={() => {
form.setValue('collection', {
ownerId: collection.ownerId,
id: collection.id,
name: collection.name,
});
setOpenCollections(false);
Expand Down
16 changes: 11 additions & 5 deletions src/@/lib/validators/bookmarkForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import { z } from 'zod';
export const bookmarkFormSchema = z.object({
url: z.string().url('This has to be a URL'),
collection: z.object({
name: z.string(),
}),
tags: z.array(z.object({
id: z.number().optional(),
ownerId: z.number().optional(),
name: z.string(),
})).nullish(),
}),
tags: z
.array(
z.object({
id: z.number().optional(),
name: z.string(),
})
)
.nullish(),
name: z.string(),
description: z.string(),
});

export type bookmarkFormValues = z.infer<typeof bookmarkFormSchema>
export type bookmarkFormValues = z.infer<typeof bookmarkFormSchema>;

0 comments on commit 51cd832

Please sign in to comment.