From 486cd4a25531e1ae9cdfb57c6067934017af1c89 Mon Sep 17 00:00:00 2001 From: MananTank Date: Mon, 28 Oct 2024 18:00:38 +0000 Subject: [PATCH] Fix API key creation on embed page (#5192) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: DASH-340 --- ## PR-Codex overview This PR focuses on enhancing the `CreateAPIKey` functionality by introducing prefill options for the API key creation process, improving the user interface for creating API keys, and adding a modal for better user experience. ### Detailed summary - Added `CreateAPIKeyPrefillOptions` type. - Introduced `DesktopAPIKeyWordingWithPrefill` story. - Updated `CreateAPIKeyDialogProps` to include `prefill`. - Modified `CreateAPIKeyDialogUI` to accept and use `prefill`. - Enhanced `CreateAPIKeyForm` to utilize prefill values. - Integrated `LazyCreateAPIKeyDialog` in the `EmbedSetup` component. - Updated button behavior to show modal for creating API keys. - Improved user prompts for signing in when no active account is detected. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../[contractAddress]/embed/embed-setup.tsx | 134 +++++++++--------- .../Create/CreateApiKeyModal.stories.tsx | 14 +- .../settings/ApiKeys/Create/index.tsx | 13 +- 3 files changed, 89 insertions(+), 72 deletions(-) diff --git a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/embed/embed-setup.tsx b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/embed/embed-setup.tsx index eb20ae201d8..a78ab073489 100644 --- a/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/embed/embed-setup.tsx +++ b/apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/embed/embed-setup.tsx @@ -1,19 +1,22 @@ "use client"; +import { Button } from "@/components/ui/button"; import { useApiKeys, useCreateApiKey } from "@3rdweb-sdk/react/hooks/useApi"; -import { Flex, FormControl, Input, Link, Select } from "@chakra-ui/react"; +import { Flex, FormControl, Input, Select } from "@chakra-ui/react"; +import { LazyCreateAPIKeyDialog } from "components/settings/ApiKeys/Create/LazyCreateAPIKeyDialog"; import { useTrack } from "hooks/analytics/useTrack"; import { useAllChainsData } from "hooks/chains/allChains"; import { useClipboard } from "hooks/useClipboard"; -import { useTxNotifications } from "hooks/useTxNotifications"; import { CheckIcon, CopyIcon } from "lucide-react"; -import { useMemo } from "react"; +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { useMemo, useState } from "react"; import { useForm } from "react-hook-form"; import type { StoredChain } from "stores/chainStores"; import type { ThirdwebContract } from "thirdweb"; import type { ChainMetadata } from "thirdweb/chains"; +import { useActiveAccount } from "thirdweb/react"; import { - Button, Card, CodeBlock, FormHelperText, @@ -211,10 +214,6 @@ export const EmbedSetup: React.FC = ({ const apiKeys = useApiKeys(); const createKeyMutation = useCreateApiKey(); - const { onSuccess, onError } = useTxNotifications( - "API key created", - "Failed to create API key", - ); const validApiKey = (apiKeys.data || []).find( (apiKey) => @@ -298,14 +297,35 @@ export const EmbedSetup: React.FC = ({ ); const { hasCopied, onCopy } = useClipboard(embedCode, 3000); + const [showCreateAPIKeyModal, setShowCreateAPIKeyModal] = useState(false); + const activeAccount = useActiveAccount(); + const pathname = usePathname(); return ( + { + trackEvent({ + category: "api-keys", + action: "create", + label: "success", + fromEmbed: true, + }); + apiKeys.refetch(); + }} + /> + - - - Configuration - + + Configuration + {ercOrMarketplace === "marketplace" ? ( Listing ID @@ -315,6 +335,7 @@ export const EmbedSetup: React.FC = ({ ) : null} + {ercOrMarketplace === "marketplace-v3" ? ( Listing type @@ -327,6 +348,7 @@ export const EmbedSetup: React.FC = ({ ) : null} + {ercOrMarketplace === "marketplace-v3" && watch("listingType") === "direct-listing" ? ( @@ -337,6 +359,7 @@ export const EmbedSetup: React.FC = ({ ) : null} + {ercOrMarketplace === "marketplace-v3" && watch("listingType") === "english-auction" ? ( @@ -347,6 +370,7 @@ export const EmbedSetup: React.FC = ({ ) : null} + {ercOrMarketplace === "erc1155" ? ( Token ID @@ -356,9 +380,20 @@ export const EmbedSetup: React.FC = ({ ) : null} + Client ID - {validApiKey ? ( + {!activeAccount ? ( + + ) : validApiKey ? ( = ({ /> ) : (