Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: warnings in console in verification flow #850

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 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,21 @@ 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){
pranalidhanavade marked this conversation as resolved.
Show resolved Hide resolved

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));
}
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
Loading