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.

supported countries embed page

Pedro Ladeira8d7bf9190eb8
diff --git a/apps/web/app/(ee)/app.dub.co/embed/supported-countries/country-grid.tsx b/apps/web/app/(ee)/app.dub.co/embed/supported-countries/country-grid.tsx
new file mode 100644
index 0000000000..81ea10231f
--- /dev/null
+++ b/apps/web/app/(ee)/app.dub.co/embed/supported-countries/country-grid.tsx
@@ -0,0 +1,59 @@
+"use client";
+
+import { useMediaQuery } from "@dub/ui";
+import { cn, COUNTRIES } from "@dub/utils";
+import { useState } from "react";
+
+export function CountryGrid({ countries }: { countries: string[] }) {
+ const { isMobile } = useMediaQuery();
+ const showCount = isMobile ? 16 : 30;
+ const [expanded, setExpanded] = useState(false);
+
+ const displayCountries =
+ countries.length <= showCount || expanded
+ ? countries
+ : countries.slice(0, showCount);
+
+ return (
+ <div className="not-prose relative px-2">
+ <div
+ className={cn(
+ "grid grid-cols-2 gap-5 py-4 sm:grid-cols-3",
+ countries.length > showCount && !expanded && "max-h-[420px]",
+ countries.length > showCount && expanded && "pb-12",
+ )}
+ >
+ {displayCountries.map((country) => (
+ <div key={country} className="flex items-center gap-3">
+ <img
+ src={`https://hatscripts.github.io/circle-flags/flags/${country.toLowerCase()}.svg`}
+ alt={country}
+ width={32}
+ height={32}
+ className="size-5 rounded-full border border-neutral-200 shadow-md"
+ draggable={false}
+ />
+ <span className="text-sm font-medium">{COUNTRIES[country]}</span>
+ </div>
+ ))}
+ </div>
+ {countries.length > showCount && (
+ <>
+ {!expanded && (
+ <div className="absolute bottom-0 h-24 w-full bg-gradient-to-t from-neutral-50 to-transparent" />
+ )}
+ <button
+ onClick={() => setExpanded(!expanded)}
+ className={`absolute left-1/2 -translate-x-1/2 transform rounded-full border border-gray-200 bg-white px-4 py-1 text-sm text-gray-500 shadow-sm hover:text-gray-700 ${
+ expanded ? "-bottom-2" : "bottom-6"
+ }`}
+ >
+ {expanded
+ ? "Show less"
+ : `Show ${countries.length - showCount} more`}
+ </button>
+ </>
+ )}
+ </div>
+ );
+}
diff --git a/apps/web/app/(ee)/app.dub.co/embed/supported-countries/page.tsx b/apps/web/app/(ee)/app.dub.co/embed/supported-countries/page.tsx
new file mode 100644
index 0000000000..8a15141ee9
--- /dev/null
+++ b/apps/web/app/(ee)/app.dub.co/embed/supported-countries/page.tsx
@@ -0,0 +1,21 @@
+import {
+ CONNECT_SUPPORTED_COUNTRIES,
+ COUNTRIES,
+ PAYPAL_SUPPORTED_COUNTRIES,
+} from "@dub/utils";
+import { CountryGrid } from "./country-grid";
+
+export function PayoutSupportedCountries() {
+ const supportedCountries = [
+ ...CONNECT_SUPPORTED_COUNTRIES,
+ ...PAYPAL_SUPPORTED_COUNTRIES,
+ ];
+ const sortedCountries = supportedCountries.sort((a, b) =>
+ COUNTRIES[a].localeCompare(COUNTRIES[b]),
+ );
+ return <CountryGrid countries={sortedCountries} />;
+}
+
+export default function SupportedCountriesEmbed() {
+ return <PayoutSupportedCountries />;
+}
diff --git a/apps/web/lib/middleware/embed.ts b/apps/web/lib/middleware/embed.ts
index 965ece1aa2..acf67e1d88 100644
--- a/apps/web/lib/middleware/embed.ts
+++ b/apps/web/lib/middleware/embed.ts
@@ -1,8 +1,14 @@
import { NextRequest, NextResponse } from "next/server";
import { parse } from "./utils/parse";
+const PUBLIC_EMBED_PATHS = ["/embed/supported-countries"];
+
export function EmbedMiddleware(req: NextRequest) {
- const { searchParamsObj, fullPath } = parse(req);
+ const { path, searchParamsObj, fullPath } = parse(req);
+
+ if (PUBLIC_EMBED_PATHS.some((p) => path === p || path.startsWith(`${p}/`))) {
+ return NextResponse.rewrite(new URL(`/app.dub.co${fullPath}`, req.url));
+ }
if (searchParamsObj.token) {
return NextResponse.rewrite(new URL(`/app.dub.co${fullPath}`, req.url));