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.

Merge branch 'domain-qr-logo' of https://github.com/dubinc/dub into domain-qr-logo

Kiran Kb8fd6e47ea3a
diff --cc apps/web/ui/domains/add-edit-domain-form.tsx
index dd2e648d35,939c213441..9a08a51b9c
--- a/apps/web/ui/domains/add-edit-domain-form.tsx
+++ b/apps/web/ui/domains/add-edit-domain-form.tsx
@@@ -1,6 -1,6 +1,7 @@@
+ import { isValidDomain } from "@/lib/api/domains";
import useWorkspace from "@/lib/swr/use-workspace";
import { DomainProps } from "@/lib/types";
+import { createDomainBodySchema } from "@/lib/zod/schemas/domains";
import { AlertCircleFill, CheckCircleFill, Lock } from "@/ui/shared/icons";
import { UpgradeRequiredToast } from "@/ui/shared/upgrade-required-toast";
import {
@@@ -24,13 -26,61 +27,55 @@@ import
} from "lucide-react";
import posthog from "posthog-js";
import { useMemo, useState } from "react";
- import { useForm } from "react-hook-form";
+ import { Controller, useForm } from "react-hook-form";
import { toast } from "sonner";
import { mutate } from "swr";
+ import { useDebouncedCallback } from "use-debounce";
import { z } from "zod";
+ import { QRCode } from "../shared/qr-code";
-const domainFormSchema = z.object({
- slug: z.string().min(1, "Domain is required"),
- logo: z.string().optional(),
- expiredUrl: z.string().url().optional().or(z.literal("")),
- notFoundUrl: z.string().url().optional().or(z.literal("")),
- placeholder: z.string().url().optional().or(z.literal("")),
-});
+type FormData = z.infer<typeof createDomainBodySchema>;
+ type DomainStatus = "checking" | "conflict" | "has site" | "available" | "idle";
+
+ const STATUS_CONFIG: Record<
+ DomainStatus,
+ {
+ prefix?: string;
+ useStrong?: boolean;
+ suffix?: string;
+ icon?: React.ElementType;
+ className?: string;
+ message?: string;
+ }
+ > = {
+ checking: {
+ prefix: "Checking availability for",
+ useStrong: true,
+ suffix: "...",
+ icon: LoadingSpinner,
+ },
+ conflict: {
+ suffix: "is already in use.",
+ icon: AlertCircleFill,
+ className: "bg-red-100 text-red-600",
+ },
+ "has site": {
+ suffix:
+ "already has a site connected. Ensure you want to connect this domain for shortlinks.",
+ icon: AlertCircleFill,
+ className: "bg-amber-100 text-amber-600",
+ },
+ available: {
+ suffix: "is ready to connect.",
+ icon: CheckCircleFill,
+ className: "bg-green-100 text-green-600",
+ },
+ idle: {
+ message: "Enter a valid domain to check availability.",
+ },
+ };
+
export function AddEditDomainForm({
props,
onSuccess,
@@@ -43,10 -93,11 +88,10 @@@
className?: string;
}) {
const { id: workspaceId, plan } = useWorkspace();
- const isDubProvisioned = !!props?.registeredDomain;
const [lockDomain, setLockDomain] = useState(true);
- const [domainStatus, setDomainStatus] = useState<
- "checking" | "conflict" | "has site" | "available" | null
- >(props ? "available" : null);
+ const [domainStatus, setDomainStatus] = useState<DomainStatus>(
+ props ? "available" : "idle",
+ );
const {
register,
@@@ -277,13 -305,15 +303,13 @@@
<div className="flex flex-col gap-y-6">
{ADVANCED_OPTIONS.map(
({ id, title, description, icon: Icon, proFeature }) => {
- const [showOption, setShowOption] = useState(
- !!watch(id as keyof z.infer<typeof domainFormSchema>),
- );
+ const [showOption, setShowOption] = useState(!!watch(id));
return (
<div key={id}>
- <label className="flex items-center justify-between gap-2">
+ <label className="flex items-center justify-between gap-4">
<div className="flex items-center gap-3">
- <div className="rounded-lg border border-neutral-200 bg-white p-2">
- <Icon className="size-5 text-neutral-600" />
+ <div className="hidden rounded-lg border border-neutral-200 bg-white p-2 sm:block">
+ <Icon className="size-5 text-neutral-500" />
</div>
<div>
<div className="flex items-center gap-2">
@@@ -321,11 -355,50 +347,48 @@@
className="-m-1 overflow-hidden p-1"
>
<div className="relative mt-2 rounded-md shadow-sm">
- <input
- {...register(id)}
- className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
- placeholder="https://yourwebsite.com"
- />
+ {id === "logo" ? (
+ <div className="flex h-24 items-center justify-center overflow-hidden rounded-md border border-gray-300">
+ {!isMobile && (
+ <ShimmerDots className="pointer-events-none z-10 opacity-30 [mask-image:radial-gradient(40%_80%,transparent_50%,black)]" />
+ )}
+ <Controller
+ control={control}
+ name="logo"
+ rules={{ required: true }}
+ render={({ field }) => (
+ <FileUpload
+ accept="images"
+ className="h-24 rounded-md"
+ iconClassName="size-5 text-neutral-700"
+ variant="plain"
+ imageSrc={field.value}
+ readFile
+ onChange={({ src }) => field.onChange(src)}
+ maxFileSizeMB={2}
+ targetResolution={{
+ width: 160,
+ height: 160,
+ }}
+ customPreview={
+ <QRCode
+ url="https://dub.co"
+ fgColor="#000"
- logo={field.value}
++ logo={field.value || ""}
+ scale={0.6}
+ />
+ }
+ />
+ )}
+ />
+ </div>
+ ) : (
+ <input
- {...register(
- id as keyof z.infer<typeof domainFormSchema>,
- )}
++ {...register(id)}
+ className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ placeholder="https://yourwebsite.com"
+ />
+ )}
</div>
</motion.div>
</div>