From 6c3535487d7aea64df7b7cd1d88b380eaec6fd97 Mon Sep 17 00:00:00 2001 From: sanjay-k1910 Date: Fri, 27 Oct 2023 15:38:26 +0530 Subject: [PATCH 1/5] feat: multi-ecosystem Signed-off-by: sanjay-k1910 --- src/api/ecosystem.ts | 3 +- src/app/LayoutCommon.astro | 2 +- src/components/Ecosystem/Dashboard.tsx | 71 ++--- src/components/Ecosystem/EcosystemList.tsx | 249 ++++++++++++++++++ .../Ecosystem/EcosystemSidebarOption.tsx | 60 +---- src/components/Ecosystem/interfaces/index.ts | 6 + src/config/ecosystem.ts | 202 +++++++------- src/config/pathRoutes.ts | 10 +- src/pages/dashboard.astro | 1 + .../dashboard.astro} | 0 .../endorsement/index.astro | 0 src/pages/ecosystems/index.astro | 16 ++ .../invitation.astro | 10 +- .../invitations.astro | 10 +- 14 files changed, 437 insertions(+), 203 deletions(-) create mode 100644 src/components/Ecosystem/EcosystemList.tsx rename src/pages/{ecosystem/index.astro => ecosystems/dashboard.astro} (100%) rename src/pages/{ecosystem => ecosystems}/endorsement/index.astro (100%) create mode 100644 src/pages/ecosystems/index.astro rename src/pages/{ecosystem => ecosystems}/invitation.astro (75%) rename src/pages/{ecosystem => ecosystems}/invitations.astro (81%) diff --git a/src/api/ecosystem.ts b/src/api/ecosystem.ts index bab35e7ca..d42ee22d7 100644 --- a/src/api/ecosystem.ts +++ b/src/api/ecosystem.ts @@ -62,9 +62,8 @@ export const updateEcosystem = async (dataPayload: CreateEcosystemPayload) => { } }; -export const getEcosystem = async (orgId: string) => { +export const getEcosystems = async (orgId: string, pageNumber?: number, pageSize?: number, search = '') => { const url = `${apiRoutes.Ecosystem.root}/${orgId}`; - const axiosPayload = { url, config: await getHeaderConfigs(), diff --git a/src/app/LayoutCommon.astro b/src/app/LayoutCommon.astro index ed0817e24..c253a4d63 100644 --- a/src/app/LayoutCommon.astro +++ b/src/app/LayoutCommon.astro @@ -46,7 +46,7 @@ const supabaseKey = process.env.PUBLIC_SUPABASE_KEY || import.meta.env.PUBLIC_SU + , 'dark:scrollbar-track-gray-900 dark:scrollbar-thumb-gray-700' , 'dark:bg-[#111827]']}> diff --git a/src/components/Ecosystem/Dashboard.tsx b/src/components/Ecosystem/Dashboard.tsx index c4600b5c2..d6c195f5a 100644 --- a/src/components/Ecosystem/Dashboard.tsx +++ b/src/components/Ecosystem/Dashboard.tsx @@ -9,7 +9,7 @@ import CustomSpinner from '../CustomSpinner'; import endorseIcon from '../../assets/endorser-icon.svg'; import memberIcon from '../../assets/member-icon.svg'; import MemberList from './MemberList'; -import { getEcosystem, getEcosystemDashboard } from '../../api/ecosystem'; +import { getEcosystems, getEcosystemDashboard } from '../../api/ecosystem'; import { EmptyListMessage } from '../EmptyListComponent'; import CreateEcosystemOrgModal from '../CreateEcosystemOrgModal'; import { AlertComponent } from '../AlertComponent'; @@ -118,20 +118,21 @@ const Dashboard = () => { const fetchEcosystemDetails = async () => { setLoading(true); const id = await getFromLocalStorage(storageKeys.ORG_ID); + const ecosystemId = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID); setOrgId(id); if (id) { - const response = await getEcosystem(id); + const response = await getEcosystems(id); const { data } = response as AxiosResponse; if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { - const ecosystemData = data?.data[0]; + const ecosystemData = data?.data.find((item: { id: string }) => item.id === ecosystemId); if (ecosystemData) { - await setToLocalStorage(storageKeys.ECOSYSTEM_ID, ecosystemData?.id); const ecosystemOrg = ecosystemData?.ecosystemOrgs && ecosystemData?.ecosystemOrgs.length > 0 && ecosystemData?.ecosystemOrgs[0]; setEcosystemDetails({ + id: ecosystemData?.id, logoUrl: ecosystemData?.logoUrl, name: ecosystemData?.name, description: ecosystemData?.description, @@ -422,36 +423,36 @@ const Dashboard = () => { )} - -
-
- - -
-
-
- -
- { - setSuccess(value); - }} - isOrganization={false} - onEditSuccess={handleEditModalClose} - entityData={ecosystemDetails} +
+
+ + window.location.href = pathRoutes.ecosystem.endorsements} + /> +
+
+
+ +
+ { + setSuccess(value); + }} + isOrganization={false} + onEditSuccess={handleEditModalClose} + entityData={ecosystemDetails} + /> ) : (
@@ -481,8 +482,8 @@ const Dashboard = () => { feature={!orgId ? Features.CRETAE_ORG : ''} message={'No Ecosystem found'} description={`Get started by creating ${!orgId - ? 'a new Organization to set up your Ecosystem' - : 'an Ecosystem' + ? 'a new Organization to set up your Ecosystem' + : 'an Ecosystem' }`} buttonContent={`${!orgId ? '' : 'Create Ecosystem'}`} svgComponent={ diff --git a/src/components/Ecosystem/EcosystemList.tsx b/src/components/Ecosystem/EcosystemList.tsx new file mode 100644 index 000000000..2af1a087a --- /dev/null +++ b/src/components/Ecosystem/EcosystemList.tsx @@ -0,0 +1,249 @@ +'use client'; + +import { Card, Pagination } from 'flowbite-react'; +import { ChangeEvent, useEffect, useState } from 'react'; +import { apiStatusCodes, storageKeys } from '../../config/CommonConstant'; + +import { AlertComponent } from '../AlertComponent'; +import type { AxiosResponse } from 'axios'; +import BreadCrumbs from '../BreadCrumbs'; +import CustomAvatar from '../Avatar' +import { Features } from '../../utils/enums/features'; +import RoleViewButton from '../RoleViewButton'; +import SearchInput from '../SearchInput'; +import { pathRoutes } from '../../config/pathRoutes'; +import { getFromLocalStorage, removeFromLocalStorage, setToLocalStorage } from '../../api/Auth'; +import { EmptyListMessage } from '../EmptyListComponent'; +import CustomSpinner from '../CustomSpinner'; +import CreateEcosystemOrgModal from '../CreateEcosystemOrgModal'; +import { getEcosystems } from '../../api/ecosystem'; +import type { IEcosystem } from './interfaces'; +import { checkEcosystem, type ICheckEcosystem } from '../../config/ecosystem'; + +const initialPageState = { + pageNumber: 1, + pageSize: 9, + total: 100, +}; + +const EcosystemList = () => { + const [openModal, setOpenModal] = useState(false); + const [loading, setLoading] = useState(true) + const [message, setMessage] = useState(null) + const [error, setError] = useState(null) + const [currentPage, setCurrentPage] = useState(initialPageState); + const onPageChange = (page: number) => { + setCurrentPage({ + ...currentPage, + pageNumber: page + }) + }; + const [searchText, setSearchText] = useState(""); + + const [ecosystemList, setEcosystemList] = useState | null>(null) + const [isEcosystemData, setIsEcosystemData] = useState() + + const createOrganizationModel = () => { + setOpenModal(true) + } + + const fetchEcosystems = async () => { + setLoading(true); + const id = await getFromLocalStorage(storageKeys.ORG_ID); + // setOrgId(id); + if (id) { + const response = await getEcosystems(id, currentPage.pageNumber, currentPage.pageSize, searchText); + const { data } = response as AxiosResponse; + + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + const ecosystemData = data?.data; + if (ecosystemData) { + console.log(6565, data) + setEcosystemList(ecosystemData) + } else { + await removeFromLocalStorage(storageKeys.ECOSYSTEM_ID); + setError(response as string) + } + } else { + await removeFromLocalStorage(storageKeys.ECOSYSTEM_ID); + setError(response as string) + } + } + setLoading(false); + }; + + //This useEffect is called when the searchText changes + useEffect(() => { + let getData: NodeJS.Timeout + + if (searchText.length >= 1) { + getData = setTimeout(() => { + fetchEcosystems() + }, 1000) + } else { + fetchEcosystems() + } + + return () => clearTimeout(getData) + }, [searchText, openModal, currentPage.pageNumber]) + + useEffect(() => { + const queryParameters = new URLSearchParams(window?.location?.search) + const isModel = queryParameters.get("orgModal") || '' + + if (isModel !== '') { + setOpenModal(true) + } + + const checkEcosystemData = async () => { + const data: ICheckEcosystem = await checkEcosystem(); + setIsEcosystemData(data) + } + checkEcosystemData(); + }, []) + + //onCHnage of Search input text + const searchInputChange = (e: ChangeEvent) => { + setSearchText(e.target.value); + } + + const redirectOrgDashboard = async (ecosystemId: string, ecosystemRole: string) => { + await setToLocalStorage(storageKeys.ECOSYSTEM_ID, ecosystemId); + await setToLocalStorage(storageKeys.ECOSYSTEM_ROLE, ecosystemRole); + window.location.href = pathRoutes.ecosystem.dashboard + } + + const isEcosystemList = Boolean(ecosystemList && ecosystemList?.length > 0) + const showCreateButton = Boolean(isEcosystemList && (isEcosystemData?.isMultiEcosystem || isEcosystemData?.isEcosystemLead)) + console.log(6534, isEcosystemData, showCreateButton, isEcosystemList, isEcosystemData?.isMultiEcosystem, isEcosystemData?.isEcosystemLead, (isEcosystemList && isEcosystemData?.isMultiEcosystem) || isEcosystemData?.isEcosystemLead) + return ( +
+
+ + +

+ Ecosystems +

+
+
+
+
+ + { + showCreateButton && + + + + +
+ } + onClickEvent={createOrganizationModel} + /> + } +
+ + { + setMessage(null) + setError(null) + }} + /> + + {loading + ?
+ +
+ : isEcosystemList ? (
+ { + isEcosystemList && ecosystemList && ecosystemList.map((item) => { + const role = item?.ecosystemOrgs && item?.ecosystemOrgs.length > 0 && item?.ecosystemOrgs[0]?.ecosystemRole?.name || "" + return ( + redirectOrgDashboard(item.id, role)} className='transform transition duration-500 hover:scale-105 hover:bg-gray-50 cursor-pointer overflow-hidden overflow-ellipsis' style={{ maxHeight: '100%', maxWidth: '100%', overflow: 'auto' }}> +
+ {(item.logoUrl) ? : } + +
+
+ {item.name} +
+

{item.description}

+
+
    +
  • +
    +
    + Roles: + {item?.ecosystemOrgs && item?.ecosystemOrgs?.length > 0 && item?.ecosystemOrgs[0].ecosystemRole && + item?.ecosystemOrgs[0]?.ecosystemRole?.name && + + {item?.ecosystemOrgs[0]?.ecosystemRole?.name} + + } +
    +
    +
  • +
+
+
+
+
+ ) + }) + } +
) + : ecosystemList && ( + + + } />) + } + +
+ { + isEcosystemList && ( + + ) + } +
+ { + setMessage(value) + if (value) { + setTimeout(() => { + window.location.reload(); + }, 2000); + } else { + fetchEcosystems(); + } + }} + isorgModal={false} + /> +
+
+
+ ) +} + +export default EcosystemList; diff --git a/src/components/Ecosystem/EcosystemSidebarOption.tsx b/src/components/Ecosystem/EcosystemSidebarOption.tsx index 0fc019aae..4904e4005 100644 --- a/src/components/Ecosystem/EcosystemSidebarOption.tsx +++ b/src/components/Ecosystem/EcosystemSidebarOption.tsx @@ -1,11 +1,9 @@ import { useEffect, useState } from 'react' import { ICheckEcosystem, checkEcosystem } from '../../config/ecosystem' import { pathRoutes } from '../../config/pathRoutes' -import React from 'react'; const EcosystemSidebarOption = () => { const [isEcosystemEnabled, setIsEcosystemEnabled] = useState(false); - const [showSubMenus, setShowSubMenus] = useState(true); useEffect(() => { const checkEcosystemData = async () => { @@ -18,12 +16,9 @@ const EcosystemSidebarOption = () => { if (isEcosystemEnabled) { return (
  • - - { - showSubMenus && - - } + Ecosystems +
  • ) } diff --git a/src/components/Ecosystem/interfaces/index.ts b/src/components/Ecosystem/interfaces/index.ts index bd8f6c334..24e41c258 100644 --- a/src/components/Ecosystem/interfaces/index.ts +++ b/src/components/Ecosystem/interfaces/index.ts @@ -1,9 +1,15 @@ export interface IEcosystem { + id: string name: string description: string logoUrl: string joinedDate?: string role?: string + ecosystemOrgs?: { + ecosystemRole: { + name: string + } + }[] } export interface Ecosystem { diff --git a/src/config/ecosystem.ts b/src/config/ecosystem.ts index deb0dbed9..7cd383955 100644 --- a/src/config/ecosystem.ts +++ b/src/config/ecosystem.ts @@ -1,114 +1,134 @@ -import type { AxiosResponse } from "axios" -import { getFromLocalStorage, setToLocalStorage } from "../api/Auth" -import { getEcosystem } from "../api/ecosystem" -import { EcosystemRoles } from "../common/enums" -import { apiStatusCodes, storageKeys } from "./CommonConstant" -import { getOrganizationById } from "../api/organization" +import type { AxiosResponse } from 'axios'; +import { getFromLocalStorage, setToLocalStorage } from '../api/Auth'; +import { getEcosystems } from '../api/ecosystem'; +import { EcosystemRoles } from '../common/enums'; +import { apiStatusCodes, storageKeys } from './CommonConstant'; +import { getOrganizationById } from '../api/organization'; export interface ICheckEcosystem { - isEnabledEcosystem: boolean; - isEcosystemMember: boolean; - isEcosystemLead: boolean; + isEnabledEcosystem: boolean; + isEcosystemMember: boolean; + isEcosystemLead: boolean; + isMultiEcosystem: boolean; } export interface IOrgDetails { - orgName: string - orgDid: string + orgName: string; + orgDid: string; } const ecosystemId = async () => { - const id = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID) - return id -} + const id = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID); + return id; +}; const getOrgData = async () => { - const data = await getFromLocalStorage(storageKeys.ORG_DETAILS) - return data -} + const data = await getFromLocalStorage(storageKeys.ORG_DETAILS); + return data; +}; const getEcosystemRole = async () => { - const data = await getFromLocalStorage(storageKeys.ECOSYSTEM_ROLE) - return data -} + const data = await getFromLocalStorage(storageKeys.ECOSYSTEM_ROLE); + return data; +}; const getOrgId = async () => { - const id = await getFromLocalStorage(storageKeys.ORG_ID) - return id -} + const id = await getFromLocalStorage(storageKeys.ORG_ID); + return id; +}; const getUserProfile = async () => { - const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE) - const userDetails = userProfile && await JSON.parse(userProfile) - return userDetails -} + const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE); + const userDetails = userProfile && (await JSON.parse(userProfile)); + return userDetails; +}; const checkEcosystem = async (): Promise => { - await getEcosystemId() - const userData = await getUserProfile() - const role = await getEcosystemRole() - - const isEnabledEcosystem = userData?.enableEcosystem - const ecosystemRole = role || EcosystemRoles.ecosystemLead - - return { - isEnabledEcosystem, - isEcosystemMember: ecosystemRole === EcosystemRoles.ecosystemMember && isEnabledEcosystem, - isEcosystemLead: ecosystemRole === EcosystemRoles.ecosystemLead && isEnabledEcosystem - } -} + await getEcosystemId(); + const userData = await getUserProfile(); + const role = await getEcosystemRole(); + + const isEnabledEcosystem = userData?.enableEcosystem; + const ecosystemRole = role || EcosystemRoles.ecosystemLead; + + const isMultiEcosystem = userData?.multiEcosystemSupport; + // const isMultiEcosystem = false + + return { + isEnabledEcosystem, + isMultiEcosystem, + isEcosystemMember: + ecosystemRole === EcosystemRoles.ecosystemMember && isEnabledEcosystem, + isEcosystemLead: + ecosystemRole === EcosystemRoles.ecosystemLead && isEnabledEcosystem, + }; +}; const getEcosystemId = async (): Promise => { - const ecoId = await ecosystemId() - const ecoRole = await getEcosystemRole() - const orgId = await getOrgId() - if (!ecoId || !ecoRole) { - try { - if(orgId){ - const { data } = await getEcosystem(orgId) as AxiosResponse - - if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS && data?.data && data?.data.length > 0) { - const response = data?.data[0] - const id = response?.id - const role = response?.ecosystemOrgs && response?.ecosystemOrgs.length > 0 && response?.ecosystemOrgs[0]?.ecosystemRole?.name - await setToLocalStorage(storageKeys.ECOSYSTEM_ID, id); - if(role){ - await setToLocalStorage(storageKeys.ECOSYSTEM_ROLE, role); - } - return id - } - } - } catch (err) { - console.log("ERROR-Get Ecosystem", err) - } - } - return ecoId -} + const ecoId = await ecosystemId(); + const ecoRole = await getEcosystemRole(); + const orgId = await getOrgId(); + if (!ecoId || !ecoRole) { + try { + if (orgId) { + const { data } = (await getEcosystems(orgId)) as AxiosResponse; + + if ( + data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS && + data?.data && + data?.data.length > 0 + ) { + const response = data?.data[0]; + const id = response?.id; + const role = + response?.ecosystemOrgs && + response?.ecosystemOrgs.length > 0 && + response?.ecosystemOrgs[0]?.ecosystemRole?.name; + await setToLocalStorage(storageKeys.ECOSYSTEM_ID, id); + if (role) { + await setToLocalStorage(storageKeys.ECOSYSTEM_ROLE, role); + } + return id; + } + } + } catch (err) { + console.log('ERROR-Get Ecosystem', err); + } + } + return ecoId; +}; const getOrgDetails = async (): Promise => { - const orgId = await getOrgId() - const org = await getOrgData() - const orgData: IOrgDetails = org && JSON.parse(org) - const isOrgData = Object.keys(orgData).length > 0 - const isOrgDid = orgData?.orgDid - if (!isOrgData || !isOrgDid) { - try { - if(orgId){ - const { data } = await getOrganizationById(orgId) as AxiosResponse - - if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { - const orgData: IOrgDetails = { - orgName: data?.data?.name, - orgDid: data?.data && data?.data?.org_agents?.length > 0 ? data?.data?.org_agents[0]?.orgDid : "" - } - await setToLocalStorage(storageKeys.ORG_DETAILS, JSON.stringify(orgData)); - return orgData - } - } - } catch (err) { - console.log("ERROR-Get ORG Details", err) - } - } - return orgData -} + const orgId = await getOrgId(); + const org = await getOrgData(); + const orgData: IOrgDetails = org && JSON.parse(org); + const isOrgData = Object.keys(orgData).length > 0; + const isOrgDid = orgData?.orgDid; + if (!isOrgData || !isOrgDid) { + try { + if (orgId) { + const { data } = (await getOrganizationById(orgId)) as AxiosResponse; + + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + const orgData: IOrgDetails = { + orgName: data?.data?.name, + orgDid: + data?.data && data?.data?.org_agents?.length > 0 + ? data?.data?.org_agents[0]?.orgDid + : '', + }; + await setToLocalStorage( + storageKeys.ORG_DETAILS, + JSON.stringify(orgData), + ); + return orgData; + } + } + } catch (err) { + console.log('ERROR-Get ORG Details', err); + } + } + return orgData; +}; -export { checkEcosystem, getEcosystemId, getOrgDetails } \ No newline at end of file +export { checkEcosystem, getEcosystemId, getOrgDetails }; diff --git a/src/config/pathRoutes.ts b/src/config/pathRoutes.ts index 0472b3f1b..1cbdb9584 100644 --- a/src/config/pathRoutes.ts +++ b/src/config/pathRoutes.ts @@ -34,11 +34,11 @@ export const pathRoutes = { }, }, ecosystem: { - root: '/ecosystem', - profile: "/ecosystem/profile", - endorsements: "/ecosystem/endorsement", - invitation:"/ecosystem/invitation", - sentinvitation:'/ecosystem/invitations' + root: '/ecosystems', + dashboard: "/ecosystems/dashboard", + endorsements: "/ecosystems/endorsement", + invitation:"/ecosystems/invitation", + sentinvitation:'/ecosystems/invitations' }, documentation: { root: 'https://docs.credebl.id' diff --git a/src/pages/dashboard.astro b/src/pages/dashboard.astro index be1dfb0df..33f76a0e4 100644 --- a/src/pages/dashboard.astro +++ b/src/pages/dashboard.astro @@ -7,6 +7,7 @@ import { checkUserSession } from '../utils/check-session'; const response = await checkUserSession(Astro.cookies); const route: string = pathRoutes.auth.sinIn if (!response) { + await localStorage.clear() return Astro.redirect(route); } --- diff --git a/src/pages/ecosystem/index.astro b/src/pages/ecosystems/dashboard.astro similarity index 100% rename from src/pages/ecosystem/index.astro rename to src/pages/ecosystems/dashboard.astro diff --git a/src/pages/ecosystem/endorsement/index.astro b/src/pages/ecosystems/endorsement/index.astro similarity index 100% rename from src/pages/ecosystem/endorsement/index.astro rename to src/pages/ecosystems/endorsement/index.astro diff --git a/src/pages/ecosystems/index.astro b/src/pages/ecosystems/index.astro new file mode 100644 index 000000000..1849c2d9d --- /dev/null +++ b/src/pages/ecosystems/index.astro @@ -0,0 +1,16 @@ +--- +import LayoutSidebar from '../../app/LayoutSidebar.astro'; +import { checkUserSession } from '../../utils/check-session'; +import { pathRoutes } from '../../config/pathRoutes'; +import EcosystemList from '../../components/Ecosystem/EcosystemList'; + +const response = await checkUserSession(Astro.cookies); +const route: string = pathRoutes.auth.sinIn +if (!response) { + return Astro.redirect(route); +} +--- + + + + \ No newline at end of file diff --git a/src/pages/ecosystem/invitation.astro b/src/pages/ecosystems/invitation.astro similarity index 75% rename from src/pages/ecosystem/invitation.astro rename to src/pages/ecosystems/invitation.astro index ab1fc836f..c7578c5f1 100644 --- a/src/pages/ecosystem/invitation.astro +++ b/src/pages/ecosystems/invitation.astro @@ -2,19 +2,15 @@ import LayoutSidebar from '../../app/LayoutSidebar.astro'; import { checkUserSession } from '../../utils/check-session'; import { pathRoutes } from '../../config/pathRoutes'; -import EcoSystemReceivedInvitations from '../../components/EcosystemInvite/EcoSystemReceivedInvitations' +import EcoSystemReceivedInvitations from '../../components/EcosystemInvite/EcoSystemReceivedInvitations'; const response = await checkUserSession(Astro.cookies); -const route = pathRoutes.auth.sinIn +const route = pathRoutes.auth.sinIn; if (!response) { return Astro.redirect(route); } --- - + - - - - diff --git a/src/pages/ecosystem/invitations.astro b/src/pages/ecosystems/invitations.astro similarity index 81% rename from src/pages/ecosystem/invitations.astro rename to src/pages/ecosystems/invitations.astro index e1edcb51e..98c1e7c39 100644 --- a/src/pages/ecosystem/invitations.astro +++ b/src/pages/ecosystems/invitations.astro @@ -2,19 +2,15 @@ import LayoutSidebar from '../../app/LayoutSidebar.astro'; import { checkUserSession } from '../../utils/check-session'; import { pathRoutes } from '../../config/pathRoutes'; -import SentInvitations from '../../components/EcosystemInvite/SentInvitations' +import SentInvitations from '../../components/EcosystemInvite/SentInvitations'; const response = await checkUserSession(Astro.cookies); -const route = pathRoutes.auth.sinIn +const route = pathRoutes.auth.sinIn; if (!response) { return Astro.redirect(route); } --- - + - - - - From 3e05e1bc35c276a118fa1ee183dd5efb0d879ee0 Mon Sep 17 00:00:00 2001 From: sanjay-k1910 Date: Mon, 30 Oct 2023 15:06:11 +0530 Subject: [PATCH 2/5] feat: added ecosystem profile card Signed-off-by: sanjay-k1910 --- src/commonComponents/EcosystemProfileCard.tsx | 143 ++++++++++++++++++ .../Ecosystem/Endorsement/index.tsx | 19 ++- src/components/Resources/Schema/Create.tsx | 41 ++--- .../Resources/Schema/SchemasList.tsx | 31 ++-- .../Resources/Schema/ViewSchema.tsx | 8 + .../organization/OrganizationsList.tsx | 17 +-- src/components/organization/WalletSpinup.tsx | 2 +- 7 files changed, 215 insertions(+), 46 deletions(-) create mode 100644 src/commonComponents/EcosystemProfileCard.tsx diff --git a/src/commonComponents/EcosystemProfileCard.tsx b/src/commonComponents/EcosystemProfileCard.tsx new file mode 100644 index 000000000..6f637b01b --- /dev/null +++ b/src/commonComponents/EcosystemProfileCard.tsx @@ -0,0 +1,143 @@ +import { useEffect, useState } from 'react' +import { Card } from 'flowbite-react'; +import type { IEcosystem } from '../components/Ecosystem/interfaces'; +import { getFromLocalStorage, removeFromLocalStorage, setToLocalStorage } from '../api/Auth'; +import { apiStatusCodes, storageKeys } from '../config/CommonConstant'; +import type { AxiosResponse } from 'axios'; +import { getEcosystems } from '../api/ecosystem'; +import CustomAvatar from '../components/Avatar'; +import { RoleTablet } from '../components/Ecosystem/Dashboard' +import CustomSpinner from '../components/CustomSpinner'; +import { pathRoutes } from '../config/pathRoutes'; +import { EmptyListMessage } from '../components/EmptyListComponent'; + +const EcosystemProfileCard = () => { + const [ecosystemDetails, setEcosystemDetails] = useState(); + const [ecosystemList, setEcosystemList] = useState(); + const [loading, setLoading] = useState(); + const [ecosystemId, setEcosystemId] = useState(); + + const fetchEcosystemDetails = async (ecoId?: string) => { + setLoading(true); + try { + const id = await getFromLocalStorage(storageKeys.ORG_ID); + const ecosystemId = ecoId || await getFromLocalStorage(storageKeys.ECOSYSTEM_ID); + console.log(4561, id) + if (id) { + const response = await getEcosystems(id); + setLoading(false) + const { data } = response as AxiosResponse; + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + setEcosystemList(data?.data) + const ecosystemData = data?.data?.find((item: { id: string }) => item.id === ecosystemId); + console.log(4545, ecosystemData) + if (ecosystemData) { + setEcosystemId(ecosystemData?.id) + const ecosystemOrg = + ecosystemData?.ecosystemOrgs && + ecosystemData?.ecosystemOrgs.length > 0 && + ecosystemData?.ecosystemOrgs[0]; + const role = ecosystemOrg && ecosystemOrg?.ecosystemRole?.name + ? ecosystemOrg?.ecosystemRole?.name + : '' + await setToLocalStorage(storageKeys.ECOSYSTEM_ROLE, role) + setEcosystemDetails({ + id: ecosystemData?.id, + logoUrl: ecosystemData?.logoUrl, + name: ecosystemData?.name, + description: ecosystemData?.description, + joinedDate: + ecosystemOrg && ecosystemOrg?.createDateTime + ? ecosystemOrg?.createDateTime + : '', + role + }); + } else { + await removeFromLocalStorage(storageKeys.ECOSYSTEM_ID); + } + } else { + await removeFromLocalStorage(storageKeys.ECOSYSTEM_ID); + } + } + } catch (err) { + setLoading(false) + } + setLoading(false); + }; + + const handleSelectEcosystem = async (e: { target: { value: string; }; }) => { + await fetchEcosystemDetails(e.target.value) + await setToLocalStorage(storageKeys.ECOSYSTEM_ID, e.target.value); + window.location.reload() + } + + + useEffect(() => { + fetchEcosystemDetails(); + }, []); + + const ecosystemOptions = ecosystemList && ecosystemList.length > 0 && ecosystemList.filter(item => item.id !== ecosystemId) + + return ( + + {ecosystemDetails ? ( +
    +
    + {ecosystemDetails?.logoUrl ? ( + + ) : ( + + )} +
    + +
    +

    + {ecosystemDetails?.name} +

    +
    + Role: {' '} + +
    +
    + + +
    + + + Go to Dashboard + + +
    + +
    + ) : !ecosystemDetails && loading ? ( + + ) : + + + } /> + } +
    + ) +} + +export default EcosystemProfileCard \ No newline at end of file diff --git a/src/components/Ecosystem/Endorsement/index.tsx b/src/components/Ecosystem/Endorsement/index.tsx index 0ad712257..0885ddd46 100644 --- a/src/components/Ecosystem/Endorsement/index.tsx +++ b/src/components/Ecosystem/Endorsement/index.tsx @@ -26,6 +26,7 @@ import { import { EndorsementStatus, EndorsementType } from '../../../common/enums'; import { AlertComponent } from '../../AlertComponent'; import { Features } from '../../../utils/enums/features'; +import EcosystemProfileCard from '../../../commonComponents/EcosystemProfileCard'; interface ISelectedRequest { attribute: IAttributes[]; @@ -68,7 +69,7 @@ const EndorsementList = () => { const [walletStatus, setWalletStatus] = useState(false); const [showPopup, setShowPopup] = useState(false); const [selectedRequest, setSelectedRequest] = useState(); - const [isEcosystemLead, setIsEcosystemLead] = useState(false); + const [isEcosystemData, setIsEcosystemData] = useState(); const [successMessage, setSuccessMessage] = useState(null); const options = [ @@ -205,7 +206,7 @@ const EndorsementList = () => { const checkEcosystemData = async () => { const data: ICheckEcosystem = await checkEcosystem(); - setIsEcosystemLead(data.isEcosystemLead); + setIsEcosystemData(data); }; checkEcosystemData(); }, []); @@ -214,13 +215,19 @@ const EndorsementList = () => {
    -

    - Endorsements -

    + { + isEcosystemData?.isEnabledEcosystem && +
    + +
    + } +

    + Endorsements +

    -
    +
    {
    -

    - {formTitle} -

    + { + isEcosystemData?.isEnabledEcosystem && +
    + +
    + } +

    + {formTitle} +

    - +
    {
    -
    +
    -
    -
    +
    +
    { )}
    -
    +
    { )}
    -
    +
    { -
    +
    {index === 0 && attribute.length === 1 ? (
    )} -
    +
    - - setShowPopup(false)} onSuccess={confirmCreateSchema} message={"Would you like to proceed? Keep in mind that this action cannot be undone."} isProcessing={createloader} /> - -
    +
    + + setShowPopup(false)} onSuccess={confirmCreateSchema} message={"Would you like to proceed? Keep in mind that this action cannot be undone."} isProcessing={createloader} /> + )} diff --git a/src/components/Resources/Schema/SchemasList.tsx b/src/components/Resources/Schema/SchemasList.tsx index f2ac944e2..a61edf323 100644 --- a/src/components/Resources/Schema/SchemasList.tsx +++ b/src/components/Resources/Schema/SchemasList.tsx @@ -19,6 +19,7 @@ import { getFromLocalStorage } from '../../../api/Auth'; import { pathRoutes } from '../../../config/pathRoutes'; import { getOrganizationById } from '../../../api/organization'; import { ICheckEcosystem, checkEcosystem } from '../../../config/ecosystem'; +import EcosystemProfileCard from '../../../commonComponents/EcosystemProfileCard'; const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaDetails: SchemaDetails) => void; }) => { const [schemaList, setSchemaList] = useState([]) @@ -152,27 +153,33 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD }, []) const schemaEndorsement = - - + + -const create =
    - - - -
    + const create =
    + + + +
    - const createSchemaTitle = isEcosystemData?.isEcosystemMember ? { title: "Schema Endorsement", svg: schemaEndorsement } : { title: "Create", svg: create } + const createSchemaTitle = isEcosystemData?.isEcosystemMember ? { title: "Schema Endorsement", svg: schemaEndorsement } : { title: "Create", svg: create } const emptyListTitle = "No Schemas" const emptyListDesc = "Get started by creating a new Schema" - const emptyListBtn = isEcosystemData?.isEcosystemMember ? { title: "Schema Endorsement", svg: schemaEndorsement } : { title: "Create Schema", svg: create } + const emptyListBtn = isEcosystemData?.isEcosystemMember ? { title: "Schema Endorsement", svg: schemaEndorsement } : { title: "Create Schema", svg: create } return (
    -

    - Schemas -

    + { + isEcosystemData?.isEnabledEcosystem && +
    + +
    + } +

    + Schemas +

    {
    + { + isEcosystemData?.isEnabledEcosystem && +
    + +
    + } +

    Schemas diff --git a/src/components/organization/OrganizationsList.tsx b/src/components/organization/OrganizationsList.tsx index 7736e68f9..b0804b8a0 100644 --- a/src/components/organization/OrganizationsList.tsx +++ b/src/components/organization/OrganizationsList.tsx @@ -80,8 +80,6 @@ const OrganizationsList = () => { //This useEffect is called when the searchText changes useEffect(() => { - - // let getData: string | number | NodeJS.Timeout | undefined; let getData: NodeJS.Timeout if (searchText.length >= 1) { @@ -162,7 +160,7 @@ const OrganizationsList = () => { isorgModal={true} /> { setMessage(null) @@ -177,19 +175,18 @@ const OrganizationsList = () => { : organizationsList && organizationsList?.length > 0 ? (
    { organizationsList.map((org) => ( - redirectOrgDashboard(org)} className='transform transition duration-500 hover:scale-105 hover:bg-gray-50 cursor-pointer overflow-hidden overflow-ellipsis' style={{ maxHeight: '100%', maxWidth: '100%', overflow: 'auto' }}> + redirectOrgDashboard(org)} className='transform transition duration-500 hover:scale-105 hover:bg-gray-50 cursor-pointer overflow-hidden overflow-ellipsis' style={{ maxHeight: '100%', maxWidth: '100%', overflow: 'auto' }}>
    {(org.logoUrl) ? : }
    -
    -

    - {org.name} -

    -
    +
    + {org?.name} +
    +

    {org?.description}

      -
    • +
    • Roles: diff --git a/src/components/organization/WalletSpinup.tsx b/src/components/organization/WalletSpinup.tsx index 7b3e329a9..5cac1c93d 100644 --- a/src/components/organization/WalletSpinup.tsx +++ b/src/components/organization/WalletSpinup.tsx @@ -123,7 +123,7 @@ const SharedAgentForm = ({ orgName, seeds, isCopied, loading, copyTextVal, submi
      { isEcosystemData?.isEnabledEcosystem && -
      +
      } From 24a4363fff99bcf1fb4ad7925c91800a7cfebbf5 Mon Sep 17 00:00:00 2001 From: sanjay-k1910 Date: Mon, 30 Oct 2023 15:29:41 +0530 Subject: [PATCH 4/5] refactor: schema list page Signed-off-by: sanjay-k1910 --- src/components/Resources/Schema/SchemasList.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/components/Resources/Schema/SchemasList.tsx b/src/components/Resources/Schema/SchemasList.tsx index a61edf323..a37eecccb 100644 --- a/src/components/Resources/Schema/SchemasList.tsx +++ b/src/components/Resources/Schema/SchemasList.tsx @@ -2,7 +2,7 @@ import { Alert, Pagination } from 'flowbite-react'; import { ChangeEvent, useEffect, useState } from 'react'; -import type { GetAllSchemaListParameter, PaginationData } from './interfaces'; +import type { GetAllSchemaListParameter } from './interfaces'; import { apiStatusCodes, storageKeys } from '../../../config/CommonConstant'; import { getAllSchemas, getAllSchemasByOrgId } from '../../../api/Schema'; @@ -19,7 +19,6 @@ import { getFromLocalStorage } from '../../../api/Auth'; import { pathRoutes } from '../../../config/pathRoutes'; import { getOrganizationById } from '../../../api/organization'; import { ICheckEcosystem, checkEcosystem } from '../../../config/ecosystem'; -import EcosystemProfileCard from '../../../commonComponents/EcosystemProfileCard'; const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaDetails: SchemaDetails) => void; }) => { const [schemaList, setSchemaList] = useState([]) @@ -171,12 +170,6 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
      - { - isEcosystemData?.isEnabledEcosystem && -
      - -
      - }

      Schemas

      From a1cc39feafffac89556f14e998da4b6839122ebd Mon Sep 17 00:00:00 2001 From: sanjay-k1910 Date: Mon, 30 Oct 2023 16:01:07 +0530 Subject: [PATCH 5/5] refactor: card and create buttons Signed-off-by: sanjay-k1910 --- src/components/Ecosystem/EcosystemList.tsx | 39 +++++----- src/components/Issuance/IssuedCrdentials.tsx | 37 +++++---- .../VerificationCredentialList.tsx | 76 ++++++++++--------- .../organization/OrganizationsList.tsx | 32 ++++---- 4 files changed, 94 insertions(+), 90 deletions(-) diff --git a/src/components/Ecosystem/EcosystemList.tsx b/src/components/Ecosystem/EcosystemList.tsx index 2af1a087a..2f69d0538 100644 --- a/src/components/Ecosystem/EcosystemList.tsx +++ b/src/components/Ecosystem/EcosystemList.tsx @@ -115,15 +115,31 @@ const EcosystemList = () => { const isEcosystemList = Boolean(ecosystemList && ecosystemList?.length > 0) const showCreateButton = Boolean(isEcosystemList && (isEcosystemData?.isMultiEcosystem || isEcosystemData?.isEcosystemLead)) - console.log(6534, isEcosystemData, showCreateButton, isEcosystemList, isEcosystemData?.isMultiEcosystem, isEcosystemData?.isEcosystemLead, (isEcosystemList && isEcosystemData?.isMultiEcosystem) || isEcosystemData?.isEcosystemLead) return (
      +
      +

      Ecosystems

      + { + showCreateButton && + + + + +
      + } + onClickEvent={createOrganizationModel} + /> + }
      { - { - showCreateButton && - - - - -
      - } - onClickEvent={createOrganizationModel} - /> - }
      {
      : isEcosystemList ? (
      { - isEcosystemList && ecosystemList && ecosystemList.map((item) => { + ecosystemList?.map((item) => { const role = item?.ecosystemOrgs && item?.ecosystemOrgs.length > 0 && item?.ecosystemOrgs[0]?.ecosystemRole?.name || "" return ( - redirectOrgDashboard(item.id, role)} className='transform transition duration-500 hover:scale-105 hover:bg-gray-50 cursor-pointer overflow-hidden overflow-ellipsis' style={{ maxHeight: '100%', maxWidth: '100%', overflow: 'auto' }}> + redirectOrgDashboard(item.id, role)} className='transform transition duration-500 hover:scale-105 hover:bg-gray-50 cursor-pointer overflow-hidden' style={{ maxHeight: '100%', maxWidth: '100%', overflow: 'auto' }}>
      {(item.logoUrl) ? : } @@ -216,7 +217,7 @@ const EcosystemList = () => {
      { - isEcosystemList && ( + isEcosystemList && ecosystemList && ecosystemList?.length > 10 && ( {
      +
      +

      Credentials

      +
      + { + walletCreated && + + + + + } + onClickEvent={schemeSelection} + /> + } +
      -
      -
      - - { - walletCreated && - - - - - } - onClickEvent={schemeSelection} - /> - } - -
      { return (
      -
      - -

      - Verification List -

      -
      +
      + +
      +
      +

      + Verification List +

      -
      -
      - { - walletCreated && - - - - } - onClickEvent={schemeSelection} - /> + { + walletCreated && + + + } -
      - { - (proofReqSuccess || errMsg) && ( -
      - setErrMsg(null)} - > - -

      - {proofReqSuccess || errMsg} -

      -
      -
      -
      - )} + onClickEvent={schemeSelection} + /> + } +
      +
      +
      +
      + { + (proofReqSuccess || errMsg) && ( +
      + setErrMsg(null)} + > + +

      + {proofReqSuccess || errMsg} +

      +
      +
      +
      + )} { !walletCreated && !loading ? diff --git a/src/components/organization/OrganizationsList.tsx b/src/components/organization/OrganizationsList.tsx index b0804b8a0..fdbbe3d63 100644 --- a/src/components/organization/OrganizationsList.tsx +++ b/src/components/organization/OrganizationsList.tsx @@ -125,9 +125,23 @@ const OrganizationsList = () => {
      +
      +

      Organizations

      + + + + +
      + } + onClickEvent={createOrganizationModel} + />
      { - - - - -
      - } - onClickEvent={createOrganizationModel} - />
      { {(org.logoUrl) ? : }
      -
      - {org?.name} -
      +
      + {org?.name} +

      {org?.description}