Skip to content

Commit

Permalink
update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
devkiran committed Nov 22, 2024
1 parent 394f64e commit 0d478fb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
9 changes: 5 additions & 4 deletions apps/web/app/api/domains/[domain]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ export const PATCH = withWorkspace(
}
}

const logoUploaded = logo
? await storage.upload(`logos/${domainId}_${nanoid(7)}`, logo)
: null;
const logoUploaded =
logo && workspace.plan !== "free"
? await storage.upload(`logos/${domainId}_${nanoid(7)}`, logo)
: null;

const domainRecord = await prisma.domain.update({
where: {
Expand All @@ -107,8 +108,8 @@ export const PATCH = withWorkspace(
...(workspace.plan != "free" && {
expiredUrl,
notFoundUrl,
...(logoUploaded && { logo: logoUploaded.url }),
}),
...(logoUploaded && { logo: logoUploaded.url }),
},
include: {
registeredDomain: true,
Expand Down
9 changes: 5 additions & 4 deletions apps/web/app/api/domains/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ export const POST = withWorkspace(

const domainId = createId({ prefix: "dom_" });

const logoUploaded = logo
? await storage.upload(`logos/${domainId}_${nanoid(7)}`, logo)
: null;
const logoUploaded =
logo && workspace.plan !== "free"
? await storage.upload(`logos/${domainId}_${nanoid(7)}`, logo)
: null;

const [domainRecord, _] = await Promise.all([
prisma.domain.create({
Expand All @@ -141,8 +142,8 @@ export const POST = withWorkspace(
...(workspace.plan !== "free" && {
expiredUrl,
notFoundUrl,
...(logoUploaded && { logo: logoUploaded.url }),
}),
...(logoUploaded && { logo: logoUploaded.url }),
},
}),

Expand Down
18 changes: 18 additions & 0 deletions apps/web/lib/swr/use-domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { fetcher } from "@dub/utils";
import useSWR from "swr";
import { DomainProps } from "../types";
import useWorkspace from "./use-workspace";

export default function useDomain(slug: string) {
const { id: workspaceId } = useWorkspace();

const { data: domain, error } = useSWR<DomainProps>(
workspaceId && slug && `/api/domains/${slug}?workspaceId=${workspaceId}`,
fetcher,
);

return {
...domain,
loading: !domain && !error,
};
}
8 changes: 6 additions & 2 deletions apps/web/ui/domains/add-edit-domain-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function AddEditDomainForm({
showAdvancedOptions?: boolean;
className?: string;
}) {
const { id: workspaceId } = useWorkspace();
const { id: workspaceId, plan } = useWorkspace();

const isDubProvisioned = !!props?.registeredDomain;

Expand Down Expand Up @@ -155,7 +155,7 @@ export function AddEditDomainForm({
className={cn("flex flex-col gap-y-6 text-left", className)}
>
<div>
<div className="mb-4 flex items-center justify-center">
<div className="mb-4 flex flex-col items-center justify-center gap-2">
<FileUpload
accept="images"
className="h-20 w-20 rounded-full border border-gray-300"
Expand All @@ -169,7 +169,11 @@ export function AddEditDomainForm({
content={null}
maxFileSizeMB={2}
targetResolution={{ width: 240, height: 240 }}
disabled={plan === "free"}
/>
<div>
<ProBadgeTooltip content="Upload a custom logo to use on QR codes for links under this domain." />
</div>
</div>

<div className="flex items-center justify-between">
Expand Down
13 changes: 6 additions & 7 deletions apps/web/ui/modals/link-builder/qr-code-preview.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import useDomain from "@/lib/swr/use-domain";
import { QRCode } from "@/ui/shared/qr-code";
import {
Button,
Expand All @@ -7,8 +8,7 @@ import {
useMediaQuery,
} from "@dub/ui";
import { Pen2, QRCode as QRCodeIcon } from "@dub/ui/src/icons";
import { linkConstructor } from "@dub/utils";
import { DUB_QR_LOGO } from "@dub/utils/src/constants";
import { DUB_QR_LOGO, linkConstructor } from "@dub/utils";
import { AnimatePresence, motion } from "framer-motion";
import { useContext, useMemo } from "react";
import { useFormContext } from "react-hook-form";
Expand All @@ -18,14 +18,15 @@ import { QRCodeDesign, useLinkQRModal } from "../link-qr-modal";

export function QRCodePreview() {
const { isMobile } = useMediaQuery();
const { workspaceLogo, workspacePlan, workspaceId } =
useContext(LinkModalContext);
const { workspacePlan, workspaceId } = useContext(LinkModalContext);

const { watch } = useFormContext<LinkFormData>();
const { key: rawKey, domain: rawDomain } = watch();
const [key] = useDebounce(rawKey, 500);
const [domain] = useDebounce(rawDomain, 500);

const { logo: domainLogo } = useDomain(rawDomain);

const [data, setData] = useLocalStorage<QRCodeDesign>(
`qr-code-design-${workspaceId}`,
{
Expand All @@ -39,9 +40,7 @@ export function QRCodePreview() {
}, [key, domain]);

const hideLogo = data.hideLogo && workspacePlan !== "free";

const logo =
workspaceLogo && workspacePlan !== "free" ? workspaceLogo : DUB_QR_LOGO;
const logo = domainLogo || DUB_QR_LOGO;

const { LinkQRModal, setShowLinkQRModal } = useLinkQRModal({
props: {
Expand Down
8 changes: 5 additions & 3 deletions apps/web/ui/modals/link-qr-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getQRAsCanvas, getQRAsSVGDataUri, getQRData } from "@/lib/qr";
import useDomain from "@/lib/swr/use-domain";
import useWorkspace from "@/lib/swr/use-workspace";
import { QRLinkProps } from "@/lib/types";
import { QRCode } from "@/ui/shared/qr-code";
Expand Down Expand Up @@ -90,9 +91,10 @@ function LinkQRModalInner({
showLinkQRModal: boolean;
setShowLinkQRModal: Dispatch<SetStateAction<boolean>>;
} & LinkQRModalProps) {
const { logo: workspaceLogo, plan, id: workspaceId, slug } = useWorkspace();
const { plan, id: workspaceId, slug } = useWorkspace();
const id = useId();
const { isMobile } = useMediaQuery();
const { logo: domainLogo } = useDomain(props.domain);

const url = useMemo(() => {
return props.key && props.domain
Expand All @@ -107,10 +109,10 @@ function LinkQRModalInner({
hideLogo: false,
},
);
const [data, setData] = useState(dataPersisted);

const logo = workspaceLogo && plan !== "free" ? workspaceLogo : DUB_QR_LOGO;
const [data, setData] = useState(dataPersisted);

const logo = domainLogo || DUB_QR_LOGO;
const hideLogo = data.hideLogo && plan !== "free";

const qrData = useMemo(
Expand Down

0 comments on commit 0d478fb

Please sign in to comment.