Replug custom domain setting

Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
Émile Ré
2025-12-29 11:23:59 +01:00
committed by Bryan Frimin
parent 278411392d
commit 6a97be5d8e
18 changed files with 1085 additions and 566 deletions

View File

@@ -1,160 +0,0 @@
import { useTranslate } from "@probo/i18n";
import { graphql } from "react-relay";
import {
Button,
Dialog,
DialogContent,
DialogFooter,
Field,
useDialogRef,
Breadcrumb,
} from "@probo/ui";
import { z } from "zod";
import { useFormWithSchema } from "/hooks/useFormWithSchema";
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
import type { ReactNode } from "react";
import type { CreateCustomDomainDialogMutation } from "./__generated__/CreateCustomDomainDialogMutation.graphql";
const createCustomDomainMutation = graphql`
mutation CreateCustomDomainDialogMutation($input: CreateCustomDomainInput!) {
createCustomDomain(input: $input) {
customDomain {
id
domain
sslStatus
dnsRecords {
type
name
value
ttl
purpose
}
createdAt
updatedAt
sslExpiresAt
}
}
}
`;
const schema = z.object({
domain: z
.string()
.min(1, "Domain is required")
.regex(
/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/i,
"Please enter a valid domain (e.g., compliance.example.com)"
),
});
type FormData = z.infer<typeof schema>;
interface CreateCustomDomainDialogProps {
children: ReactNode;
organizationId: string;
}
export function CreateCustomDomainDialog({
children,
organizationId,
}: CreateCustomDomainDialogProps) {
const { __ } = useTranslate();
const dialogRef = useDialogRef();
const { register, handleSubmit, formState, reset } = useFormWithSchema(
schema,
{
defaultValues: {
domain: "",
},
}
);
const [createCustomDomain, isCreating] =
useMutationWithToasts<CreateCustomDomainDialogMutation>(
createCustomDomainMutation,
{
successMessage: __(
"Domain added successfully. Configure the DNS records to verify and activate your domain."
),
errorMessage: __("Failed to add domain"),
}
);
const onSubmit = handleSubmit(async (data: FormData) => {
const normalizedDomain = data.domain
.trim()
.toLowerCase()
.replace(/^https?:\/\//, "")
.replace(/\/$/, "");
await createCustomDomain({
variables: {
input: {
organizationId,
domain: normalizedDomain,
},
},
updater: (store, data) => {
// Update the cache by setting the new customDomain on the organization
const organizationRecord = store.get(organizationId);
if (organizationRecord && data?.createCustomDomain?.customDomain) {
const customDomainRecord = store.get(
data.createCustomDomain.customDomain.id
);
if (customDomainRecord) {
organizationRecord.setLinkedRecord(
customDomainRecord,
"customDomain"
);
}
}
},
onSuccess: () => {
reset();
dialogRef.current?.close();
},
});
});
return (
<Dialog
ref={dialogRef}
trigger={children}
title={<Breadcrumb items={[__("Custom Domain"), __("Add Domain")]} />}
>
<form onSubmit={onSubmit}>
<DialogContent padded className="space-y-4">
<div>
<p className="text-sm text-txt-secondary mb-4">
{__(
"Enter your domain and we'll generate the DNS records you need to add"
)}
</p>
</div>
<Field
{...register("domain")}
label={__("Domain")}
type="text"
placeholder="compliance.example.com"
error={formState.errors.domain?.message}
autoFocus
/>
<div className="bg-subtle rounded-lg p-4">
<p className="text-xs text-txt-secondary">
<strong>{__("Examples:")}</strong> compliance.example.com,
trust.example.com
</p>
</div>
</DialogContent>
<DialogFooter>
<Button type="submit" disabled={isCreating || !formState.isValid}>
{isCreating ? __("Adding...") : __("Add Domain")}
</Button>
</DialogFooter>
</form>
</Dialog>
);
}

View File

@@ -1,155 +0,0 @@
import { useTranslate } from "@probo/i18n";
import { Button, Card, Badge, IconPlusLarge } from "@probo/ui";
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
import { graphql } from "relay-runtime";
import type { CustomDomainManagerDeleteMutation } from "./__generated__/CustomDomainManagerDeleteMutation.graphql";
import { CreateCustomDomainDialog } from "./CreateCustomDomainDialog";
import { DeleteCustomDomainDialog } from "./DeleteCustomDomainDialog";
import { DomainDetailsDialog } from "./DomainDetailsDialog";
import { PermissionsContext } from "/providers/PermissionsContext";
import { use } from "react";
const deleteCustomDomainMutation = graphql`
mutation CustomDomainManagerDeleteMutation($input: DeleteCustomDomainInput!) {
deleteCustomDomain(input: $input) {
deletedCustomDomainId
}
}
`;
type CustomDomain = {
readonly id: string;
readonly domain: string;
readonly sslStatus: string;
readonly dnsRecords?:
| readonly {
readonly type: string;
readonly name: string;
readonly value: string;
readonly ttl?: number;
readonly purpose: string;
}[]
| null;
readonly createdAt?: string | null;
readonly updatedAt?: string | null;
readonly sslExpiresAt?: string | null;
};
interface CustomDomainManagerProps {
organizationId: string;
customDomain: CustomDomain | null | undefined;
}
export function CustomDomainManager({
organizationId,
customDomain,
}: CustomDomainManagerProps) {
const { __ } = useTranslate();
const { isAuthorized } = use(PermissionsContext);
const [deleteCustomDomain] =
useMutationWithToasts<CustomDomainManagerDeleteMutation>(
deleteCustomDomainMutation,
{
successMessage: __("Domain deleted successfully"),
errorMessage: __("Failed to delete domain"),
}
);
const domain = customDomain;
const getStatusBadge = (domain: CustomDomain) => {
if (domain.sslStatus === "ACTIVE") {
return <Badge variant="success">{__("Active")}</Badge>;
}
if (
domain.sslStatus === "PROVISIONING" ||
domain.sslStatus === "RENEWING"
) {
return <Badge variant="warning">{__("Provisioning")}</Badge>;
}
if (domain.sslStatus === "PENDING") {
return <Badge variant="warning">{__("Pending")}</Badge>;
}
if (domain.sslStatus === "FAILED") {
return <Badge variant="danger">{__("Failed")}</Badge>;
}
if (domain.sslStatus === "EXPIRED") {
return <Badge variant="danger">{__("Expired")}</Badge>;
}
return <Badge variant="neutral">{__("Unknown")}</Badge>;
};
const handleDeleteDomain = async () => {
return deleteCustomDomain({
variables: {
input: { organizationId },
},
updater: (store) => {
// Update the cache by setting customDomain to null
const organizationRecord = store.get(organizationId);
if (organizationRecord) {
organizationRecord.setValue(null, "customDomain");
}
},
});
};
if (!domain) {
return (
<Card padded>
<div className="text-center py-8">
<h3 className="text-lg font-semibold mb-2">
{__("No custom domain configured")}
</h3>
<p className="text-txt-tertiary mb-4">
{__(
"Add your own domain to make your trust center more professional"
)}
</p>
<div className="flex justify-center">
{isAuthorized("Organization", "createCustomDomain") && (
<CreateCustomDomainDialog organizationId={organizationId}>
<Button icon={IconPlusLarge}>{__("Add Domain")}</Button>
</CreateCustomDomainDialog>
)}
</div>
</div>
</Card>
);
}
return (
<Card>
<div className="p-4">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div>
<div className="font-medium mb-1">{domain.domain}</div>
<div className="text-sm text-txt-secondary">
{domain.sslStatus === "ACTIVE"
? __("Verified")
: __("Pending verification")}
</div>
</div>
{getStatusBadge(domain)}
</div>
<div className="flex items-center gap-2">
<DomainDetailsDialog domain={domain}>
<Button variant="secondary">{__("View Details")}</Button>
</DomainDetailsDialog>
{isAuthorized("CustomDomain", "deleteCustomDomain") && (
<DeleteCustomDomainDialog
domainName={domain.domain}
onConfirm={handleDeleteDomain}
>
<Button variant="danger">{__("Delete")}</Button>
</DeleteCustomDomainDialog>
)}
</div>
</div>
</div>
</Card>
);
}

View File

@@ -1,97 +0,0 @@
import { useTranslate } from "@probo/i18n";
import {
Button,
Dialog,
DialogContent,
DialogFooter,
Field,
useDialogRef,
IconTrashCan,
} from "@probo/ui";
import { useState, useEffect, type ReactNode } from "react";
import { sprintf } from "@probo/helpers";
interface DeleteCustomDomainDialogProps {
children: ReactNode;
domainName: string;
onConfirm: () => Promise<void>;
}
export function DeleteCustomDomainDialog({
children,
domainName,
onConfirm,
}: DeleteCustomDomainDialogProps) {
const { __ } = useTranslate();
const [inputValue, setInputValue] = useState("");
const [isDeleting, setIsDeleting] = useState(false);
const dialogRef = useDialogRef();
const isConfirmDisabled = inputValue !== domainName || isDeleting;
const handleConfirm = async () => {
if (inputValue === domainName && !isDeleting) {
setIsDeleting(true);
try {
await onConfirm();
dialogRef.current?.close();
} finally {
setIsDeleting(false);
}
}
};
useEffect(() => {
if (!isDeleting) {
setInputValue("");
}
}, [isDeleting]);
return (
<Dialog
className="max-w-lg"
ref={dialogRef}
trigger={children}
title={__("Delete Custom Domain")}
>
<DialogContent padded className="space-y-4">
<p className="text-txt-secondary text-sm">
{sprintf(
__(
"This will permanently delete the custom domain %s and all its configuration."
),
domainName
)}
</p>
<p className="text-red-600 text-sm font-medium">
{__("This action cannot be undone.")}
</p>
<Field
label={sprintf(
__('To confirm deletion, type "%s" below:'),
domainName
)}
type="text"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder={domainName}
disabled={isDeleting}
autoComplete="off"
autoFocus
/>
</DialogContent>
<DialogFooter>
<Button
variant="danger"
icon={IconTrashCan}
onClick={handleConfirm}
disabled={isConfirmDisabled}
>
{isDeleting ? __("Deleting...") : __("Delete Domain")}
</Button>
</DialogFooter>
</Dialog>
);
}

View File

@@ -1,185 +0,0 @@
import { useTranslate } from "@probo/i18n";
import {
Button,
Dialog,
DialogContent,
Badge,
useDialogRef,
useToast,
} from "@probo/ui";
import type { ReactNode } from "react";
interface DomainDetailsDialogProps {
children: ReactNode;
domain: {
readonly id: string;
readonly domain: string;
readonly sslStatus: string;
readonly dnsRecords?:
| readonly {
readonly type: string;
readonly name: string;
readonly value: string;
readonly ttl?: number;
readonly purpose: string;
}[]
| null;
readonly sslExpiresAt?: string | null;
};
}
export function DomainDetailsDialog({
children,
domain,
}: DomainDetailsDialogProps) {
const { __ } = useTranslate();
const { toast } = useToast();
const dialogRef = useDialogRef();
const getStatusBadge = (domain: DomainDetailsDialogProps["domain"]) => {
if (domain.sslStatus === "ACTIVE") {
return <Badge variant="success">{__("Active")}</Badge>;
}
if (
domain.sslStatus === "PROVISIONING" ||
domain.sslStatus === "RENEWING"
) {
return <Badge variant="warning">{__("Provisioning")}</Badge>;
}
if (domain.sslStatus === "PENDING") {
return <Badge variant="warning">{__("Pending")}</Badge>;
}
if (domain.sslStatus === "FAILED") {
return <Badge variant="danger">{__("Failed")}</Badge>;
}
if (domain.sslStatus === "EXPIRED") {
return <Badge variant="danger">{__("Expired")}</Badge>;
}
return <Badge variant="neutral">{__("Unknown")}</Badge>;
};
const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text);
toast({
title: __("Copied"),
description: __("Value copied to clipboard"),
variant: "success",
});
};
return (
<Dialog
ref={dialogRef}
trigger={children}
title={
<div className="flex items-center gap-3">
<span>{domain.domain}</span>
{getStatusBadge(domain)}
</div>
}
>
<DialogContent padded className="space-y-6">
{domain.sslStatus === "ACTIVE" ? (
<div className="bg-subtle rounded-lg p-4">
<div className="flex items-start">
<svg
className="w-5 h-5 text-green-500 mt-0.5 mr-3 flex-shrink-0"
fill="none"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<div>
<p className="font-medium mb-1">{__("Domain is active")}</p>
<p className="text-sm text-txt-secondary">
{__(
"Your custom domain is verified and SSL certificate is active"
)}
</p>
{domain.sslExpiresAt && (
<p className="text-xs text-txt-tertiary mt-2">
{__("SSL expires")}{" "}
{new Date(domain.sslExpiresAt).toLocaleDateString()}
</p>
)}
</div>
</div>
</div>
) : (
<div>
<h4 className="font-medium mb-3">{__("DNS Configuration")}</h4>
<p className="text-sm text-txt-secondary mb-4">
{__(
"Add these DNS records to your domain to complete verification"
)}
</p>
<div className="space-y-3">
{domain.dnsRecords?.map((record, index) => (
<div key={index} className="bg-subtle rounded-lg p-4">
<div className="flex items-center justify-between mb-2">
<span className="text-sm font-medium">{record.type}</span>
<Badge variant="neutral">{record.purpose}</Badge>
</div>
<div className="space-y-2">
<div>
<label className="text-xs text-txt-tertiary">
{__("Name")}
</label>
<div className="flex items-center gap-2 mt-1">
<code className="flex-1 text-sm bg-subtle px-2 py-1 rounded">
{record.name}
</code>
<Button
variant="secondary"
onClick={() => copyToClipboard(record.name)}
>
{__("Copy")}
</Button>
</div>
</div>
<div>
<label className="text-xs text-txt-tertiary">
{__("Value")}
</label>
<div className="flex items-center gap-2 mt-1">
<code className="flex-1 text-sm bg-subtle px-2 py-1 rounded break-all">
{record.value}
</code>
<Button
variant="secondary"
onClick={() => copyToClipboard(record.value)}
>
{__("Copy")}
</Button>
</div>
</div>
{record.ttl && (
<div className="text-xs text-txt-tertiary">
TTL: {record.ttl}
</div>
)}
</div>
</div>
))}
</div>
{domain.sslStatus === "PENDING" && (
<div className="bg-subtle rounded-lg p-4 mt-4">
<p className="text-sm">
{__(
"After adding the DNS records, verification will happen automatically. This may take a few minutes to propagate."
)}
</p>
</div>
)}
</div>
)}
</DialogContent>
</Dialog>
);
}

View File

@@ -1,200 +0,0 @@
/**
* @generated SignedSource<<c1db974cc1fa82299f39a71ece9bf7e3>>
* @lightSyntaxTransform
* @nogrep
*/
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type SSLStatus = "ACTIVE" | "EXPIRED" | "FAILED" | "PENDING" | "PROVISIONING" | "RENEWING";
export type CreateCustomDomainInput = {
domain: string;
organizationId: string;
};
export type CreateCustomDomainDialogMutation$variables = {
input: CreateCustomDomainInput;
};
export type CreateCustomDomainDialogMutation$data = {
readonly createCustomDomain: {
readonly customDomain: {
readonly createdAt: any;
readonly dnsRecords: ReadonlyArray<{
readonly name: string;
readonly purpose: string;
readonly ttl: number;
readonly type: string;
readonly value: string;
}>;
readonly domain: string;
readonly id: string;
readonly sslExpiresAt: any | null | undefined;
readonly sslStatus: SSLStatus;
readonly updatedAt: any;
};
};
};
export type CreateCustomDomainDialogMutation = {
response: CreateCustomDomainDialogMutation$data;
variables: CreateCustomDomainDialogMutation$variables;
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "input"
}
],
v1 = [
{
"alias": null,
"args": [
{
"kind": "Variable",
"name": "input",
"variableName": "input"
}
],
"concreteType": "CreateCustomDomainPayload",
"kind": "LinkedField",
"name": "createCustomDomain",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "CustomDomain",
"kind": "LinkedField",
"name": "customDomain",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "domain",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "sslStatus",
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "DNSRecordInstruction",
"kind": "LinkedField",
"name": "dnsRecords",
"plural": true,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "type",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "value",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "ttl",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "purpose",
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "createdAt",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "updatedAt",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "sslExpiresAt",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
];
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Fragment",
"metadata": null,
"name": "CreateCustomDomainDialogMutation",
"selections": (v1/*: any*/),
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Operation",
"name": "CreateCustomDomainDialogMutation",
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "5e5bf90d17b1dc5129d6a0fc5d68d46c",
"id": null,
"metadata": {},
"name": "CreateCustomDomainDialogMutation",
"operationKind": "mutation",
"text": "mutation CreateCustomDomainDialogMutation(\n $input: CreateCustomDomainInput!\n) {\n createCustomDomain(input: $input) {\n customDomain {\n id\n domain\n sslStatus\n dnsRecords {\n type\n name\n value\n ttl\n purpose\n }\n createdAt\n updatedAt\n sslExpiresAt\n }\n }\n}\n"
}
};
})();
(node as any).hash = "fb3bede811b12db54f54af3dd375e335";
export default node;

View File

@@ -1,92 +0,0 @@
/**
* @generated SignedSource<<b25e2b88094ba632cc451508af4df1e3>>
* @lightSyntaxTransform
* @nogrep
*/
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type DeleteCustomDomainInput = {
organizationId: string;
};
export type CustomDomainManagerDeleteMutation$variables = {
input: DeleteCustomDomainInput;
};
export type CustomDomainManagerDeleteMutation$data = {
readonly deleteCustomDomain: {
readonly deletedCustomDomainId: string;
};
};
export type CustomDomainManagerDeleteMutation = {
response: CustomDomainManagerDeleteMutation$data;
variables: CustomDomainManagerDeleteMutation$variables;
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "input"
}
],
v1 = [
{
"alias": null,
"args": [
{
"kind": "Variable",
"name": "input",
"variableName": "input"
}
],
"concreteType": "DeleteCustomDomainPayload",
"kind": "LinkedField",
"name": "deleteCustomDomain",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "deletedCustomDomainId",
"storageKey": null
}
],
"storageKey": null
}
];
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Fragment",
"metadata": null,
"name": "CustomDomainManagerDeleteMutation",
"selections": (v1/*: any*/),
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Operation",
"name": "CustomDomainManagerDeleteMutation",
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "9f4a3ed02de61bc60a8370e3771ca7bd",
"id": null,
"metadata": {},
"name": "CustomDomainManagerDeleteMutation",
"operationKind": "mutation",
"text": "mutation CustomDomainManagerDeleteMutation(\n $input: DeleteCustomDomainInput!\n) {\n deleteCustomDomain(input: $input) {\n deletedCustomDomainId\n }\n}\n"
}
};
})();
(node as any).hash = "e3878d11e361c3da2471363664150f3d";
export default node;