diff --git a/.changeset/fresh-panthers-drive.md b/.changeset/fresh-panthers-drive.md new file mode 100644 index 0000000..3ec476a --- /dev/null +++ b/.changeset/fresh-panthers-drive.md @@ -0,0 +1,5 @@ +--- +'x-boilerplate': patch +--- + +moved resend query to `#/state` diff --git a/src/app/(marketing)/resend/page.tsx b/src/app/(marketing)/resend/page.tsx index dd87c93..ce1460a 100644 --- a/src/app/(marketing)/resend/page.tsx +++ b/src/app/(marketing)/resend/page.tsx @@ -13,7 +13,7 @@ import * as z from 'zod'; import { sendEmailSchema } from '@/utils/validations/send-email'; import Header from '@/components/header'; -import { useResendEmail } from '@/hooks/services/resend/email/use-resend-email.hook'; +import { useResendEmailMutation } from '#/state/queries/resend'; type FormValues = z.infer; @@ -29,7 +29,7 @@ function ResendPage() { resolver: zodResolver(sendEmailSchema), }); - const { mutate: handleResendEmail, isPending } = useResendEmail({ + const { mutate: handleResendEmail, isPending } = useResendEmailMutation({ onSuccess: (_data) => { toast.success('Congratulations, you have successfully sent an email.'); reset(); diff --git a/src/app/api/resend/email/route.ts b/src/app/api/resend/email/route.ts index 5a1e4ab..348f019 100644 --- a/src/app/api/resend/email/route.ts +++ b/src/app/api/resend/email/route.ts @@ -4,14 +4,14 @@ import InviteEmail from '~/app/(marketing)/resend/InviteEmail'; import { Resend } from 'resend'; -import { emailSchema } from '@/hooks/services/resend/email/email.schema'; +import { zSendEmailParams } from '#/state/queries/resend'; const resend = new Resend(process.env.RESEND_API_KEY); export async function POST(req: Request) { try { const json = await req.json(); - const emailContent = emailSchema.parse(json); + const emailContent = zSendEmailParams().parse(json); const { data } = await resend.emails.send({ from: process.env.RESEND_DOMAIN, diff --git a/src/hooks/services/resend/email/email.schema.ts b/src/hooks/services/resend/email/email.schema.ts deleted file mode 100644 index c95de05..0000000 --- a/src/hooks/services/resend/email/email.schema.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { z } from 'zod'; - -export const emailSchema = z.object({ - emailTo: z.string().email(), - subject: z.string(), - inviteLink: z.string(), - invitedByUsername: z.string().optional(), -}); - -export const emailPayload = z.object({ - id: z.string().min(1), -}); - -export const zEmail = () => emailSchema; -export type Email = z.infer>; - -export const zEmailPayload = () => emailPayload; -export type EmailPayload = z.infer>; diff --git a/src/hooks/services/resend/email/use-resend-email.hook.ts b/src/state/queries/resend/index.ts similarity index 65% rename from src/hooks/services/resend/email/use-resend-email.hook.ts rename to src/state/queries/resend/index.ts index 59a5bf3..16574c5 100644 --- a/src/hooks/services/resend/email/use-resend-email.hook.ts +++ b/src/state/queries/resend/index.ts @@ -1,8 +1,10 @@ import { useMutation, UseMutationOptions } from '@tanstack/react-query'; -import { Email, EmailPayload, zEmailPayload } from './email.schema'; +import { Email, EmailPayload, zEmailPayload } from './schema'; -export const useResendEmail = (config: UseMutationOptions = {}) => { +export * from '#/state/queries/resend/schema'; + +export const useResendEmailMutation = (config: UseMutationOptions = {}) => { return useMutation({ mutationFn: async ({ emailTo, subject, inviteLink }) => { const response = await fetch('/api/resend/email', { @@ -18,8 +20,5 @@ export const useResendEmail = (config: UseMutationOptions { - config?.onSuccess?.(data, ...args); - }, }); }; diff --git a/src/state/queries/resend/schema.ts b/src/state/queries/resend/schema.ts new file mode 100644 index 0000000..0691637 --- /dev/null +++ b/src/state/queries/resend/schema.ts @@ -0,0 +1,19 @@ +import { z } from 'zod'; + +export const zSendEmailParams = () => + z.object({ + emailTo: z.string().email(), + subject: z.string(), + inviteLink: z.string(), + invitedByUsername: z.string().optional(), + }); +export type SendEmailParams = z.infer>; + +export const zEmail = () => zSendEmailParams(); +export type Email = z.infer>; + +export const zEmailPayload = () => + z.object({ + id: z.string().min(1), + }); +export type EmailPayload = z.infer>;