diff --git a/src/api/ecosystem.ts b/src/api/ecosystem.ts index 112476acc..7d3445153 100644 --- a/src/api/ecosystem.ts +++ b/src/api/ecosystem.ts @@ -110,10 +110,11 @@ export const getEndorsementList = async ( export const createSchemaRequest = async ( data: object, + schemaType: string, endorsementId: string, orgId: string, ) => { - const url = `${apiRoutes.Ecosystem.root}/${endorsementId}/${orgId}${apiRoutes.Ecosystem.endorsements.createSchemaRequest}`; + const url = `${apiRoutes.Ecosystem.root}/${endorsementId}/${orgId}${apiRoutes.Ecosystem.endorsements.createSchemaRequest}?schemaType=${schemaType}`; const payload = data; const axiosPayload = { url, diff --git a/src/common/enums.ts b/src/common/enums.ts index 7abdc1dff..dd66bea4f 100644 --- a/src/common/enums.ts +++ b/src/common/enums.ts @@ -31,6 +31,10 @@ export enum ProofRequestStateUserText { abandoned = 'Declined', } +export enum SchemaType { + INDY = 'indy', + W3C = 'w3c' +} export enum IssueCredentialUserText { offerSent = 'Offered', done = 'Accepted', diff --git a/src/components/AddOrganizationInEcosystem.tsx b/src/components/AddOrganizationInEcosystem.tsx index e96d9e1fd..623432475 100644 --- a/src/components/AddOrganizationInEcosystem.tsx +++ b/src/components/AddOrganizationInEcosystem.tsx @@ -227,6 +227,7 @@ const AddOrganizationInEcosystem = () => { }; const refreshPage = () => { + setLocalOrgs([]); getOwnerOrganizations(listAPIParameter); }; @@ -241,43 +242,104 @@ const AddOrganizationInEcosystem = () => { } const handleAddOrganization = async () => { - const orgId = await getFromLocalStorage(storageKeys.ORG_ID) || ""; - const ecosystemId = await getFromLocalStorage(storageKeys.ECOSYSTEM_ID) || ""; - setLoader(true) + const orgId = (await getFromLocalStorage(storageKeys.ORG_ID)) || ''; + const ecosystemId = + (await getFromLocalStorage(storageKeys.ECOSYSTEM_ID)) || ''; + setLoader(true); try { - const response = await addOrganizationInEcosystem(localOrgs, ecosystemId, orgId); + const response = await addOrganizationInEcosystem( + localOrgs, + ecosystemId, + orgId, + ); const { data } = response as AxiosResponse; - setLoader(false) + setLoader(false); + setLocalOrgs([]); + setErrorList([]); + setOrganizationsList( + (prevState) => + prevState?.map((org) => ({ ...org, checked: false, error: '' })) || + [], + ); + switch (data?.statusCode) { case apiStatusCodes.API_STATUS_CREATED: - await removeFromLocalStorage(storageKeys.SELECT_ORG_IN_ECOSYSTEM) - setSuccess(data.message) + await removeFromLocalStorage(storageKeys.SELECT_ORG_IN_ECOSYSTEM); + setSuccess(data.message); setTimeout(() => { window.location.href = pathRoutes.ecosystem.dashboard; }, 1000); break; + case apiStatusCodes.API_STATUS_PARTIALLY_COMPLETED: - await removeFromLocalStorage(storageKeys.SELECT_ORG_IN_ECOSYSTEM) - const errors = data?.data?.filter((item: IErrorResponse) => item.statusCode !== apiStatusCodes.API_STATUS_CREATED) - const errorData = errors.map((item: IErrorResponse) => ({ id: item?.data?.orgId || "", error: item.message })) - await setToLocalStorage(storageKeys.ERROR_ORG_IN_ECOSYSTEM, JSON.stringify(errorData)) - setErrorList(errorData) - const updateWithError = organizationsList && organizationsList?.length > 0 ? organizationsList?.map((item => ({ - ...item, - error: errors?.find((ele: IErrorResponse) => ele?.data?.orgId === item.id)?.message || "" - }))) : [] + await removeFromLocalStorage(storageKeys.SELECT_ORG_IN_ECOSYSTEM); + const errors = data?.data?.filter( + (item: IErrorResponse) => + item.statusCode !== apiStatusCodes.API_STATUS_CREATED, + ); + const errorData = errors.map((item: IErrorResponse) => ({ + id: item?.data?.orgId || '', + error: item.message, + })); + await setToLocalStorage( + storageKeys.ERROR_ORG_IN_ECOSYSTEM, + JSON.stringify(errorData), + ); + setErrorList(errorData); + setLocalOrgs([]); + + const updateWithError = + organizationsList && organizationsList?.length > 0 + ? organizationsList?.map((item) => ({ + ...item, + error: + errors?.find( + (ele: IErrorResponse) => ele?.data?.orgId === item.id, + )?.message || '', + checked: false + })) + : []; setSuccess(data?.message); - setOrganizationsList(updateWithError) + setOrganizationsList(updateWithError); + setErrorList([]); break; default: - setError(response as string || data?.message) + setError((response as string) || data?.message); + setErrorList([]); + setLocalOrgs([]); + setOrganizationsList( + (prevState) => + prevState?.map((org) => ({ + ...org, + checked: false, + error: '', + })) || [], + ); + break; } } catch (error) { - setError(error.message as string) - setLoader(false) + setError(error.message as string); + setLoader(false); + setLocalOrgs([]); + setErrorList([]); + setOrganizationsList( + (prevState) => + prevState?.map((org) => ({ ...org, checked: false, error: '' })) || + [], + ); } - } + }; + + useEffect(() => { + const clearLocalStorage = async () => { + await removeFromLocalStorage(storageKeys.SELECT_ORG_IN_ECOSYSTEM); + await removeFromLocalStorage(storageKeys.ERROR_ORG_IN_ECOSYSTEM); + }; + clearLocalStorage(); + refreshPage(); + + }, []); useEffect(() => { getOwnerOrganizations(listAPIParameter); @@ -291,7 +353,7 @@ const AddOrganizationInEcosystem = () => { await removeFromLocalStorage(storageKeys.ERROR_ORG_IN_ECOSYSTEM); })() }, []) - + useEffect(() => { (async () => { await setToLocalStorage(storageKeys.SELECT_ORG_IN_ECOSYSTEM, JSON.stringify(localOrgs)) diff --git a/src/components/Issuance/ConnectionList.tsx b/src/components/Issuance/ConnectionList.tsx index d0bea4c98..17e5800fa 100644 --- a/src/components/Issuance/ConnectionList.tsx +++ b/src/components/Issuance/ConnectionList.tsx @@ -13,7 +13,11 @@ import { dateConversion } from '../../utils/DateConversion'; import DateTooltip from '../Tooltip'; import type { IConnectionList } from './interface'; import NewDataTable from '../../commonComponents/datatable/SortDataTable'; -import { getFromLocalStorage, setToLocalStorage } from '../../api/Auth'; +import { + getFromLocalStorage, + removeFromLocalStorage, + setToLocalStorage, +} from '../../api/Auth'; const initialPageState = { itemPerPage: 10, @@ -28,14 +32,14 @@ type LocalOrgs = { connectionId: string; theirLabel: string; createDateTime: string; -} +}; const ConnectionList = (props: { selectConnection: (connections: IConnectionList[]) => void; }) => { const [listAPIParameter, setListAPIParameter] = useState(initialPageState); const [tableData, setTableData] = useState([]); - const [connectionList, setConnectionList] = useState([]) + const [connectionList, setConnectionList] = useState([]); const [localOrgs, setLocalOrgs] = useState([]); const [loading, setLoading] = useState(false); @@ -47,91 +51,106 @@ const ConnectionList = (props: { lastPage: '', }); - const selectOrganization = async (item: IConnectionList, checked: boolean) => { + const selectOrganization = async ( + item: IConnectionList, + checked: boolean, + ) => { try { - const index = localOrgs?.length > 0 ? localOrgs.findIndex(ele => ele.connectionId === item.connectionId) : -1 + const index = + localOrgs?.length > 0 + ? localOrgs.findIndex((ele) => ele.connectionId === item.connectionId) + : -1; const { connectionId, theirLabel, createDateTime } = item || {}; if (index === -1) { - setLocalOrgs((prev: LocalOrgs[]) => [...prev, { - connectionId, - theirLabel, - createDateTime - }]) + setLocalOrgs((prev: LocalOrgs[]) => [ + ...prev, + { + connectionId, + theirLabel, + createDateTime, + }, + ]); } else { - const updateLocalOrgs = [...localOrgs] + const updateLocalOrgs = [...localOrgs]; if (!checked) { updateLocalOrgs.splice(index, 1); } - setLocalOrgs(updateLocalOrgs) + setLocalOrgs(updateLocalOrgs); } } catch (error) { - console.error("SELECTED ORGANIZATION:::", error) + console.error('SELECTED ORGANIZATION:::', error); } - } + }; const generateTable = async (connections: IConnectionList[]) => { try { - const connectionsData = connections?.length > 0 && connections?.map((ele: IConnectionList) => { - const createdOn = ele?.createDateTime - ? ele?.createDateTime - : 'Not available'; - const connectionId = ele.connectionId - ? ele.connectionId - : 'Not available'; - const userName = ele?.theirLabel ? ele.theirLabel : 'Not available'; + const connectionsData = + connections?.length > 0 && + connections?.map((ele: IConnectionList) => { + const createdOn = ele?.createDateTime + ? ele?.createDateTime + : 'Not available'; + const connectionId = ele.connectionId + ? ele.connectionId + : 'Not available'; + const userName = ele?.theirLabel ? ele.theirLabel : 'Not available'; - const isChecked = localOrgs.map(item => item.connectionId).includes(ele.connectionId) + const isChecked = localOrgs + .map((item) => item.connectionId) + .includes(ele.connectionId); - return { - data: [ - { - data: ( -
- ) => { - const inputElement = event.target as HTMLInputElement; + return { + data: [ + { + data: ( +
+ , + ) => { + const inputElement = event.target as HTMLInputElement; - const updateConnectionList = connections?.map(item => { - if (item.connectionId === ele.connectionId) { - selectOrganization(item, inputElement.checked) - return { - ...item, - checked: inputElement.checked - } - } - return item - }) - setConnectionList(updateConnectionList) - }} - checked={ele.checked || isChecked} - className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded-lg dark:ring-offset-gray-800 dark:bg-gray-700 dark:border-gray-600 cursor-pointer" - /> -
- ), - }, - { data: userName }, - { data: connectionId }, - { - data: ( - - {' '} - {dateConversion(createdOn)}{' '} - - ), - }, - ], - }; - }); - - setTableData(connectionsData) - } catch (err) { + const updateConnectionList = connections?.map( + (item) => { + if (item.connectionId === ele.connectionId) { + selectOrganization(item, inputElement.checked); + return { + ...item, + checked: inputElement.checked, + }; + } + return item; + }, + ); + setConnectionList(updateConnectionList); + }} + checked={ele.checked || isChecked} + className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded-lg dark:ring-offset-gray-800 dark:bg-gray-700 dark:border-gray-600 cursor-pointer" + /> +
+ ), + }, + { data: userName }, + { data: connectionId }, + { + data: ( + + {' '} + {dateConversion(createdOn)}{' '} + + ), + }, + ], + }; + }); - } - } + setTableData(connectionsData); + } catch (err) {} + }; const getConnections = async (apiParameter: IConnectionListAPIParameter) => { setLoading(true); @@ -185,14 +204,25 @@ const ConnectionList = (props: { }; const refreshPage = () => { + setLocalOrgs([]); getConnections(listAPIParameter); }; const updateLocalOrgs = async () => { - const res = await getFromLocalStorage(storageKeys.SELECTED_CONNECTIONS) - const selectedOrg = res ? JSON.parse(res) : [] + const res = await getFromLocalStorage(storageKeys.SELECTED_CONNECTIONS); + const selectedOrg = res ? JSON.parse(res) : []; setLocalOrgs(selectedOrg); - } + }; + + useEffect(() => { + const clearStorageAndRefresh = async () => { + refreshPage(); + await removeFromLocalStorage(storageKeys.SELECTED_CONNECTIONS); + await removeFromLocalStorage(storageKeys.SELECTED_USER); + }; + + clearStorageAndRefresh(); + }, []); useEffect(() => { props.selectConnection(localOrgs); @@ -200,17 +230,20 @@ const ConnectionList = (props: { useEffect(() => { generateTable(connectionList); - }, [connectionList, localOrgs]) + }, [connectionList, localOrgs]); useEffect(() => { (async () => { - await setToLocalStorage(storageKeys.SELECTED_CONNECTIONS, JSON.stringify(localOrgs)) - })() - }, [localOrgs]) + await setToLocalStorage( + storageKeys.SELECTED_CONNECTIONS, + JSON.stringify(localOrgs), + ); + })(); + }, [localOrgs]); useEffect(() => { let getData: NodeJS.Timeout; - updateLocalOrgs() + updateLocalOrgs(); if (listAPIParameter?.search?.length >= 1) { getData = setTimeout(() => { getConnections(listAPIParameter); @@ -223,8 +256,8 @@ const ConnectionList = (props: { }, [listAPIParameter]); useEffect(() => { - updateLocalOrgs() - }, []) + updateLocalOrgs(); + }, []); return (
diff --git a/src/components/Issuance/Issuance.tsx b/src/components/Issuance/Issuance.tsx index 694c03737..fa5340228 100644 --- a/src/components/Issuance/Issuance.tsx +++ b/src/components/Issuance/Issuance.tsx @@ -5,8 +5,8 @@ import * as Yup from 'yup'; import { Alert, Button, Card } from 'flowbite-react'; import { Field, FieldArray, Form, Formik } from 'formik'; import { apiStatusCodes, storageKeys } from '../../config/CommonConstant'; -import { getFromLocalStorage, removeFromLocalStorage, setToLocalStorage } from '../../api/Auth'; -import React, { useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; +import { getFromLocalStorage, removeFromLocalStorage } from '../../api/Auth'; import BackButton from '../../commonComponents/backbutton'; import type { AxiosResponse } from 'axios'; import BreadCrumbs from '../BreadCrumbs'; @@ -76,10 +76,10 @@ const IssueCred = () => { const attributesArray = attributes.map((attr) => ({ name: attr.attributeName, value: '', - dataType: attr?.schemaDataType, - isRequired: attr.isRequired + dataType: attr?.schemaDataType, + isRequired: attr.isRequired, })); - + return { connectionId: user.connectionId, attributes: attributesArray, @@ -99,14 +99,14 @@ const IssueCred = () => { const createAttributeValidationSchema = ( name: string, value: string, - isRequired: boolean + isRequired: boolean, ) => { - let attributeSchema = Yup.string();; + let attributeSchema = Yup.string(); if (name) { name = name .split('_') - .map(item => item.charAt(0).toUpperCase() + item.slice(1)) + .map((item) => item.charAt(0).toUpperCase() + item.slice(1)) .join(' '); } @@ -122,17 +122,20 @@ const IssueCred = () => { }; const validationSchema = Yup.object().shape({ - credentialData: Yup.array().of( - Yup.object().shape({ + credentialData: Yup.array().of( + Yup.object().shape({ attributes: Yup.array().of( - Yup.lazy((attr) => { - return createAttributeValidationSchema(attr?.name, attr?.value, attr?.isRequired) + Yup.lazy((attr) => { + return createAttributeValidationSchema( + attr?.name, + attr?.value, + attr?.isRequired, + ); }), - ), - }), - ), - }); - + ), + }), + ), + }); const getSchemaDetails = async (): Promise => { const schemaAttributes = await getFromLocalStorage(storageKeys.SCHEMA_ATTR); @@ -162,18 +165,18 @@ const IssueCred = () => { const handleSubmit = async (values: IssuanceFormPayload) => { const issuancePayload = { - credentialData: values.credentialData.map(item => { + credentialData: values.credentialData.map((item) => { return { ...item, - attributes: item.attributes.map(attr => ({ + attributes: item.attributes.map((attr) => ({ name: attr.name, - value: attr.value.toString() - })) - } + value: attr.value.toString(), + })), + }; }), - credentialDefinitionId: values.credentialDefinitionId, - orgId: values.orgId - }; + credentialDefinitionId: values.credentialDefinitionId, + orgId: values.orgId, + }; const convertedAttributesValues = { ...issuancePayload, @@ -237,7 +240,7 @@ const IssueCred = () => { validationSchema={validationSchema} onSubmit={handleSubmit} > - {({ values, errors, touched, isValid }) => ( + {({ values, errors, touched }) => (
{failure && (
@@ -248,7 +251,7 @@ const IssueCred = () => {
)} - + {(arrayHelpers) => ( <> {values?.credentialData.map((user, index) => ( @@ -280,27 +283,11 @@ const IssueCred = () => { >