Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enabled multi ecosystem #391

Merged
merged 7 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/api/ecosystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/app/LayoutCommon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const supabaseKey = process.env.PUBLIC_SUPABASE_KEY || import.meta.env.PUBLIC_SU
<body class:list={[ // clazz, 'bg-gray-50 dark:bg-gray-800'
, 'scrollbar scrollbar-w-3 scrollbar-thumb-rounded-[0.25rem]'
, 'scrollbar-track-slate-200 scrollbar-thumb-gray-400'
, 'dark:scrollbar-track-gray-900 dark:scrollbar-thumb-gray-700' , ]}>
, 'dark:scrollbar-track-gray-900 dark:scrollbar-thumb-gray-700' , 'dark:bg-[#111827]']}>
<slot />
</body>

Expand Down
143 changes: 143 additions & 0 deletions src/commonComponents/EcosystemProfileCard.tsx
Original file line number Diff line number Diff line change
@@ -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<IEcosystem | null>();
const [ecosystemList, setEcosystemList] = useState<IEcosystem[] | null>();
const [loading, setLoading] = useState<boolean>();
const [ecosystemId, setEcosystemId] = useState<string>();

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 (
<Card className="m-0">
{ecosystemDetails ? (
<div
className={`flex flex-wrap items-center`}
>
<div className="mr-4">
{ecosystemDetails?.logoUrl ? (
<CustomAvatar size="60" src={ecosystemDetails?.logoUrl} />
) : (
<CustomAvatar size="70" name={ecosystemDetails?.name} />
)}
</div>

<div className="w-full sm:w-100/22rem min-w-[12rem]">
<h3 className="mb-1 text-xl font-bold text-gray-900 dark:text-white">
{ecosystemDetails?.name}
</h3>
<div className="flex items-center">
<span className="dark:text-white">Role: </span>{' '}
<RoleTablet role={ecosystemDetails?.role || ''} />
</div>
</div>


<div className="inline-flex items-end ml-auto flex-col">
<select
className="bg-gray-50 sm:min-w-[244px] border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
onChange={handleSelectEcosystem}
disabled={Boolean(ecosystemOptions && ecosystemOptions.length <= 1)}
>
<option selected>Select Ecosystem</option>
{
ecosystemOptions && ecosystemOptions.length > 0 && ecosystemOptions.map(item => (
<option key={item.id} value={item.id}>{item.name}</option>
))
}
</select>
<a href={pathRoutes.ecosystem.dashboard} className='mt-4 flex text-primary-700 dark:text-secondary-700 text-sm font-medium underline-offset-4 hover:underline'>
Go to Dashboard
<svg fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" className='h-4 w-4 text-primary-700 dark:text-secondary-700 ml-1'>
<path stroke-linecap="round" stroke-linejoin="round" d="M13.5 6H5.25A2.25 2.25 0 003 8.25v10.5A2.25 2.25 0 005.25 21h10.5A2.25 2.25 0 0018 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25"></path>
</svg>
</a>
</div>

</div>
) : !ecosystemDetails && loading ? (
<CustomSpinner />
) :
<EmptyListMessage
message={'No Ecosystem'}
description={'Get started by creating a new Ecosystem'}
buttonContent={''}
svgComponent={<svg className='pr-2 mr-1' xmlns="http://www.w3.org/2000/svg" width="24" height="15" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>} />
}
</Card>
)
}

export default EcosystemProfileCard
71 changes: 36 additions & 35 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-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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -422,36 +423,36 @@ const Dashboard = () => {
)}
</div>
</div>

<div className="mt-4 p-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<div className="grid w-full grid-cols-1 gap-4 mt-0 md:grid-cols-2 xl:grid-cols-2 2xl:grid-cols-2">
<DashboardCard
icon={memberIcon}
backgroundColor="linear-gradient(279deg, #FFF -18.24%, #2F80ED -0.8%, #1F4EAD 61.45%)"
label="Member"
value={ecosystemDashboard?.membersCount ?? 0}
/>
<DashboardCard
icon={endorseIcon}
backgroundColor="linear-gradient(279deg, #FFF -15.85%, #40F683 22.4%, #22C55E 59.86%)"
label="Endorsements"
value={ecosystemDashboard?.endorsementsCount ?? 0}
/>
</div>
</div>
<div>
<MemberList />
</div>
<EditPopupModal
openModal={editOpenModal}
setOpenModal={setEditOpenModal}
setMessage={(value) => {
setSuccess(value);
}}
isOrganization={false}
onEditSuccess={handleEditModalClose}
entityData={ecosystemDetails}
<div className="mt-4 p-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<div className="grid w-full grid-cols-1 gap-4 mt-0 md:grid-cols-2 xl:grid-cols-2 2xl:grid-cols-2">
<DashboardCard
icon={memberIcon}
backgroundColor="linear-gradient(279deg, #FFF -18.24%, #2F80ED -0.8%, #1F4EAD 61.45%)"
label="Member"
value={ecosystemDashboard?.membersCount ?? 0}
/>
<DashboardCard
icon={endorseIcon}
backgroundColor="linear-gradient(279deg, #FFF -15.85%, #40F683 22.4%, #22C55E 59.86%)"
label="Endorsements"
value={ecosystemDashboard?.endorsementsCount ?? 0}
onClickHandler={() => window.location.href = pathRoutes.ecosystem.endorsements}
/>
</div>
</div>
<div>
<MemberList />
</div>
<EditPopupModal
openModal={editOpenModal}
setOpenModal={setEditOpenModal}
setMessage={(value) => {
setSuccess(value);
}}
isOrganization={false}
onEditSuccess={handleEditModalClose}
entityData={ecosystemDetails}
/>
</div>
) : (
<div>
Expand Down Expand Up @@ -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={
Expand Down
Loading