From 7a04eacaac615890229e507dd5a546da0f329dea Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Sat, 12 Apr 2025 00:47:31 +0000 Subject: [PATCH] Refactor: Update API token management to use customer context instead of organization context. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/ecabd077-2aac-4a91-b90f-ed6223e22432.jpg --- client/src/pages/api-tokens.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/src/pages/api-tokens.tsx b/client/src/pages/api-tokens.tsx index 8d2ccad..bd22edb 100644 --- a/client/src/pages/api-tokens.tsx +++ b/client/src/pages/api-tokens.tsx @@ -3,7 +3,7 @@ import { useQuery, useMutation } from "@tanstack/react-query"; import { MainLayout } from "@/components/layouts/main-layout"; import { ApiToken, InsertApiToken, systemRoles, CustomRole } from "@shared/schema"; import { useAuth } from "@/hooks/use-auth"; -import { useOrganization } from "@/context/organization-context"; +import { useCustomer } from "@/context/customer-context"; import { apiRequest, queryClient } from "@/lib/queryClient"; import { useToast } from "@/hooks/use-toast"; import { useForm, useWatch } from "react-hook-form"; @@ -110,7 +110,7 @@ const tokenFormSchema = z.object({ export default function ApiTokensPage() { const { toast } = useToast(); const { user } = useAuth(); - const { currentOrganization } = useOrganization(); + const { currentCustomer } = useCustomer(); const [isAddTokenDialogOpen, setIsAddTokenDialogOpen] = useState(false); const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false); @@ -123,8 +123,8 @@ export default function ApiTokensPage() { // Fetch API tokens const { data: tokens = [], isLoading } = useQuery({ - queryKey: ["/api/api-tokens", currentOrganization?.id], - enabled: !!currentOrganization?.id, + queryKey: ["/api/api-tokens", currentCustomer?.id], + enabled: !!currentCustomer?.id, }); // Fetch custom roles @@ -148,7 +148,7 @@ export default function ApiTokensPage() { // Instead of using expiresAt directly, send the form data and let the server handle it const tokenData: any = { name: data.name, - organizationId: currentOrganization?.id || "1", + customerId: currentCustomer?.id || "1", role: data.role, isActive: true, expiresIn: data.expiresIn || 'never', @@ -179,7 +179,7 @@ export default function ApiTokensPage() { return await res.json(); }, onSuccess: (data) => { - queryClient.invalidateQueries({ queryKey: ["/api/api-tokens", currentOrganization?.id] }); + queryClient.invalidateQueries({ queryKey: ["/api/api-tokens", currentCustomer?.id] }); setIsAddTokenDialogOpen(false); setNewToken(data.token); setShowTokenDialog(true); @@ -204,7 +204,7 @@ export default function ApiTokensPage() { await apiRequest("DELETE", `/api/api-tokens/${tokenId}`); }, onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ["/api/api-tokens", currentOrganization?.id] }); + queryClient.invalidateQueries({ queryKey: ["/api/api-tokens", currentCustomer?.id] }); setIsDeleteDialogOpen(false); setSelectedToken(null); toast({ @@ -229,7 +229,7 @@ export default function ApiTokensPage() { }, onSuccess: (data) => { // Force refresh the tokens list - queryClient.invalidateQueries({ queryKey: ["/api/api-tokens", currentOrganization?.id] }); + queryClient.invalidateQueries({ queryKey: ["/api/api-tokens", currentCustomer?.id] }); // If we're viewing the token details dialog, update the selected token if (isViewTokenDialogOpen && selectedToken && data.id === selectedToken.id) {