Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

improvement: accurate subdomain config help

Mingjie Jiang5b91df8a0778
diff --git a/components/app/settings/custom-domain/domain-configuration.tsx b/components/app/settings/custom-domain/domain-configuration.tsx
index 1ff6827e89..8f0434df29 100644
--- a/components/app/settings/custom-domain/domain-configuration.tsx
+++ b/components/app/settings/custom-domain/domain-configuration.tsx
@@ -1,4 +1,5 @@
import { DomainVerificationStatusProps } from "@/lib/types";
+import { getSubdomain } from "@/lib/utils";
import { useState } from "react";
const InlineSnippet = ({ children }: { children: string }) => {
@@ -14,44 +15,45 @@ export default function DomainConfiguration({
}: {
data: { status: DomainVerificationStatusProps; response: any };
}) {
- const [recordType, setRecordType] = useState("A");
const { domainJson } = data.response;
+ const subdomain = getSubdomain(domainJson.name, domainJson.apexName);
+ const [recordType, setRecordType] = useState(!!subdomain ? "CNAME" : "A");
- if (data.status === "Pending Verification") {
- const txtVerification = domainJson.verification.find(
- (x: any) => x.type === "TXT"
- );
- return (
- <div className="border-t border-gray-200 pt-5">
- <p className="mb-5 text-sm">
- Please set the following TXT record on{" "}
- <InlineSnippet>{domainJson.apexName}</InlineSnippet> to prove
- ownership of <InlineSnippet>{domainJson.name}</InlineSnippet>:
- </p>
- <div className="flex justify-start items-start space-x-10 bg-gray-50 p-2 rounded-md">
- <div>
- <p className="text-sm font-bold">Type</p>
- <p className="text-sm font-mono mt-2">{txtVerification.type}</p>
- </div>
- <div>
- <p className="text-sm font-bold">Name</p>
- <p className="text-sm font-mono mt-2">
- {txtVerification.domain.slice(
- 0,
- txtVerification.domain.length - domainJson.apexName.length - 1
- )}
- </p>
- </div>
- <div>
- <p className="text-sm font-bold">Value</p>
- <p className="text-sm font-mono mt-2">
- <span className="text-ellipsis">{txtVerification.value}</span>
- </p>
- </div>
- </div>
- </div>
- );
- }
+ // if (data.status === "Pending Verification") {
+ // const txtVerification = domainJson.verification.find(
+ // (x: any) => x.type === "TXT"
+ // );
+ // return (
+ // <div className="border-t border-gray-200 pt-5">
+ // <p className="mb-5 text-sm">
+ // Please set the following TXT record on{" "}
+ // <InlineSnippet>{domainJson.apexName}</InlineSnippet> to prove
+ // ownership of <InlineSnippet>{domainJson.name}</InlineSnippet>:
+ // </p>
+ // <div className="flex justify-start items-start space-x-10 bg-gray-50 p-2 rounded-md">
+ // <div>
+ // <p className="text-sm font-bold">Type</p>
+ // <p className="text-sm font-mono mt-2">{txtVerification.type}</p>
+ // </div>
+ // <div>
+ // <p className="text-sm font-bold">Name</p>
+ // <p className="text-sm font-mono mt-2">
+ // {txtVerification.domain.slice(
+ // 0,
+ // txtVerification.domain.length - domainJson.apexName.length - 1
+ // )}
+ // </p>
+ // </div>
+ // <div>
+ // <p className="text-sm font-bold">Value</p>
+ // <p className="text-sm font-mono mt-2">
+ // <span className="text-ellipsis">{txtVerification.value}</span>
+ // </p>
+ // </div>
+ // </div>
+ // </div>
+ // );
+ // }
if (data.status === "Unknown Error") {
return (
@@ -102,7 +104,7 @@ export default function DomainConfiguration({
<div>
<p className="text-sm font-bold">Name</p>
<p className="text-sm font-mono mt-2">
- {recordType === "A" ? "@" : "www"}
+ {recordType === "A" ? "@" : subdomain ?? "www"}
</p>
</div>
<div>
diff --git a/lib/utils.ts b/lib/utils.ts
index 2ec652f376..c708b71aae 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -168,3 +168,8 @@ export const getFirstAndLastDay = (day: number) => {
};
}
};
+
+export const getSubdomain = (name: string, apexName: string) => {
+ if (name === apexName) return null;
+ return name.slice(0, name.length - apexName.length - 1);
+};