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 'main' into partners-nav

Tim Wilson7579e2cb2ea2
diff --cc apps/web/ui/partners/online-presence-form.tsx
index 8b8e47ed59,da6a31f611..ac2092a017
--- a/apps/web/ui/partners/online-presence-form.tsx
+++ b/apps/web/ui/partners/online-presence-form.tsx
@@@ -68,82 -66,123 +68,88 @@@ export function useOnlinePresenceForm(
tiktok: partner?.tiktok || undefined,
},
});
+}
- const {
- register,
- setError,
- getValues,
- handleSubmit,
- reset,
- formState: { errors, isSubmitting, isSubmitSuccessful },
- } = form;
-
- const { executeAsync } = useAction(updateOnlinePresenceAction, {
- onSuccess: (result) => {
- if (!result?.data?.success)
- setError("root.serverError", {
- message: "Failed to update online presence",
- });
- else mutate("/api/partner-profile");
- },
- onError: ({ error }) => {
- toast.error(parseActionError(error, "Failed to update online presence"));
-
- reset(form.getValues(), { keepErrors: true });
- },
- });
-
- const [domainVerificationData, setDomainVerificationData] = useState<{
- domain: string;
- txtRecord: string;
- } | null>(null);
+type OnlinePresenceFormWithFormProps = OnlinePresenceFormProps & {
+ form?: ReturnType<typeof useOnlinePresenceForm>;
+};
- const startVerification = useOAuthVerification(variant);
+export const OnlinePresenceForm = forwardRef<
+ HTMLFormElement,
+ OnlinePresenceFormWithFormProps
+>(
+ (
+ {
+ form: formProp,
+ variant = "onboarding",
+ partner,
+ onSubmitSuccessful,
+ }: OnlinePresenceFormWithFormProps,
+ ref,
+ ) => {
+ const form = formProp ?? useOnlinePresenceForm({ partner });
- return (
- <>
- <DomainVerificationModal
- showDomainVerificationModal={domainVerificationData !== null}
- setShowDomainVerificationModal={() => setDomainVerificationData(null)}
- domain={domainVerificationData?.domain || ""}
- txtRecord={domainVerificationData?.txtRecord || ""}
- />
- <FormProvider {...form}>
- <form
- onSubmit={handleSubmit(async (data) => {
- const result = await executeAsync(data);
+ const {
+ register,
+ setError,
+ getValues,
+ handleSubmit,
+ reset,
+ formState: { errors, isSubmitting, isSubmitSuccessful },
+ } = form;
- if (result?.data?.success) onSubmitSuccessful?.();
- })}
- >
- <div
- className={cn(
- "flex w-full flex-col gap-6 text-left",
- variant === "settings" && "gap-0 divide-y divide-neutral-200 p-5",
- )}
- >
- <FormRow
- variant={variant}
- label="Website"
- input={
- <input
- type="text"
- className={cn(
- "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="example.com"
- {...register("website")}
- />
- }
- button={
- <VerifyButton
- property="website"
- verifiedAtField="websiteVerifiedAt"
- icon={Globe}
- onClick={async () => {
- try {
- const result =
- await updateOnlinePresenceAction(getValues());
+ const { executeAsync } = useAction(updateOnlinePresenceAction, {
+ onSuccess: (result) => {
+ if (!result?.data?.success)
+ setError("root.serverError", {
+ message: "Failed to update online presence",
+ });
+ else mutate("/api/partner-profile");
+ },
+ onError: ({ error }) => {
+ toast.error(
+ parseActionError(error, "Failed to update online presence"),
+ );
- if (
- !result?.data?.website ||
- !result?.data?.websiteTxtRecord
- ) {
- throw new Error(
- "Missing website or TXT record in update result",
- );
- }
+ reset(form.getValues(), { keepErrors: true });
+ },
+ });
- setDomainVerificationData({
- domain: new URL(result.data.website).hostname,
- txtRecord: result.data.websiteTxtRecord,
- });
+ const [domainVerificationData, setDomainVerificationData] = useState<{
+ domain: string;
+ txtRecord: string;
+ } | null>(null);
- mutate("/api/partner-profile");
- } catch (e) {
- toast.error("Failed to start website verification");
- console.error("Failed to start website verification", e);
- }
+ const startVerification = useOAuthVerification(variant);
- return false;
- }}
- />
- }
- />
+ return (
+ <>
+ <DomainVerificationModal
+ showDomainVerificationModal={domainVerificationData !== null}
+ setShowDomainVerificationModal={() => setDomainVerificationData(null)}
+ domain={domainVerificationData?.domain || ""}
+ txtRecord={domainVerificationData?.txtRecord || ""}
+ />
+ <FormProvider {...form}>
+ <form
+ ref={ref}
+ onSubmit={handleSubmit(async (data) => {
+ const result = await executeAsync(data);
- <FormRow
- variant={variant}
- 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>
- <span className="absolute inset-y-0 left-[6.7rem] flex items-center pl-3 text-sm text-neutral-400">
- @
- </span>
+ if (result?.data?.success) onSubmitSuccessful?.();
+ })}
+ >
- <div className={cn("flex w-full flex-col gap-4 text-left")}>
++ <div
++ className={cn(
++ "flex w-full flex-col gap-6 text-left",
++ variant === "settings" &&
++ "gap-0 divide-y divide-neutral-200 p-5",
++ )}
++ >
+ <FormRow
+ variant={variant}
+ label="Website"
+ input={
<input
type="text"
className={cn(