Skip to content

Commit

Permalink
fix lint/type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
noxify committed Jun 13, 2024
1 parent c21170e commit 056d82e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
4 changes: 3 additions & 1 deletion apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"superjson": "2.2.1",
"zod": "3.23.8"
"zod": "3.23.8",
"react-hook-form": "7.51.5",
"@hookform/resolvers": "3.6.0"
},
"devDependencies": {
"@acme/eslint-config": "workspace:*",
Expand Down
35 changes: 21 additions & 14 deletions apps/nextjs/src/app/_components/posts.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use client"

import { use } from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"

import type { RouterOutputs } from "@acme/api"
import { CreatePostSchema } from "@acme/db/schema"
Expand All @@ -13,18 +15,19 @@ import {
FormField,
FormItem,
FormMessage,
useForm,
} from "@acme/ui/form"
import { Input } from "@acme/ui/input"
import { toast } from "@acme/ui/toast"
import { useToast } from "@acme/ui/use-toast"

import { api } from "~/trpc/react"

export function CreatePostForm() {
const t = useI18n()

const { toast } = useToast()

const form = useForm({
schema: CreatePostSchema,
resolver: zodResolver(CreatePostSchema),
defaultValues: {
content: "",
title: "",
Expand All @@ -38,11 +41,13 @@ export function CreatePostForm() {
await utils.post.invalidate()
},
onError: (err) => {
toast.error(
err.data?.code === "UNAUTHORIZED"
? t("error.not_authorized")
: t("posts.create.failed"),
)
toast({
description:
err.data?.code === "UNAUTHORIZED"
? t("error.not_authorized")
: t("posts.create.failed"),
variant: "destructive",
})
},
})

Expand Down Expand Up @@ -124,18 +129,20 @@ export function PostCard(props: {
post: RouterOutputs["post"]["all"][number]
}) {
const t = useI18n()

const { toast } = useToast()
const utils = api.useUtils()
const deletePost = api.post.delete.useMutation({
onSuccess: async () => {
await utils.post.invalidate()
},
onError: (err) => {
toast.error(
err.data?.code === "UNAUTHORIZED"
? t("error.not_authorized")
: t("posts.delete.failed"),
)
toast({
description:
err.data?.code === "UNAUTHORIZED"
? t("error.not_authorized")
: t("posts.delete.failed"),
variant: "destructive",
})
},
})

Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 056d82e

Please sign in to comment.