From 639053679ffe1c45c851dcaa865f79fba1a7ddf0 Mon Sep 17 00:00:00 2001 From: mit-27 Date: Tue, 21 May 2024 02:19:30 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Fix=20UI=20of=20Dynamic=20integr?= =?UTF-8?q?ations=20Catalog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/PanoraDynamicCatalog.tsx | 189 +++++++++++------- apps/embedded-catalog/react/src/global.css | 36 ++++ 2 files changed, 148 insertions(+), 77 deletions(-) diff --git a/apps/embedded-catalog/react/src/components/PanoraDynamicCatalog.tsx b/apps/embedded-catalog/react/src/components/PanoraDynamicCatalog.tsx index 14214565f..2e12cdf67 100644 --- a/apps/embedded-catalog/react/src/components/PanoraDynamicCatalog.tsx +++ b/apps/embedded-catalog/react/src/components/PanoraDynamicCatalog.tsx @@ -1,6 +1,7 @@ import React,{useState,useEffect} from 'react' import {findProviderByName, providersArray,categoriesVerticals,getLogoURL} from '@panora/shared'; import useOAuth from '@/hooks/useOAuth'; +import config from '@/helpers/config'; interface DynamicCardProp { projectId: string; @@ -12,11 +13,12 @@ interface DynamicCardProp { type DataState = { [key: string]: string[] }; -const MainCatalog = ({projectId,returnUrl,linkedUserId,optionalApiUrl} : DynamicCardProp) => { +const DynamicCatalog = ({projectId,returnUrl,linkedUserId,optionalApiUrl} : DynamicCardProp) => { - const [selectedVertical, setselectedVertical] = useState(''); // Default to the first category + const [selectedVertical, setSelectedVertical] = useState(''); // Default to the first category const [selectedProvider, setSelectedProvider] = useState(''); - const [data,setData] = useState({}) + const [data,setData] = useState({}); + const [isLoading,setLoading] = useState(true); const [error,setError] = useState(false) const { open, isReady } = useOAuth({ @@ -33,7 +35,7 @@ const MainCatalog = ({projectId,returnUrl,linkedUserId,optionalApiUrl} : Dynamic const FetchData = async () => { try{ - const res = await fetch(`http://localhost:3000/catalog-options/single?projectID=${projectId}`,{ + const res = await fetch(`${optionalApiUrl? optionalApiUrl : config.API_URL!}/catalog-options/single?projectID=${projectId}`,{ method:'GET', headers: { 'Content-Type': 'application/json', @@ -43,20 +45,31 @@ const MainCatalog = ({projectId,returnUrl,linkedUserId,optionalApiUrl} : Dynamic { throw new Error("Not found") } - const data = await res.json(); - console.log(data) - setData(JSON.parse(data.selected_catalog)) - setError(false) - } catch(error) + let data = await res.json(); + + data = JSON.parse(data.selected_catalog) + // console.log(data) + setData(data); + if(Object.keys(data).length >0) + { + setSelectedVertical(Object.keys(data)[0]) + } + setError(false); + setLoading(false); + + } + catch(error) { - setError(true) + setError(true); + setLoading(false); console.log(error) } } if(projectId===undefined || !projectId.match('[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}')) { - setError(true) + setError(true); + setLoading(false); return; } @@ -71,7 +84,7 @@ const MainCatalog = ({projectId,returnUrl,linkedUserId,optionalApiUrl} : Dynamic }; const handleCategoryClick = (category: string) => { - setselectedVertical(category); + setSelectedVertical(category); }; const onConnect = () => { @@ -79,78 +92,100 @@ const MainCatalog = ({projectId,returnUrl,linkedUserId,optionalApiUrl} : Dynamic console.log("Auth completed!") }); } + + + if(isLoading) + { + return ( + <> + + ) + } return ( -
-
- {error ? ( - <> -
Error
- - ) - : - ( - <> -
- {/* */} - {/*
Select your Integration
*/} -
-
-
- {data && Object.keys(data).map((vertical) => ( - + ))} +
+ {( + <> +
+ {selectedVertical!=='' && data && data[selectedVertical].map((provider)=> ( +
handleWalletClick(provider)} > - {vertical} - - ))} -
- {( - <> - {selectedVertical!=='' && data && data[selectedVertical].map((provider) => ( - - // - -
handleWalletClick(provider)} - > -
- {provider} - {provider.substring(0,1).toUpperCase().concat(provider.substring(1,provider.length))} -
- -
- ))} +
+ {provider} + {provider.substring(0,1).toUpperCase().concat(provider.substring(1,provider.length))} +
- - )} -
- -
-
+ + )} +
+ +
+ -
- - ) - } -
-
+ + className={`text-white ${(selectedProvider==='' || selectedVertical==='') ? "opacity-50 cursor-not-allowed" : ""} focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded text-sm px-5 py-2.5 me-2 mb-2 bg-indigo-600 hover:bg-indigo-700 focus:ring-gray-700 border-gray-700 w-full`} + > + Connect + + + + + + + ) + } + ) } -export default MainCatalog \ No newline at end of file +export default DynamicCatalog \ No newline at end of file diff --git a/apps/embedded-catalog/react/src/global.css b/apps/embedded-catalog/react/src/global.css index b5c61c956..6e066f761 100644 --- a/apps/embedded-catalog/react/src/global.css +++ b/apps/embedded-catalog/react/src/global.css @@ -1,3 +1,39 @@ @tailwind base; @tailwind components; @tailwind utilities; + +@layer utilities { + /* Chrome, Safari and Opera */ + .no-scrollbar::-webkit-scrollbar { + scrollbar-face-color: #646464; + scrollbar-base-color: #646464; + scrollbar-3dlight-color: #646464; + scrollbar-highlight-color: #646464; + scrollbar-track-color: #000; + scrollbar-arrow-color: #000; + scrollbar-shadow-color: #646464; + scrollbar-dark-shadow-color: #646464; + } + + .no-scrollbar { + /* -ms-overflow-style: none; IE and Edge */ + /* scrollbar-width: 1; Firefox */ + scrollbar-face-color: #646464; + scrollbar-base-color: #646464; + scrollbar-3dlight-color: #646464; + scrollbar-highlight-color: #646464; + scrollbar-track-color: #000; + scrollbar-arrow-color: #000; + scrollbar-shadow-color: #646464; + scrollbar-dark-shadow-color: #646464; + + } + + ::-webkit-scrollbar { width: 8px; height: 3px;} + ::-webkit-scrollbar-button { background-color: #666; } + ::-webkit-scrollbar-track { background-color: #646464;} + ::-webkit-scrollbar-track-piece { background-color: #000;} + ::-webkit-scrollbar-thumb { height: 50px; background-color: #666; border-radius: 3px;} + ::-webkit-scrollbar-corner { background-color: #646464;} + ::-webkit-resizer { background-color: #666;} + }