Skip to content

Commit

Permalink
refactor: accept and create ecosystem api and stored ecosystem rol fr…
Browse files Browse the repository at this point in the history
…om api response

Signed-off-by: sanjay-k1910 <sanjay.khatal@ayanworks.com>
  • Loading branch information
sanjay-k1910 committed Oct 11, 2023
1 parent c148a79 commit f3ae44c
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 314 deletions.
373 changes: 187 additions & 186 deletions src/api/invitations.ts

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/components/CreateEcosystemOrgModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { asset } from '../../lib/data.js';
import { createOrganization } from "../../api/organization";
import { getFromLocalStorage } from "../../api/Auth";
import { createEcosystems } from "../../api/ecosystem";

import React from "react";
import { getOrgDetails } from "../../config/ecosystem";

interface Values {
name: string;
Expand Down Expand Up @@ -162,13 +163,16 @@ const CreateEcosystemOrgModal = (props: IProps) => {
const submitCreateEcosystem = async (values: EcoValues) => {
try {
setLoading(true)
const orgDetails = await getOrgDetails()
const user_data = JSON.parse(await getFromLocalStorage(storageKeys.USER_PROFILE))
const ecoData = {
name: values.name,
description: values.description,
logo: logoImage?.imagePreviewUrl as string || "",
tags: "",
userId: Number(user_data?.id)
userId: Number(user_data?.id),
orgName: orgDetails?.orgName,
orgDid: orgDetails?.orgDid
}
const resCreateEco = await createEcosystems(ecoData)

Expand Down
44 changes: 24 additions & 20 deletions src/components/Ecosystem/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getEcosystem, getEcosystemDashboard } from '../../api/ecosystem';
import { EmptyListMessage } from '../EmptyListComponent';
import CreateEcosystemOrgModal from '../CreateEcosystemOrgModal';
import { AlertComponent } from '../AlertComponent';
import { ICheckEcosystem, checkEcosystem } from '../../config/ecosystem';
import { ICheckEcosystem, checkEcosystem, getEcosystemId } from '../../config/ecosystem';
import RoleViewButton from '../RoleViewButton';
import SendInvitationModal from '../organization/invitations/SendInvitationModal';
import { Dropdown } from 'flowbite-react';
Expand Down Expand Up @@ -106,13 +106,15 @@ const Dashboard = () => {

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,
});
if (ecosystemData) {
await setToLocalStorage(storageKeys.ECOSYSTEM_ID, ecosystemData?.id);
setEcosystemId(ecosystemData?.id);
setEcosystemDetails({
logoUrl: ecosystemData.logoUrl,
name: ecosystemData.name,
description: ecosystemData.description,
});
}
} else {
setEcosystemDetailsNotFound(true);

Expand All @@ -126,21 +128,23 @@ const Dashboard = () => {
setLoading(true)

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

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

const { data } = response as AxiosResponse
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)
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
setEcosystemDashboard(data?.data)
}
else {
setFailure(response as string)
setFailure(response as string);
setLoading(false);
}
}
setLoading(false)

}

Expand Down
14 changes: 10 additions & 4 deletions src/components/Ecosystem/Endorsement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const EndorsementList = () => {
const [walletStatus, setWalletStatus] = useState(false)
const [showPopup, setShowPopup] = useState(false)
const [selectedRequest, setSelectedRequest] = useState<ISelectedRequest>()

const [isEcosystemLead, setIsEcosystemLead] = useState(false);

const options = [
{
Expand Down Expand Up @@ -170,6 +170,12 @@ const EndorsementList = () => {

useEffect(() => {
fetchOrganizationDetails()

const checkEcosystemData = async () => {
const data: ICheckEcosystem = await checkEcosystem();
setIsEcosystemLead(data.isEcosystemLead)
}
checkEcosystemData();
}, [])

return (
Expand Down Expand Up @@ -258,8 +264,8 @@ const EndorsementList = () => {
{walletStatus ?
<EmptyListMessage
message={'No Endorsement Requests'}
description={'Get started by requesting Endorsement'}
buttonContent={'Request Endorsements'}
description={''}
buttonContent={isEcosystemLead ? '' : 'Request Endorsements'}
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>}
Expand All @@ -285,7 +291,7 @@ const EndorsementList = () => {
)
}
</div>
<EndorsementPopup openModal={showPopup} closeModal={hidePopup} isAccepted={(flag: boolean) => console.log('Is accepted::', flag)} endorsementData={selectedRequest}/>
<EndorsementPopup openModal={showPopup} closeModal={hidePopup} isAccepted={(flag: boolean) => console.log('Is accepted::', flag)} endorsementData={selectedRequest} />
</div>
)
}
Expand Down
104 changes: 54 additions & 50 deletions src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import CustomSpinner from '../CustomSpinner';
import { getFromLocalStorage } from '../../api/Auth';
import { getOrganizations } from '../../api/organization';
import EcoInvitationList from './EcoInvitationList';
import { getOrgDetails } from '../../config/ecosystem';

const initialPageState = {
pageNumber: 1,
Expand Down Expand Up @@ -45,7 +46,7 @@ const ReceivedInvitations = () => {
const [loading, setLoading] = useState<boolean>(false);
const [message, setMessage] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
const [organizationsList, setOrganizationsList] =useState<Array<Organisation> | null>(null);
const [organizationsList, setOrganizationsList] = useState<Array<Organisation> | null>(null);
const [currentPage, setCurrentPage] = useState(initialPageState);
const [selectedId, setSelectedId] = useState<number>();
const [searchText, setSearchText] = useState('');
Expand Down Expand Up @@ -103,7 +104,7 @@ const ReceivedInvitations = () => {
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const totalPages = data?.data?.totalPages;

const invitationList = data?.data?.invitations.filter((invitation: { status: string; })=>{
const invitationList = data?.data?.invitations.filter((invitation: { status: string; }) => {
return invitation.status === 'pending'
})
setInvitationsData(invitationList);
Expand Down Expand Up @@ -131,16 +132,19 @@ const ReceivedInvitations = () => {

return () => clearTimeout(getData);
}, [searchText, openModal, currentPage.pageNumber]);

const respondToEcosystemInvitations = async (
invite: Invitation,
status: string,
) => {
setLoading(true);
const orgDetails = await getOrgDetails()
const response = await acceptRejectEcosystemInvitations(
invite.id,
Number(selectedId),
status,
orgDetails.orgName,
orgDetails.orgDid
);
const { data } = response as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) {
Expand Down Expand Up @@ -168,59 +172,59 @@ const ReceivedInvitations = () => {
useEffect(() => {
getOrgId();
}, []);

const rejectEnv=
<svg
className="mr-1 h-6 w-6 text-primary-700"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>

const acceptEnv=<svg
className="mr-1 h-6 w-6 text-white"
width="20"
height="20"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>
const rejectEnv =
<svg
className="mr-1 h-6 w-6 text-primary-700"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>

const acceptEnv = <svg
className="mr-1 h-6 w-6 text-white"
width="20"
height="20"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M5 12l5 5l10 -10" />
</svg>

return (
<div className="px-4 pt-6">
<div className="mb-4 col-span-full xl:mb-2">
<div className="flex justify-between items-center">
<div className="flex justify-between items-center">
<BreadCrumbs />
<Button
type="submit"
color='bg-primary-800'
onClick={() => {
window.location.href = `${pathRoutes.ecosystem.root}`
}}
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700
type="submit"
color='bg-primary-800'
onClick={() => {
window.location.href = `${pathRoutes.ecosystem.root}`
}}
className='bg-secondary-700 ring-primary-700 bg-white-700 hover:bg-secondary-700
ring-2 text-black font-medium rounded-lg text-sm px-4 lg:px-5 py-2
lg:py-2.5 mr-2 ml-auto dark:text-white dark:hover:text-black
dark:hover:bg-primary-50'
style={{ height: '2.5rem', width: '5rem', minWidth: '2rem' }}
>
<svg className='mr-1' xmlns="http://www.w3.org/2000/svg" width="22" height="12" fill="none" viewBox="0 0 30 20">
<path fill="#1F4EAD" d="M.163 9.237a1.867 1.867 0 0 0-.122 1.153c.083.387.287.742.587 1.021l8.572 7.98c.198.19.434.343.696.447a2.279 2.279 0 0 0 1.657.013c.263-.1.503-.248.704-.435.201-.188.36-.41.468-.655a1.877 1.877 0 0 0-.014-1.543 1.999 1.999 0 0 0-.48-.648l-4.917-4.576h20.543c.568 0 1.113-.21 1.515-.584.402-.374.628-.882.628-1.411 0-.53-.226-1.036-.628-1.41a2.226 2.226 0 0 0-1.515-.585H7.314l4.914-4.574c.205-.184.368-.404.48-.648a1.878 1.878 0 0 0 .015-1.542 1.99 1.99 0 0 0-.468-.656A2.161 2.161 0 0 0 11.55.15a2.283 2.283 0 0 0-1.657.013 2.154 2.154 0 0 0-.696.447L.626 8.589a1.991 1.991 0 0 0-.463.648Z" />
</svg>
<span className="min-[320px]:hidden sm:block"> Back</span>
</Button>
style={{ height: '2.5rem', width: '5rem', minWidth: '2rem' }}
>
<svg className='mr-1' xmlns="http://www.w3.org/2000/svg" width="22" height="12" fill="none" viewBox="0 0 30 20">
<path fill="#1F4EAD" d="M.163 9.237a1.867 1.867 0 0 0-.122 1.153c.083.387.287.742.587 1.021l8.572 7.98c.198.19.434.343.696.447a2.279 2.279 0 0 0 1.657.013c.263-.1.503-.248.704-.435.201-.188.36-.41.468-.655a1.877 1.877 0 0 0-.014-1.543 1.999 1.999 0 0 0-.48-.648l-4.917-4.576h20.543c.568 0 1.113-.21 1.515-.584.402-.374.628-.882.628-1.411 0-.53-.226-1.036-.628-1.41a2.226 2.226 0 0 0-1.515-.585H7.314l4.914-4.574c.205-.184.368-.404.48-.648a1.878 1.878 0 0 0 .015-1.542 1.99 1.99 0 0 0-.468-.656A2.161 2.161 0 0 0 11.55.15a2.283 2.283 0 0 0-1.657.013 2.154 2.154 0 0 0-.696.447L.626 8.589a1.991 1.991 0 0 0-.463.648Z" />
</svg>
<span className="min-[320px]:hidden sm:block"> Back</span>
</Button>
</div>
<h1 className="ml-1 text-xl font-semibold text-gray-900 sm:text-2xl dark:text-white">
Received Ecosystem Invitations
Expand Down Expand Up @@ -249,12 +253,12 @@ stroke-linejoin="round"
<Card key={invitation.id} className="p-4 mb-4">
<div id={invitation.email} className="flex flex-wrap justify-between 2xl:flex align-center">
<div id={invitation.email} className=" xl:mb-4 2xl:mb-0">
<EcoInvitationList
invitationId={invitation.id}
ecosytem={invitation.ecosystem}
<EcoInvitationList
invitationId={invitation.id}
ecosytem={invitation.ecosystem}
/>

<div id={invitation.email} className="flex">
<div id={invitation.email} className="flex">
<Button
onClick={() =>
respondToEcosystemInvitations(
Expand Down
52 changes: 28 additions & 24 deletions src/components/Resources/Schema/SchemasList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,19 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
}
props.schemaSelectionCallback(schemaId, schemaDetails)
}
// const options = ["All", "Approved", "Requested", "Rejected"]

// const handleFilter = (e: React.ChangeEvent<HTMLSelectElement>) => {
// console.log("Handle filter", e.target.value)
// if (e.target.value === 'All schemas') {
// setAllSchemaFlag(true)
// }
// else {
// setAllSchemaFlag(false)
// getSchemaList(schemaListAPIParameter, false)
// }
// };
const options = ["All schemas"]

const handleFilter = (e: React.ChangeEvent<HTMLSelectElement>) => {
console.log("Handle filter", e.target.value)
if (e.target.value === 'All schemas') {
setAllSchemaFlag(true)
}
else {
setAllSchemaFlag(false)
getSchemaList(schemaListAPIParameter, false)
}
};

const fetchOrganizationDetails = async () => {
setLoading(true)
Expand Down Expand Up @@ -171,19 +172,22 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
<SearchInput
onInputChange={onSearch}
/>
{/* <select onChange={handleFilter} id="schamfilter"
className="bg-gray-50 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 h-11">
<option selected>Organization's schema</option>
{options.map((opt) => (
<option
key={opt}
className=""
value={opt}
>
{opt}
</option>
))}
</select> */}
{
!isEcosystemData?.isEnabledEcosystem &&
<select onChange={handleFilter} id="schamfilter"
className="bg-gray-50 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 h-11">
<option selected>Organization's schema</option>
{options.map((opt) => (
<option
key={opt}
className=""
value={opt}
>
{opt}
</option>
))}
</select>
}
</div>
<div className='flex space-x-2'>
{walletStatus ? <RoleViewButton
Expand Down
Loading

0 comments on commit f3ae44c

Please sign in to comment.