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.

Showing change country modal warning (#3486)

Marcus Farrell231861757381
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
index 6d61a6fefb..454365ce22 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx
@@ -4,6 +4,7 @@ import { mutatePrefix } from "@/lib/swr/mutate";
import { PartnerProps } from "@/lib/types";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
import { CountryCombobox } from "@/ui/partners/country-combobox";
+import { useCountryChangeWarningModal } from "@/ui/partners/use-country-change-warning-modal";
import {
PartnerPlatformsForm,
usePartnerPlatformsForm,
@@ -22,7 +23,7 @@ import {
import { OG_AVATAR_URL, cn } from "@dub/utils";
import { AnimatePresence, LayoutGroup, motion } from "motion/react";
import { useAction } from "next-safe-action/hooks";
-import { RefObject, useEffect, useRef } from "react";
+import { RefObject, useEffect, useRef, useState } from "react";
import {
Controller,
FormProvider,
@@ -171,6 +172,8 @@ function BasicInfoForm({
}, [isSubmitSuccessful, reset, getValues]);
const { profileType } = watch();
+ const [isCountryComboboxOpen, setIsCountryComboboxOpen] = useState(false);
+ const countryChangeWarning = useCountryChangeWarningModal();
const { executeAsync } = useAction(updatePartnerProfileAction, {
onSuccess: async ({ data }) => {
@@ -201,6 +204,12 @@ function BasicInfoForm({
},
});
+ const shouldShowCountryChangeWarning =
+ !disabled &&
+ !partner?.payoutsEnabledAt &&
+ !!partner?.country &&
+ !countryChangeWarning.isAcknowledged;
+
return (
<form
ref={formRef}
@@ -213,6 +222,7 @@ function BasicInfoForm({
});
})}
>
+ {countryChangeWarning.modal}
<div className="flex flex-col gap-6">
<label>
<div className="flex items-center gap-5">
@@ -302,6 +312,22 @@ function BasicInfoForm({
value={field.value || ""}
onChange={field.onChange}
error={errors.country ? true : false}
+ open={isCountryComboboxOpen}
+ onOpenChange={(open) => {
+ if (!open) {
+ setIsCountryComboboxOpen(false);
+ return;
+ }
+
+ if (shouldShowCountryChangeWarning) {
+ countryChangeWarning.acknowledgeAndContinue(() => {
+ setIsCountryComboboxOpen(true);
+ });
+ return;
+ }
+
+ setIsCountryComboboxOpen(true);
+ }}
disabledTooltip={
disabled ? (
"You don't have permission to update this field"
diff --git a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx
index 5def5cd422..68d054e821 100644
--- a/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(onboarding)/onboarding/onboarding-form.tsx
@@ -1,11 +1,11 @@
"use client";
import { parseActionError } from "@/lib/actions/parse-action-errors";
-import { PartnerData } from "@/lib/actions/partners/create-program-application";
import { onboardPartnerAction } from "@/lib/actions/partners/onboard-partner";
import { getValidInternalRedirectPath } from "@/lib/middleware/utils/is-valid-internal-redirect";
import { onboardPartnerSchema } from "@/lib/zod/schemas/partners";
import { CountryCombobox } from "@/ui/partners/country-combobox";
+import { useCountryChangeWarningModal } from "@/ui/partners/use-country-change-warning-modal";
import { Partner } from "@dub/prisma/client";
import {
Button,
@@ -13,7 +13,6 @@ import {
ToggleGroup,
TooltipContent,
useEnterSubmit,
- useLocalStorage,
useMediaQuery,
} from "@dub/ui";
import { cn } from "@dub/utils";
@@ -49,7 +48,9 @@ export function OnboardingForm({
const searchParams = useSearchParams();
const { isMobile } = useMediaQuery();
const [accountCreated, setAccountCreated] = useState(false);
+ const [isCountryComboboxOpen, setIsCountryComboboxOpen] = useState(false);
const { data: session, update: refreshSession } = useSession();
+ const countryChangeWarning = useCountryChangeWarningModal();
const {
register,
@@ -70,20 +71,14 @@ export function OnboardingForm({
},
});
- const { name, image, country, profileType } = watch();
-
- const [partnerData] = useLocalStorage<PartnerData | null>(
- `application-form-partner-data`,
- null,
- );
+ const { name, image, profileType } = watch();
useEffect(() => {
if (session?.user) {
- !name && setValue("name", partnerData?.name ?? session.user.name ?? "");
+ !name && setValue("name", session.user.name ?? "");
!image && setValue("image", session.user.image ?? "");
- !country && setValue("country", partnerData?.country ?? "");
}
- }, [session?.user, name, image, country, partnerData]);
+ }, [session?.user, name, image, setValue]);
// refresh the session after the Partner account is created
useEffect(() => {
@@ -118,6 +113,7 @@ export function OnboardingForm({
onSubmit={handleSubmit(async (data) => await executeAsync(data))}
className="flex w-full flex-col gap-6 text-left"
>
+ {countryChangeWarning.modal}
<label>
<span className="text-sm font-medium text-neutral-800">Name</span>
<input
@@ -180,6 +176,25 @@ export function OnboardingForm({
<CountryCombobox
{...field}
error={errors.country ? true : false}
+ open={isCountryComboboxOpen}
+ onOpenChange={(open) => {
+ if (!open) {
+ setIsCountryComboboxOpen(false);
+ return;
+ }
+
+ const shouldShowCountryChangeWarning =
+ !partner?.payoutsEnabledAt;
+
+ if (shouldShowCountryChangeWarning) {
+ countryChangeWarning.acknowledgeAndContinue(() => {
+ setIsCountryComboboxOpen(true);
+ });
+ return;
+ }
+
+ setIsCountryComboboxOpen(true);
+ }}
disabledTooltip={
partner?.payoutsEnabledAt ? (
<TooltipContent
diff --git a/apps/web/ui/layout/sidebar/user-dropdown.tsx b/apps/web/ui/layout/sidebar/user-dropdown.tsx
index d09997e587..c6c63f8b52 100644
--- a/apps/web/ui/layout/sidebar/user-dropdown.tsx
+++ b/apps/web/ui/layout/sidebar/user-dropdown.tsx
@@ -74,10 +74,11 @@ export function UserDropdown() {
type: "button",
label: "Log out",
icon: LogOut,
- onClick: () =>
+ onClick: () => {
signOut({
callbackUrl: "/login",
- }),
+ });
+ },
});
return options;
diff --git a/apps/web/ui/partners/country-combobox.tsx b/apps/web/ui/partners/country-combobox.tsx
index dfb3ae77f4..5548e299b2 100644
--- a/apps/web/ui/partners/country-combobox.tsx
+++ b/apps/web/ui/partners/country-combobox.tsx
@@ -8,12 +8,16 @@ export function CountryCombobox({
disabledTooltip,
error,
className,
+ open,
+ onOpenChange,
}: {
value: string;
onChange: (value: string) => void;
disabledTooltip?: string | ReactNode;
error?: boolean;
className?: string;
+ open?: boolean;
+ onOpenChange?: (open: boolean) => void;
}) {
const options = useMemo(
() =>
@@ -67,6 +71,8 @@ export function CountryCombobox({
),
disabledTooltip,
}}
+ open={open}
+ onOpenChange={onOpenChange}
/>
);
}
diff --git a/apps/web/ui/partners/use-country-change-warning-modal.tsx b/apps/web/ui/partners/use-country-change-warning-modal.tsx
new file mode 100644
index 0000000000..e624f42332
--- /dev/null
+++ b/apps/web/ui/partners/use-country-change-warning-modal.tsx
@@ -0,0 +1,83 @@
+"use client";
+
+import { Button, Modal } from "@dub/ui";
+import { useCallback, useRef, useState } from "react";
+
+export function useCountryChangeWarningModal() {
+ const [showModalState, setShowModalState] = useState(false);
+ const [isAcknowledged, setIsAcknowledged] = useState(false);
+ const onAcknowledgeRef = useRef<(() => void) | null>(null);
+
+ const handleCancel = useCallback(() => {
+ onAcknowledgeRef.current = null;
+ setShowModalState(false);
+ }, []);
+
+ const handleAcknowledge = useCallback(() => {
+ setIsAcknowledged(true);
+ setShowModalState(false);
+ onAcknowledgeRef.current?.();
+ onAcknowledgeRef.current = null;
+ }, []);
+
+ const modal = (
+ <Modal
+ showModal={showModalState}
+ setShowModal={setShowModalState}
+ onClose={handleCancel}
+ >
+ <div className="border-border-subtle bg-white border-b p-5 text-left">
+ <h3 className="text-content-emphasis text-base font-semibold">
+ Updating your country
+ </h3>
+ </div>
+
+ <div className="text-content-subtle bg-neutral-50 p-5 text-sm">
+ <p>
+ You must select the country where you legally reside for tax
+ purposes. Providing incorrect information may result in account
+ suspension, loss of payouts, and legal action.
+ </p>
+ <p className="mt-4">
+ Dub is not responsible for legal or tax consequences resulting from
+ misrepresentation.
+ </p>
+ </div>
+
+ <div className="border-border-subtle bg-neutral-50 flex items-center justify-end gap-2 border-t px-5 py-4">
+ <Button
+ variant="secondary"
+ className="h-8 w-fit px-3"
+ text="Cancel"
+ onClick={handleCancel}
+ />
+ <Button
+ variant="primary"
+ className="h-8 w-fit px-3"
+ text="I acknowledge"
+ onClick={handleAcknowledge}
+ />
+ </div>
+ </Modal>
+ );
+
+ const showModal = useCallback(() => {
+ onAcknowledgeRef.current = null;
+ setShowModalState(true);
+ }, []);
+
+ const acknowledgeAndContinue = useCallback(
+ (callback?: () => void) => {
+ onAcknowledgeRef.current = callback ?? null;
+ setShowModalState(true);
+ },
+ [],
+ );
+
+ return {
+ modal,
+ showModal,
+ isAcknowledged,
+ acknowledgeAndContinue,
+ };
+}