From f3ae44ce3a6406152aae0e4558bd783cebf4a682 Mon Sep 17 00:00:00 2001 From: sanjay-k1910 Date: Wed, 11 Oct 2023 23:47:34 +0530 Subject: [PATCH 1/2] refactor: accept and create ecosystem api and stored ecosystem rol from api response Signed-off-by: sanjay-k1910 --- src/api/invitations.ts | 373 +++++++++--------- .../CreateEcosystemOrgModal/index.tsx | 8 +- src/components/Ecosystem/Dashboard.tsx | 44 ++- .../Ecosystem/Endorsement/index.tsx | 14 +- .../EcoSystemReceivedInvitations.tsx | 104 ++--- .../Resources/Schema/SchemasList.tsx | 52 +-- src/components/User/UserDashBoard.tsx | 40 +- src/config/CommonConstant.ts | 4 +- src/config/ecosystem.ts | 55 ++- 9 files changed, 380 insertions(+), 314 deletions(-) diff --git a/src/api/invitations.ts b/src/api/invitations.ts index 3b341c467..9fd30583f 100644 --- a/src/api/invitations.ts +++ b/src/api/invitations.ts @@ -1,4 +1,4 @@ -import { axiosDelete, axiosGet, axiosPost } from "../services/apiRequests" +import { axiosDelete, axiosGet, axiosPost, axiosPut } from "../services/apiRequests" import { apiRoutes } from "../config/apiRoutes"; import { getFromLocalStorage } from "./Auth"; @@ -6,66 +6,66 @@ import { storageKeys } from "../config/CommonConstant"; export const getOrganizationInvitations = async (pageNumber: number, pageSize: number, search = '') => { - const orgId = await getFromLocalStorage(storageKeys.ORG_ID) - - if (!orgId) { - return "Organization is required"; - } - - const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.organizations.invitations}?&pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}` - - 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 - } + const orgId = await getFromLocalStorage(storageKeys.ORG_ID) + + if (!orgId) { + return "Organization is required"; + } + + const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.organizations.invitations}?&pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}` + + 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 + } } export const createInvitations = async (invitationList: Array) => { - const orgId = await getFromLocalStorage(storageKeys.ORG_ID) - - const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.organizations.invitations}` - const payload = { - invitations: invitationList, - orgId: Number(orgId) - } - const token = await getFromLocalStorage(storageKeys.TOKEN) - - const config = { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } - } - const axiosPayload = { - url, - payload, - config - } - - try { - return await axiosPost(axiosPayload); - } - catch (error) { - const err = error as Error - return err?.message - } + const orgId = await getFromLocalStorage(storageKeys.ORG_ID) + + const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.organizations.invitations}` + const payload = { + invitations: invitationList, + orgId: Number(orgId) + } + const token = await getFromLocalStorage(storageKeys.TOKEN) + + const config = { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } + } + const axiosPayload = { + url, + payload, + config + } + + try { + return await axiosPost(axiosPayload); + } + catch (error) { + const err = error as Error + return err?.message + } } export const getEcosystemList = async () => { @@ -75,78 +75,78 @@ export const getEcosystemList = async () => { const token = await getFromLocalStorage(storageKeys.TOKEN) const config = { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } } const axiosPayload = { - url, - config + url, + config } try { - return await axiosGet(axiosPayload); + return await axiosGet(axiosPayload); } catch (error) { - const err = error as Error - return err?.message + const err = error as Error + return err?.message } } -export const createEcoSystemInvitations = async (invitationList: Array,ecosystemId: string) => { - const orgId = await getFromLocalStorage(storageKeys.ORG_ID); - const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}${apiRoutes.Ecosystem.invitations}` +export const createEcoSystemInvitations = async (invitationList: Array, ecosystemId: string) => { + const orgId = await getFromLocalStorage(storageKeys.ORG_ID); + const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}${apiRoutes.Ecosystem.invitations}` const payload = { - invitations: invitationList, + invitations: invitationList, } const token = await getFromLocalStorage(storageKeys.TOKEN) const config = { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } } const axiosPayload = { - url, - payload, - config + url, + payload, + config } try { - return await axiosPost(axiosPayload); + return await axiosPost(axiosPayload); } catch (error) { - const err = error as Error - return err?.message + const err = error as Error + return err?.message } } // Received Invitations by User export const getUserInvitations = async (pageNumber: number, pageSize: number, search = '') => { - const url = `${apiRoutes.users.invitations}?pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}` - - 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 - } + const url = `${apiRoutes.users.invitations}?pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}` + + 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 + } } @@ -158,22 +158,22 @@ export const getUserEcosystemInvitations = async (pageNumber: number, pageSize: const token = await getFromLocalStorage(storageKeys.TOKEN) const config = { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } } const axiosPayload = { - url, - config + url, + config } try { - return await axiosGet(axiosPayload); + return await axiosGet(axiosPayload); } catch (error) { - const err = error as Error - return err?.message + const err = error as Error + return err?.message } } @@ -186,139 +186,140 @@ export const getEcosytemReceivedInvitations = async (pageNumber: number, pageSiz const token = await getFromLocalStorage(storageKeys.TOKEN) const config = { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } } const axiosPayload = { - url, - config + url, + config } try { - return await axiosGet(axiosPayload); + return await axiosGet(axiosPayload); } catch (error) { - const err = error as Error - return err?.message + const err = error as Error + return err?.message } } -export const getEcosystemInvitations = async (pageNumber: number, pageSize: number, search:string) => { +export const getEcosystemInvitations = async (pageNumber: number, pageSize: number, search: string) => { const ecosystemId = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID); - + const orgId = await getFromLocalStorage(storageKeys.ORG_ID); const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}${apiRoutes.Ecosystem.invitations}` const token = await getFromLocalStorage(storageKeys.TOKEN) const config = { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } } const axiosPayload = { - url, - config + url, + config } try { - return await axiosGet(axiosPayload); + return await axiosGet(axiosPayload); } catch (error) { - const err = error as Error - return err?.message + const err = error as Error + return err?.message } } // Accept/ Reject Invitations -export const acceptRejectEcosystemInvitations = async (invitationId: number,orgId: number, status: string) => { - - const url = `${apiRoutes.Ecosystem.root}/${orgId}${apiRoutes.Ecosystem.invitations}/${invitationId}` - - const payload = { - orgId: Number(orgId), - status - } - const token = await getFromLocalStorage(storageKeys.TOKEN) - - const config = { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } - } - const axiosPayload = { - url, - payload, - config - } - - try { - return await axiosPost(axiosPayload); - } - catch (error) { - const err = error as Error - return err?.message - } +export const acceptRejectEcosystemInvitations = async (invitationId: number, orgId: number, status: string, orgName: string, orgDid: string) => { + + const url = `${apiRoutes.Ecosystem.root}/${orgId}${apiRoutes.Ecosystem.invitations}/${invitationId}` + + const payload = { + status, + orgName, + orgDid + } + const token = await getFromLocalStorage(storageKeys.TOKEN) + + const config = { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } + } + const axiosPayload = { + url, + payload, + config + } + + try { + return await axiosPut(axiosPayload); + } + catch (error) { + const err = error as Error + return err?.message + } } -export const acceptRejectInvitations = async (invitationId: number,orgId: number, status: string) => { +export const acceptRejectInvitations = async (invitationId: number, orgId: number, status: string) => { const url = `${apiRoutes.users.invitations}/${invitationId}` - + const payload = { - orgId: Number(orgId), - status + orgId: Number(orgId), + status } const token = await getFromLocalStorage(storageKeys.TOKEN) const config = { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } } const axiosPayload = { - url, - payload, - config + url, + payload, + config } try { - return await axiosPost(axiosPayload); + return await axiosPost(axiosPayload); } catch (error) { - const err = error as Error - return err?.message + const err = error as Error + return err?.message } } export const deleteEcosystemInvitations = async (invitationId: number) => { - + const ecosystemId = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID); - const orgId = await getFromLocalStorage(storageKeys.ORG_ID) + const orgId = await getFromLocalStorage(storageKeys.ORG_ID) const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}${apiRoutes.Ecosystem.invitations}/${invitationId}` - + const token = await getFromLocalStorage(storageKeys.TOKEN) const config = { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - } + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } } const axiosPayload = { - url, - config + url, + config } try { - return await axiosDelete(axiosPayload); + return await axiosDelete(axiosPayload); } catch (error) { - const err = error as Error - return err?.message + const err = error as Error + return err?.message } } diff --git a/src/components/CreateEcosystemOrgModal/index.tsx b/src/components/CreateEcosystemOrgModal/index.tsx index bfc98cdc0..7e7403fdd 100644 --- a/src/components/CreateEcosystemOrgModal/index.tsx +++ b/src/components/CreateEcosystemOrgModal/index.tsx @@ -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; @@ -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) diff --git a/src/components/Ecosystem/Dashboard.tsx b/src/components/Ecosystem/Dashboard.tsx index 5a451d411..f020b9eda 100644 --- a/src/components/Ecosystem/Dashboard.tsx +++ b/src/components/Ecosystem/Dashboard.tsx @@ -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'; @@ -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); @@ -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) } diff --git a/src/components/Ecosystem/Endorsement/index.tsx b/src/components/Ecosystem/Endorsement/index.tsx index 6e65902e3..7bdebf4ab 100644 --- a/src/components/Ecosystem/Endorsement/index.tsx +++ b/src/components/Ecosystem/Endorsement/index.tsx @@ -57,7 +57,7 @@ const EndorsementList = () => { const [walletStatus, setWalletStatus] = useState(false) const [showPopup, setShowPopup] = useState(false) const [selectedRequest, setSelectedRequest] = useState() - + const [isEcosystemLead, setIsEcosystemLead] = useState(false); const options = [ { @@ -170,6 +170,12 @@ const EndorsementList = () => { useEffect(() => { fetchOrganizationDetails() + + const checkEcosystemData = async () => { + const data: ICheckEcosystem = await checkEcosystem(); + setIsEcosystemLead(data.isEcosystemLead) + } + checkEcosystemData(); }, []) return ( @@ -258,8 +264,8 @@ const EndorsementList = () => { {walletStatus ? } @@ -285,7 +291,7 @@ const EndorsementList = () => { ) } - console.log('Is accepted::', flag)} endorsementData={selectedRequest}/> + console.log('Is accepted::', flag)} endorsementData={selectedRequest} /> ) } diff --git a/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx b/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx index e8d0477f5..8d9c53d45 100644 --- a/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx +++ b/src/components/EcosystemInvite/EcoSystemReceivedInvitations.tsx @@ -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, @@ -45,7 +46,7 @@ const ReceivedInvitations = () => { const [loading, setLoading] = useState(false); const [message, setMessage] = useState(null); const [error, setError] = useState(null); - const [organizationsList, setOrganizationsList] =useState | null>(null); + const [organizationsList, setOrganizationsList] = useState | null>(null); const [currentPage, setCurrentPage] = useState(initialPageState); const [selectedId, setSelectedId] = useState(); const [searchText, setSearchText] = useState(''); @@ -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); @@ -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) { @@ -168,59 +172,59 @@ const ReceivedInvitations = () => { useEffect(() => { getOrgId(); }, []); - -const rejectEnv= - - - -const acceptEnv= - - - + const rejectEnv = + + + + + const acceptEnv = + + + return (
-
+
+ style={{ height: '2.5rem', width: '5rem', minWidth: '2rem' }} + > + + + + Back +

Received Ecosystem Invitations @@ -249,12 +253,12 @@ stroke-linejoin="round"
- -
+
{walletStatus ? { if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { const totalPages = data?.data?.totalPages; - const invitationPendingList = data?.data?.invitations.filter( + 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) { setEcoMessage(`You have received invitation to join ecosystem `); setViewButton(true); } @@ -284,25 +284,23 @@ const UserDashBoard = () => {
{activityList ? (
    - {activityList && - activityList.map((activity) => { - return ( -
  1. -
    - -

    - {activity.action} -

    -

    - {activity.details} -

    -
  2. - ); - })} + {activityList.map((activity) => ( +
  3. +
    + +

    + {activity.action} +

    +

    + {activity.details} +

    +
  4. + ) + )}
) : ( activityList && ( diff --git a/src/config/CommonConstant.ts b/src/config/CommonConstant.ts index 2ca1b7805..07975899d 100644 --- a/src/config/CommonConstant.ts +++ b/src/config/CommonConstant.ts @@ -28,5 +28,7 @@ export const storageKeys = { CRED_DEF_ID:'cred_def_id', SCHEMA_DID: 'schema_did', LOGIN_USER_EMAIL: 'login_user_email', - ECOSYSTEM_ID: "ecosystem_id" + ECOSYSTEM_ID: "ecosystem_id", + ORG_DETAILS: "org_details", + ECOSYSTEM_ROLE: "ecosystem_role" } diff --git a/src/config/ecosystem.ts b/src/config/ecosystem.ts index 861689688..21abc1b20 100644 --- a/src/config/ecosystem.ts +++ b/src/config/ecosystem.ts @@ -3,6 +3,7 @@ import { getFromLocalStorage, setToLocalStorage } from "../api/Auth" import { getEcosystem } from "../api/ecosystem" import { EcosystemRoles } from "../common/enums" import { apiStatusCodes, storageKeys } from "./CommonConstant" +import { getOrganizationById } from "../api/organization" export interface ICheckEcosystem { isEnabledEcosystem: boolean; @@ -10,11 +11,26 @@ export interface ICheckEcosystem { isEcosystemLead: boolean; } +export interface IOrgDetails { + orgName: string + orgDid: string +} + const ecosystemId = async () => { const id = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID) return id } +const getOrgData = async () => { + const data = await getFromLocalStorage(storageKeys.ORG_DETAILS) + return data +} + +const getEcosystemRole = async () => { + const data = await getFromLocalStorage(storageKeys.ECOSYSTEM_ROLE) + return data +} + const getOrgId = async () => { const id = await getFromLocalStorage(storageKeys.ORG_ID) return id @@ -27,10 +43,9 @@ const getUserProfile = async () => { } const checkEcosystem = async (): Promise => { + await getEcosystemId() const userData = await getUserProfile() - - // Added this key to change ecosystem role from localstorage until we'll get ecosystem role from backend - const role = await localStorage.getItem("eco_role") + const role = await getEcosystemRole() const isEnabledEcosystem = userData?.enableEcosystem const ecosystemRole = role ?? EcosystemRoles.ecosystemLead @@ -43,14 +58,18 @@ const checkEcosystem = async (): Promise => { const getEcosystemId = async (): Promise => { const ecoId = await ecosystemId() + const ecoRole = await getEcosystemRole() const orgId = await getOrgId() - if (!ecoId) { + if (!ecoId || !ecoRole) { try { const { data } = await getEcosystem(orgId) as AxiosResponse if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS && data?.data && data?.data.length > 0) { - const id = data?.data[0].id + const response = data?.data[0] + const id = response?.id + const role = response?.ecosystemOrgs[0].ecosystemRole.name await setToLocalStorage(storageKeys.ECOSYSTEM_ID, id); + await setToLocalStorage(storageKeys.ECOSYSTEM_ROLE, role); return id } } catch (err) { @@ -60,4 +79,28 @@ const getEcosystemId = async (): Promise => { return ecoId } -export { checkEcosystem, getEcosystemId } \ No newline at end of file +const getOrgDetails = async (): Promise => { + const orgId = await getOrgId() + const org = await getOrgData() + const orgData: IOrgDetails = org && JSON.parse(org) + const isOrgData = Object.keys(orgData).length > 0 + if (!isOrgData) { + try { + const { data } = await getOrganizationById(orgId) as AxiosResponse + + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + const orgData: IOrgDetails = { + orgName: data?.data?.name, + orgDid: data?.data && data?.data?.org_agents?.length > 0 ? data?.data?.org_agents[0]?.orgDid : "" + } + await setToLocalStorage(storageKeys.ORG_DETAILS, JSON.stringify(orgData)); + return orgData + } + } catch (err) { + console.log("ERROR-Get ORG Details", err) + } + } + return orgData +} + +export { checkEcosystem, getEcosystemId, getOrgDetails } \ No newline at end of file From 037c388c37de80aaaea4c826848fda8d1ce41da6 Mon Sep 17 00:00:00 2001 From: sanjay-k1910 Date: Thu, 12 Oct 2023 02:13:17 +0530 Subject: [PATCH 2/2] refactor: signin and ecosystem flow Signed-off-by: sanjay-k1910 --- src/common/enums.ts | 5 +- src/components/Authentication/SignInUser.tsx | 1 + .../CreateEcosystemOrgModal/index.tsx | 1 - src/components/Ecosystem/Dashboard.tsx | 269 +++++++++--------- .../Ecosystem/Endorsement/EndorsementCard.tsx | 115 ++++---- .../Ecosystem/Endorsement/index.tsx | 23 +- .../EcosystemInvite/SentInvitations.tsx | 12 +- src/config/ecosystem.ts | 10 +- 8 files changed, 238 insertions(+), 198 deletions(-) diff --git a/src/common/enums.ts b/src/common/enums.ts index c5c225ff6..6cffb8b95 100644 --- a/src/common/enums.ts +++ b/src/common/enums.ts @@ -39,14 +39,15 @@ export enum IssueCredentialUserText { export enum EndorsementType { schema = 'schema', - credDef = 'credDef' + credDef = 'credential-definition' } export enum EndorsementStatus { all = "all", approved = "approved", rejected = "rejected", - requested = "requested" + requested = "requested", + submitted = "submitted" } export enum EcosystemRoles { diff --git a/src/components/Authentication/SignInUser.tsx b/src/components/Authentication/SignInUser.tsx index c5cda6154..499a81e70 100644 --- a/src/components/Authentication/SignInUser.tsx +++ b/src/components/Authentication/SignInUser.tsx @@ -75,6 +75,7 @@ const SignInUser = () => { const saveEmail = async (values: emailValue) => { setEmail(values) + await localStorage.clear(); setCurrentComponent('password'); await setToLocalStorage(storageKeys.LOGIN_USER_EMAIL, values.email); setIsPasskeySuccess(true); diff --git a/src/components/CreateEcosystemOrgModal/index.tsx b/src/components/CreateEcosystemOrgModal/index.tsx index 7e7403fdd..9e02683e2 100644 --- a/src/components/CreateEcosystemOrgModal/index.tsx +++ b/src/components/CreateEcosystemOrgModal/index.tsx @@ -13,7 +13,6 @@ 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 { diff --git a/src/components/Ecosystem/Dashboard.tsx b/src/components/Ecosystem/Dashboard.tsx index f020b9eda..3bffbdd54 100644 --- a/src/components/Ecosystem/Dashboard.tsx +++ b/src/components/Ecosystem/Dashboard.tsx @@ -31,55 +31,56 @@ const initialPageState = { }; const Dashboard = () => { - const [ecosystemDetails, setEcosystemDetails] = useState(); - const [success, setSuccess] = useState(null); - const [failure, setFailure] = useState(null); - const [message, setMessage] = useState(null); - const [loading, setLoading] = useState(true); - const [ecosystemId, setEcosystemId] = useState('') - const [editOpenModal, setEditOpenModal] = useState(false); - const [dropdownOpen, setDropdownOpen] = useState(false); - const [error, setError] = useState(null); - const [openModal, setOpenModal] = useState(false); - const [viewButton, setViewButton] = useState(false); - const [currentPage, setCurrentPage] = useState(initialPageState); - const [isEcosystemLead, setIsEcosystemLead] = useState(false); + const [ecosystemDetails, setEcosystemDetails] = useState(); + const [success, setSuccess] = useState(null); + const [failure, setFailure] = useState(null); + const [message, setMessage] = useState(null); + const [loading, setLoading] = useState(true); + const [ecosystemId, setEcosystemId] = useState('') + const [editOpenModal, setEditOpenModal] = useState(false); + const [dropdownOpen, setDropdownOpen] = useState(false); + const [error, setError] = useState(null); + const [openModal, setOpenModal] = useState(false); + const [viewButton, setViewButton] = useState(false); + const [currentPage, setCurrentPage] = useState(initialPageState); + const [isEcosystemLead, setIsEcosystemLead] = useState(false); const [ecosystemDashboard, setEcosystemDashboard] = useState(null) - const [ecosystemDetailsNotFound, setEcosystemDetailsNotFound] = useState(false); + const [ecosystemDetailsNotFound, setEcosystemDetailsNotFound] = useState(false); + const [orgId, setOrgId] = useState(''); + const [isOrgModal, setIsOrgModal] = useState(false) - - const createEcosystemModel = () => { - setOpenModal(true); - }; + const createEcosystemModel = () => { + setOpenModal(true); + }; - const createInvitationsModel = () => { - setOpenModal(true); - }; + const createInvitationsModel = () => { + setOpenModal(true); + }; - const EditEcosystemOrgModal = () => { - setEditOpenModal(true); - }; + const EditEcosystemOrgModal = () => { + setEditOpenModal(true); + }; - const handleEditModalClose = () => { - setEditOpenModal(false); - setDropdownOpen(false); + const handleEditModalClose = () => { + setEditOpenModal(false); + setDropdownOpen(false); fetchEcosystemDetails() - }; + }; const getAllEcosystemInvitations = async () => { - - setLoading(true); - const response = await getUserEcosystemInvitations( - currentPage.pageNumber, - currentPage.pageSize, - '', + + setLoading(true); + const response = await getUserEcosystemInvitations( + currentPage.pageNumber, + currentPage.pageSize, + '', ); const { data } = response as AxiosResponse; - + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { - const totalPages = data?.data?.totalPages; - - const invitationPendingList = data?.data?.invitations.filter((invitation: { status: string; }) => { + const totalPages = data?.data?.totalPages; + + const invitationPendingList = data?.data?.invitations.filter((invitation: { status: string; }) => { return invitation.status === 'pending' }) @@ -98,14 +99,15 @@ 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]; + setLoading(true); + const id = await getFromLocalStorage(storageKeys.ORG_ID); + setOrgId(id) + if (id) { + const response = await getEcosystem(id); + const { data } = response as AxiosResponse; + + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + const ecosystemData = data?.data[0]; if (ecosystemData) { await setToLocalStorage(storageKeys.ECOSYSTEM_ID, ecosystemData?.id); setEcosystemId(ecosystemData?.id); @@ -115,20 +117,20 @@ const Dashboard = () => { description: ecosystemData.description, }); } - } else { - setEcosystemDetailsNotFound(true); - - } - } - setLoading(false); - }; + } else { + setEcosystemDetailsNotFound(true); - const fetchEcosystemDashboard = async () => { + } + } + setLoading(false); + }; + + const fetchEcosystemDashboard = async () => { setLoading(true) const orgId = await getFromLocalStorage(storageKeys.ORG_ID); - const ecosystemId = await getEcosystemId(); + const ecosystemId = await getEcosystemId(); if (ecosystemId && orgId) { const response = await getEcosystemDashboard(ecosystemId, orgId); @@ -145,25 +147,25 @@ const Dashboard = () => { } } setLoading(false) - + } - const checkOrgId = async () => { - const orgId = await getFromLocalStorage(storageKeys.ORG_ID); - if (orgId) { - await getAllEcosystemInvitations(); - } - }; + const checkOrgId = async () => { + const orgId = await getFromLocalStorage(storageKeys.ORG_ID); + if (orgId) { + await getAllEcosystemInvitations(); + } + }; - const getDashboardData = async () => { - await checkOrgId(); - await fetchEcosystemDetails(); - await fetchEcosystemDashboard(); - }; + const getDashboardData = async () => { + await checkOrgId(); + await fetchEcosystemDetails(); + await fetchEcosystemDashboard(); + }; useEffect(() => { - getDashboardData(); - + getDashboardData(); + const checkEcosystemData = async () => { const data: ICheckEcosystem = await checkEcosystem(); setIsEcosystemLead(data.isEcosystemLead) @@ -174,7 +176,7 @@ const Dashboard = () => { - return ( + return (
@@ -197,8 +199,8 @@ const Dashboard = () => {
{ { setMessage(null); @@ -276,38 +278,36 @@ const Dashboard = () => { onClickEvent={createInvitationsModel} /> setDropdownOpen(!dropdownOpen)} - renderTrigger={() => } - > - -
- Edit Ecosystem -
-
- -
- Enable/Disable Ecosystem -
-
- -
- Manual Registration -
-
- - -
+ label={"test"} + open={dropdownOpen} + onToggle={() => setDropdownOpen(!dropdownOpen)} + renderTrigger={() => } + > + +
+ Edit Ecosystem +
+
+ +
+ Enable/Disable Ecosystem +
+
+ +
+ Manual Registration +
+
+
)}
@@ -339,7 +339,7 @@ const Dashboard = () => { Endorsements

- {ecosystemDashboard?.endorsementsCount} + {ecosystemDashboard?.endorsementsCount}
@@ -349,15 +349,15 @@ const Dashboard = () => {
{ - setSuccess(value); - }} - isOrganization={false} - onEditSuccess={handleEditModalClose} - entityData={ecosystemDetails} - /> + openModal={editOpenModal} + setOpenModal={setEditOpenModal} + setMessage={(value) => { + setSuccess(value); + }} + isOrganization={false} + onEditSuccess={handleEditModalClose} + entityData={ecosystemDetails} + /> )} @@ -375,14 +375,21 @@ const Dashboard = () => { setOpenModal={setOpenModal} setMessage={(value) => { setSuccess(value); - fetchEcosystemDetails(); + if (isOrgModal && value) { + setTimeout(() => { + window.location.reload(); + }, 2000); + } else { + fetchEcosystemDetails(); + } }} - isorgModal={false} + isorgModal={isOrgModal} /> { /> } - onClick={() => createEcosystemModel()} + onClick={() => { + setIsOrgModal(Boolean(!orgId)) + createEcosystemModel() + } + } /> @@ -406,16 +417,16 @@ const Dashboard = () => { )} -{ecosystemDetailsNotFound && ( - { - setEcosystemDetailsNotFound(false); - setFailure(null); - }} - /> - )} + {ecosystemDetailsNotFound && ( + { + setEcosystemDetailsNotFound(false); + setFailure(null); + }} + /> + )} ); }; diff --git a/src/components/Ecosystem/Endorsement/EndorsementCard.tsx b/src/components/Ecosystem/Endorsement/EndorsementCard.tsx index 59fc45764..1f5cf9bba 100644 --- a/src/components/Ecosystem/Endorsement/EndorsementCard.tsx +++ b/src/components/Ecosystem/Endorsement/EndorsementCard.tsx @@ -1,7 +1,7 @@ import { Card } from 'flowbite-react'; import { dateConversion } from '../../../utils/DateConversion'; import DateTooltip from '../../../components/Tooltip'; -import { EndorsementStatus } from '../../../common/enums'; +import { EndorsementStatus, EndorsementType } from '../../../common/enums'; import StatusTabletTag from '../../../commonComponents/StatusTabletTag'; import { ICheckEcosystem, checkEcosystem } from '../../../config/ecosystem'; import { useEffect, useState } from 'react'; @@ -20,17 +20,18 @@ const EndorsementCard = ({ fromEndorsementList, data, onClickCallback, cardTrans useEffect(() => { const checkEcosystemData = async () => { const data: ICheckEcosystem = await checkEcosystem(); - setIsEcosystemLead(data.isEnabledEcosystem) + setIsEcosystemLead(data.isEcosystemLead) } checkEcosystemData(); }, []) - const enableAction = (!fromEndorsementList && data?.status === EndorsementStatus.approved) || Boolean(fromEndorsementList) + const isSchema = data?.type === EndorsementType.schema + const enableAction = (!fromEndorsementList && data?.status === EndorsementStatus.approved) || Boolean(fromEndorsementList) const requestPayload = data?.requestPayload && JSON.parse(data?.requestPayload) - const requestData = requestPayload?.operation?.data + const requestData = isSchema ? requestPayload?.operation?.data : requestPayload?.operation const attributesData = allAttributes ? requestData?.attr_names : requestData?.attr_names?.slice(0, 3) return ( @@ -39,15 +40,18 @@ const EndorsementCard = ({ fromEndorsementList, data, onClickCallback, cardTrans onClickCallback(data) } }} - className={`${cardTransitionDisabled ? "" : "transform transition duration-500 hover:scale-105 hover:bg-gray-50 cursor-pointer"} ${enableAction ? "cursor-pointer": cardTransitionDisabled ? "cursor-default" : "cursor-not-allowed"} ${cardTransitionDisabled && "shadow-none"} m-3`} + className={`${cardTransitionDisabled ? "" : "transform transition duration-500 hover:scale-105 hover:bg-gray-50 cursor-pointer"} ${enableAction ? "cursor-pointer" : cardTransitionDisabled ? "cursor-default" : "cursor-not-allowed"} ${cardTransitionDisabled && "shadow-none"} m-3 h-full`} >
- {requestData?.name} + {isSchema ? requestData?.name : requestData?.tag}
-

- Version: {requestData?.version} -

+ { + isSchema && +

+ Version: {requestData?.version} +

+ }

@@ -57,21 +61,33 @@ const EndorsementCard = ({ fromEndorsementList, data, onClickCallback, cardTrans

- { - data?.status && -
-
- Status: -
-
- +
+ { + data?.status && +
+
+ Status: +
+
+ +
+ } +
+ {isSchema ? "Schema" : "Credential Definition"}
- } +
< div className="min-w-0 flex-1" > -

- Schema ID: {data?.schemaId} -

+ {!isSchema && + <> +

+ Schema Name: NA +

+

+ Schema Version: NA +

+ + }

Author DID: {data?.authorDid}

@@ -85,35 +101,38 @@ const EndorsementCard = ({ fromEndorsementList, data, onClickCallback, cardTrans }
-
-
    -
  • -
    -
    - Attributes: -
    -
    + { + isSchema && +
    +
      +
    • +
      +
      + Attributes: +
      +
      - {attributesData && attributesData.length > 0 && ( - <> - {attributesData.map((element: string, index: number) => ( -
      - - {element} - -
      - ))} - {attributesData.length === 3 && ...} - - )} + {attributesData && attributesData.length > 0 && ( + <> + {attributesData.map((element: string, index: number) => ( +
      + + {element} + +
      + ))} + {attributesData.length === 3 && ...} + + )} +
      -
    -
  • -
-
+ + +
+ } ) } diff --git a/src/components/Ecosystem/Endorsement/index.tsx b/src/components/Ecosystem/Endorsement/index.tsx index 7bdebf4ab..13234e7d6 100644 --- a/src/components/Ecosystem/Endorsement/index.tsx +++ b/src/components/Ecosystem/Endorsement/index.tsx @@ -12,11 +12,12 @@ import SearchInput from '../../SearchInput'; import { getFromLocalStorage } from '../../../api/Auth'; import { pathRoutes } from '../../../config/pathRoutes'; import { getOrganizationById } from '../../../api/organization'; -import { getEcosystemId } from '../../../config/ecosystem'; +import { ICheckEcosystem, checkEcosystem, getEcosystemId } from '../../../config/ecosystem'; import type { IAttributes } from '../../Resources/Schema/interfaces'; import EndorsementPopup from './EndorsementPopup'; import EndorsementCard from './EndorsementCard'; import { GetEndorsementListParameter, getEndorsementList } from '../../../api/ecosystem'; +import { EndorsementStatus, EndorsementType } from '../../../common/enums'; interface ISelectedRequest { attribute: IAttributes[]; @@ -61,34 +62,38 @@ const EndorsementList = () => { const options = [ { - name: "All", + name: "Select Status", value: "" }, { - name: "Approved", - value: "approved" + name: "Signed", + value: EndorsementStatus.approved }, { name: "Requested", - value: "requested" + value: EndorsementStatus.requested }, { name: "Rejected", - value: "rejected" + value: EndorsementStatus.rejected }, + { + name: "Submitted", + value: EndorsementStatus.submitted + } ] const typeOptions = [{ - name: "All", + name: "Select Type", value: "" }, { name: "Schema", - value: "schema" + value: EndorsementType.schema }, { name: "Credential-definition", - value: "credential-definition" + value: EndorsementType.credDef } ] diff --git a/src/components/EcosystemInvite/SentInvitations.tsx b/src/components/EcosystemInvite/SentInvitations.tsx index 09b3bdbcf..82493cced 100644 --- a/src/components/EcosystemInvite/SentInvitations.tsx +++ b/src/components/EcosystemInvite/SentInvitations.tsx @@ -19,7 +19,7 @@ const initialPageState = { }; const SentInvitations = () => { - const [loading, setLoading] = useState(false); + const [loading, setLoading] = useState(true); const [message, setMessage] = useState(null); const [error, setError] = useState(null); const [currentPage, setCurrentPage] = useState(initialPageState); @@ -232,15 +232,15 @@ const SentInvitations = () => { ) : (
- {!(invitationsList && invitationsList?.length > 0) && !loading ? ( + {!(invitationsList && invitationsList?.length > 0) && loading ? ( +
+ +
+ ) : ( - ) : ( -
- -
)}
)} diff --git a/src/config/ecosystem.ts b/src/config/ecosystem.ts index 21abc1b20..d6c427abd 100644 --- a/src/config/ecosystem.ts +++ b/src/config/ecosystem.ts @@ -46,9 +46,11 @@ const checkEcosystem = async (): Promise => { await getEcosystemId() const userData = await getUserProfile() const role = await getEcosystemRole() + const isEnabledEcosystem = userData?.enableEcosystem - const ecosystemRole = role ?? EcosystemRoles.ecosystemLead + const ecosystemRole = role || EcosystemRoles.ecosystemLead + return { isEnabledEcosystem, isEcosystemMember: ecosystemRole === EcosystemRoles.ecosystemMember && isEnabledEcosystem, @@ -67,9 +69,11 @@ const getEcosystemId = async (): Promise => { if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS && data?.data && data?.data.length > 0) { const response = data?.data[0] const id = response?.id - const role = response?.ecosystemOrgs[0].ecosystemRole.name + const role = response?.ecosystemOrgs && response?.ecosystemOrgs.length > 0 && response?.ecosystemOrgs[0]?.ecosystemRole?.name await setToLocalStorage(storageKeys.ECOSYSTEM_ID, id); - await setToLocalStorage(storageKeys.ECOSYSTEM_ROLE, role); + if(role){ + await setToLocalStorage(storageKeys.ECOSYSTEM_ROLE, role); + } return id } } catch (err) {