({
currentCommunity,
api,
dnsSettings,
}: {
currentCommunity: SerializedAccount;
api: ApiClient;
dnsSettings(mounted: boolean): void;
})
| 380 | } |
| 381 | |
| 382 | function DomainStatus({ |
| 383 | currentCommunity, |
| 384 | api, |
| 385 | dnsSettings, |
| 386 | }: { |
| 387 | currentCommunity: SerializedAccount; |
| 388 | api: ApiClient; |
| 389 | dnsSettings(mounted: boolean): void; |
| 390 | }) { |
| 391 | const [statusText, setStatusText] = useState<string>( |
| 392 | getDefaultDomainStatus(currentCommunity) |
| 393 | ); |
| 394 | const [statusColor, setStatusColor] = useState<'green' | 'red'>( |
| 395 | currentCommunity.redirectDomainPropagate ? 'green' : 'red' |
| 396 | ); |
| 397 | const [loading, setLoading] = useState(false); |
| 398 | |
| 399 | const validateDomain = async () => { |
| 400 | const form = document.getElementById('branding-form') as HTMLFormElement; |
| 401 | if (!form) { |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | try { |
| 406 | setLoading(true); |
| 407 | const domain = stripProtocol(form.redirectDomain.value).toLowerCase(); |
| 408 | |
| 409 | if (domain !== currentCommunity.redirectDomain) { |
| 410 | await api.updateAccount({ |
| 411 | accountId: currentCommunity.id, |
| 412 | redirectDomain: domain, |
| 413 | }); |
| 414 | dnsSettings(true); |
| 415 | currentCommunity.redirectDomain = domain; |
| 416 | } |
| 417 | |
| 418 | const result = await api.validateDomain({ |
| 419 | domain, |
| 420 | accountId: currentCommunity.id, |
| 421 | }); |
| 422 | |
| 423 | if (result.ok) { |
| 424 | setStatusColor('green'); |
| 425 | setStatusText('Custom domain is working.'); |
| 426 | } else { |
| 427 | setStatusColor('red'); |
| 428 | setStatusText(result.cause || 'Invalid, try again later.'); |
| 429 | } |
| 430 | } catch (error: any) { |
| 431 | setStatusColor('red'); |
| 432 | setStatusText(error.details || 'Something went wrong.'); |
| 433 | } finally { |
| 434 | setLoading(false); |
| 435 | } |
| 436 | }; |
| 437 | |
| 438 | return ( |
| 439 | <div className={styles.domainValidationWrapper}> |
nothing calls this directly
no test coverage detected