diff --git a/src/api/invitations.ts b/src/api/invitations.ts index 28303043e..47bfbd2d5 100644 --- a/src/api/invitations.ts +++ b/src/api/invitations.ts @@ -233,7 +233,7 @@ export const getEcosystemInvitations = async (pageNumber: number, pageSize: numb } // Accept/ Reject Invitations -export const acceptRejectEcosystemInvitations = async (invitationId: number, orgId: number, status: string, orgName: string, orgDid: string) => { +export const acceptRejectEcosystemInvitations = async (invitationId: string, orgId: number, status: string, orgName: string, orgDid: string) => { const url = `${apiRoutes.Ecosystem.root}/${orgId}${apiRoutes.Ecosystem.invitations}/${invitationId}` diff --git a/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx b/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx index 6a4d54ab5..85bb62408 100644 --- a/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx +++ b/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx @@ -7,14 +7,13 @@ import { import { AlertComponent } from '../AlertComponent'; import type { AxiosResponse } from 'axios'; import BreadCrumbs from '../BreadCrumbs'; -import type { Invitation } from '../organization/interfaces/invitations'; import type { Organisation } from '../organization/interfaces'; import { apiStatusCodes, storageKeys } from '../../config/CommonConstant'; import { pathRoutes } from '../../config/pathRoutes'; import { EmptyListMessage } from '../EmptyListComponent'; import CustomSpinner from '../CustomSpinner'; import { getFromLocalStorage } from '../../api/Auth'; -import { getOrganizations } from '../../api/organization'; +import { getOrganizationById, getOrganizations } from '../../api/organization'; import EcoInvitationList from './EcoInvitationList'; import { getOrgDetails } from '../../config/ecosystem'; import BackButton from '../../commonComponents/backbutton' @@ -25,6 +24,10 @@ const initialPageState = { total: 0, }; +interface IOrgData { + orgDid: string + orgName: string +} export interface EcosystemInvitation { ecosystem: [] @@ -38,6 +41,8 @@ export interface EcosystemInvitation { orgId: string status: string email: string + selected?: boolean + orgData?: IOrgData } @@ -51,6 +56,7 @@ const ReceivedInvitations = () => { const [selectedId, setSelectedId] = useState(); const [searchText, setSearchText] = useState(''); const [invitationsData, setInvitationsData] = useState | null>(null); + const [getOrgError, setGetOrgError] = useState(null); const onPageChange = (page: number) => { setCurrentPage({ @@ -59,8 +65,6 @@ const ReceivedInvitations = () => { }); }; - const props = { openModal, setOpenModal }; - const getAllOrganizationsForEcosystem = async () => { setLoading(true); const response = await getOrganizations( @@ -104,7 +108,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); @@ -134,31 +138,77 @@ const ReceivedInvitations = () => { }, [searchText, openModal, currentPage.pageNumber]); const respondToEcosystemInvitations = async ( - invite: Invitation, + invite: EcosystemInvitation, 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) { - setMessage(data?.message); - setLoading(false); - getAllInvitations() - } else { - setError(response as string); - setLoading(false); + try { + const orgDid = invite?.orgData?.orgDid || "" + const orgName = invite?.orgData?.orgName || "" + if (orgDid) { + const response = await acceptRejectEcosystemInvitations( + invite.id, + Number(selectedId), + status, + orgName, + orgDid + ); + setLoading(false) + const { data } = response as AxiosResponse; + if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) { + setMessage(data?.message); + getAllInvitations() + } else { + setError(response as string); + } + } + setLoading(false) + } catch (err) { + console.log("ERROR - Accept/Reject Ecosystem::", err) } }; - const handleDropdownChange = (e: { target: { value: any } }) => { + const getSelectedOrgDetails = async (orgId: string): Promise => { + try { + const response = await getOrganizationById(orgId); + const { data } = response as AxiosResponse; + const orgData = data?.data + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + if (orgData.org_agents[0]?.orgDid) { + setGetOrgError(null) + return { + orgDid: orgData.org_agents[0]?.orgDid || "", + orgName: orgData.name + } + } else { + setGetOrgError("Please create your wallet for this organization to accept the invitation.") + return null + } + } + return null + } catch (err) { + console.log("ERROR::", err) + return null + } + } + + const handleDropdownChange = async (e: { target: { value: any } }, id: string) => { const value = e.target.value; + const orgData: IOrgData | null | undefined = await getSelectedOrgDetails(value) + const updateInvitationData = invitationsData && invitationsData.length > 0 ? invitationsData.map((item) => { + if (id === item.id) { + return { + ...item, + orgId: value, + selected: true, + orgData: orgData || undefined + } + } + return { + ...item, + selected: false + } + }) : null + setInvitationsData(updateInvitationData) setSelectedId(value); }; @@ -226,7 +276,7 @@ const ReceivedInvitations = () => { /> {loading ? ( -
+
) : invitationsData && invitationsData?.length > 0 ? ( @@ -234,7 +284,7 @@ const ReceivedInvitations = () => {
    {invitationsData.map((invitation) => ( - +
    { 'accepted', ) } + disabled={!invitation?.orgData} id={invitation.id} className='mx-5 mt-5 text-base font-medium text-center text-white bg-primary-700 hover:!bg-primary-800 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-700 dark:hover:!bg-primary-800 dark:focus:ring-primary-800"' > @@ -272,24 +323,34 @@ const ReceivedInvitations = () => {
    - -
    +
    + { + invitation.selected && + { + setGetOrgError(null); + }} + /> + }
    ))}
@@ -304,7 +365,7 @@ const ReceivedInvitations = () => { ) )} - {currentPage.total > 1 &&
+ {currentPage.total > 1 &&
{ fetchOrganizationDetails() const checkEcosystemData = async () => { - const data: ICheckEcosystem = await checkEcosystem(); - setIsEcosystemData(data) - } - - checkEcosystemData(); + const data: ICheckEcosystem = await checkEcosystem(); + setIsEcosystemData(data) + } + + checkEcosystemData(); }, []) const createSchemaTitle = isEcosystemData?.isEcosystemMember ? "Request Endorsement" : "Create" @@ -172,22 +172,21 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD - { - !isEcosystemData?.isEnabledEcosystem && - - } + + +
{walletStatus ? { > {orgList?.length > 0 ? (
    {orgList?.map((org) => { diff --git a/src/components/organization/invitations/SendInvitationModal.tsx b/src/components/organization/invitations/SendInvitationModal.tsx index 0dcb522f9..4c1898878 100644 --- a/src/components/organization/invitations/SendInvitationModal.tsx +++ b/src/components/organization/invitations/SendInvitationModal.tsx @@ -238,7 +238,7 @@ const SendInvitationModal = (props: {
      {invitations.map((invitation) => (
    • -
      +