@@ -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" ;
3636import { Tooltip , TooltipContent , TooltipProvider , TooltipTrigger } from "@comp/ui/tooltip" ;
3737
3838const 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