Add verify domain button (#22)
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Domain" ADD COLUMN "isVerifying" BOOLEAN NOT NULL DEFAULT false;
|
@@ -115,6 +115,7 @@ model Domain {
|
|||||||
dmarcAdded Boolean @default(false)
|
dmarcAdded Boolean @default(false)
|
||||||
errorMessage String?
|
errorMessage String?
|
||||||
subdomain String?
|
subdomain String?
|
||||||
|
isVerifying Boolean @default(false)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||||
|
@@ -24,15 +24,35 @@ import React from "react";
|
|||||||
import { Switch } from "@unsend/ui/src/switch";
|
import { Switch } from "@unsend/ui/src/switch";
|
||||||
import DeleteDomain from "./delete-domain";
|
import DeleteDomain from "./delete-domain";
|
||||||
import SendTestMail from "./send-test-mail";
|
import SendTestMail from "./send-test-mail";
|
||||||
|
import { Button } from "@unsend/ui/src/button";
|
||||||
|
|
||||||
export default function DomainItemPage({
|
export default function DomainItemPage({
|
||||||
params,
|
params,
|
||||||
}: {
|
}: {
|
||||||
params: { domainId: string };
|
params: { domainId: string };
|
||||||
}) {
|
}) {
|
||||||
const domainQuery = api.domain.getDomain.useQuery({
|
const domainQuery = api.domain.getDomain.useQuery(
|
||||||
id: Number(params.domainId),
|
{
|
||||||
});
|
id: Number(params.domainId),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
refetchInterval: (q) => (q?.state.data?.isVerifying ? 10000 : false),
|
||||||
|
refetchIntervalInBackground: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const verifyQuery = api.domain.startVerification.useMutation();
|
||||||
|
|
||||||
|
const handleVerify = () => {
|
||||||
|
verifyQuery.mutate(
|
||||||
|
{ id: Number(params.domainId) },
|
||||||
|
{
|
||||||
|
onSettled: () => {
|
||||||
|
domainQuery.refetch();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -67,9 +87,24 @@ export default function DomainItemPage({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{domainQuery.data ? (
|
<div className="flex gap-4">
|
||||||
<SendTestMail domain={domainQuery.data} />
|
<div>
|
||||||
) : null}
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleVerify}
|
||||||
|
disabled={domainQuery.data?.isVerifying}
|
||||||
|
>
|
||||||
|
{domainQuery.data?.isVerifying
|
||||||
|
? "Verifying..."
|
||||||
|
: domainQuery.data?.status === DomainStatus.SUCCESS
|
||||||
|
? "Verify again"
|
||||||
|
: "Verify domain"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{domainQuery.data ? (
|
||||||
|
<SendTestMail domain={domainQuery.data} />
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className=" border rounded-lg p-4">
|
<div className=" border rounded-lg p-4">
|
||||||
@@ -155,9 +190,14 @@ export default function DomainItemPage({
|
|||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell className="">TXT</TableCell>
|
<TableCell className="">TXT</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<TextWithCopyButton
|
<div className="flex gap-2 items-center">
|
||||||
value={`_dmarc.${domainQuery.data?.subdomain || domainQuery.data?.name}`}
|
<span className="text-sm text-muted-foreground">
|
||||||
/>
|
(optional)
|
||||||
|
</span>
|
||||||
|
<TextWithCopyButton
|
||||||
|
value={`_dmarc.${domainQuery.data?.subdomain || domainQuery.data?.name}`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="">
|
<TableCell className="">
|
||||||
<TextWithCopyButton
|
<TextWithCopyButton
|
||||||
|
@@ -16,6 +16,7 @@ import {
|
|||||||
import { api } from "~/trpc/react";
|
import { api } from "~/trpc/react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Plus } from "lucide-react";
|
import { Plus } from "lucide-react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
export default function AddDomain() {
|
export default function AddDomain() {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
@@ -23,6 +24,7 @@ export default function AddDomain() {
|
|||||||
const addDomainMutation = api.domain.createDomain.useMutation();
|
const addDomainMutation = api.domain.createDomain.useMutation();
|
||||||
|
|
||||||
const utils = api.useUtils();
|
const utils = api.useUtils();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
function handleSave() {
|
function handleSave() {
|
||||||
addDomainMutation.mutate(
|
addDomainMutation.mutate(
|
||||||
@@ -30,8 +32,9 @@ export default function AddDomain() {
|
|||||||
name: domainName,
|
name: domainName,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: async (data) => {
|
||||||
utils.domain.domains.invalidate();
|
utils.domain.domains.invalidate();
|
||||||
|
await router.push(`/domains/${data.id}`);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,15 @@ export const domainRouter = createTRPCRouter({
|
|||||||
return createDomain(ctx.team.id, input.name);
|
return createDomain(ctx.team.id, input.name);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
startVerification: teamProcedure
|
||||||
|
.input(z.object({ id: z.number() }))
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
await ctx.db.domain.update({
|
||||||
|
where: { id: input.id },
|
||||||
|
data: { isVerifying: true },
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
domains: teamProcedure.query(async ({ ctx }) => {
|
domains: teamProcedure.query(async ({ ctx }) => {
|
||||||
const domains = await db.domain.findMany({
|
const domains = await db.domain.findMany({
|
||||||
where: {
|
where: {
|
||||||
|
@@ -33,7 +33,7 @@ export async function getDomain(id: number) {
|
|||||||
throw new Error("Domain not found");
|
throw new Error("Domain not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (domain.status !== "SUCCESS") {
|
if (domain.isVerifying) {
|
||||||
const domainIdentity = await ses.getDomainIdentity(
|
const domainIdentity = await ses.getDomainIdentity(
|
||||||
domain.name,
|
domain.name,
|
||||||
domain.region
|
domain.region
|
||||||
@@ -48,27 +48,23 @@ export async function getDomain(id: number) {
|
|||||||
const _dmarcRecord = await getDmarcRecord(domain.name);
|
const _dmarcRecord = await getDmarcRecord(domain.name);
|
||||||
const dmarcRecord = _dmarcRecord?.[0]?.[0];
|
const dmarcRecord = _dmarcRecord?.[0]?.[0];
|
||||||
|
|
||||||
console.log(domainIdentity);
|
domain = await db.domain.update({
|
||||||
console.log(dmarcRecord);
|
where: {
|
||||||
|
id,
|
||||||
if (
|
},
|
||||||
domain.dkimStatus !== dkimStatus ||
|
data: {
|
||||||
domain.spfDetails !== spfDetails ||
|
dkimStatus,
|
||||||
domain.status !== verificationStatus ||
|
spfDetails,
|
||||||
domain.dmarcAdded !== (dmarcRecord ? true : false)
|
status: verificationStatus ?? "NOT_STARTED",
|
||||||
) {
|
dmarcAdded: dmarcRecord ? true : false,
|
||||||
domain = await db.domain.update({
|
isVerifying:
|
||||||
where: {
|
verificationStatus === "SUCCESS" &&
|
||||||
id,
|
dkimStatus === "SUCCESS" &&
|
||||||
},
|
spfDetails === "SUCCESS"
|
||||||
data: {
|
? false
|
||||||
dkimStatus,
|
: true,
|
||||||
spfDetails,
|
},
|
||||||
status: verificationStatus ?? "NOT_STARTED",
|
});
|
||||||
dmarcAdded: dmarcRecord ? true : false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...domain,
|
...domain,
|
||||||
|
Reference in New Issue
Block a user