Skip to content

Commit

Permalink
Merge pull request #329 from credebl/ecosystem-count
Browse files Browse the repository at this point in the history
feat: Ecosystem Dashboard count
  • Loading branch information
nishad-ayanworks authored Oct 11, 2023
2 parents 66c7a87 + afebb85 commit 228df53
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 31 deletions.
29 changes: 28 additions & 1 deletion src/api/ecosystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,31 @@ export const createCredDefRequest = async (data: object, ecosystemId: string, or
const err = error as Error
return err?.message
}
}
}

export const getEcosystemDashboard = async (ecosystemId: string, orgId: string) => {

const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}/dashboard`

const token = await getFromLocalStorage(storageKeys.TOKEN)

const config = {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
}
const axiosPayload = {
url,
config
}

try {
return await axiosGet(axiosPayload);
}
catch (error) {
const err = error as Error
return err?.message
}

}
104 changes: 74 additions & 30 deletions src/components/Ecosystem/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CustomSpinner from '../CustomSpinner';
import endorseIcon from '../../assets/endorser-card.svg';
import userCard from '../../assets/User_Card.svg';
import MemberList from './MemberList';
import { getEcosystem } from '../../api/ecosystem';
import { getEcosystem, getEcosystemDashboard } from '../../api/ecosystem';
import { EmptyListMessage } from '../EmptyListComponent';
import CreateEcosystemOrgModal from '../CreateEcosystemOrgModal';
import { AlertComponent } from '../AlertComponent';
Expand All @@ -21,6 +21,7 @@ import EditPopupModal from '../EditEcosystemOrgModal';
import { getFromLocalStorage, setToLocalStorage } from '../../api/Auth';
import { getEcosytemReceivedInvitations } from '../../api/invitations';
import { pathRoutes } from '../../config/pathRoutes';
import type { EcosystemDashboard } from '../organization/interfaces';


const initialPageState = {
Expand All @@ -43,6 +44,9 @@ const Dashboard = () => {
const [viewButton, setViewButton] = useState<boolean>(false);
const [currentPage, setCurrentPage] = useState(initialPageState);
const [isEcosystemLead, setIsEcosystemLead] = useState(false);
const [ecosystemDashboard, setEcosystemDashboard] = useState<EcosystemDashboard | null>(null)
const [ecosystemDetailsNotFound, setEcosystemDetailsNotFound] = useState(false);


const createEcosystemModel = () => {
setOpenModal(true);
Expand Down Expand Up @@ -78,11 +82,11 @@ const Dashboard = () => {
const ecoSystemName = invitationList.map((invitations: { name: string; }) => {
return invitations.name
})
const invitationPendingList = data?.data?.invitations.filter((invitation: { status: string; }) => {
const invitationPendingList = data?.data?.invitations && data?.data?.invitations?.filter((invitation: { status: string; }) => {
return invitation.status === 'pending'
})

if (invitationPendingList.length > 0) {
if (invitationPendingList && invitationPendingList.length > 0) {
setMessage(`You have received invitation to join ${ecoSystemName} ecosystem `)
setViewButton(true);
}
Expand All @@ -97,33 +101,60 @@ const Dashboard = () => {
};

const fetchEcosystemDetails = async () => {
setLoading(true);
const orgId = await getFromLocalStorage(storageKeys.ORG_ID)
if (orgId) {
const response = await getEcosystem(orgId);
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const ecosystemData = data?.data[0]
if (ecosystemData?.id) {
await setToLocalStorage(storageKeys.ECOSYSTEM_ID, ecosystemData?.id)
setEcosystemId(ecosystemData?.id)
setEcosystemDetails({
logoUrl: ecosystemData.logoUrl,
name: ecosystemData.name,
description: ecosystemData.description
})
}
} else {
setFailure(response as string)
}
}
setLoading(false)
setLoading(true);
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
if (orgId) {
const response = await getEcosystem(orgId);
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const ecosystemData = data?.data[0];
await setToLocalStorage(storageKeys.ECOSYSTEM_ID, ecosystemData?.id);
setEcosystemId(ecosystemData?.id);
setEcosystemDetails({
logoUrl: ecosystemData.logoUrl,
name: ecosystemData.name,
description: ecosystemData.description,
});
} else {
setEcosystemDetailsNotFound(true);

}
}
setLoading(false);
};

const fetchEcosystemDashboard = async () => {

setLoading(true)

const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const ecosystemId = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID);

const response = await getEcosystemDashboard(ecosystemId as string, orgId as string);

const { data } = response as AxiosResponse

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
setEcosystemDashboard(data?.data)
}
else {
setFailure(response as string)
setFailure(response as string);
setLoading(false);
}
setLoading(false)

}

const getDashboardData = async () => {
await fetchEcosystemDetails();
await fetchEcosystemDashboard();
getAllEcosystemInvitations();
};

useEffect(() => {
fetchEcosystemDetails();
getAllEcosystemInvitations();
getDashboardData();

const checkEcosystemData = async () => {
const data: ICheckEcosystem = await checkEcosystem();
Expand All @@ -133,7 +164,9 @@ const Dashboard = () => {

}, []);

return (


return (
<div className="px-4 pt-6">
<div className="mb-4 col-span-full xl:mb-2">
<BreadCrumbs />
Expand Down Expand Up @@ -286,7 +319,7 @@ const Dashboard = () => {
Member
</h3>
<span className="text-2xl font-semi-bold leading-none text-white sm:text-3xl dark:text-white">
23
{ecosystemDashboard?.membersCount}
</span>
</div>
</div>
Expand All @@ -300,7 +333,7 @@ const Dashboard = () => {
Endorsements
</h3>
<span className="text-2xl font-semi-bold leading-none text-white sm:text-3xl dark:text-white">
598
{ecosystemDashboard?.endorsementsCount}
</span>
</div>
</div>
Expand Down Expand Up @@ -366,6 +399,17 @@ const Dashboard = () => {
)}
</div>
)}

{ecosystemDetailsNotFound && (
<AlertComponent
message="Ecosystem details not found."
type="failure"
onAlertClose={() => {
setEcosystemDetailsNotFound(false);
setFailure(null);
}}
/>
)}
</div>
);
};
Expand Down
5 changes: 5 additions & 0 deletions src/components/organization/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ export interface Connection {
lastChangedDateTime: string
lastChangedBy: number
}

export interface EcosystemDashboard {
membersCount: number
endorsementsCount: number
}
1 change: 1 addition & 0 deletions src/config/pathRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const pathRoutes = {
},
ecosystem: {
root: '/ecosystem',
profile: "/ecosystem/profile",
endorsements: "/ecosystem/endorsement",
invitation:"/ecosystem/invitation"
},
Expand Down

0 comments on commit 228df53

Please sign in to comment.