Skip to content

Email for professionals and teams

improve domain card

Hieu Nguyen (Jack)833ed824aee0
diff --git a/src/app/(admin)/domains/DomainDnsDetails.tsx b/src/app/(admin)/domains/DomainDnsDetails.tsx
index bb1d66f..730dad5 100644
--- a/src/app/(admin)/domains/DomainDnsDetails.tsx
+++ b/src/app/(admin)/domains/DomainDnsDetails.tsx
@@ -1,7 +1,6 @@
import { AlertTriangle, Check } from "lucide-react";
import { Button } from "@/components/ui/button";
-import { getDnsRecordLabel } from "./domain-dns-details-utils";
-import { dnsAuthRecords, getDnsAuthItemClass, getDnsAuthStatusLabel } from "./utils";
+import { dnsAuthDescriptions, dnsAuthRecords, getDnsAuthItemClass, getDnsAuthStatusLabel } from "./utils";
import type { DomainDnsDetailsProps } from "./types";
export default function DomainDnsDetails({
@@ -22,119 +21,113 @@ export default function DomainDnsDetails({
? "Email sending is configured"
: "Email sending is not configured"
: "Sending has not configured for this domain";
+ const routingOk = dns.routing.missing.length === 0 && (dns.routing.records.length > 0 || domain.routingEnabled);
+ const routingLabel = routingOk
+ ? "Email routing is configured"
+ : dns.routing.missing.length > 0
+ ? `${dns.routing.missing.length} DNS record${dns.routing.missing.length === 1 ? "" : "s"} missing`
+ : "No routing DNS records found";
return (
- <div className="border-t border-neutral-100 pt-5">
+ <div className="px-4 pb-4 pt-4 sm:px-5 sm:pb-5">
{audit && (
- <section className="space-y-3">
- <h2 className="text-sm font-medium text-neutral-900">Authentication</h2>
- <ul className="space-y-2">
- {dnsAuthRecords.map((record) => {
- const item = audit[record];
- const ok = item.status === "ok";
- const statusStr = getDnsAuthStatusLabel(item.status);
-
- return (
- <li
- key={record}
- className={`flex items-start gap-2 rounded-xl px-3 py-2 text-sm ${getDnsAuthItemClass(item.status)}`}
- >
- {ok ? (
- <Check className="mt-0.5 h-4 w-4 shrink-0 text-green-600" />
- ) : (
- <AlertTriangle
- className={`mt-0.5 h-4 w-4 shrink-0 ${item.status === "missing" ? "text-red-600" : "text-neutral-400"}`}
- />
- )}
- <span className="min-w-0 flex-1">
- <span className="font-medium">{item.label}</span>{" "}
- <span className="break-all">{item.name}</span>{" "}
-
- {item.found.length > 0 ? (
- <span className="block break-all text-xs opacity-80">
- {item.found.join(", ")}
- </span>
- ) : !ok && <span className="block break-all text-xs opacity-80 capitalize">{statusStr}</span>}
- </span>
-
- {ok ? <span className="capitalize">{statusStr}</span> : (
- <Button
- variant="outline"
- size="sm"
- className="shrink-0"
- disabled={manual || setupRecord === record}
- title={
- manual
- ? "DNS for this domain is managed manually"
- : `Create the ${item.label} record`
- }
- onClick={() => onSetup?.(record)}
- >
- {setupRecord === record ? "Setting up..." : "Setup"}
- </Button>
- )}
- </li>
- );
- })}
- </ul>
- {manual && (
- <p className="text-xs text-neutral-500">
- DNS is managed manually for this domain, so records must be created
- where the domain&apos;s nameservers are hosted.
- </p>
- )}
- {setupMessage && <p className="text-xs text-red-600">{setupMessage}</p>}
- </section>
- )}
-
- <section className={audit ? "space-y-3 mt-8" : "space-y-3"}>
- <h2 className="text-sm font-medium text-neutral-900">Email Routing</h2>
- <ul className="space-y-2">
- {dns.routing.records.map((record, index) => (
- <li
- key={`routing-${record.type}-${record.name}-${index}`}
- className="flex items-start gap-2 rounded-xl bg-green-50 px-3 py-2 text-sm text-green-800"
- >
- <Check className="mt-0.5 h-4 w-4 shrink-0 text-green-600" />
- <span className="break-all">{getDnsRecordLabel(record)}</span>
- </li>
- ))}
- {dns.routing.missing.map((record, index) => (
- <li
- key={`missing-${record.type}-${record.name}-${index}`}
- className="flex items-start gap-2 rounded-xl bg-red-50 px-3 py-2 text-sm text-red-800"
- >
- <AlertTriangle className="mt-0.5 h-4 w-4 shrink-0 text-red-600" />
- <span className="break-all">{getDnsRecordLabel(record)}</span>
- </li>
- ))}
- {dns.routing.records.length === 0 && dns.routing.missing.length === 0 && (
- <li className={`flex items-center gap-2 rounded-xl px-3 py-2 text-sm ${domain.routingEnabled ? "bg-green-50 text-green-800" : "bg-red-50 text-red-800"}`}>
- {domain.routingEnabled ? (
- <Check className="h-4 w-4 shrink-0 text-green-600" />
- ) : (
- <AlertTriangle className="h-4 w-4 shrink-0 text-red-600" />
- )}
- {domain.routingEnabled ? "Email routing is configured" : "No routing DNS records found"}
- </li>
- )}
- </ul>
- </section>
+ <section>
+ <h2 className="text-base font-semibold text-neutral-900">Domain setup</h2>
+ <p className="mt-0.5 text-sm text-neutral-500">
+ Review routing, sending, and DNS authentication for reliable email delivery.
+ </p>
+ <ul className="mt-3 space-y-2">
+ <li
+ className={`grid gap-3 rounded-xl px-4 py-3 text-sm sm:grid-cols-[auto_minmax(8rem,14rem)_minmax(0,1fr)_auto] sm:items-start ${routingOk ? "bg-green-50 text-green-800" : "bg-red-50 text-red-800"}`}
+ >
+ {routingOk ? (
+ <span className="flex h-7 w-7 items-center justify-center rounded-full bg-green-600 text-white">
+ <Check className="h-4 w-4" />
+ </span>
+ ) : (
+ <span className="flex h-7 w-7 items-center justify-center rounded-full bg-white/70">
+ <AlertTriangle className="h-4 w-4 text-red-600" />
+ </span>
+ )}
+ <span className="min-w-0">
+ <span className="block font-medium text-neutral-900">Email Routing</span>
+ <span className="block text-xs text-neutral-500">Routes incoming email to Mailflare</span>
+ </span>
+ <span className="min-w-0 break-all text-neutral-500">{routingLabel}</span>
+ </li>
- <section className="space-y-3 mt-8">
- <h2 className="text-sm font-medium text-neutral-900">Email Sending</h2>
- <ul className="space-y-2">
<li
- className={`flex items-center gap-2 rounded-xl px-3 py-2 text-sm ${sendingOk ? "bg-green-50 text-green-800" : "bg-red-50 text-red-800"}`}
+ className={`grid gap-3 rounded-xl px-4 py-3 text-sm sm:grid-cols-[auto_minmax(8rem,14rem)_minmax(0,1fr)_auto] sm:items-start ${sendingOk ? "bg-green-50 text-green-800" : "bg-red-50 text-red-800"}`}
>
{sendingOk ? (
- <Check className="h-4 w-4 shrink-0 text-green-600" />
+ <span className="flex h-7 w-7 items-center justify-center rounded-full bg-green-600 text-white">
+ <Check className="h-4 w-4" />
+ </span>
) : (
- <AlertTriangle className="h-4 w-4 shrink-0 text-red-600" />
+ <span className="flex h-7 w-7 items-center justify-center rounded-full bg-white/70">
+ <AlertTriangle className="h-4 w-4 text-red-600" />
+ </span>
)}
- {sendingLabel}
+ <span className="min-w-0">
+ <span className="block font-medium text-neutral-900">Email Sending</span>
+ <span className="block text-xs text-neutral-500">Sends outgoing email from this domain</span>
+ </span>
+ <span className="min-w-0 break-all text-neutral-500">{sendingLabel}</span>
</li>
+
+ {dnsAuthRecords.map((record) => {
+ const item = audit[record];
+ const ok = item.status === "ok";
+
+ return (
+ <li
+ key={record}
+ className={`grid gap-3 rounded-xl px-4 py-3 text-sm sm:grid-cols-[auto_minmax(8rem,14rem)_minmax(0,1fr)_auto] sm:items-start ${getDnsAuthItemClass(item.status)}`}
+ >
+ {ok ? (
+ <span className="flex h-7 w-7 items-center justify-center rounded-full bg-green-600 text-white">
+ <Check className="h-4 w-4" />
+ </span>
+ ) : (
+ <span className="flex h-7 w-7 items-center justify-center rounded-full bg-white/70">
+ <AlertTriangle className={`h-4 w-4 ${item.status === "missing" ? "text-red-600" : "text-neutral-400"}`} />
+ </span>
+ )}
+ <span className="min-w-0">
+ <span className="block font-medium text-neutral-900">{item.label} record</span>
+ <span className="block text-xs text-neutral-500">{dnsAuthDescriptions[record]}</span>
+ </span>
+
+ {ok ? <span className="min-w-0 break-all text-neutral-500">
+ {item.found.length > 0 ? item.found.join(", ") : item.name}
+ </span> : (
+ <Button
+ variant="outline"
+ size="sm"
+ className="shrink-0 bg-white"
+ disabled={manual || setupRecord === record}
+ title={
+ manual
+ ? "DNS for this domain is managed manually"
+ : `Create the ${item.label} record`
+ }
+ onClick={() => onSetup?.(record)}
+ >
+ {setupRecord === record ? "Setting up..." : "Setup"}
+ </Button>
+ )}
+ </li>
+ );
+ })}
</ul>
+ {manual && (
+ <p className="text-xs text-neutral-500">
+ DNS is managed manually for this domain, so records must be created
+ where the domain&apos;s nameservers are hosted.
+ </p>
+ )}
+ {setupMessage && <p className="text-xs text-red-600">{setupMessage}</p>}
</section>
+ )}
</div>
);
}
diff --git a/src/app/(admin)/domains/DomainDnsSkeleton.tsx b/src/app/(admin)/domains/DomainDnsSkeleton.tsx
index ec33ccd..e67c6e3 100644
--- a/src/app/(admin)/domains/DomainDnsSkeleton.tsx
+++ b/src/app/(admin)/domains/DomainDnsSkeleton.tsx
@@ -2,11 +2,12 @@ import { Skeleton } from "@/components/ui/skeleton";
export default function DomainDnsSkeleton() {
return (
- <div className="space-y-3 border-t border-neutral-100 pt-5">
+ <div className="space-y-3 px-4 pb-4 pt-4 sm:px-5 sm:pb-5">
<Skeleton className="h-4 w-28" />
+ <Skeleton className="h-3 w-96 max-w-full" />
<div className="space-y-2">
{Array.from({ length: 4 }, (_, index) => (
- <Skeleton key={index} className="h-9 w-full rounded-xl" />
+ <Skeleton key={index} className="h-16 w-full rounded-xl" />
))}
</div>
</div>
diff --git a/src/app/(admin)/domains/DomainItemCard.tsx b/src/app/(admin)/domains/DomainItemCard.tsx
index 4456aee..b8b36a7 100644
--- a/src/app/(admin)/domains/DomainItemCard.tsx
+++ b/src/app/(admin)/domains/DomainItemCard.tsx
@@ -1,4 +1,5 @@
import { Fragment } from "react";
+import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { ListRow } from "@/components/ui/list";
@@ -12,6 +13,7 @@ import {
ChevronDown,
ChevronRight,
Globe2,
+ MoreVertical,
Trash2,
} from "lucide-react";
import type { DomainItemCardProps } from "./types";
@@ -124,23 +126,42 @@ export default function DomainItemCard({
setupMessage={setupMessage}
/>
) : dnsError ? (
- <div className="border-t border-neutral-100 pt-5 text-sm text-red-600">
+ <div className="px-4 pb-4 pt-4 text-sm text-red-600 sm:px-5 sm:pb-5">
{dnsError}
</div>
) : dnsLoading ? (
<DomainDnsSkeleton />
) : null)}
- <Button
- variant="destructive"
- size="sm"
- className="absolute right-4 top-4 opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100"
- onClick={() => remove.mutate(item.id)}
- disabled={remove.isPending}
- aria-label={`Remove ${item.hostname}`}
- >
- <Trash2 className="h-4 w-4" />
- </Button>
+ <DropdownMenu.Root>
+ <DropdownMenu.Trigger asChild>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="absolute right-4 top-4 h-8 w-8 p-0"
+ disabled={remove.isPending}
+ aria-label={`Actions for ${item.hostname}`}
+ >
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenu.Trigger>
+ <DropdownMenu.Portal>
+ <DropdownMenu.Content
+ align="end"
+ sideOffset={6}
+ className="z-50 min-w-40 rounded-lg border border-neutral-200 bg-white p-1 text-sm shadow-lg"
+ >
+ <DropdownMenu.Item
+ disabled={remove.isPending}
+ onSelect={() => remove.mutate(item.id)}
+ className="flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-red-600 outline-none hover:bg-red-50 focus:bg-red-50 data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
+ >
+ <Trash2 className="h-4 w-4" />
+ Remove domain
+ </DropdownMenu.Item>
+ </DropdownMenu.Content>
+ </DropdownMenu.Portal>
+ </DropdownMenu.Root>
</ListRow>
);
}
diff --git a/src/app/(admin)/domains/page.tsx b/src/app/(admin)/domains/page.tsx
index c0206c4..9a9425d 100644
--- a/src/app/(admin)/domains/page.tsx
+++ b/src/app/(admin)/domains/page.tsx
@@ -17,7 +17,7 @@ import { Switch } from "@/components/ui/switch";
import { List } from "@/components/ui/list";
import { CheckCircle2, LoaderCircle, Plus } from "lucide-react";
import { authFetch } from "@/lib/auth/client";
-import type { DnsAuthRecord, DnsStatusSummary, Domain, DomainDnsView, DomainPreflight } from "./types";
+import type { DnsAuthRecord, DnsStatusSummary, Domain, DomainDnsCache, DomainDnsView, DomainPreflight } from "./types";
import DomainItemCard from "./DomainItemCard";
import { SectionRowSkeleton } from "@/components/page-skeletons";
import { checkDomain } from "./utils";
@@ -42,10 +42,7 @@ export default function DomainsPage() {
const expandedIdRef = useRef<string | null>(null);
const [dnsLoading, setDnsLoading] = useState(false);
const [dnsError, setDnsError] = useState<string | null>(null);
- const [dnsView, setDnsView] = useState<{
- domain: Domain;
- dns: DomainDnsView;
- } | null>(null);
+ const [dnsViews, setDnsViews] = useState<DomainDnsCache>({});
const { data, isLoading } = useQuery({
queryKey: ["domains"],
@@ -116,17 +113,15 @@ export default function DomainsPage() {
if (!res.ok || !json.domain || !json.dns) {
throw new Error(json.error ?? "Failed to load DNS");
}
- // Ignore a response that arrives after the user expanded another domain.
- if (expandedIdRef.current !== id) return;
- setDnsView({ domain: json.domain, dns: json.dns });
- setSetupMessage(null);
+ const loadedView = { domain: json.domain, dns: json.dns };
+ setDnsViews((current) => ({ ...current, [id]: loadedView }));
+ if (expandedIdRef.current === id) setSetupMessage(null);
};
const toggleDns = async (id: string) => {
if (expandedDomainId === id) {
expandedIdRef.current = null;
setExpandedDomainId(null);
- setDnsView(null);
setSetupMessage(null);
setDnsLoading(false);
setDnsError(null);
@@ -136,9 +131,12 @@ export default function DomainsPage() {
// than leaving the card unchanged until the request resolves.
expandedIdRef.current = id;
setExpandedDomainId(id);
- setDnsView(null);
setSetupMessage(null);
setDnsError(null);
+ if (dnsViews[id]) {
+ setDnsLoading(false);
+ return;
+ }
setDnsLoading(true);
try {
await loadDns(id);
@@ -152,6 +150,8 @@ export default function DomainsPage() {
};
const setupDns = async (record: DnsAuthRecord) => {
+ if (!expandedDomainId) return;
+ const dnsView = dnsViews[expandedDomainId];
if (!dnsView) return;
setSetupRecord(record);
setSetupMessage(null);
@@ -167,8 +167,13 @@ export default function DomainsPage() {
error?: string;
};
if (!res.ok) throw new Error(json.error ?? "Failed to set up DNS record");
- if (json.domain && json.dns) setDnsView({ domain: json.domain, dns: json.dns });
- else await loadDns(dnsView.domain.id);
+ if (json.domain && json.dns) {
+ const updatedView = { domain: json.domain, dns: json.dns };
+ setDnsViews((current) => ({
+ ...current,
+ [dnsView.domain.id]: updatedView,
+ }));
+ } else await loadDns(dnsView.domain.id);
qc.invalidateQueries({ queryKey: ["domains"] });
} catch (error) {
setSetupMessage(error instanceof Error ? error.message : "Failed to set up DNS record");
@@ -323,7 +328,7 @@ export default function DomainsPage() {
<DomainItemCard
key={d.id}
dns={dns}
- dnsDetails={dnsView?.domain.id === d.id ? dnsView.dns : undefined}
+ dnsDetails={dnsViews[d.id]?.dns}
dnsLoading={expandedDomainId === d.id && dnsLoading}
dnsError={expandedDomainId === d.id ? dnsError : null}
expanded={expandedDomainId === d.id}
diff --git a/src/app/(admin)/domains/types.d.ts b/src/app/(admin)/domains/types.d.ts
index 8aa8d2e..6b7c964 100644
--- a/src/app/(admin)/domains/types.d.ts
+++ b/src/app/(admin)/domains/types.d.ts
@@ -59,6 +59,8 @@ export type DomainDnsView = {
audit?: DomainDnsAudit;
};
+export type DomainDnsCache = Record<string, { domain: Domain; dns: DomainDnsView }>;
+
export type DomainDnsDetailsProps = {
domain: Domain;
dns: DomainDnsView;
diff --git a/src/app/(admin)/domains/utils.ts b/src/app/(admin)/domains/utils.ts
index 123ec33..9510e0c 100644
--- a/src/app/(admin)/domains/utils.ts
+++ b/src/app/(admin)/domains/utils.ts
@@ -3,6 +3,13 @@ import type { DnsAuthRecord, DnsAuthStatus, DomainPreflightResponse } from "./ty
export const dnsAuthRecords: DnsAuthRecord[] = ["mx", "spf", "dkim", "dmarc"];
+export const dnsAuthDescriptions: Record<DnsAuthRecord, string> = {
+ mx: "Routes incoming email to Mailflare",
+ spf: "Authorizes Mailflare to send email",
+ dkim: "Signs outgoing email for deliverability",
+ dmarc: "Helps prevent email spoofing",
+};
+
export function getDnsAuthStatusLabel(status: DnsAuthStatus): string {
switch (status) {
case "ok":