The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
almost done with custom domains – stashing changes
Steven Tey47c3a13931c1
diff --git a/components/app/custom-domain/configurations-placeholder.tsx b/components/app/custom-domain/configurations-placeholder.tsxdeleted file mode 100644index c8cc7aef9a..0000000000--- a/components/app/custom-domain/configurations-placeholder.tsx+++ /dev/null@@ -1,10 +0,0 @@-const ConfigurationsPlaceholder = () => {- return (- <div className="flex items-center space-x-3 mt-3 px-2 sm:px-10">- <div className="w-6 h-6 rounded-full bg-gray-300 animate-pulse" />- <p className="text-gray-500 font-normal text-sm">Loading Configuration</p>- </div>- );-};--export default ConfigurationsPlaceholder;diff --git a/components/app/custom-domain/configurations.tsx b/components/app/custom-domain/configurations.tsxdeleted file mode 100644index dbeb1677e9..0000000000--- a/components/app/custom-domain/configurations.tsx+++ /dev/null@@ -1,204 +0,0 @@-import { useState } from "react";-import ConfigurationsPlaceholder from "./configurations-placeholder";--function getVerificationError(verificationResponse: any) {- try {- const error = verificationResponse.error;- if (error.code === "missing_txt_record") {- return null;- }- return error.message;- } catch {- return null;- }-}--const Configurations = ({ data }: { data: any }) => {- const [recordType, setRecordType] = useState("CNAME");- if (!data) {- return <ConfigurationsPlaceholder />;- }-- if (!data.verified) {- const txtVerification = data.verification.find(- (x: any) => x.type === "TXT"- );- return (- <>- <div className="flex items-center space-x-3 my-3 px-2 sm:px-10">- <svg- viewBox="0 0 24 24"- width="24"- height="24"- strokeWidth="1.5"- strokeLinecap="round"- strokeLinejoin="round"- shapeRendering="geometricPrecision"- >- <circle cx="12" cy="12" r="10" fill="#d32f2f" />- <>- <path d="M15 9l-6 6" stroke="white" />- <path d="M9 9l6 6" stroke="white" />- </>- </svg>- <p className={`text-red-700 font-medium text-sm`}>- Domain is pending verification- </p>- </div>-- <div className="w-full border-t border-gray-100 mt-5 mb-8" />-- <div className="px-2 sm:px-10">- <div className="flex justify-start space-x-4">- <div- onClick={() => setRecordType("CNAME")}- className={`${- recordType == "CNAME"- ? "text-black border-black"- : "text-gray-400 border-white"- } text-sm border-b-2 pb-1 transition-all ease duration-150`}- >- Verify Domain Ownership- </div>- </div>- <div className="my-3 text-left">- <p className="my-5 text-sm">- Please set the following TXT record on {data.apexName} to prove- ownership of {data.name}:- </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 - data.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>- {getVerificationError(data.verificationResponse) && (- <p className="my-5 text-sm text-red-700">- {getVerificationError(data.verificationResponse)}- </p>- )}- </div>- </div>- </>- );- }-- return (- <>- <div className="flex items-center space-x-3">- <svg- viewBox="0 0 24 24"- width="24"- height="24"- strokeWidth="1.5"- strokeLinecap="round"- strokeLinejoin="round"- shapeRendering="geometricPrecision"- >- <circle- cx="12"- cy="12"- r="10"- fill={data.configured ? "#1976d2" : "#d32f2f"}- />- {data.configured ? (- <>- <path- d="M8 11.8571L10.5 14.3572L15.8572 9"- fill="none"- stroke="white"- />- </>- ) : (- <>- <path d="M15 9l-6 6" stroke="white" />- <path d="M9 9l6 6" stroke="white" />- </>- )}- </svg>- <p- className={`${- data.configured- ? "text-black font-normal"- : "text-red-700 font-medium"- } text-sm`}- >- {data.configured ? "Valid" : "Invalid"} Configuration- </p>- </div>-- {!data.configured && (- <>- <div className="w-full border-t border-gray-100 mt-5 mb-8" />-- <div className="px-2 sm:px-10">- <div className="flex justify-start space-x-4">- <button- onClick={() => setRecordType("CNAME")}- className={`${- recordType == "CNAME"- ? "text-black border-black"- : "text-gray-400 border-white"- } text-sm border-b-2 pb-1 transition-all ease duration-150`}- >- CNAME Record (subdomains)- </button>- <button- onClick={() => setRecordType("A")}- className={`${- recordType == "A"- ? "text-black border-black"- : "text-gray-400 border-white"- } text-sm border-b-2 pb-1 transition-all ease duration-150`}- >- A Record (apex domain)- </button>- </div>- <div className="my-3 text-left">- <p className="my-5 text-sm">- Set the following record on your DNS provider to continue:- </p>- <div className="flex justify-start items-center 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">{recordType}</p>- </div>- <div>- <p className="text-sm font-bold">Name</p>- <p className="text-sm font-mono mt-2">- {recordType == "CNAME" ? "www" : "@"}- </p>- </div>- <div>- <p className="text-sm font-bold">Value</p>- <p className="text-sm font-mono mt-2">- {recordType == "CNAME"- ? `cname.platformize.co`- : `76.76.21.21`}- </p>- </div>- </div>- </div>- </div>- </>- )}- </>- );-};--export default Configurations;diff --git a/components/app/custom-domain/domain-configuration.tsx b/components/app/custom-domain/domain-configuration.tsxnew file mode 100644index 0000000000..e5f03c159b--- /dev/null+++ b/components/app/custom-domain/domain-configuration.tsx@@ -0,0 +1,151 @@+import { DomainVerificationStatusProps } from "@/lib/types";+import { useState } from "react";++function getVerificationError(verificationResponse: any) {+ try {+ const error = verificationResponse.error;+ if (error.code === "missing_txt_record") {+ return null;+ }+ return error.message;+ } catch {+ return null;+ }+}++export default function DomainConfiguration({+ status,+}: {+ status: DomainVerificationStatusProps;+}) {+ const [recordType, setRecordType] = useState("CNAME");++ // if (status === "Pending Verification") {+ // const txtVerification = data.verification.find(+ // (x: any) => x.type === "TXT"+ // );+ // return (+ // <>+ // <div className="flex items-center space-x-3 my-3 px-2 sm:px-10">+ // <svg+ // viewBox="0 0 24 24"+ // width="24"+ // height="24"+ // strokeWidth="1.5"+ // strokeLinecap="round"+ // strokeLinejoin="round"+ // shapeRendering="geometricPrecision"+ // >+ // <circle cx="12" cy="12" r="10" fill="#d32f2f" />+ // <>+ // <path d="M15 9l-6 6" stroke="white" />+ // <path d="M9 9l6 6" stroke="white" />+ // </>+ // </svg>+ // <p className={`text-red-700 font-medium text-sm`}>+ // Domain is pending verification+ // </p>+ // </div>++ // <div className="w-full border-t border-gray-100 mt-5 mb-8" />++ // <div className="px-2 sm:px-10">+ // <div className="flex justify-start space-x-4">+ // <div+ // onClick={() => setRecordType("CNAME")}+ // className={`${+ // recordType == "CNAME"+ // ? "text-black border-black"+ // : "text-gray-400 border-white"+ // } text-sm border-b-2 pb-1 transition-all ease duration-150`}+ // >+ // Verify Domain Ownership+ // </div>+ // </div>+ // <div className="my-3 text-left">+ // <p className="my-5 text-sm">+ // Please set the following TXT record on {data.apexName} to prove+ // ownership of {data.name}:+ // </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 - data.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>+ // {getVerificationError(data.verificationResponse) && (+ // <p className="my-5 text-sm text-red-700">+ // {getVerificationError(data.verificationResponse)}+ // </p>+ // )}+ // </div>+ // </div>+ // </>+ // );+ // }++ return (+ <div className="border-t border-gray-200 pt-5">+ <div className="flex justify-start space-x-4">+ <button+ onClick={() => setRecordType("CNAME")}+ className={`${+ recordType == "CNAME"+ ? "text-black border-black"+ : "text-gray-400 border-white"+ } text-sm border-b-2 pb-1 transition-all ease duration-150`}+ >+ CNAME Record (subdomains)+ </button>+ <button+ onClick={() => setRecordType("A")}+ className={`${+ recordType == "A"+ ? "text-black border-black"+ : "text-gray-400 border-white"+ } text-sm border-b-2 pb-1 transition-all ease duration-150`}+ >+ A Record (apex domain)+ </button>+ </div>+ <div className="my-3 text-left">+ <p className="my-5 text-sm">+ Set the following record on your DNS provider to continue:+ </p>+ <div className="flex justify-start items-center 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">{recordType}</p>+ </div>+ <div>+ <p className="text-sm font-bold">Name</p>+ <p className="text-sm font-mono mt-2">+ {recordType == "CNAME" ? "www" : "@"}+ </p>+ </div>+ <div>+ <p className="text-sm font-bold">Value</p>+ <p className="text-sm font-mono mt-2">+ {recordType == "CNAME" ? `cname.dub.sh` : `76.76.21.21`}+ </p>+ </div>+ </div>+ </div>+ </div>+ );+}diff --git a/components/app/custom-domain/edit-domain-modal.tsx b/components/app/custom-domain/edit-domain-modal.tsxindex e0b03d116e..40ff463349 100644--- a/components/app/custom-domain/edit-domain-modal.tsx+++ b/components/app/custom-domain/edit-domain-modal.tsx@@ -26,7 +26,6 @@ function EditDomainModalHelper({const router = useRouter();const { slug } = router.query;const [saving, setSaving] = useState(false);- const [buttonText, setButtonText] = useState("Confirm domain change");const [domainExistsError, setdomainExistsError] = useState(false);const [data, setData] = useState(domain);@@ -77,11 +76,8 @@ function EditDomainModalHelper({}).then((res) => {setSaving(false);if (res.status === 200) {- setButtonText("Saved!");mutate(`/api/projects/${slug}`);- setTimeout(() => {- setButtonText("Save changes");- });+ setShowEditDomainModal(false);}});}}@@ -139,7 +135,11 @@ function EditDomainModalHelper({: "bg-red-600 hover:bg-white hover:text-red-600 border-red-600 text-white"} flex justify-center items-center w-full text-sm h-10 rounded-md border transition-all focus:outline-none`}>- {saving ? <LoadingDots color="#808080" /> : <p>{buttonText}</p>}+ {saving ? (+ <LoadingDots color="#808080" />+ ) : (+ <p>Confirm domain change</p>+ )}</button></form></div>diff --git a/components/app/custom-domain/index.tsx b/components/app/custom-domain/index.tsxindex 2b2b1a036f..f33e8485d3 100644--- a/components/app/custom-domain/index.tsx+++ b/components/app/custom-domain/index.tsx@@ -10,24 +10,19 @@ import {XCircleFill,} from "@/components/shared/icons";import { useEditDomainModal } from "./edit-domain-modal";--interface DomainResponse {- status:- | "Valid Configuration"- | "Invalid Configuration"- | "Pending Verification"- | "Domain Not Found";-}+import { DomainVerificationStatusProps } from "@/lib/types";+import DomainConfiguration from "./domain-configuration";export default function CustomDomain({ domain }: { domain: string }) {const router = useRouter();const { slug } = router.query as { slug: string };- const { data, isValidating } = useSWR<DomainResponse>(- `/api/projects/${slug}/domains/${domain}/verify`,- fetcher,- { revalidateOnMount: true, refreshInterval: 5000 }- );+ const { data, isValidating } = useSWR<{+ status: DomainVerificationStatusProps;+ }>(`/api/projects/${slug}/domains/${domain}/verify`, fetcher, {+ revalidateOnMount: true,+ refreshInterval: 5000,+ });const { setShowEditDomainModal, EditDomainModal } = useEditDomainModal({domain,@@ -106,6 +101,9 @@ export default function CustomDomain({ domain }: { domain: string }) {{data ? data.status : "Checking Domain Status"}</p></div>+ {data && data.status !== "Valid Configuration" && (+ <DomainConfiguration status={data.status} />+ )}</div></div>);diff --git a/lib/types.ts b/lib/types.tsindex f695512adc..9f2ad0f9a1 100644--- a/lib/types.ts+++ b/lib/types.ts@@ -12,3 +12,9 @@ export interface ProjectProps {domainVerified: boolean;links: LinkProps[];}++export type DomainVerificationStatusProps =+ | "Valid Configuration"+ | "Invalid Configuration"+ | "Pending Verification"+ | "Domain Not Found";diff --git a/pages/api/projects/[slug]/domains/[domain]/verify.ts b/pages/api/projects/[slug]/domains/[domain]/verify.tsindex ed113d7986..681d7a1521 100644--- a/pages/api/projects/[slug]/domains/[domain]/verify.ts+++ b/pages/api/projects/[slug]/domains/[domain]/verify.ts@@ -1,16 +1,11 @@import { withProjectAuth } from "@/lib/auth";import { NextApiRequest, NextApiResponse } from "next";--type StatusProps =- | "Valid Configuration"- | "Invalid Configuration"- | "Pending Verification"- | "Domain Not Found";+import { DomainVerificationStatusProps } from "@/lib/types";export default withProjectAuth(async (req: NextApiRequest, res: NextApiResponse) => {const { domain } = req.query as { domain: string };- let status: StatusProps = "Valid Configuration";+ let status: DomainVerificationStatusProps = "Valid Configuration";const [domainResponse, configResponse] = await Promise.all([fetch(