Skip to content

Commit 60663ee

Browse files
authored
Merge pull request #572 from trycompai/main
[comp] Production Deploy
2 parents 0f538ee + e1df926 commit 60663ee

File tree

2 files changed

+109
-10
lines changed

2 files changed

+109
-10
lines changed

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/settings/trust-portal/actions/check-dns-record.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export const checkDnsRecordAction = authActionClient
9494
Array.isArray(record.txt) &&
9595
record.txt.length > 0
9696
) {
97-
return record.txt.includes(expectedTxtValue);
97+
return record.txt.some(
98+
(txt: string) => txt === expectedTxtValue,
99+
);
98100
}
99101
return false;
100102
});
@@ -103,13 +105,19 @@ export const checkDnsRecordAction = authActionClient
103105
const isVerified = isCnameVerified && isTxtVerified;
104106

105107
if (!isVerified) {
106-
throw new Error(
107-
"Error verifying DNS records. Please ensure both CNAME and TXT records are correctly configured, or wait a few minutes and try again.",
108-
);
108+
return {
109+
success: false,
110+
isCnameVerified,
111+
isTxtVerified,
112+
error: "Error verifying DNS records. Please ensure both CNAME and TXT records are correctly configured, or wait a few minutes and try again.",
113+
};
109114
}
110115

111116
if (!env.VERCEL_PROJECT_ID) {
112-
throw new Error("Vercel project ID is not set.");
117+
return {
118+
success: false,
119+
error: "Vercel project ID is not set.",
120+
};
113121
}
114122

115123
const isExistingRecord = await vercel.projects.getProjectDomains({
@@ -157,5 +165,7 @@ export const checkDnsRecordAction = authActionClient
157165

158166
return {
159167
success: true,
168+
isCnameVerified,
169+
isTxtVerified,
160170
};
161171
});

apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/settings/trust-portal/components/TrustPortalDomain.tsx

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
AlertCircle,
3333
CheckCircle,
3434
} from "lucide-react";
35-
import React from "react";
35+
import React, { useEffect, useState } from "react";
3636
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@comp/ui/tooltip";
3737

3838
const trustPortalDomainSchema = z.object({
@@ -57,6 +57,15 @@ export function TrustPortalDomain({
5757
orgId: string;
5858
}) {
5959
const t = useI18n();
60+
const [isCnameVerified, setIsCnameVerified] = useState(false);
61+
const [isTxtVerified, setIsTxtVerified] = useState(false);
62+
63+
useEffect(() => {
64+
const isCnameVerified = localStorage.getItem(`${initialDomain}-isCnameVerified`);
65+
const isTxtVerified = localStorage.getItem(`${initialDomain}-isTxtVerified`);
66+
setIsCnameVerified(isCnameVerified === "true");
67+
setIsTxtVerified(isTxtVerified === "true");
68+
}, []);
6069

6170
const updateCustomDomain = useAction(customDomainAction, {
6271
onSuccess: (data) => {
@@ -69,7 +78,28 @@ export function TrustPortalDomain({
6978

7079
const checkDnsRecord = useAction(checkDnsRecordAction, {
7180
onSuccess: (data) => {
72-
toast.success("DNS record verified.");
81+
if (data?.data?.error) {
82+
toast.error(data.data.error);
83+
84+
if (data.data?.isCnameVerified) {
85+
setIsCnameVerified(true);
86+
localStorage.setItem(`${initialDomain}-isCnameVerified`, "true");
87+
}
88+
if (data.data?.isTxtVerified) {
89+
setIsTxtVerified(true);
90+
localStorage.setItem(`${initialDomain}-isTxtVerified`, "true");
91+
}
92+
} else {
93+
if (data.data?.isCnameVerified) {
94+
setIsCnameVerified(true);
95+
localStorage.removeItem(`${initialDomain}-isTxtVerified`);
96+
}
97+
if (data.data?.isTxtVerified) {
98+
setIsTxtVerified(true);
99+
localStorage.removeItem(`${initialDomain}-isCnameVerified`);
100+
}
101+
toast.success("DNS record verified.");
102+
}
73103
},
74104
onError: (error) => {
75105
toast.error("DNS record verification failed, check the records are valid or try again later.");
@@ -174,17 +204,25 @@ export function TrustPortalDomain({
174204
{form.watch("domain") === initialDomain && !domainVerified && (
175205
<div className="space-y-2 pt-2">
176206
<div className="rounded-md border">
177-
<div className="w-full text-sm">
178-
<table className="w-full hidden md:table">
207+
<div className="text-sm">
208+
<table className="hidden lg:table w-full">
179209
<thead>
180210
<tr className="[&_th]:px-3 [&_th]:py-2 [&_th]:text-left">
211+
<th>Verified</th>
181212
<th>Type</th>
182213
<th>Name</th>
183214
<th>Value</th>
184215
</tr>
185216
</thead>
186217
<tbody>
187218
<tr className="border-t [&_td]:px-3 [&_td]:py-2">
219+
<td>
220+
{isCnameVerified ? (
221+
<CheckCircle className="h-4 w-4 text-green-500" />
222+
) : (
223+
<AlertCircle className="h-4 w-4 text-amber-500" />
224+
)}
225+
</td>
188226
<td>CNAME</td>
189227
<td>
190228
<div className="flex items-center justify-between gap-2">
@@ -223,6 +261,13 @@ export function TrustPortalDomain({
223261
</td>
224262
</tr>
225263
<tr className="border-t [&_td]:px-3 [&_td]:py-2">
264+
<td>
265+
{isTxtVerified ? (
266+
<CheckCircle className="h-4 w-4 text-green-500" />
267+
) : (
268+
<AlertCircle className="h-4 w-4 text-amber-500" />
269+
)}
270+
</td>
226271
<td>TXT</td>
227272
<td>
228273
<div className="flex items-center justify-between gap-2">
@@ -265,7 +310,7 @@ export function TrustPortalDomain({
265310
</tbody>
266311
</table>
267312

268-
<div className="md:hidden space-y-4 p-4">
313+
<div className="lg:hidden space-y-4 p-4">
269314
<div>
270315
<div className="font-medium mb-1">Type:</div>
271316
<div>CNAME</div>
@@ -307,6 +352,50 @@ export function TrustPortalDomain({
307352
</Button>
308353
</div>
309354
</div>
355+
<div className="border-b" />
356+
<div>
357+
<div className="font-medium mb-1">Type:</div>
358+
<div>TXT</div>
359+
</div>
360+
<div>
361+
<div className="font-medium mb-1">Name:</div>
362+
<div className="flex items-center justify-between gap-2">
363+
<span className="min-w-0 break-words">
364+
@
365+
</span>
366+
<Button
367+
variant="ghost"
368+
size="icon"
369+
type="button"
370+
onClick={() => handleCopy(`compai-domain-verification=${orgId}`, "Name")}
371+
className="h-6 w-6 flex-shrink-0"
372+
>
373+
<ClipboardCopy className="h-4 w-4" />
374+
</Button>
375+
</div>
376+
</div>
377+
<div>
378+
<div className="font-medium mb-1">Value:</div>
379+
<div className="flex items-center justify-between gap-2">
380+
<span className="min-w-0 break-words">
381+
compai-domain-verification={orgId}
382+
</span>
383+
<Button
384+
variant="ghost"
385+
size="icon"
386+
type="button"
387+
onClick={() =>
388+
handleCopy(
389+
`compai-domain-verification=${orgId}`,
390+
"Value",
391+
)
392+
}
393+
className="h-6 w-6 flex-shrink-0"
394+
>
395+
<ClipboardCopy className="h-4 w-4" />
396+
</Button>
397+
</div>
398+
</div>
310399
</div>
311400
</div>
312401
</div>

0 commit comments

Comments
 (0)