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.

Update import-partnerstack-modal.tsx

Kiran K8ae89d43cb87
diff --git a/apps/web/ui/modals/import-partnerstack-modal.tsx b/apps/web/ui/modals/import-partnerstack-modal.tsx
index 7487be79a2..73ed42d1b4 100644
--- a/apps/web/ui/modals/import-partnerstack-modal.tsx
+++ b/apps/web/ui/modals/import-partnerstack-modal.tsx
@@ -1,4 +1,3 @@
-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";
@@ -52,7 +51,9 @@ 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.
@@ -73,109 +74,93 @@ function ImportPartnerStackModal({
);
}
-function TokenForm({
- onClose,
-}: {
- onClose: () => void;
-}) {
- const { isMobile } = useMediaQuery();
+function TokenForm({ onClose }: { onClose: () => void }) {
const router = useRouter();
+ const { isMobile } = useMediaQuery();
+ const [publicKey, setPublicKey] = useState("");
+ const [secretKey, setSecretKey] = useState("");
const { id: workspaceId, slug } = useWorkspace();
- const [token, setToken] = useState("");
-
- const { executeAsync: setTokenAsync, isPending: isSettingToken } = useAction(
- setPartnerStackTokenAction,
- {
- onError: ({ error }) => {
- toast.error(error.serverError);
- },
+ 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`);
},
- );
-
- 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);
- },
- });
+ onError: ({ error }) => {
+ toast.error(error.serverError);
+ },
+ });
const onSubmit = async (e: React.FormEvent) => {
e.preventDefault();
- if (!workspaceId || !token) {
+ if (!workspaceId || !publicKey || !secretKey) {
+ toast.error("Please fill in all required fields.");
return;
}
- 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);
- }
+ await executeAsync({
+ workspaceId,
+ publicKey,
+ secretKey,
+ });
};
- const isLoading = isSettingToken || isStartingImport;
-
return (
<form onSubmit={onSubmit} className="flex flex-col space-y-4">
<div>
<label
- htmlFor="token"
+ htmlFor="publicKey"
className="block text-sm font-medium text-neutral-700"
>
- PartnerStack API Key
+ PartnerStack Public Key
</label>
<input
type="password"
- id="token"
- value={token}
+ id="publicKey"
+ value={publicKey}
autoFocus={!isMobile}
- onChange={(e) => setToken(e.target.value)}
+ onChange={(e) => setPublicKey(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/api"
+ href="https://app.partnerstack.com/settings/integrations"
target="_blank"
rel="noopener noreferrer"
className="text-blue-500 hover:text-blue-600"
>
- API settings
+ 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={
- isLoading
- ? isSettingToken
- ? "Validating credentials..."
- : "Starting import..."
- : "Start Import"
- }
- loading={isLoading}
- disabled={!token || isLoading}
+ text={isPending ? "Starting import..." : "Start Import"}
+ loading={isPending}
+ disabled={!publicKey || !secretKey}
/>
</form>
);
@@ -200,4 +185,4 @@ export function useImportPartnerStackModal() {
setShowImportPartnerStackModal,
ImportPartnerStackModal: ImportPartnerStackModalCallback,
};
-}
\ No newline at end of file
+}