Skip to content

Commit

Permalink
fix: warnings in console in verification flow (#850)
Browse files Browse the repository at this point in the history
* fix: onclick function warnings in console

Signed-off-by: pranalidhanavade <[email protected]>

* fix: console error in verification flow and imported common interface

Signed-off-by: pranalidhanavade <[email protected]>

* resolve comments on pull request

Signed-off-by: pranalidhanavade <[email protected]>

* resolve comments on pull request

Signed-off-by: pranalidhanavade <[email protected]>

---------

Signed-off-by: pranalidhanavade <[email protected]>
  • Loading branch information
pranalidhanavade authored Jan 3, 2025
1 parent 9f10e7d commit b7d9e13
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 497 deletions.
47 changes: 29 additions & 18 deletions src/commonComponents/CustomCheckbox.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import React, { useEffect, useState } from 'react';
import { setToLocalStorage } from '../api/Auth';
import { getFromLocalStorage, setToLocalStorage } from '../api/Auth';
import { storageKeys } from '../config/CommonConstant';
import type { ICustomCheckboxProps, ISchemaData } from './interface';

const CustomCheckbox: React.FC<ICustomCheckboxProps> = ({ showCheckbox, isVerificationUsingEmail, onChange, schemaData }) => {
const [checked, setChecked] = useState<boolean>(false);

useEffect(() => {
if (schemaData) {
try {
const selectedSchemas = JSON.parse(localStorage.getItem('selectedSchemas') ?? '[]');
const isChecked = selectedSchemas.some((schema: ISchemaData) => schema.schemaId === schemaData.schemaId);
setChecked(isChecked);
} catch (error) {
console.error('Error parsing JSON from localStorage:', error);
const fetchSelectedSchemas = async () => {
if (schemaData) {
try {
const storedSchemaData = await getFromLocalStorage(storageKeys.SELECTED_SCHEMAS);
if(storedSchemaData){
const selectedSchemas= JSON.parse(storedSchemaData);
const isChecked = selectedSchemas.some((schema: ISchemaData) => schema.schemaId === schemaData.schemaId);
setChecked(isChecked);
}
} catch (error) {
console.error('Error parsing JSON from localStorage:', error);
}
}
}
};
fetchSelectedSchemas();
}, [schemaData]);

const handleCheckboxChange = async () => {
Expand All @@ -24,17 +30,22 @@ const CustomCheckbox: React.FC<ICustomCheckboxProps> = ({ showCheckbox, isVerifi
onChange(newChecked, schemaData);

try {
const selectedSchemas = JSON.parse(localStorage.getItem('selectedSchemas') ?? '[]');

if (newChecked) {
selectedSchemas.push(schemaData);
} else {
const index = selectedSchemas.findIndex((schema: ISchemaData) => schema.schemaId === schemaData?.schemaId);
if (index > -1) {
selectedSchemas.splice(index, 1);
const storedSchemaData = await getFromLocalStorage(storageKeys.SELECTED_SCHEMAS);
if(storedSchemaData){
const selectedSchemas = JSON.parse(storedSchemaData);
if (newChecked) {
selectedSchemas.push(schemaData);
} else {
const index = selectedSchemas.findIndex((schema: ISchemaData) => schema.schemaId === schemaData?.schemaId);
if (index > -1) {
selectedSchemas.splice(index, 1);
}
}
await setToLocalStorage(storageKeys.SELECTED_SCHEMAS, JSON.stringify(selectedSchemas));
} else {
throw new Error('Schema data is empty.');

}
await setToLocalStorage(storageKeys.SELECTED_SCHEMAS, JSON.stringify(selectedSchemas));
} catch (error) {
console.error('Error updating localStorage:', error);
}
Expand Down
23 changes: 14 additions & 9 deletions src/commonComponents/SchemaCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { limitedAttributesLength, storageKeys } from '../config/CommonConstant';
import type { IAttribute, ISchemaCardProps, ISchemaData } from './interface';
import CustomCheckbox from './CustomCheckbox';
import { Ledgers, Network, PolygonNetworks } from '../common/enums';
import React from 'react';

const SchemaCard = (props: ISchemaCardProps) => {
const orgDidDetails = async () => {
Expand Down Expand Up @@ -65,16 +66,14 @@ const handleCheckboxChange = (checked: boolean, schemaData?: ISchemaData) => {
}
};

const SchemaData = {
schemaId: props.schemaId,
attributes: props.attributes,
issuerDid: props.issuerDid,
created: props.created,
};

return (
<Card onClick={() => {

if (!props.w3cSchema) {
props.onClickCallback(props.schemaId, props.attributes, props.issuerDid, props.created)
}

if (props.w3cSchema) {
const W3CSchemaData = {
const W3CSchemaData = {
schemaId: props.schemaId,
schemaName: props.schemaName,
version: props.version,
Expand All @@ -83,6 +82,12 @@ const handleCheckboxChange = (checked: boolean, schemaData?: ISchemaData) => {
created: props.created,
};

return (
<Card onClick={() => {
if (!props.w3cSchema && props.onClickCallback) {
props.onClickCallback(SchemaData);
}
if (props.w3cSchema && props.onClickW3CCallback) {
props.onClickW3CCallback(W3CSchemaData);
}
}}
Expand Down
4 changes: 2 additions & 2 deletions src/commonComponents/datatable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { TableData, TableHeader } from './interface';
import type { ITableData, TableHeader } from './interface';
import CustomSpinner from '../../components/CustomSpinner';

interface DataTableProps {
header: TableHeader[];
data: TableData[];
data: ITableData[];
loading: boolean;
callback?: (clickId: string | null | undefined) => void;
displaySelect?: boolean;
Expand Down
6 changes: 5 additions & 1 deletion src/commonComponents/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export interface ISchemaCardProps {
created: string;
isClickable?: boolean;
showCheckbox?: boolean;
onClickCallback: (schemaId: string, attributes: string[], issuerDid: string, created: string) => void;
onClickCallback: (SchemaData:{
schemaId: string;
attributes: string[];
issuerDid: string;
created: string}) => void;

onClickW3CCallback: (W3CSchemaData: {
schemaId: string;
Expand Down
Loading

0 comments on commit b7d9e13

Please sign in to comment.