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.

Update domain-selector.tsx

Kiran K9f85a4f2376f
diff --git a/apps/web/ui/domains/domain-selector.tsx b/apps/web/ui/domains/domain-selector.tsx
index 5497d12945..bc37006377 100644
--- a/apps/web/ui/domains/domain-selector.tsx
+++ b/apps/web/ui/domains/domain-selector.tsx
@@ -1,8 +1,14 @@
import useDomains from "@/lib/swr/use-domains";
-import { Button, Combobox, Globe, StatusBadge } from "@dub/ui";
-import { cn } from "@dub/utils";
-import { useMemo, useState } from "react";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { DomainVerificationStatusProps } from "@/lib/types";
+import { Button, CircleCheck, Combobox, Globe, StatusBadge } from "@dub/ui";
+import { cn, fetcher } from "@dub/utils";
+import { motion } from "framer-motion";
+import Link from "next/link";
+import { useMemo, useRef, useState } from "react";
+import useSWRImmutable from "swr/immutable";
import { useAddEditDomainModal } from "../modals/add-edit-domain-modal";
+import DomainConfiguration from "./domain-configuration";
interface DomainSelectorProps {
selectedDomain: string;
@@ -13,9 +19,21 @@ export function DomainSelector({
selectedDomain,
setSelectedDomain,
}: DomainSelectorProps) {
+ const { id: workspaceId } = useWorkspace();
+ const domainRef = useRef<HTMLDivElement>(null);
const [openPopover, setOpenPopover] = useState(false);
const { allWorkspaceDomains, loading } = useDomains();
+ const { data: verificationData } = useSWRImmutable<{
+ status: DomainVerificationStatusProps;
+ response: any;
+ }>(
+ workspaceId && selectedDomain
+ ? `/api/domains/${selectedDomain}/verify?workspaceId=${workspaceId}`
+ : null,
+ fetcher,
+ );
+
const { AddEditDomainModal, setShowAddEditDomainModal } =
useAddEditDomainModal({
onSuccess: (domain) => {
@@ -68,47 +86,78 @@ export function DomainSelector({
return (
<>
<AddEditDomainModal />
- <Combobox
- options={loading ? undefined : domainOptions}
- setSelected={(option) => {
- setSelectedDomain(option.value);
- }}
- selected={selectedOption}
- icon={loading ? null : selectedOption?.icon}
- caret={true}
- placeholder={loading ? "" : "Select domain"}
- searchPlaceholder="Search domain..."
- matchTriggerWidth
- open={openPopover}
- onOpenChange={setOpenPopover}
- buttonProps={{
- className: cn(
- "w-full justify-start border-neutral-300 px-3",
- "data-[state=open]:ring-1 data-[state=open]:ring-neutral-500 data-[state=open]:border-neutral-500",
- "focus:ring-1 focus:ring-neutral-500 focus:border-neutral-500 transition-none",
- ),
- }}
- emptyState={
- <div className="flex w-full flex-col items-center gap-2 py-4">
- No domains found
- <Button
- onClick={() => {
- setOpenPopover(false);
- setShowAddEditDomainModal(true);
- }}
- variant="primary"
- className="h-7 w-fit px-2"
- text="Add custom domain"
- />
- </div>
- }
- >
- {loading ? (
- <div className="my-0.5 h-4 animate-pulse rounded bg-neutral-200" />
- ) : (
- selectedOption?.label
+ <div ref={domainRef}>
+ <Combobox
+ options={loading ? undefined : domainOptions}
+ setSelected={(option) => {
+ setSelectedDomain(option.value);
+ }}
+ selected={selectedOption}
+ icon={loading ? null : selectedOption?.icon}
+ caret={true}
+ placeholder={loading ? "" : "Select domain"}
+ searchPlaceholder="Search domain..."
+ matchTriggerWidth
+ open={openPopover}
+ onOpenChange={setOpenPopover}
+ buttonProps={{
+ className: cn(
+ "w-full justify-start border-neutral-300 px-3",
+ "data-[state=open]:ring-1 data-[state=open]:ring-neutral-500 data-[state=open]:border-neutral-500",
+ "focus:ring-1 focus:ring-neutral-500 focus:border-neutral-500 transition-none",
+ ),
+ }}
+ emptyState={
+ <div className="flex w-full flex-col items-center gap-2 py-4">
+ No domains found
+ <Button
+ onClick={() => {
+ setOpenPopover(false);
+ setShowAddEditDomainModal(true);
+ }}
+ variant="primary"
+ className="h-7 w-fit px-2"
+ text="Add custom domain"
+ />
+ </div>
+ }
+ >
+ {loading ? (
+ <div className="my-0.5 h-4 animate-pulse rounded bg-neutral-200" />
+ ) : (
+ selectedOption?.label
+ )}
+ </Combobox>
+
+ {selectedDomain && verificationData && (
+ <motion.div
+ initial={false}
+ animate={{ height: "auto" }}
+ className="mt-5 overflow-hidden rounded-md border border-neutral-200 bg-neutral-50 px-5 pb-5"
+ >
+ {verificationData.status === "Valid Configuration" ? (
+ <div className="mt-4 flex items-center gap-2 text-pretty rounded-lg bg-green-100/80 p-3 text-sm text-green-600">
+ <CircleCheck className="h-5 w-5 shrink-0" />
+ <div>
+ Good news! Your DNS records are set up correctly, but it can
+ take some time for them to propagate globally.{" "}
+ <Link
+ href="https://dub.co/help/article/how-to-add-custom-domain#how-long-do-i-have-to-wait-for-my-domain-to-work"
+ target="_blank"
+ className="underline transition-colors hover:text-green-800"
+ >
+ Learn more.
+ </Link>
+ </div>
+ </div>
+ ) : (
+ <div className="mt-4">
+ <DomainConfiguration data={verificationData} />
+ </div>
+ )}
+ </motion.div>
)}
- </Combobox>
+ </div>
</>
);
}