Skip to content

Commit

Permalink
fix: show error if user tries to add same manga
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Oct 13, 2022
1 parent 216b926 commit cc2d6dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/addManga/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function AddMangaForm({ onClose }: { onClose: () => void }) {
form.setFieldValue('query', '');
form.setFieldValue('mangaOrder', -1);
form.setFieldValue('mangaTitle', '');
form.setFieldValue('interval', '');
}
if (active === 3) {
form.setFieldValue('interval', '');
Expand All @@ -117,7 +118,7 @@ export function AddMangaForm({ onClose }: { onClose: () => void }) {
title: 'Manga',
message: (
<Text>
Failed to create add manga. <Code color="red">{`${err}`}</Code>
<Code color="red">{`${err}`}</Code>
</Text>
),
});
Expand Down
6 changes: 5 additions & 1 deletion src/server/trpc/router/manga.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
import { getAvailableSources, getMangaDetail, search } from '../../../utils/mangal';
import { t } from '../trpc';
Expand Down Expand Up @@ -71,7 +72,10 @@ export const mangaRouter = t.router({
},
});
if (result) {
return result;
throw new TRPCError({
code: 'CONFLICT',
message: `${title} already exists in the library.`,
});
}

return ctx.prisma.manga.create({
Expand Down

0 comments on commit cc2d6dd

Please sign in to comment.