Skip to content

Commit

Permalink
fix: OOB issuance with other organizations schema (#741)
Browse files Browse the repository at this point in the history
* fix: create did ui fixes

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* fix: sonarcloud issues

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* fix: OOB issuance with other organizations schema

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* fix: removed consoles

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* fix: sonarcloud issues

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

---------

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>
  • Loading branch information
pranalidhanavade authored Aug 28, 2024
1 parent 48b580b commit b51c2e4
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 99 deletions.
99 changes: 81 additions & 18 deletions src/components/Issuance/BulkIssuance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import RoleViewButton from '../RoleViewButton';
import { Features } from '../../utils/enums/features';
import { Create, SchemaEndorsement } from './Constant';
import { DidMethod, SchemaTypes } from '../../common/enums';
import type { GetAllSchemaListParameter } from '../Resources/Schema/interfaces';
import { getAllSchemas } from '../../api/Schema';

export interface SelectRef {
clearValue(): void;
Expand All @@ -32,7 +34,7 @@ const BulkIssuance = () => {
const [requestId, setRequestId] = useState("");
const [process, setProcess] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(true);
const [credentialOptions, setCredentialOptions] = useState([]);
const [ credentialOptionsData, setCredentialOptionsData] = useState([]);
const [credentialSelected, setCredentialSelected] = useState<ICredentials | null>();
const [isFileUploaded, setIsFileUploaded] = useState(false);
const [uploadedFileName, setUploadedFileName] = useState('');
Expand All @@ -46,6 +48,15 @@ const BulkIssuance = () => {
const [mounted, setMounted] = useState<boolean>(false)
const [schemaType, setSchemaType]= useState<SchemaTypes>();
const [selectedTemplate, setSelectedTemplate] = useState<any>();
const [isAllSchema, setIsAllSchema] = useState<string>();
const [schemaListAPIParameters, setSchemaListAPIParameters] = useState({
itemPerPage: 9,
page: 1,
search: '',
sortBy: 'id',
sortingOrder: 'desc',
allSearch: '',
});


const onPageChange = (page: number) => {
Expand All @@ -61,12 +72,15 @@ const BulkIssuance = () => {
};
const [currentPage, setCurrentPage] = useState(initialPageState);

const getSchemaCredentials = async () => {
const getSchemaCredentials = async (schemaListAPIParameters: GetAllSchemaListParameter) => {
try {
setLoading(true);
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);

const orgDid = await getFromLocalStorage(storageKeys.ORG_DID);

const isAllSchemaSelectedFlag = await getFromLocalStorage(storageKeys.ALL_SCHEMAS)
setIsAllSchema(isAllSchemaSelectedFlag)

let currentSchemaType = schemaType;

Expand All @@ -77,14 +91,14 @@ const BulkIssuance = () => {
}

setSchemaType(currentSchemaType);
if (currentSchemaType && orgId) {
if (currentSchemaType && orgId && isAllSchemaSelectedFlag =='false') {
const response = await getSchemaCredDef(currentSchemaType);
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const { data: credentialDefs } = data;
const { data: credentialDefsData } = data;

const options = credentialDefs.map(
const options = credentialDefsData.map(
({
schemaName,
schemaVersion,
Expand All @@ -103,7 +117,40 @@ const BulkIssuance = () => {
schemaAttributes: schemaAttributes && typeof schemaAttributes === "string" && JSON.parse(schemaAttributes)
}),
);
setCredentialOptions(options);
setCredentialOptionsData(options);
} else {
setUploadMessage({message: response as string, type: "failure"});
setSuccess(null)
setFailure(null)
}
setLoading(false);
}

if (currentSchemaType && orgId &&isAllSchemaSelectedFlag =='true') {
const response = await getAllSchemas(schemaListAPIParameters,currentSchemaType);
const { data } = response as AxiosResponse;


if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const credentialDefsData = data.data.data;


const options = credentialDefsData.map(({
name,
version,
schemaLedgerId,
attributes,
type
} : ICredentials) => ({
value: version,
label: `${name} [${version}]`,
schemaName: name,
type:type,
schemaVersion: version,
schemaIdentifier: schemaLedgerId,
attributes: Array.isArray(attributes) ? attributes : (attributes ? JSON.parse(attributes) : []),
}));
setCredentialOptionsData(options);
} else {
setUploadMessage({message: response as string, type: "failure"});
setSuccess(null)
Expand All @@ -119,7 +166,7 @@ const BulkIssuance = () => {
};

useEffect(() => {
getSchemaCredentials();
getSchemaCredentials(schemaListAPIParameters);
setMounted(true);
(async () => {
try {
Expand Down Expand Up @@ -433,7 +480,7 @@ const BulkIssuance = () => {

const isCredSelected = Boolean(credentialSelected);

const selectedCred: ICredentials | boolean | undefined = credentialOptions && credentialOptions.length > 0 && credentialOptions.find(
const selectedCred: ICredentials | boolean | undefined = credentialOptionsData && credentialOptionsData.length > 0 && credentialOptionsData.find(
(item: { value: string }) =>
item.value &&
item.value === credentialSelected,
Expand Down Expand Up @@ -529,7 +576,7 @@ const BulkIssuance = () => {
isRtl={false}
isSearchable={true}
name="color"
options={credentialOptions}
options={ credentialOptionsData}
onChange={(value: ICredentials | null) => {
if (schemaType === SchemaTypes.schema_INDY) {
setSelectedTemplate(value?.credentialDefinitionId);
Expand Down Expand Up @@ -562,16 +609,32 @@ const BulkIssuance = () => {
</p>
<span className='text-black dark:text-white font-semibold'>Attributes:</span>
<div className="flex flex-wrap overflow-hidden">
{credentialSelected?.schemaAttributes.map(
(element: IAttributes) => (
<div key={element.attributeName}>
<span className="m-1 bg-blue-100 text-blue-800 text-sm font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300">
{element.attributeName}
</span>
</div>
),
)}
{
isAllSchema ==='false' ? (
credentialSelected?.schemaAttributes?.map(
(element: IAttributes) => (
<div key={element.attributeName}>
<span className="m-1 bg-blue-100 text-blue-800 text-sm font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300">
{element.attributeName}
</span>
</div>
),
)
) : (
credentialSelected?.attributes?.map(
(element: IAttributes) => (
<div key={element.attributeName}>
<span className="m-1 bg-blue-100 text-blue-800 text-sm font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300">
{element.attributeName}
</span>
</div>
),
)
)

}
</div>

</div>
</Card>
)}
Expand Down
Loading

0 comments on commit b51c2e4

Please sign in to comment.