From 9dd7bdb3b62637babe1674b2fc98877f3c2efdc7 Mon Sep 17 00:00:00 2001 From: Yee Kit Date: Mon, 20 May 2024 17:15:16 +0800 Subject: [PATCH] Hotfix: createdCollectionID is sometimes undefined --- frontend/app/components/ui/query/query-document-upload.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/app/components/ui/query/query-document-upload.tsx b/frontend/app/components/ui/query/query-document-upload.tsx index 4e66d15..4ea5afe 100644 --- a/frontend/app/components/ui/query/query-document-upload.tsx +++ b/frontend/app/components/ui/query/query-document-upload.tsx @@ -19,7 +19,6 @@ export default function QueryDocumentUpload() { const indexerApi = process.env.NEXT_PUBLIC_INDEXER_API; const { data: session } = useSession(); const supabaseAccessToken = session?.supabaseAccessToken; - const [createdCollectionId, setCreatedCollectionId] = useState(''); // NOTE: allowedTypes is an array of allowed MIME types for file uploads // The allowedTypesString is a string of allowed file extensions for the file input // Both must be kept in sync to ensure that the file input only accepts the allowed file types @@ -94,6 +93,7 @@ export default function QueryDocumentUpload() { }; const handleSubmit = (event: React.FormEvent) => { + let createdCollectionId = ''; event.preventDefault(); // Perform validation and submit logic here console.log("Display Name:", displayName); @@ -152,7 +152,8 @@ export default function QueryDocumentUpload() { // Get the response data const data = await response.json(); console.log('Insert New Collection Results:', data); - setCreatedCollectionId(data.collectionId); + createdCollectionId = await data.collectionId; // ensure that the collection_id is returned + console.log('Created Collection ID:', createdCollectionId); // Show success dialog Swal.fire({ title: 'Success!', @@ -296,8 +297,6 @@ export default function QueryDocumentUpload() { }); setisLoading(false); }); - // Reset createCollectionId state - setCreatedCollectionId(''); } else { setisLoading(false);