From 4bb38b9f43cf495cf08ec6d95466e1b8cea409ce Mon Sep 17 00:00:00 2001 From: Nana Kofi Larbi Mantey Date: Mon, 28 Oct 2024 09:22:57 +0000 Subject: [PATCH] fix: incorrect domain verification records --- .../dashboard/src/pages/settings/identity.tsx | 555 +++++++++--------- 1 file changed, 279 insertions(+), 276 deletions(-) diff --git a/packages/dashboard/src/pages/settings/identity.tsx b/packages/dashboard/src/pages/settings/identity.tsx index f15aef3..ddae40f 100644 --- a/packages/dashboard/src/pages/settings/identity.tsx +++ b/packages/dashboard/src/pages/settings/identity.tsx @@ -12,305 +12,308 @@ import { useActiveProject, useActiveProjectVerifiedIdentity, useProjects } from import { network } from "../../lib/network"; interface EmailValues { - email: string; + email: string; } interface FromValues { - from: string; + from: string; } /** * */ export default function Index() { - const activeProject = useActiveProject(); - const { mutate: projectsMutate } = useProjects(); - const { data: identity, mutate: identityMutate } = useActiveProjectVerifiedIdentity(); + const activeProject = useActiveProject(); + const { mutate: projectsMutate } = useProjects(); + const { data: identity, mutate: identityMutate } = useActiveProjectVerifiedIdentity(); - const { - register, - handleSubmit, - formState: { errors }, - } = useForm({ - resolver: zodResolver(IdentitySchemas.create.omit({ id: true })), - }); + const { + register, + handleSubmit, + formState: { errors }, + } = useForm({ + resolver: zodResolver(IdentitySchemas.create.omit({ id: true })), + }); - const { - register: registerUpdate, - handleSubmit: handleSubmitUpdate, - formState: { errors: errorsUpdate }, - reset, - } = useForm({ - resolver: zodResolver(IdentitySchemas.update.omit({ id: true })), - }); + const { + register: registerUpdate, + handleSubmit: handleSubmitUpdate, + formState: { errors: errorsUpdate }, + reset, + } = useForm({ + resolver: zodResolver(IdentitySchemas.update.omit({ id: true })), + }); - useEffect(() => { - if (!activeProject) { - return; - } + useEffect(() => { + if (!activeProject) { + return; + } - reset({ from: activeProject.from ?? undefined }); - }, [reset, activeProject]); + reset({ from: activeProject.from ?? undefined }); + }, [reset, activeProject]); - if (!activeProject || !identity) { - return ; - } + if (!activeProject || !identity) { + return ; + } - const create = async (data: EmailValues) => { - toast.promise( - network.fetch< - { - success: true; - tokens: string[]; - }, - typeof IdentitySchemas.create - >("POST", "/identities/create", { - id: activeProject.id, - ...data, - }), - { - loading: "Adding your domain", - success: (res) => { - void identityMutate({ tokens: res.tokens }, { revalidate: false }); - void projectsMutate(); + const create = async (data: EmailValues) => { + toast.promise( + network.fetch< + { + success: true; + tokens: string[]; + }, + typeof IdentitySchemas.create + >("POST", "/identities/create", { + id: activeProject.id, + ...data, + }), + { + loading: "Adding your domain", + success: (res) => { + void identityMutate({ tokens: res.tokens }, { revalidate: false }); + void projectsMutate(); - return "Added your domain"; - }, - error: "Could not add domain", - }, - ); - }; + return "Added your domain"; + }, + error: "Could not add domain", + }, + ); + }; - const update = async (data: FromValues) => { - toast.promise( - network.fetch< - { - success: true; - }, - typeof IdentitySchemas.update - >("PUT", "/projects/update/identity", { - id: activeProject.id, - ...data, - }), - { - loading: "Updating your sender name", - success: "Updated your sender name", - error: "Could not update sender name", - }, - ); + const update = async (data: FromValues) => { + toast.promise( + network.fetch< + { + success: true; + }, + typeof IdentitySchemas.update + >("PUT", "/projects/update/identity", { + id: activeProject.id, + ...data, + }), + { + loading: "Updating your sender name", + success: "Updated your sender name", + error: "Could not update sender name", + }, + ); - await identityMutate(); - await projectsMutate(); - }; + await identityMutate(); + await projectsMutate(); + }; - const unlink = async () => { - toast.promise( - network.fetch< - { - success: true; - }, - typeof UtilitySchemas.id - >("POST", "/identities/reset", { - id: activeProject.id, - }), - { - loading: "Unlinking your domain", - success: "Unlinked your domain", - error: "Could not unlink domain", - }, - ); + const unlink = async () => { + toast.promise( + network.fetch< + { + success: true; + }, + typeof UtilitySchemas.id + >("POST", "/identities/reset", { + id: activeProject.id, + }), + { + loading: "Unlinking your domain", + success: "Unlinked your domain", + error: "Could not unlink domain", + }, + ); - window.location.reload(); - }; + window.location.reload(); + }; - return ( - <> - - + const domain = activeProject.email?.split("@")[1] ?? ""; + const subdomain = domain.split(".").length > 2 ? domain.split(".")[0] : ""; - - - - ) - } - > - {activeProject.email && !activeProject.verified ? ( - <> - - Please add the following records to {activeProject.email.split("@")[1]} to verify {activeProject.email}, this - may take up to 15 minutes to register.
- In the meantime you can already start sending emails, we will automatically switch to your domain once it is - verified. -
+ return ( + <> + + -
- TXT, - Key: ( -
{ - void navigator.clipboard.writeText("plunk"); - toast.success("Copied key to clipboard"); - }} - > -

plunk

- -
- ), - Value: ( -
{ - void navigator.clipboard.writeText("v=spf1 include:amazonses.com ~all"); - toast.success("Copied value to clipboard"); - }} - > -

v=spf1 include:amazonses.com ~all

-
- ), - }, - { - type: MX, - Key: ( -
{ - void navigator.clipboard.writeText("plunk"); - toast.success("Copied key to clipboard"); - }} - > -

plunk

- -
- ), - Value: ( -
{ - void navigator.clipboard.writeText(`10 feedback-smtp.${AWS_REGION}.amazonses.com`); - toast.success("Copied value to clipboard"); - }} - > -

10 feedback-smtp.{AWS_REGION}.amazonses.com

- -
- ), - }, - ...identity.tokens.map((token) => { - return { - Type: CNAME, - Key: ( -
{ - void navigator.clipboard.writeText(`${token}._domainkey`); - toast.success("Copied key to clipboard"); - }} - > -

{token}._domainkey

- -
- ), - Value: ( -
{ - void navigator.clipboard.writeText(`${token}.dkim.amazonses.com`); - toast.success("Copied value to clipboard"); - }} - > -

{token}.dkim.amazonses.com

- -
- ), - }; - }), - ]} - /> - - - ) : activeProject.email && activeProject.verified ? ( - <> - - You have confirmed {activeProject.email} as your domain. Any emails sent by Plunk will now use this address. - - - ) : ( - <> - - - - - - - - Verify domain - - - - )} - + + + + ) + } + > + {activeProject.email && !activeProject.verified ? ( + <> + + Please add the following records to {activeProject.email.split("@")[1]} to verify {activeProject.email}, this + may take up to 15 minutes to register.
+ In the meantime you can already start sending emails, we will automatically switch to your domain once it is + verified. +
- -
- +
+
TXT, + Key: ( +
{ + void navigator.clipboard.writeText("plunk"); + toast.success("Copied key to clipboard"); + }} + > +

plunk

+ +
+ ), + Value: ( +
{ + void navigator.clipboard.writeText("v=spf1 include:amazonses.com ~all"); + toast.success("Copied value to clipboard"); + }} + > +

v=spf1 include:amazonses.com ~all

+
+ ), + }, + { + type: MX, + Key: ( +
{ + void navigator.clipboard.writeText("plunk"); + toast.success("Copied key to clipboard"); + }} + > +

plunk

+ +
+ ), + Value: ( +
{ + void navigator.clipboard.writeText(`10 feedback-smtp.${AWS_REGION}.amazonses.com`); + toast.success("Copied value to clipboard"); + }} + > +

10 feedback-smtp.{AWS_REGION}.amazonses.com

+ +
+ ), + }, + ...identity.tokens.map((token) => { + return { + Type: CNAME, + Key: ( +
{ + void navigator.clipboard.writeText(`${token}._domainkey${subdomain ? '.' + subdomain : ''}`); + toast.success("Copied key to clipboard"); + }} + > +

{token}._domainkey{subdomain ? '.' + subdomain : ''}

+ +
+ ), + Value: ( +
{ + void navigator.clipboard.writeText(`${token}.dkim.amazonses.com`); + toast.success("Copied value to clipboard"); + }} + > +

{token}.dkim.amazonses.com

+ +
+ ), + }; + }), + ]} + /> + + + ) : activeProject.email && activeProject.verified ? ( + <> + + You have confirmed {activeProject.email} as your domain. Any emails sent by Plunk will now use this address. + + + ) : ( + <> + + + + + + + + Verify domain + + + + )} + - - Save - - - - - - ); + +
+ + + + Save + + +
+ + + ); }