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.

WIP adding online presence form to settings

Tim Wilson86742c3aa11d
diff --git a/apps/web/app/partners.dub.co/(dashboard)/settings/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/settings/page-client.tsx
index 1182312925..c50223d81d 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/settings/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/settings/page-client.tsx
@@ -12,6 +12,7 @@ import {
useEnterSubmit,
} from "@dub/ui";
import { cn, DICEBEAR_AVATAR_URL } from "@dub/utils";
+import { OnlinePresenceForm } from "app/partners.dub.co/(onboarding)/onboarding/online-presence/online-presence-form";
import { useAction } from "next-safe-action/hooks";
import { PropsWithChildren, useRef } from "react";
import { Controller, useForm } from "react-hook-form";
@@ -22,7 +23,7 @@ export function ProfileSettingsPageClient() {
const { partner, error } = usePartnerProfile();
return (
- <MaxWidthWrapper>
+ <MaxWidthWrapper className="mb-20 flex flex-col gap-8">
<div className="max-w-screen-md rounded-lg border border-neutral-200 bg-white">
<div className="border-b border-neutral-200 p-6">
<h2 className="text-xl font-medium text-neutral-800">About you</h2>
@@ -41,6 +42,30 @@ export function ProfileSettingsPageClient() {
</div>
)}
</div>
+
+ <div className="max-w-screen-md rounded-lg border border-neutral-200 bg-white">
+ <div className="border-b border-neutral-200 p-6">
+ <h2 className="text-xl font-medium text-neutral-800">
+ Online presence
+ </h2>
+ <p className="text-sm text-neutral-700">
+ These improve your reputation score and rank you higher.{" "}
+ </p>
+ </div>
+ {partner ? (
+ <OnlinePresenceForm partner={partner} variant="settings" />
+ ) : (
+ <div className="flex h-32 w-full items-center justify-center">
+ {error ? (
+ <span className="text-sm text-neutral-500">
+ Failed to load online presence data
+ </span>
+ ) : (
+ <LoadingSpinner />
+ )}
+ </div>
+ )}
+ </div>
</MaxWidthWrapper>
);
}
diff --git a/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/online-presence-form.tsx b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/online-presence-form.tsx
index 92a023d13e..af8e28dac6 100644
--- a/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/online-presence-form.tsx
+++ b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/online-presence-form.tsx
@@ -14,8 +14,7 @@ import {
} from "@dub/ui";
import { cn } from "@dub/utils/src/functions";
import { useAction } from "next-safe-action/hooks";
-import { useRouter } from "next/navigation";
-import { useState } from "react";
+import { ReactNode, useState } from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { mutate } from "swr";
@@ -32,7 +31,7 @@ const onlinePresenceSchema = z.object({
type OnlinePresenceFormData = z.infer<typeof onlinePresenceSchema>;
interface OnlinePresenceFormProps {
- country: string | null;
+ variant?: "onboarding" | "settings";
partner?: {
website: string | null;
instagram: string | null;
@@ -40,14 +39,14 @@ interface OnlinePresenceFormProps {
youtube: string | null;
twitter: string | null;
} | null;
+ onSubmitSuccessful?: () => void;
}
export function OnlinePresenceForm({
- country,
+ variant = "onboarding",
partner,
+ onSubmitSuccessful,
}: OnlinePresenceFormProps) {
- const router = useRouter();
-
const { partner: partnerProfile } = usePartnerProfile();
const {
@@ -114,211 +113,250 @@ export function OnlinePresenceForm({
onSubmit={handleSubmit(async (data) => {
const result = await executeAsync(data);
- if (result?.data?.success)
- router.push(country === "US" ? "/onboarding/verify" : "/programs");
+ if (result?.data?.success) onSubmitSuccessful?.();
})}
- className="flex w-full flex-col gap-4 text-left"
>
- <label>
- <span className="text-sm font-medium text-neutral-800">Website</span>
- <div className="relative">
- <input
- type="url"
- className={cn(
- "mt-2 block w-full rounded-md focus:outline-none sm:text-sm",
- errors.website
- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
- )}
- placeholder="https://example.com"
- {...register("website")}
- />
- <Button
- className={cn(
- "absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5",
- isWebsiteVerified &&
- "border-green-100 bg-green-100 text-green-700",
- )}
- variant="secondary"
- text={isWebsiteVerified ? "Verified" : "Verify"}
- icon={
- isWebsiteVerified ? (
- <CircleCheckFill className="size-4 text-green-700" />
- ) : (
- <Globe className="size-4" />
- )
- }
- loading={isSavingWebsite || !partnerProfile}
- disabled={
- !website ||
- getFieldState("website").invalid ||
- isWebsiteVerified
- }
- onClick={async () => {
- setIsSavingWebsite(true);
- try {
- const result = await updateOnlinePresenceAction({
- website: getValues("website"),
- });
-
- try {
- if (
- !result?.data?.website ||
- !result?.data?.websiteTxtRecord
- ) {
- throw new Error(
- "Missing website or TXT record in update result",
- );
- }
-
- setDomainVerificationData({
- domain: new URL(result.data.website).hostname,
- txtRecord: result.data.websiteTxtRecord,
- });
- } catch (e) {
- toast.error("Failed to start website verification");
- console.error("Failed to start website verification", e);
- }
-
- mutate("/api/partner-profile");
- } finally {
- setIsSavingWebsite(false);
- }
- }}
- />
- </div>
- <p className="mt-1.5 text-xs text-neutral-500">
- Verification may take up to 48 hours.
- </p>
- </label>
-
- <label>
- <span className="text-sm font-medium text-neutral-800">
- Instagram
- </span>
- <div className="relative">
- <div className="mt-2 flex rounded-md">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- instagram.com/
- </span>
+ <div
+ className={cn(
+ "flex w-full flex-col gap-4 text-left",
+ variant === "settings" && "p-5",
+ )}
+ >
+ <FormRow
+ label="Website"
+ input={
<input
- type="text"
+ type="url"
className={cn(
- "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
- errors.instagram
+ "block w-full rounded-md focus:outline-none sm:text-sm",
+ errors.website
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
)}
- placeholder="handle"
- {...register("instagram")}
+ placeholder="https://example.com"
+ {...register("website")}
/>
- </div>
- <Button
- className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
- variant="secondary"
- text="Verify"
- icon={<Instagram className="size-3.5" />}
- onClick={() => alert("WIP")}
- />
- </div>
- </label>
-
- <label>
- <span className="text-sm font-medium text-neutral-800">TikTok</span>
- <div className="relative">
- <div className="mt-2 flex rounded-md">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- tiktok.com/@
- </span>
- <input
- type="text"
+ }
+ button={
+ <Button
className={cn(
- "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
- errors.tiktok
- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ "absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5",
+ isWebsiteVerified &&
+ "border-green-100 bg-green-100 text-green-700",
)}
- placeholder="handle"
- {...register("tiktok")}
+ variant="secondary"
+ text={isWebsiteVerified ? "Verified" : "Verify"}
+ icon={
+ isWebsiteVerified ? (
+ <CircleCheckFill className="size-4 text-green-700" />
+ ) : (
+ <Globe className="size-4" />
+ )
+ }
+ loading={isSavingWebsite || !partnerProfile}
+ disabled={
+ !website ||
+ getFieldState("website").invalid ||
+ isWebsiteVerified
+ }
+ onClick={async () => {
+ setIsSavingWebsite(true);
+ try {
+ const result = await updateOnlinePresenceAction({
+ website: getValues("website"),
+ });
+
+ try {
+ if (
+ !result?.data?.website ||
+ !result?.data?.websiteTxtRecord
+ ) {
+ throw new Error(
+ "Missing website or TXT record in update result",
+ );
+ }
+
+ setDomainVerificationData({
+ domain: new URL(result.data.website).hostname,
+ txtRecord: result.data.websiteTxtRecord,
+ });
+ } catch (e) {
+ toast.error("Failed to start website verification");
+ console.error("Failed to start website verification", e);
+ }
+
+ mutate("/api/partner-profile");
+ } finally {
+ setIsSavingWebsite(false);
+ }
+ }}
/>
- </div>
- <Button
- className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
- variant="secondary"
- text="Verify"
- icon={<TikTok className="size-3.5" />}
- onClick={() => alert("WIP")}
- />
- </div>
- </label>
+ }
+ />
- <label>
- <span className="text-sm font-medium text-neutral-800">YouTube</span>
- <div className="relative">
- <div className="mt-2 flex rounded-md">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- youtube.com/@
- </span>
- <input
- type="text"
- className={cn(
- "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
- errors.youtube
- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
- )}
- placeholder="handle"
- {...register("youtube")}
+ <FormRow
+ label="Instagram"
+ input={
+ <div className="flex rounded-md">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ instagram.com/
+ </span>
+ <input
+ type="text"
+ className={cn(
+ "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ errors.instagram
+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ )}
+ placeholder="handle"
+ {...register("instagram")}
+ />
+ </div>
+ }
+ button={
+ <Button
+ className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
+ variant="secondary"
+ text="Verify"
+ icon={<Instagram className="size-3.5" />}
+ onClick={() => alert("WIP")}
/>
- </div>
- <Button
- className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
- variant="secondary"
- text="Verify"
- icon={<YouTube className="size-3.5" />}
- onClick={() => alert("WIP")}
- />
- </div>
- </label>
+ }
+ />
- <label>
- <span className="text-sm font-medium text-neutral-800">
- X/Twitter
- </span>
- <div className="relative">
- <div className="mt-2 flex rounded-md">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- x.com/
- </span>
- <input
- type="text"
- className={cn(
- "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
- errors.twitter
- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
- )}
- placeholder="handle"
- {...register("twitter")}
+ <FormRow
+ label="TikTok"
+ input={
+ <div className="flex rounded-md">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ tiktok.com/@
+ </span>
+ <input
+ type="text"
+ className={cn(
+ "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ errors.tiktok
+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ )}
+ placeholder="handle"
+ {...register("tiktok")}
+ />
+ </div>
+ }
+ button={
+ <Button
+ className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
+ variant="secondary"
+ text="Verify"
+ icon={<TikTok className="size-3.5" />}
+ onClick={() => alert("WIP")}
+ />
+ }
+ />
+
+ <FormRow
+ label="YouTube"
+ input={
+ <div className="flex rounded-md">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ youtube.com/@
+ </span>
+ <input
+ type="text"
+ className={cn(
+ "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ errors.youtube
+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ )}
+ placeholder="handle"
+ {...register("youtube")}
+ />
+ </div>
+ }
+ button={
+ <Button
+ className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
+ variant="secondary"
+ text="Verify"
+ icon={<YouTube className="size-3.5" />}
+ onClick={() => alert("WIP")}
+ />
+ }
+ />
+
+ <FormRow
+ label="X/Twitter"
+ input={
+ <div className="flex rounded-md">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ x.com/
+ </span>
+ <input
+ type="text"
+ className={cn(
+ "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ errors.twitter
+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ )}
+ placeholder="handle"
+ {...register("twitter")}
+ />
+ </div>
+ }
+ button={
+ <Button
+ className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
+ variant="secondary"
+ text="Verify"
+ icon={<Twitter className="size-3.5" />}
+ onClick={() => alert("WIP")}
/>
- </div>
+ }
+ />
+ </div>
+
+ {variant === "onboarding" ? (
+ <Button
+ type="submit"
+ text="Continue"
+ className="mt-6"
+ loading={isSubmitting || isSubmitSuccessful}
+ />
+ ) : (
+ <div className="flex justify-end rounded-b-lg border-t border-neutral-200 bg-neutral-100 px-5 py-3.5">
<Button
- className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
- variant="secondary"
- text="Verify"
- icon={<Twitter className="size-3.5" />}
- onClick={() => alert("WIP")}
+ type="submit"
+ text="Save changes"
+ className="h-8 w-fit px-2.5"
+ loading={isSubmitting}
/>
</div>
- </label>
-
- <Button
- type="submit"
- text="Continue"
- className="mt-2"
- loading={isSubmitting || isSubmitSuccessful}
- />
+ )}
</form>
</>
);
}
+
+function FormRow({
+ label,
+ input,
+ button,
+}: {
+ label: string;
+ input: ReactNode;
+ button: ReactNode;
+}) {
+ return (
+ <label>
+ <span className="text-sm font-medium text-neutral-800">{label}</span>
+ <div className="relative mt-2">
+ {input}
+ {button}
+ </div>
+ </label>
+ );
+}
diff --git a/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page-client.tsx b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page-client.tsx
new file mode 100644
index 0000000000..dc1f589d05
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page-client.tsx
@@ -0,0 +1,21 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+import { ComponentProps } from "react";
+import { OnlinePresenceForm } from "./online-presence-form";
+
+export function OnlinePresencePageClient({
+ country,
+ ...rest
+}: { country: string | null } & ComponentProps<typeof OnlinePresenceForm>) {
+ const router = useRouter();
+
+ return (
+ <OnlinePresenceForm
+ onSubmitSuccessful={() =>
+ router.push(country === "US" ? "/onboarding/verify" : "/programs")
+ }
+ {...rest}
+ />
+ );
+}
diff --git a/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page.tsx b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page.tsx
index 90a3e4ac79..d943bea42c 100644
--- a/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page.tsx
+++ b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page.tsx
@@ -2,6 +2,7 @@ import { getSession } from "@/lib/auth";
import { prisma } from "@dub/prisma";
import { Suspense } from "react";
import { OnlinePresenceForm } from "./online-presence-form";
+import { OnlinePresencePageClient } from "./page-client";
export default function OnlinePresencePage() {
return (
@@ -18,9 +19,7 @@ export default function OnlinePresencePage() {
</p>
<div className="mt-8">
- <Suspense
- fallback={<OnlinePresenceForm country={null} partner={null} />}
- >
+ <Suspense fallback={<OnlinePresenceForm partner={null} />}>
<OnlinePresenceFormRSC />
</Suspense>
</div>
@@ -76,7 +75,7 @@ async function OnlinePresenceFormRSC() {
}
return (
- <OnlinePresenceForm
+ <OnlinePresencePageClient
country={partner.country}
partner={{
...partner,