From 7e36e874404d9caaff6b53feff6bfc09e4fc79c3 Mon Sep 17 00:00:00 2001 From: sanjay-k1910 Date: Tue, 17 Oct 2023 02:17:11 +0530 Subject: [PATCH 1/2] refactor: invitation list for accept and reject flow Signed-off-by: sanjay-k1910 --- src/api/invitations.ts | 2 +- .../EcoSystemReceivedInvitations.tsx | 128 +++++++++++++----- .../Resources/Schema/SchemasList.tsx | 41 +++--- src/components/organization/OrgDropDown.tsx | 2 +- 4 files changed, 116 insertions(+), 57 deletions(-) diff --git a/src/api/invitations.ts b/src/api/invitations.ts index 9fd30583f..4611f9922 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 b28d1d6f7..cfb19afd2 100644 --- a/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx +++ b/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx @@ -7,16 +7,14 @@ 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'; const initialPageState = { pageNumber: 1, @@ -24,6 +22,10 @@ const initialPageState = { total: 0, }; +interface IOrgData { + orgDid: string + orgName: string +} export interface EcosystemInvitation { ecosystem: [] @@ -37,6 +39,8 @@ export interface EcosystemInvitation { orgId: string status: string email: string + selected?: boolean + orgData?: IOrgData } @@ -50,6 +54,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({ @@ -58,8 +63,6 @@ const ReceivedInvitations = () => { }); }; - const props = { openModal, setOpenModal }; - const getAllOrganizationsForEcosystem = async () => { setLoading(true); const response = await getOrganizations( @@ -103,7 +106,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); @@ -133,31 +136,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); }; @@ -241,7 +290,7 @@ const ReceivedInvitations = () => { /> {loading ? ( -
+
) : invitationsData && invitationsData?.length > 0 ? ( @@ -249,7 +298,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"' > @@ -287,24 +337,34 @@ const ReceivedInvitations = () => {
    - -
    +
    + { + invitation.selected && + { + setGetOrgError(null); + }} + /> + }
    ))}
@@ -319,7 +379,7 @@ const ReceivedInvitations = () => { ) )} - {currentPage.pageNumber > 1 &&
+ {currentPage.pageNumber > 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) => { From a79714dadb967838ec6d5ba8f065feda94e5dc85 Mon Sep 17 00:00:00 2001 From: sanjay-k1910 Date: Tue, 17 Oct 2023 02:17:58 +0530 Subject: [PATCH 2/2] refactor: responsiveness of invitation form popup Signed-off-by: sanjay-k1910 --- src/components/organization/invitations/SendInvitationModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organization/invitations/SendInvitationModal.tsx b/src/components/organization/invitations/SendInvitationModal.tsx index 26381f748..6a1eeaf82 100644 --- a/src/components/organization/invitations/SendInvitationModal.tsx +++ b/src/components/organization/invitations/SendInvitationModal.tsx @@ -236,7 +236,7 @@ const SendInvitationModal = (props: {
      {invitations.map((invitation) => (
    • -
      +