fix(frontend): correct submission version field name

Fix pending submission detection by using 'agent_version' field instead
of 'version' to match the StoreSubmission interface. This ensures
creators don't see duplicate publish update banners when they have
pending submissions.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Zamil Majdy
2025-12-18 08:41:20 +01:00
parent ca53b752d2
commit fc0d0903f2
2 changed files with 43 additions and 15 deletions

View File

@@ -5,7 +5,7 @@ import { Text } from "@/components/atoms/Text/Text";
import { Breadcrumbs } from "@/components/molecules/Breadcrumbs/Breadcrumbs";
import { ErrorCard } from "@/components/molecules/ErrorCard/ErrorCard";
import { cn } from "@/lib/utils";
import { PlusIcon, Clock } from "@phosphor-icons/react";
import { PlusIcon } from "@phosphor-icons/react";
import * as React from "react";
import { RunAgentModal } from "./components/modals/RunAgentModal/RunAgentModal";
import { useMarketplaceUpdate } from "./hooks/useMarketplaceUpdate";
@@ -203,14 +203,6 @@ export function NewAgentLibraryView() {
initialInputValues={activeTemplate?.inputs}
initialInputCredentials={activeTemplate?.credentials}
/>
<Button
size="small"
variant="ghost"
onClick={() => setChangelogOpen(true)}
className="mt-3 w-full text-neutral-600 hover:bg-neutral-100 hover:text-neutral-900 dark:text-neutral-400 dark:hover:bg-neutral-800 dark:hover:text-neutral-100"
>
<Clock size={16} /> Version History
</Button>
</div>
<SidebarRunsList

View File

@@ -1,4 +1,7 @@
import { useGetV2GetSpecificAgent } from "@/app/api/__generated__/endpoints/store/store";
import {
useGetV2GetSpecificAgent,
useGetV2ListMySubmissions,
} from "@/app/api/__generated__/endpoints/store/store";
import {
usePatchV2UpdateLibraryAgent,
getGetV2GetLibraryAgentQueryKey,
@@ -6,6 +9,7 @@ import {
import { useToast } from "@/components/molecules/Toast/use-toast";
import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
import { useQueryClient } from "@tanstack/react-query";
import { useSupabaseStore } from "@/lib/supabase/hooks/useSupabaseStore";
import * as React from "react";
import { useState } from "react";
@@ -17,6 +21,7 @@ export function useMarketplaceUpdate({ agent }: UseMarketplaceUpdateProps) {
const [modalOpen, setModalOpen] = useState(false);
const { toast } = useToast();
const queryClient = useQueryClient();
const user = useSupabaseStore((state) => state.user);
// Get marketplace data if agent has marketplace listing
const { data: storeAgentData } = useGetV2GetSpecificAgent(
@@ -32,6 +37,16 @@ export function useMarketplaceUpdate({ agent }: UseMarketplaceUpdateProps) {
},
);
// Get user's submissions to check for pending submissions
const { data: submissionsData } = useGetV2ListMySubmissions(
{ page: 1, page_size: 50 }, // Get enough to cover recent submissions
{
query: {
enabled: !!user?.id, // Only fetch if user is authenticated
},
},
);
const updateToLatestMutation = usePatchV2UpdateLibraryAgent({
mutation: {
onError: (err) => {
@@ -76,11 +91,32 @@ export function useMarketplaceUpdate({ agent }: UseMarketplaceUpdateProps) {
? Math.max(...storeAgent.agentGraphVersions.map((v) => parseInt(v, 10)))
: undefined;
// For now, we treat all users as non-creators for marketplace updates
// TODO: Implement proper creator detection if needed
const isUserCreator = false;
// Determine if the user is the creator of this agent
// Compare current user ID with the marketplace listing creator ID
const isUserCreator =
user?.id && agent.marketplace_listing?.creator.id === user.id;
// Check if there's a pending submission for this specific agent version
const hasPendingSubmissionForCurrentVersion =
isUserCreator &&
submissionsData?.status === 200 &&
submissionsData.data.submissions.some(
(submission) =>
submission.agent_id === agent.graph_id &&
submission.agent_version === agent.graph_version &&
submission.status === "PENDING",
);
// If user is creator and their version is newer than marketplace, show publish update banner
// BUT only if there's no pending submission for this version
const hasPublishUpdate =
isUserCreator &&
!hasPendingSubmissionForCurrentVersion &&
latestMarketplaceVersion !== undefined &&
agent.graph_version > latestMarketplaceVersion;
// If marketplace version is newer than user's version, show update banner
// This applies to both creators and non-creators
const hasMarketplaceUpdate =
latestMarketplaceVersion !== undefined &&
latestMarketplaceVersion > agent.graph_version;
@@ -89,9 +125,9 @@ export function useMarketplaceUpdate({ agent }: UseMarketplaceUpdateProps) {
hasUpdate: hasMarketplaceUpdate,
latestVersion: latestMarketplaceVersion,
isUserCreator,
hasPublishUpdate: false, // TODO: Implement creator publish update detection
hasPublishUpdate,
};
}, [agent, storeAgentData]);
}, [agent, storeAgentData, user, submissionsData]);
const handlePublishUpdate = () => {
setModalOpen(true);