The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
wip
Kiran K062568248569
diff --git a/apps/web/lib/partnerstack/types.ts b/apps/web/lib/partnerstack/types.tsindex e2db94c8b3..aca341366d 100644--- a/apps/web/lib/partnerstack/types.ts+++ b/apps/web/lib/partnerstack/types.ts@@ -1,31 +1,53 @@import { z } from "zod";-import {- partnerStackCommission,- partnerStackCustomer,- partnerStackImportPayloadSchema,- partnerStackLink,- partnerStackPartner,-} from "./schemas";export interface PartnerStackConfig {- publicKey: string;- secretKey: string;+ token: string;+ userId: string;+ partnerstackProgramId?: string;}export interface PartnerStackListResponse<T> {- data: {- items: T[];- };+ success: true;+ total_count: number;+ data: T[];}-export type PartnerStackImportPayload = z.infer<- typeof partnerStackImportPayloadSchema->;--export type PartnerStackPartner = z.infer<typeof partnerStackPartner>;+// Basic types - these will be expanded as we implement the API+export interface PartnerStackAffiliate {+ id: string;+ email: string;+ first_name: string;+ last_name: string;+ company_name?: string;+ country_code?: string;+ profile_type?: string;+ created_at: string;+}-export type PartnerStackLink = z.infer<typeof partnerStackLink>;+export interface PartnerStackLink {+ id: string;+ tracking_url: string;+ token: string;+ partner_id: string;+ created_at: string;+}-export type PartnerStackCustomer = z.infer<typeof partnerStackCustomer>;+export interface PartnerStackReferral {+ id: string;+ email: string;+ first_name: string;+ last_name: string;+ company_name?: string;+ partner_id: string;+ created_at: string;+}-export type PartnerStackCommission = z.infer<typeof partnerStackCommission>;+export interface PartnerStackCommission {+ id: string;+ amount: number;+ commission_amount: number;+ status: string;+ partner_id: string;+ customer_id: string;+ created_at: string;+}diff --git a/apps/web/ui/modals/import-partnerstack-modal.tsx b/apps/web/ui/modals/import-partnerstack-modal.tsxindex 73ed42d1b4..7487be79a2 100644--- a/apps/web/ui/modals/import-partnerstack-modal.tsx+++ b/apps/web/ui/modals/import-partnerstack-modal.tsx@@ -1,3 +1,4 @@+import { setPartnerStackTokenAction } from "@/lib/actions/partners/set-partnerstack-token";import { startPartnerStackImportAction } from "@/lib/actions/partners/start-partnerstack-import";import useWorkspace from "@/lib/swr/use-workspace";import { Button, Logo, Modal, useMediaQuery, useRouterStuff } from "@dub/ui";@@ -51,9 +52,7 @@ function ImportPartnerStackModal({<ArrowRight className="h-5 w-5 text-neutral-600" /><Logo /></div>- <h3 className="text-lg font-medium">- Import Your PartnerStack Program- </h3>+ <h3 className="text-lg font-medium">Import Your PartnerStack Program</h3><p className="text-center text-sm text-neutral-500">Import your existing PartnerStack program into{" "}{process.env.NEXT_PUBLIC_APP_NAME} with just a few clicks.@@ -74,93 +73,109 @@ function ImportPartnerStackModal({);}-function TokenForm({ onClose }: { onClose: () => void }) {- const router = useRouter();+function TokenForm({+ onClose,+}: {+ onClose: () => void;+}) {const { isMobile } = useMediaQuery();- const [publicKey, setPublicKey] = useState("");- const [secretKey, setSecretKey] = useState("");+ const router = useRouter();const { id: workspaceId, slug } = useWorkspace();- const { executeAsync, isPending } = useAction(startPartnerStackImportAction, {- onSuccess: () => {- onClose();- toast.success(- "Successfully added program to import queue! We will send you an email when your program has been fully imported.",- );- router.push(`/${slug}/program/partners`);- },- onError: ({ error }) => {- toast.error(error.serverError);+ const [token, setToken] = useState("");++ const { executeAsync: setTokenAsync, isPending: isSettingToken } = useAction(+ setPartnerStackTokenAction,+ {+ onError: ({ error }) => {+ toast.error(error.serverError);+ },},- });+ );++ const { executeAsync: startImportAsync, isPending: isStartingImport } =+ useAction(startPartnerStackImportAction, {+ onSuccess: () => {+ onClose();+ toast.success(+ "Successfully added program to import queue! We will send you an email when your program has been fully imported.",+ );+ router.push(`/${slug}/program/partners`);+ },+ onError: ({ error }) => {+ toast.error(error.serverError);+ },+ });const onSubmit = async (e: React.FormEvent) => {e.preventDefault();- if (!workspaceId || !publicKey || !secretKey) {- toast.error("Please fill in all required fields.");+ if (!workspaceId || !token) {return;}- await executeAsync({- workspaceId,- publicKey,- secretKey,- });+ try {+ // First set the token+ await setTokenAsync({+ workspaceId,+ token,+ });++ // Then start the import+ await startImportAsync({+ workspaceId,+ });+ } catch (error) {+ // Error handling is done in the action callbacks+ console.error("Import error:", error);+ }};+ const isLoading = isSettingToken || isStartingImport;+return (<form onSubmit={onSubmit} className="flex flex-col space-y-4"><div><label- htmlFor="publicKey"+ htmlFor="token"className="block text-sm font-medium text-neutral-700">- PartnerStack Public Key+ PartnerStack API Key</label><inputtype="password"- id="publicKey"- value={publicKey}+ id="token"+ value={token}autoFocus={!isMobile}- onChange={(e) => setPublicKey(e.target.value)}+ onChange={(e) => setToken(e.target.value)}className="mt-1 block w-full rounded-md border border-neutral-200 px-3 py-2 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"required/><p className="mt-1.5 text-xs text-neutral-500">You can find your PartnerStack API key in your{" "}<a- href="https://app.partnerstack.com/settings/integrations"+ href="https://app.partnerstack.com/settings/api"target="_blank"rel="noopener noreferrer"className="text-blue-500 hover:text-blue-600">- Settings+ API settings</a></p></div>- <div>- <label- htmlFor="secretKey"- className="block text-sm font-medium text-neutral-700"- >- PartnerStack Secret Key- </label>- <input- type="password"- id="secretKey"- value={secretKey}- onChange={(e) => setSecretKey(e.target.value)}- className="mt-1 block w-full rounded-md border border-neutral-200 px-3 py-2 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"- required- />- </div>+<Button- text={isPending ? "Starting import..." : "Start Import"}- loading={isPending}- disabled={!publicKey || !secretKey}+ text={+ isLoading+ ? isSettingToken+ ? "Validating credentials..."+ : "Starting import..."+ : "Start Import"+ }+ loading={isLoading}+ disabled={!token || isLoading}/></form>);@@ -185,4 +200,4 @@ export function useImportPartnerStackModal() {setShowImportPartnerStackModal,ImportPartnerStackModal: ImportPartnerStackModalCallback,};-}+}\ No newline at end of file