diff --git a/src/api/ecosystem.ts b/src/api/ecosystem.ts index 1a607eb15..a0156b569 100644 --- a/src/api/ecosystem.ts +++ b/src/api/ecosystem.ts @@ -23,7 +23,6 @@ export interface GetEndorsementListParameter { status: string } - export const createEcosystems = async (dataPayload: CreateEcosystemPayload) => { const orgId = await getFromLocalStorage(storageKeys.ORG_ID); @@ -66,7 +65,6 @@ export const updateEcosystem = async (dataPayload: CreateEcosystemPayload) => { } } - export const getEcosystem = async (orgId: string) => { const url = `${apiRoutes.Ecosystem.root}/${orgId}` @@ -139,6 +137,23 @@ export const createCredDefRequest = async (data: object, ecosystemId: string, or } } +export const SignEndorsementRequest = async ( ecosystemId: string, orgId: string, endorsementId: string) => { + + const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}${apiRoutes.Ecosystem.endorsements.signRequest}${endorsementId}` + + const axiosPayload = { + url, + config: await getHeaderConfigs() + } + try { + return await axiosPost(axiosPayload); + } + catch (error) { + const err = error as Error + return err?.message + } +} + export const getEcosystemDashboard = async (ecosystemId: string, orgId: string) => { const url = `${apiRoutes.Ecosystem.root}/${ecosystemId}/${orgId}/dashboard` diff --git a/src/common/enums.ts b/src/common/enums.ts index 6cffb8b95..4358390e3 100644 --- a/src/common/enums.ts +++ b/src/common/enums.ts @@ -43,11 +43,10 @@ export enum EndorsementType { } export enum EndorsementStatus { - all = "all", - approved = "approved", - rejected = "rejected", - requested = "requested", - submitted = "submitted" + signed = "signed", + rejected = "declined", + requested = "requested", + submitted = "submited" } export enum EcosystemRoles { diff --git a/src/commonComponents/StatusTabletTag.tsx b/src/commonComponents/StatusTabletTag.tsx index 41a112f07..c750d94cd 100644 --- a/src/commonComponents/StatusTabletTag.tsx +++ b/src/commonComponents/StatusTabletTag.tsx @@ -7,7 +7,7 @@ interface IStatusTabletTag { const StatusTabletTag = ({ status }: IStatusTabletTag) => { const color = () => { switch (true) { - case status === EndorsementStatus.approved: + case status === EndorsementStatus.signed || status === EndorsementStatus.submitted: return { style: `bg-[#70ffa01a] text-[#28C76F]`, title: "Accepted" @@ -22,6 +22,11 @@ const StatusTabletTag = ({ status }: IStatusTabletTag) => { style: `bg-[#EEE] text-[#7D7D7D]`, title: "Requested" } + case status === EndorsementStatus.submitted: + return { + style: `bg-[#70ffa01a] text-[#28C76F] `, + title: "Submitted" + } default: return { style: `bg-[#FFE4E4] text-[#EA5455]`, diff --git a/src/components/Ecosystem/Endorsement/EndorsementCard.tsx b/src/components/Ecosystem/Endorsement/EndorsementCard.tsx index 1f5cf9bba..fe7dbf84b 100644 --- a/src/components/Ecosystem/Endorsement/EndorsementCard.tsx +++ b/src/components/Ecosystem/Endorsement/EndorsementCard.tsx @@ -25,10 +25,9 @@ const EndorsementCard = ({ fromEndorsementList, data, onClickCallback, cardTrans checkEcosystemData(); }, []) + const enableAction = (!fromEndorsementList && data?.status === EndorsementStatus.signed) || 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 = isSchema ? requestPayload?.operation?.data : requestPayload?.operation diff --git a/src/components/Ecosystem/Endorsement/EndorsementPopup.tsx b/src/components/Ecosystem/Endorsement/EndorsementPopup.tsx index 39169a651..53bae91b7 100644 --- a/src/components/Ecosystem/Endorsement/EndorsementPopup.tsx +++ b/src/components/Ecosystem/Endorsement/EndorsementPopup.tsx @@ -1,135 +1,228 @@ import { Button, Modal } from 'flowbite-react'; import { EndorsementStatus } from '../../../common/enums'; -import { ICheckEcosystem, checkEcosystem } from '../../../config/ecosystem'; +import { + ICheckEcosystem, + checkEcosystem, + getEcosystemId, +} from '../../../config/ecosystem'; import EndorsementCard from './EndorsementCard'; import { useEffect, useState } from 'react'; +import { apiStatusCodes, storageKeys } from '../../../config/CommonConstant'; +import { SignEndorsementRequest } from '../../../api/ecosystem'; +import type { AxiosResponse } from 'axios'; +import { AlertComponent } from '../../AlertComponent'; +import { getFromLocalStorage } from '../../../api/Auth'; const EndorsementPopup = (props: { - openModal: boolean; - closeModal: () => void; - isAccepted: (flag: boolean) => void; - endorsementData: any + openModal: boolean; + closeModal: () => void; + isAccepted: (flag: boolean) => void; + setMessage: (message: string) => void; + endorsementData: any; + onAlertClose: boolean; }) => { + const [loading, setLoading] = useState(false); + const [errMsg, setErrMsg] = useState(null); + const [isEcosystemData, setIsEcosystemData] = useState(); - const [isEcosystemData, setIsEcosystemData] = useState(); + useEffect(() => { + const checkEcosystemData = async () => { + const data: ICheckEcosystem = await checkEcosystem(); + setIsEcosystemData(data); + }; + checkEcosystemData(); + }, []); - useEffect(() => { - const checkEcosystemData = async () => { - const data: ICheckEcosystem = await checkEcosystem(); - setIsEcosystemData(data) - } - checkEcosystemData(); - }, []) + useEffect(() => { + props.setMessage(""); + }, [props.onAlertClose]); - return ( - - - {isEcosystemData?.isEcosystemLead ? ( -
- Requested {props.endorsementData?.type} -
- ) : ( -
- View {props.endorsementData?.type} -
- )} + const SignEndorsement = async (endorsementId: string) => { + try { + setLoading(true); + const organizationId = await getFromLocalStorage(storageKeys.ORG_ID); + const ecoId = await getEcosystemId(); + const SignEndorsementrequest = await SignEndorsementRequest( + ecoId, + organizationId, + endorsementId, + ); -
+ const response = SignEndorsementrequest as AxiosResponse; + if (response?.data?.statusCode === apiStatusCodes.API_STATUS_CREATED) { + props.isAccepted(true); + props.setMessage(response?.data.message); + } else { + setErrMsg(response as unknown as string); + } + setLoading(false); + } catch (error) { + setLoading(false); + setErrMsg('error from catch'); + console.error('Error while fetching schema list:', error); + } + }; - + return ( + + + {isEcosystemData?.isEcosystemLead ? ( +
Requested {props.endorsementData?.type}
+ ) : ( +
View {props.endorsementData?.type}
+ )} +
+
+ { + setErrMsg(null); + }} + /> +
+ -
-
- {isEcosystemData?.isEcosystemLead && props.endorsementData?.status === EndorsementStatus.requested ? ( -
- + Reject + - + +
+ ) : ( + <> + {!isEcosystemData?.isEcosystemLead && + isEcosystemData?.isEcosystemMember && + props.endorsementData?.status === EndorsementStatus.signed ? ( +
+
- ) : - ( - <> - { - !isEcosystemData?.isEcosystemLead && isEcosystemData?.isEcosystemMember && props.endorsementData?.status === EndorsementStatus.requested ? - ( -
- + +
+ ) : ( +
+ - -
- ) - : - ( -
- -
- ) - } - - ) - - } -
-
-
- ); + Close + + + )} + + )} + + +
+ ); }; -export default EndorsementPopup; \ No newline at end of file +export default EndorsementPopup; diff --git a/src/components/Ecosystem/Endorsement/index.tsx b/src/components/Ecosystem/Endorsement/index.tsx index 13234e7d6..3294de0b4 100644 --- a/src/components/Ecosystem/Endorsement/index.tsx +++ b/src/components/Ecosystem/Endorsement/index.tsx @@ -3,7 +3,7 @@ import { Alert, Pagination } from 'flowbite-react'; import { ChangeEvent, useEffect, useState } from 'react'; import { apiStatusCodes, storageKeys } from '../../../config/CommonConstant'; - +import EndorsementPopup from './EndorsementPopup'; import type { AxiosResponse } from 'axios'; import BreadCrumbs from '../../BreadCrumbs'; import CustomSpinner from '../../CustomSpinner'; @@ -12,294 +12,362 @@ import SearchInput from '../../SearchInput'; import { getFromLocalStorage } from '../../../api/Auth'; import { pathRoutes } from '../../../config/pathRoutes'; import { getOrganizationById } from '../../../api/organization'; -import { ICheckEcosystem, checkEcosystem, 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 { + GetEndorsementListParameter, + getEndorsementList, +} from '../../../api/ecosystem'; import { EndorsementStatus, EndorsementType } from '../../../common/enums'; +import { AlertComponent } from '../../AlertComponent'; interface ISelectedRequest { - attribute: IAttributes[]; - issuerDid: string; - createdDate: string; - schemaId: string; + attribute: IAttributes[]; + issuerDid: string; + createdDate: string; + schemaId: string; } interface IEndorsementList { - id: string - endorserDid: string - authorDid: string - status: string - type: string - ecosystemOrgs: { - orgId: number - } - requestPayload: string - responsePayload: string - createDateTime: string + id: string; + endorserDid: string; + authorDid: string; + status: string; + type: string; + ecosystemOrgs: { + orgId: number; + }; + requestPayload: string; + responsePayload: string; + createDateTime: string; } const EndorsementList = () => { - const [schemaList, setSchemaList] = useState([]) - const [schemaListErr, setSchemaListErr] = useState('') - const [loading, setLoading] = useState(true) - const [orgId, setOrgId] = useState('') - const [endorsementListAPIParameter, setEndorsementListAPIParameter] = useState({ - itemPerPage: 9, - page: 1, - search: "", - sortBy: "id", - sortingOrder: "DESC", - type: "", - status: "" - }) - const [totalPages, setTotalPages] = useState(0) - const [walletStatus, setWalletStatus] = useState(false) - const [showPopup, setShowPopup] = useState(false) - const [selectedRequest, setSelectedRequest] = useState() - const [isEcosystemLead, setIsEcosystemLead] = useState(false); - - const options = [ - { - name: "Select Status", - value: "" - }, - { - name: "Signed", - value: EndorsementStatus.approved - }, - { - name: "Requested", - value: EndorsementStatus.requested - }, - { - name: "Rejected", - value: EndorsementStatus.rejected - }, - { - name: "Submitted", - value: EndorsementStatus.submitted - } - ] + const [schemaList, setSchemaList] = useState([]); + const [schemaListErr, setSchemaListErr] = useState(''); + const [loading, setLoading] = useState(true); + const [alertClose, setAlertClose] = useState(true); + const [orgId, setOrgId] = useState(''); + const [endorsementListAPIParameter, setEndorsementListAPIParameter] = + useState({ + itemPerPage: 9, + page: 1, + search: '', + sortBy: 'id', + sortingOrder: 'DESC', + type: '', + status: '', + }); + const [totalPages, setTotalPages] = useState(0); + const [walletStatus, setWalletStatus] = useState(false); + const [showPopup, setShowPopup] = useState(false); + const [selectedRequest, setSelectedRequest] = useState(); + const [isEcosystemLead, setIsEcosystemLead] = useState(false); + const [successMessage, setSuccessMessage] = useState(null); - const typeOptions = [{ - name: "Select Type", - value: "" - }, - { - name: "Schema", - value: EndorsementType.schema - }, - { - name: "Credential-definition", - value: EndorsementType.credDef - } + const options = [ + { + name: 'Select Status', + value: '', + }, + { + name: 'Signed', + value: EndorsementStatus.signed, + }, + { + name: 'Requested', + value: EndorsementStatus.requested, + }, + { + name: 'Rejected', + value: EndorsementStatus.rejected, + }, + { + name: 'Submitted', + value: EndorsementStatus.submitted, + }, + ]; - ] + const typeOptions = [ + { + name: 'Select Type', + value: '', + }, + { + name: 'Schema', + value: EndorsementType.schema, + }, + { + name: 'Credential-definition', + value: EndorsementType.credDef, + }, + ]; - const getEndorsementListData = async (endorsementListAPIParameter: GetEndorsementListParameter) => { - try { - const organizationId = await getFromLocalStorage(storageKeys.ORG_ID); - setOrgId(organizationId) - const id = await getEcosystemId(); - const endorsementList = await getEndorsementList(endorsementListAPIParameter, organizationId, id); + const getEndorsementListData = async ( + endorsementListAPIParameter: GetEndorsementListParameter, + ) => { + try { + const organizationId = await getFromLocalStorage(storageKeys.ORG_ID); + setOrgId(organizationId); + const id = await getEcosystemId(); + const endorsementList = await getEndorsementList( + endorsementListAPIParameter, + organizationId, + id, + ); - const { data } = endorsementList as AxiosResponse; + const { data } = endorsementList as AxiosResponse; - if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { - if (data?.data?.transactions) { - setSchemaList(data?.data?.transactions); - setTotalPages(data?.data?.totalPages) - setLoading(false); - } else { - setLoading(false); - } - } else { - setLoading(false); - } - } catch (error) { - console.error('Error while fetching schema list:', error); - } - } + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + if (data?.data?.transactions) { + setSchemaList(data?.data?.transactions); + setTotalPages(data?.data?.totalPages); + setLoading(false); + } else { + setLoading(false); + } + } else { + setLoading(false); + } + } catch (error) { + console.error('Error while fetching schema list:', error); + } + }; - const onPageChange = (page: number) => { + const onPageChange = (page: number) => { setEndorsementListAPIParameter({ ...endorsementListAPIParameter, page, }); }; - useEffect(() => { - getEndorsementListData(endorsementListAPIParameter) - }, [endorsementListAPIParameter]) + useEffect(() => { + getEndorsementListData(endorsementListAPIParameter); + }, [endorsementListAPIParameter]); - const onSearch = async (event: ChangeEvent): Promise => { - event.preventDefault() - setEndorsementListAPIParameter({ ...endorsementListAPIParameter, search: event.target.value }) - } - - const requestSelectionCallback = (data: any) => { - setSelectedRequest(data) - setShowPopup(true) - } + const onSearch = async ( + event: ChangeEvent, + ): Promise => { + event.preventDefault(); + setEndorsementListAPIParameter({ + ...endorsementListAPIParameter, + search: event.target.value, + }); + }; - const handleFilter = (e: React.ChangeEvent, filter: "typeFilter" | "statusFilter") => { - const updateFilter = endorsementListAPIParameter - if (filter === "typeFilter") { - updateFilter["type"] = e.target.value - } - if (filter === "statusFilter") { - updateFilter["status"] = e.target.value - } - setEndorsementListAPIParameter(updateFilter) - getEndorsementListData(updateFilter) - }; + const requestSelectionCallback = (data: any) => { + setSelectedRequest(data); + setShowPopup(true); + }; - const fetchOrganizationDetails = async () => { - setLoading(true) - const orgId = await getFromLocalStorage(storageKeys.ORG_ID) - const response = await getOrganizationById(orgId); - const { data } = response as AxiosResponse - if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { - if (data?.data?.org_agents && data?.data?.org_agents?.length > 0) { - setWalletStatus(true) - } - } - setLoading(false) - } + const handleFilter = ( + e: React.ChangeEvent, + filter: 'typeFilter' | 'statusFilter', + ) => { + const updateFilter = endorsementListAPIParameter; + if (filter === 'typeFilter') { + updateFilter['type'] = e.target.value; + } + if (filter === 'statusFilter') { + updateFilter['status'] = e.target.value; + } + setEndorsementListAPIParameter(updateFilter); + getEndorsementListData(updateFilter); + }; - const hidePopup = () => { - setShowPopup(false) - } + const fetchOrganizationDetails = async () => { + setLoading(true); + const orgId = await getFromLocalStorage(storageKeys.ORG_ID); + const response = await getOrganizationById(orgId); + const { data } = response as AxiosResponse; + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + if (data?.data?.org_agents && data?.data?.org_agents?.length > 0) { + setWalletStatus(true); + } + } + setLoading(false); + }; - useEffect(() => { - fetchOrganizationDetails() + const hidePopup = () => { + setShowPopup(false); + }; - const checkEcosystemData = async () => { - const data: ICheckEcosystem = await checkEcosystem(); - setIsEcosystemLead(data.isEcosystemLead) - } - checkEcosystemData(); - }, []) + useEffect(() => { + fetchOrganizationDetails(); - return ( -
-
- -

- Endorsements -

-
-
-
-
-
- - - -
-
-
- { - schemaListErr && - setSchemaListErr(null)} - > - -

- {schemaListErr} -

-
-
- } - {schemaList && schemaList.length > 0 ? ( -
-
- { - schemaList.map((item: IEndorsementList) => ( -
- -
- ))} -
-
- -
-
- ) : - ( -
- { - !(schemaList && schemaList.length > 0) && loading ? - (
- -
) - : -
- {walletStatus ? - - - } - onClick={() => { - window.location.href = `${pathRoutes.organizations.createSchema}?OrgId=${orgId}` - }} - /> - : - - - } - onClick={() => { - window.location.href = `${pathRoutes.organizations.dashboard}?OrgId=${orgId}` - }} - />} -
- } -
- ) - } -
- console.log('Is accepted::', flag)} endorsementData={selectedRequest} /> -
- ) -} + const checkEcosystemData = async () => { + const data: ICheckEcosystem = await checkEcosystem(); + setIsEcosystemLead(data.isEcosystemLead); + }; + checkEcosystemData(); + }, []); + return ( +
+
+ +

+ Endorsements +

+
+
+
+
+
+ + + +
+
+
+ {successMessage && ( + setAlertClose(!alertClose)} + /> + )} + {schemaListErr && ( + setSchemaListErr(null)}> + +

{schemaListErr}

+
+
+ )} + {schemaList && schemaList.length > 0 ? ( +
+
+ {schemaList.map((item: IEndorsementList) => ( +
+ +
+ ))} +
+
+ +
+
+ ) : ( +
+ {!(schemaList && schemaList.length > 0) && loading ? ( +
+ +
+ ) : ( +
+ {walletStatus ? ( + + + + } + onClick={() => { + window.location.href = `${pathRoutes.organizations.createSchema}?OrgId=${orgId}`; + }} + /> + ) : ( + + + + } + onClick={() => { + window.location.href = `${pathRoutes.organizations.dashboard}?OrgId=${orgId}`; + }} + /> + )} +
+ )} +
+ )} +
+ { + if (flag) { + getEndorsementListData(endorsementListAPIParameter); + setShowPopup(false); + } + }} + onAlertClose={alertClose} + endorsementData={selectedRequest} + setMessage={setSuccessMessage} + /> +
+ ); +}; -export default EndorsementList +export default EndorsementList; diff --git a/src/components/EditEcosystemOrgModal/index.tsx b/src/components/EditEcosystemOrgModal/index.tsx index 9b2891547..2cb99fb5e 100644 --- a/src/components/EditEcosystemOrgModal/index.tsx +++ b/src/components/EditEcosystemOrgModal/index.tsx @@ -46,7 +46,6 @@ const EditPopupModal = (props: EditEntityModalProps) => { }); useEffect(() => { - console.log(6565, props.entityData) if (props.openModal && props.entityData) { setInitialEntityData({ name: props.entityData.name ?? "",