diff --git a/src/api/BulkIssuance.ts b/src/api/BulkIssuance.ts
index 64f18a7dd..1d5d0ebdf 100644
--- a/src/api/BulkIssuance.ts
+++ b/src/api/BulkIssuance.ts
@@ -6,6 +6,7 @@ import {
} from '../config/GetHeaderConfigs';
import { axiosGet, axiosPost } from '../services/apiRequests';
import { getFromLocalStorage } from './Auth';
+import type { IConnectionListAPIParameter } from './connection';
export const getSchemaCredDef = async () => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
@@ -40,7 +41,10 @@ export const DownloadCsvTemplate = async (credDefId: string) => {
}
};
-export const uploadCsvFile = async (payload: {file: Uint8Array | Blob, fileName:string}, credefId: string) => {
+export const uploadCsvFile = async (
+ payload: { file: Uint8Array | Blob; fileName: string },
+ credefId: string,
+) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Issuance.bulk.uploadCsv}?credDefId=${credefId}`;
@@ -80,7 +84,10 @@ export const getCsvFileData = async (
}
};
-export const issueBulkCredential = async (requestId: string, clientId: string) => {
+export const issueBulkCredential = async (
+ requestId: string,
+ clientId: string,
+) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.organizations.root}/${orgId}/${requestId}${apiRoutes.Issuance.bulk.bulk}`;
@@ -88,8 +95,8 @@ export const issueBulkCredential = async (requestId: string, clientId: string) =
url,
config: await getHeaderConfigs(),
payload: {
- clientId
- }
+ clientId,
+ },
};
try {
@@ -100,31 +107,33 @@ export const issueBulkCredential = async (requestId: string, clientId: string) =
}
};
-export const retryBulkIssuance = async (fileId:string, clientId:string) => {
- const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
- const url = `${apiRoutes.organizations.root}/${orgId}/${fileId}${apiRoutes.Issuance.bulk.retry}`;
-
- const axiosPayload = {
- url,
- payload:{clientId:clientId},
- config: await getHeaderConfigs(),
- };
-
- try {
- return await axiosPost(axiosPayload);
- } catch (error) {
- const err = error as Error;
- return err?.message;
- }
+export const retryBulkIssuance = async (fileId: string, clientId: string) => {
+ const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
+ const url = `${apiRoutes.organizations.root}/${orgId}/${fileId}${apiRoutes.Issuance.bulk.retry}`;
+
+ const axiosPayload = {
+ url,
+ payload: { clientId: clientId },
+ config: await getHeaderConfigs(),
+ };
+
+ try {
+ return await axiosPost(axiosPayload);
+ } catch (error) {
+ const err = error as Error;
+ return err?.message;
+ }
};
-export const getFilesHistory = async (
- pageNumber: number,
- pageSize: number,
- search: string,
-) => {
+export const getFilesHistory = async ({
+ page,
+ itemPerPage,
+ search,
+ sortBy,
+ sortingOrder,
+}: IConnectionListAPIParameter) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
- const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Issuance.bulk.files}?pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}`;
+ const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Issuance.bulk.files}?pageSize=${itemPerPage}&pageNumber=${page}&searchByText=${search}&sortBy=${sortingOrder}&sortField=${sortBy}`;
const axiosPayload = {
url,
@@ -141,13 +150,14 @@ export const getFilesHistory = async (
export const getFilesDataHistory = async (
requestId: string,
- pageNumber: number,
- pageSize: number,
+ itemPerPage: number,
+ page: number,
search: string,
- sortBy:string
+ sortingOrder: string,
+ sortBy: string,
) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
- const url = `${apiRoutes.organizations.root}/${orgId}/${requestId}${apiRoutes.Issuance.bulk.filesData}?pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}&sortBy=${sortBy}`;
+ const url = `${apiRoutes.organizations.root}/${orgId}/${requestId}${apiRoutes.Issuance.bulk.filesData}?pageSize=${itemPerPage}&pageNumber=${page}&searchByText=${search}&sortBy=${sortBy}&sortField=${sortingOrder}`;
const axiosPayload = {
url,
diff --git a/src/app/NavBarSidebar.astro b/src/app/NavBarSidebar.astro
index 1f55009d7..a776d5259 100644
--- a/src/app/NavBarSidebar.astro
+++ b/src/app/NavBarSidebar.astro
@@ -13,14 +13,12 @@ import { getFromCookies } from '../api/Auth';
import { RolePermissions } from '../config/permissions';
const { hideOrgAgent } = Astro.props;
-console.log(3242, hideOrgAgent)
const role = getFromCookies(Astro.cookies, 'role');
const permittedPages = RolePermissions.find(
(item) => item.role === role,
)?.pages;
-
---
{
- !hideOrgAgent &&
-
+
+
+
+ )
}
-
+
-
>
)
}
@@ -392,9 +396,21 @@ const permittedPages = RolePermissions.find(
>
View
-
-
-
+
+
+
-
+
Profile
+ class="flex space-x-2 px-4 py-2 my-2 text-sm text-gray-700 dark:text-white hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"
+ role="menuitem"
+ >
+
+
+ Profile
+
diff --git a/src/common/enums.ts b/src/common/enums.ts
index e3ebf2630..2613bd443 100644
--- a/src/common/enums.ts
+++ b/src/common/enums.ts
@@ -64,6 +64,13 @@ export enum OrganizationRoles {
organizationVerifier = "verifier"
}
+export enum OrganizationRoles {
+ organizationMember = "member",
+ organizationOwner = "owner",
+ organizationIssuer = "issuer",
+ organizationVerifier = "verifier"
+}
+
export enum PlatformRoles {
platformAdmin = "platform_admin"
}
diff --git a/src/commonComponents/PasseyAddDevicePopup.tsx b/src/commonComponents/PasseyAddDevicePopup.tsx
index a6a7707e9..a80c7f30c 100644
--- a/src/commonComponents/PasseyAddDevicePopup.tsx
+++ b/src/commonComponents/PasseyAddDevicePopup.tsx
@@ -18,7 +18,8 @@ interface PasswordValue {
}
const PasskeyAddDevice = (props: {
- setOpenModel(arg0: boolean): unknown; openModal: boolean; closeModal: (flag: boolean) => void; registerWithPasskey: (flag: boolean) => Promise
+ setOpenModel(arg0: boolean): unknown; openModal: boolean; closeModal: (flag: boolean) => void;
+ registerWithPasskey: (flag: boolean) => Promise
}
) => {
const [fidoUserError, setFidoUserError] = useState(null)
diff --git a/src/commonComponents/datatable/SortDataTable.tsx b/src/commonComponents/datatable/SortDataTable.tsx
index 33ebfe2d0..fefc37d94 100644
--- a/src/commonComponents/datatable/SortDataTable.tsx
+++ b/src/commonComponents/datatable/SortDataTable.tsx
@@ -2,7 +2,7 @@ import type { IDataTable } from './interface';
import CustomSpinner from '../../components/CustomSpinner';
import SearchInput from '../../components/SearchInput';
import { Pagination } from 'flowbite-react';
-import { useState } from 'react';
+import { ChangeEvent, useState } from 'react';
import { EmptyListMessage } from '../../components/EmptyListComponent';
const SortDataTable: React.FC = ({
@@ -34,7 +34,9 @@ const SortDataTable: React.FC = ({
const handleSortByValues = (event: { target: { value: any } }) => {
const newSelectedValue = event.target.value;
setSelectedValue(newSelectedValue);
- searchSortByValue(newSelectedValue);
+ if(searchSortByValue){
+ searchSortByValue(newSelectedValue);
+ }
};
const {
@@ -53,9 +55,9 @@ const SortDataTable: React.FC = ({
const sortValues = [
{
label: 'Descending',
- value: 'DESC',
+ value: 'desc',
},
- { label: 'Ascending', value: 'ASC' },
+ { label: 'Ascending', value: 'asc' },
];
return (
diff --git a/src/commonComponents/formikerror/index.tsx b/src/commonComponents/formikerror/index.tsx
new file mode 100644
index 000000000..2a8ad083d
--- /dev/null
+++ b/src/commonComponents/formikerror/index.tsx
@@ -0,0 +1,6 @@
+import React from 'react';
+
+const ErrorMessage = ({ error, touched }) => {
+ return touched && {error} ;
+};
+export default ErrorMessage;
diff --git a/src/components/ConnectionsList/index.tsx b/src/components/ConnectionsList/index.tsx
index b891faf89..099e2d4c9 100644
--- a/src/components/ConnectionsList/index.tsx
+++ b/src/components/ConnectionsList/index.tsx
@@ -22,7 +22,7 @@ const initialPageState = {
page: 1,
search: '',
sortBy: 'createDateTime',
- sortingOrder: 'DESC',
+ sortingOrder: 'desc',
allSearch: '',
};
const ConnectionList = () => {
diff --git a/src/components/Ecosystem/Endorsement/index.tsx b/src/components/Ecosystem/Endorsement/index.tsx
index 05fc2cead..231e5e417 100644
--- a/src/components/Ecosystem/Endorsement/index.tsx
+++ b/src/components/Ecosystem/Endorsement/index.tsx
@@ -61,7 +61,7 @@ const EndorsementList = () => {
page: 1,
search: '',
sortBy: 'id',
- sortingOrder: 'DESC',
+ sortingOrder: 'desc',
type: '',
status: '',
});
diff --git a/src/components/Ecosystem/interfaces/index.ts b/src/components/Ecosystem/interfaces/index.ts
index a1939c6fb..29f782a9c 100644
--- a/src/components/Ecosystem/interfaces/index.ts
+++ b/src/components/Ecosystem/interfaces/index.ts
@@ -26,4 +26,24 @@ export interface Ecosystem {
website: string
roles: string[]
logoFile:string
-}
\ No newline at end of file
+}
+
+export interface EditEntityModalProps {
+ openModal: boolean;
+ setMessage: (message: string) => void;
+ setOpenModal: (flag: boolean) => void;
+ onEditSuccess?: () => void;
+ entityData: Ecosystem | null;
+ isOrganization: boolean;
+}
+
+export interface EditEntityValues {
+ name: string;
+ description: string;
+}
+
+export interface ILogoImage {
+ logoFile: string | File;
+ imagePreviewUrl: string | ArrayBuffer | null | File;
+ fileName: string;
+}
diff --git a/src/components/EditEcosystemOrgModal/index.tsx b/src/components/EditEcosystemOrgModal/index.tsx
index 549fc273d..e649fd707 100644
--- a/src/components/EditEcosystemOrgModal/index.tsx
+++ b/src/components/EditEcosystemOrgModal/index.tsx
@@ -1,396 +1,366 @@
-import * as yup from "yup";
+import * as yup from 'yup';
import { Avatar, Button, Label, Modal } from 'flowbite-react';
import { Field, Form, Formik, FormikHelpers } from 'formik';
-import { IMG_MAX_HEIGHT, IMG_MAX_WIDTH, apiStatusCodes, imageSizeAccepted } from '../../config/CommonConstant';
-import { calculateSize, dataURItoBlob } from "../../utils/CompressImage";
-import { AlertComponent } from "../AlertComponent";
+import { apiStatusCodes } from '../../config/CommonConstant';
+import { AlertComponent } from '../AlertComponent';
import type { AxiosResponse } from 'axios';
-import { updateOrganization } from "../../api/organization";
-import { updateEcosystem } from "../../api/ecosystem";
-import type { Ecosystem } from "../Ecosystem/interfaces";
-import React, { useEffect, useState } from "react";
-import EndorsementTooltip from "../../commonComponents/EndorsementTooltip";
-
-interface EditEntityModalProps {
- openModal: boolean;
- setMessage: (message: string) => void;
- setOpenModal: (flag: boolean) => void;
- onEditSuccess?: () => void;
- entityData: Ecosystem | null;
- isOrganization: boolean;
-
-}
-
-interface EditEntityValues {
- name: string;
- description: string;
-}
-
-interface ILogoImage {
- logoFile: string | File;
- imagePreviewUrl: string | ArrayBuffer | null | File;
- fileName: string;
-}
+import { updateOrganization } from '../../api/organization';
+import { updateEcosystem } from '../../api/ecosystem';
+import type {
+ EditEntityModalProps,
+ EditEntityValues,
+ ILogoImage,
+} from '../Ecosystem/interfaces';
+import React, { useEffect, useState } from 'react';
+import EndorsementTooltip from '../../commonComponents/EndorsementTooltip';
+import { processImage } from '../../utils/processImage';
+import FormikErrorMessage from '../../commonComponents/formikerror/index'
const EditPopupModal = (props: EditEntityModalProps) => {
- const [logoImage, setLogoImage] = useState({
- logoFile: "",
- imagePreviewUrl: props?.entityData?.logoUrl ?? "",
- fileName: '',
- });
-
- const [loading, setLoading] = useState(false);
- const [isImageEmpty, setIsImageEmpty] = useState(true);
- const [initialEntityData, setInitialEntityData] = useState({
- name: "",
- description: ""
- });
-
- useEffect(() => {
- if (props.openModal && props.entityData) {
- setInitialEntityData({
- name: props.entityData.name ?? "",
- description: props.entityData.description ?? "",
- });
- SetisAutoEndorse(props.entityData.autoEndorsement)
- setLogoImage({
- logoFile: "",
- imagePreviewUrl: props.entityData.logoUrl ?? "",
- fileName: props.entityData.logoFile ?? "",
- });
- }
- }, [props.entityData, props.openModal]);
-
- const [errMsg, setErrMsg] = useState(null);
- const [imgError, setImgError] = useState('');
- const [isAutoEndorse, SetisAutoEndorse] = useState(false)
+ const [logoImage, setLogoImage] = useState({
+ logoFile: '',
+ imagePreviewUrl: props?.entityData?.logoUrl ?? '',
+ fileName: '',
+ });
+ const [loading, setLoading] = useState(false);
+ const [initialEntityData, setInitialEntityData] = useState({
+ name: '',
+ description: '',
+ });
- useEffect(() => {
- if (!props.openModal) {
- setInitialEntityData({
- name: "",
- description: "",
- });
+ useEffect(() => {
+ if (props.openModal && props.entityData) {
+ setInitialEntityData({
+ name: props.entityData.name ?? '',
+ description: props.entityData.description ?? '',
+ });
+ setIsAutoEndorse(props.entityData.autoEndorsement);
+ setLogoImage({
+ logoFile: '',
+ imagePreviewUrl: props.entityData.logoUrl ?? '',
+ fileName: props.entityData.logoFile ?? '',
+ });
+ }
+ }, [props.entityData, props.openModal]);
- setLogoImage({
- logoFile: "",
- imagePreviewUrl: "",
- fileName: "",
- });
- setImgError('');
- setErrMsg(null);
- setLoading(false);
- }
- }, [props.openModal]);
-
- const processImage = (e: any): string | undefined => {
- const file = e?.target?.files[0];
- if (!file) return;
+ const [errMsg, setErrMsg] = useState(null);
+ const [imgError, setImgError] = useState('');
+ const [isAutoEndorse, setIsAutoEndorse] = useState(false);
- const reader = new FileReader();
- reader.readAsDataURL(file);
+ useEffect(() => {
+ if (!props.openModal) {
+ setInitialEntityData({
+ name: '',
+ description: '',
+ });
- reader.onload = (event): void => {
- const imgElement = document.createElement("img");
- if (imgElement) {
- imgElement.src = typeof event?.target?.result === 'string' ? event.target.result : "";
- imgElement.onload = (e): void => {
- let fileUpdated: File | string = file;
- let srcEncoded = '';
- const canvas = document.createElement("canvas");
+ setLogoImage({
+ logoFile: '',
+ imagePreviewUrl: '',
+ fileName: '',
+ });
+ setImgError('');
+ setErrMsg(null);
+ setLoading(false);
+ }
+ }, [props.openModal]);
- const { width, height, ev } = calculateSize(imgElement, IMG_MAX_WIDTH, IMG_MAX_HEIGHT);
- canvas.width = width;
- canvas.height = height;
+ const handleImageChange = (event: any): void => {
+ setImgError('');
+ processImage(event, (result: any, error: any) => {
+ if (result) {
+ setLogoImage({
+ logoFile: '',
+ imagePreviewUrl: result,
+ fileName: event.target.files[0].name,
+ });
+ } else {
+ setImgError(error || 'An error occurred while processing the image.');
+ }
+ });
+ };
- const ctx = canvas.getContext("2d");
- if (ctx && e?.target) {
- ctx.imageSmoothingEnabled = true;
- ctx.imageSmoothingQuality = "high";
- ctx.drawImage(ev, 0, 0, canvas.width, canvas.height);
- srcEncoded = ctx.canvas.toDataURL(ev, file.type);
- const blob = dataURItoBlob(srcEncoded, file.type);
- fileUpdated = new File([blob], file.name, { type: file.type, lastModified: new Date().getTime() });
- setLogoImage({
- logoFile: fileUpdated,
- imagePreviewUrl: srcEncoded,
- fileName: file.name
- });
- }
- };
- }
- };
- };
-
- const handleImageChange = (event: any): void => {
- setImgError('');
- const reader = new FileReader();
- const file = event?.target?.files;
-
- const fileSize = Number((file[0]?.size / 1024 / 1024)?.toFixed(2));
- const extension = file[0]?.name?.substring(file[0]?.name?.lastIndexOf(".") + 1)?.toLowerCase();
+ const submitUpdateEntity = async (values: EditEntityValues) => {
+ setLoading(true);
- if (extension === "png" || extension === "jpeg" || extension === "jpg") {
- if (fileSize <= imageSizeAccepted) {
- reader.onloadend = (): void => {
- processImage(event);
- setIsImageEmpty(false);
- };
- reader.readAsDataURL(file[0]);
- event.preventDefault();
- } else {
- setImgError("Please check image size");
- }
- } else {
- setImgError("Invalid image type");
- }
- };
+ const entityData = {
+ id: props?.entityData?.id,
+ name: values.name,
+ description: values.description,
+ logo:
+ (logoImage?.imagePreviewUrl as string) || props?.entityData?.logoUrl,
+ autoEndorsement: isAutoEndorse,
+ };
- const isEmpty = (object: any): boolean => {
+ try {
+ if (props.isOrganization) {
+ const response = await updateOrganization(
+ entityData,
+ entityData.id?.toString() as string,
+ );
+ const { data } = response as AxiosResponse;
+ if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
+ if (props?.onEditSuccess) {
+ props?.onEditSuccess();
+ }
+ props.setOpenModal(false);
+ props.setMessage(data?.message);
+ } else {
+ setErrMsg(response as string);
+ setLoading(false);
+ }
+ } else {
+ const response = await updateEcosystem(entityData);
+ const { data } = response as AxiosResponse;
- return true;
- };
+ if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
+ if (props?.onEditSuccess) {
+ props?.onEditSuccess();
+ }
+ props.setOpenModal(false);
+ props.setMessage(data?.message);
+ } else {
+ setErrMsg(response as string);
+ setLoading(false);
+ }
+ }
+ } catch (error) {
+ console.error('An error occurred:', error);
+ setLoading(false);
+ }
+ };
- const submitUpdateEntity = async (values: EditEntityValues) => {
- setLoading(true);
+ return (
+ {
+ setLogoImage({
+ logoFile: '',
+ imagePreviewUrl: '',
+ fileName: '',
+ });
+ setInitialEntityData({
+ name: '',
+ description: '',
+ });
+ props.setOpenModal(false);
+ }}
+ >
+
+ Edit {props.isOrganization ? 'Organization' : 'Ecosystem'}
+
+
+ {
+ setErrMsg(null);
+ }}
+ />
+ ,
+ ) => {
+ await submitUpdateEntity(values);
+ }}
+ >
+ {(formikHandlers): JSX.Element => (
+
);
};
diff --git a/src/components/Issuance/HistoryDetails.tsx b/src/components/Issuance/HistoryDetails.tsx
index fbf5b52df..e7b206f71 100644
--- a/src/components/Issuance/HistoryDetails.tsx
+++ b/src/components/Issuance/HistoryDetails.tsx
@@ -1,20 +1,17 @@
'use client';
import { ChangeEvent, useEffect, useState } from 'react';
-import DataTable from '../../commonComponents/datatable';
import type { TableData } from '../../commonComponents/datatable/interface';
import { apiStatusCodes } from '../../config/CommonConstant';
import { AlertComponent } from '../AlertComponent';
import BreadCrumbs from '../BreadCrumbs';
-import CustomSpinner from '../CustomSpinner';
-import { EmptyListMessage } from '../EmptyListComponent';
import { pathRoutes } from '../../config/pathRoutes';
import BackButton from '../../commonComponents/backbutton';
-import SearchInput from '../SearchInput';
import { getFilesDataHistory } from '../../api/BulkIssuance';
import type { AxiosResponse } from 'axios';
-import { Pagination } from 'flowbite-react';
import { BulkIssuanceStatus } from '../../common/enums';
+import SortDataTable from '../../commonComponents/datatable/SortDataTable';
+import type { IConnectionListAPIParameter } from '../../api/connection';
interface IProps {
requestId: string;
@@ -22,76 +19,55 @@ interface IProps {
const HistoryDetails = ({ requestId }: IProps) => {
const initialPageState = {
- pageNumber: 1,
- pageSize: 10,
- total: 0,
+ itemPerPage: 10,
+ page: 1,
+ search: '',
+ sortBy: 'createDateTime',
+ sortingOrder: 'desc',
};
+
+ const [listAPIParameter, setListAPIParameter] = useState(initialPageState);
const [historyList, setHistoryList] = useState([]);
- const [options, setOptions] = useState(['All', 'Successful', 'Failed']);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
- const [currentPage, setCurrentPage] = useState(initialPageState);
- const [searchText, setSearchText] = useState('');
- const [sortBy, setSortBy] = useState('All');
-
- const onPageChange = (page: number) => {
- setCurrentPage({
- ...currentPage,
- pageNumber: page,
- });
- };
- useEffect(() => {
- let getData: NodeJS.Timeout;
-
- if (searchText.length >= 1) {
- getData = setTimeout(() => {
- getHistoryDetails();
- }, 1000);
- return () => clearTimeout(getData);
- } else {
- getHistoryDetails();
- }
-
- return () => clearTimeout(getData);
- }, [searchText, currentPage.pageNumber]);
+ const [totalItem, setTotalItem] = useState(0);
+ const [pageInfo, setPageInfo] = useState({
+ totalItem: '',
+ nextPage: '',
+ lastPage: '',
+ });
useEffect(() => {
let getData: NodeJS.Timeout;
- if (sortBy !== 'All') {
+ if (listAPIParameter.search.length >= 1) {
getData = setTimeout(() => {
- getHistoryDetails();
+ getHistoryDetails(listAPIParameter);
}, 1000);
+ return () => clearTimeout(getData);
} else {
- getHistoryDetails();
+ getHistoryDetails(listAPIParameter);
}
return () => clearTimeout(getData);
- }, [sortBy]);
-
- const searchInputChange = (e: ChangeEvent) => {
- setSearchText(e.target.value);
- };
+ }, [listAPIParameter]);
- const handleFilter = async (e: React.ChangeEvent) => {
- setSortBy(e.target.value);
- };
-
- const getHistoryDetails = async () => {
+ const getHistoryDetails = async (apiParameter: IConnectionListAPIParameter) => {
setLoading(true);
- const response = await getFilesDataHistory(
- requestId,
- currentPage.pageNumber,
- currentPage.pageSize,
- searchText,
- sortBy,
- );
+ const response = await getFilesDataHistory(requestId, apiParameter.itemPerPage, apiParameter.page, apiParameter.search, apiParameter.sortBy, apiParameter.sortingOrder);
const { data } = response as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const totalPages = data?.data?.lastPage;
+ setTotalItem(data?.data.totalItems);
+ const { totalItems, nextPage, lastPage } = data.data;
+ setPageInfo({
+ totalItem: totalItems,
+ nextPage: nextPage,
+ lastPage: lastPage,
+ });
const historyData = data?.data?.data?.map(
(history: {
isError: any;
@@ -116,13 +92,17 @@ const HistoryDetails = ({ requestId }: IProps) => {
: 'bg-red-100 text-red-800 border border-red-100 dark:border-red-400 dark:bg-gray-700 dark:text-red-400'
} text-md font-medium sm:mr-0 md:mr-2 min-[320]:px-3 sm:px-3 lg:px-3 py-0.5 rounded-md flex justify-center max-w-[120px]`}
>
- {history?.isError === false ? BulkIssuanceStatus.successful : BulkIssuanceStatus.failed}
+ {history?.isError === false
+ ? BulkIssuanceStatus.successful
+ : BulkIssuanceStatus.failed}
),
},
{
data: history?.error
- ? history?.error === 'Http Exception' ? 'Credential Issuance failed due to error in Wallet Agent' : history?.error?.replace(/[[\]"{},]/g, ' ')
+ ? history?.error === 'Http Exception'
+ ? 'Credential Issuance failed due to error in Wallet Agent'
+ : history?.error?.replace(/[[\]"{},]/g, ' ')
: '-',
},
],
@@ -130,16 +110,31 @@ const HistoryDetails = ({ requestId }: IProps) => {
},
);
setHistoryList(historyData);
- setCurrentPage({
- ...currentPage,
- total: totalPages,
- });
} else {
setError(response as string);
}
setLoading(false);
};
+ const searchInputChange = (e: ChangeEvent) => {
+ setListAPIParameter({
+ ...listAPIParameter,
+ search: e.target.value,
+ page: 1,
+ });
+ };
+
+ const searchSortByValue = (value: any) => {
+ setListAPIParameter({
+ ...listAPIParameter,
+ page: 1,
+ sortingOrder: value,
+ });
+ };
+
+ const refreshPage = () => {
+ getHistoryDetails(listAPIParameter);
+ };
const header = [
{ columnName: 'User' },
{ columnName: 'Status' },
@@ -163,24 +158,6 @@ const HistoryDetails = ({ requestId }: IProps) => {
Bulk Issuance History Details
-
-
-
-
- {options.map((opt) => (
-
- {opt}
-
- ))}
-
-
{
}}
/>
- {loading ? (
-
-
-
- ) : historyList && historyList?.length > 0 ? (
-
-
- {currentPage.total > 1 && (
-
- )}
-
- ) : (
-
-
-
- )}
+ {
+ setListAPIParameter((prevState) => ({
+ ...prevState,
+ page,
+ }));
+ }}
+ searchSortByValue={searchSortByValue}
+ totalPages={Math.ceil(totalItem / listAPIParameter?.itemPerPage)}
+ pageInfo={pageInfo}
+ isHeader={true}
+ isSearch={true}
+ isRefresh={true}
+ isSort={true}
+ message={'No History'}
+ discription={"You don't have any activities yet"}
+ >
);
};
diff --git a/src/components/Issuance/IssuedCrdentials.tsx b/src/components/Issuance/IssuedCrdentials.tsx
index bba369239..e605abe66 100644
--- a/src/components/Issuance/IssuedCrdentials.tsx
+++ b/src/components/Issuance/IssuedCrdentials.tsx
@@ -27,7 +27,7 @@ const initialPageState = {
page: 1,
search: '',
sortBy: 'createDateTime',
- sortingOrder: 'DESC',
+ sortingOrder: 'desc',
allSearch: '',
};
diff --git a/src/components/Profile/AddPasskey.tsx b/src/components/Profile/AddPasskey.tsx
index 184ee14e5..8485daaf8 100644
--- a/src/components/Profile/AddPasskey.tsx
+++ b/src/components/Profile/AddPasskey.tsx
@@ -58,7 +58,13 @@ const AddPasskey = ({ responseMessages }: { responseMessages: (value: IResponseM
const addDevice = async (): Promise => {
try {
- setOpenModel(true);
+ if(deviceList?.length > 0){
+ registerWithPasskey(true)
+ setOpenModel(false);
+ }else{
+ setOpenModel(true);
+
+ }
} catch (error) {
setFidoLoader(false);
}
diff --git a/src/components/Profile/DisplayUser.tsx b/src/components/Profile/DisplayUser.tsx
index b8af4dc59..120d9848d 100644
--- a/src/components/Profile/DisplayUser.tsx
+++ b/src/components/Profile/DisplayUser.tsx
@@ -27,16 +27,16 @@ const DisplayUser = () => {
userObj &&
<>
{userObj['firstName']}
-
+
{userObj['email']}
{TextTittlecase(userObj['roles'])}
@@ -49,4 +49,4 @@ const DisplayUser = () => {
)
}
-export default DisplayUser
\ No newline at end of file
+export default DisplayUser
diff --git a/src/components/Resources/Schema/SchemasList.tsx b/src/components/Resources/Schema/SchemasList.tsx
index f03b7073f..48e89bd15 100644
--- a/src/components/Resources/Schema/SchemasList.tsx
+++ b/src/components/Resources/Schema/SchemasList.tsx
@@ -36,7 +36,7 @@ const SchemaList = (props: {
page: 1,
search: '',
sortBy: 'id',
- sortingOrder: 'DESC',
+ sortingOrder: 'desc',
allSearch: '',
});
const [walletStatus, setWalletStatus] = useState(false);
diff --git a/src/components/SignOutButton/index.tsx b/src/components/SignOutButton/index.tsx
index 91172287c..13e1ba46f 100644
--- a/src/components/SignOutButton/index.tsx
+++ b/src/components/SignOutButton/index.tsx
@@ -1,34 +1,57 @@
-import { removeFromLocalStorage } from "../../api/Auth"
-import { storageKeys } from "../../config/CommonConstant"
+import { removeFromLocalStorage } from '../../api/Auth';
+import { storageKeys } from '../../config/CommonConstant';
const SignOutButton = () => {
+ const signOut = async () => {
+ await removeFromLocalStorage(storageKeys.TOKEN);
+ await removeFromLocalStorage(storageKeys.USER_EMAIL);
+ await removeFromLocalStorage(storageKeys.ORG_ID);
+ await removeFromLocalStorage(storageKeys.ORG_ROLES);
+ await removeFromLocalStorage(storageKeys.ECOSYSTEM_ID);
+ await removeFromLocalStorage(storageKeys.ECOSYSTEM_ROLE);
+ await removeFromLocalStorage(storageKeys.USER_PROFILE);
- const signOut = async () => {
+ const response = await fetch('/api/auth/signout', {
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ });
- await removeFromLocalStorage(storageKeys.TOKEN)
- await removeFromLocalStorage(storageKeys.USER_EMAIL)
- await removeFromLocalStorage(storageKeys.ORG_ID)
- await removeFromLocalStorage(storageKeys.ORG_ROLES)
- await removeFromLocalStorage(storageKeys.ECOSYSTEM_ID)
- await removeFromLocalStorage(storageKeys.ECOSYSTEM_ROLE)
- await removeFromLocalStorage(storageKeys.USER_PROFILE)
+ if (response.redirected) {
+ window.location.assign(response.url);
+ }
+ };
+ return (
+
+ {' '}
+
+
+
+
+
+ Sign out
+
+ );
+};
- const response = await fetch('/api/auth/signout', {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- }
- });
-
- if (response.redirected) {
- window.location.assign(response.url);
- }
- }
- return (
- Sign out
- )
-}
-
-export default SignOutButton
\ No newline at end of file
+export default SignOutButton;
diff --git a/src/components/User/UserDashBoard.tsx b/src/components/User/UserDashBoard.tsx
index d250c5be6..d808ce07c 100644
--- a/src/components/User/UserDashBoard.tsx
+++ b/src/components/User/UserDashBoard.tsx
@@ -66,7 +66,7 @@ const UserDashBoard = () => {
page: 1,
search: '',
sortBy: 'id',
- sortingOrder: 'DESC',
+ sortingOrder: 'desc',
allSearch: '',
});
const [ecoCount, setEcoCount] = useState(0);
@@ -531,10 +531,10 @@ const UserDashBoard = () => {
- Wallet lets you create schemas and credential-definitions
+ Wallet lets you create schemas and credential definitions
- Please create wallet for your organisation which would
+ Please create wallet for your organization which would
help you to issue and verify credentials for your users.
diff --git a/src/components/Verification/ConnectionList.tsx b/src/components/Verification/ConnectionList.tsx
index f56d9dfc6..134a4fe5b 100644
--- a/src/components/Verification/ConnectionList.tsx
+++ b/src/components/Verification/ConnectionList.tsx
@@ -6,22 +6,20 @@ import {
IConnectionListAPIParameter,
getConnectionsByOrg,
} from '../../api/connection';
-import DataTable from '../../commonComponents/datatable';
import type { TableData } from '../../commonComponents/datatable/interface';
import { apiStatusCodes } from '../../config/CommonConstant';
import { AlertComponent } from '../AlertComponent';
import { dateConversion } from '../../utils/DateConversion';
import DateTooltip from '../Tooltip';
-import SearchInput from '../SearchInput';
-import { Pagination } from 'flowbite-react';
import type { IConnectionList } from './interface';
+import SortDataTable from '../../commonComponents/datatable/SortDataTable';
const initialPageState = {
itemPerPage: 10,
page: 1,
search: '',
sortBy: 'createDateTime',
- sortingOrder: 'DESC',
+ sortingOrder: 'desc',
allSearch: '',
};
@@ -32,19 +30,32 @@ const ConnectionList = (props: {
const [selectedConnectionList, setSelectedConnectionList] = useState<
TableData[]
>([]);
-
const [loading, setLoading] = useState
(false);
const [listAPIParameter, setListAPIParameter] =
useState(initialPageState);
const [totalItem, setTotalItem] = useState(0);
const [error, setError] = useState(null);
+ const [pageInfo, setPageInfo] = useState({
+ totalItem: '',
+ nextPage: '',
+ lastPage: '',
+ });
//This useEffect is called when the searchText changes
useEffect(() => {
- getConnectionsVerification(listAPIParameter);
- }, [listAPIParameter]);
+ let getData: NodeJS.Timeout;
- //onChange of Search input text
+ if (listAPIParameter?.search?.length >= 1) {
+ getData = setTimeout(() => {
+ getConnectionsVerification(listAPIParameter);
+ }, 1000);
+ return () => clearTimeout(getData);
+ } else {
+ getConnectionsVerification(listAPIParameter);
+ }
+ return () => clearTimeout(getData);
+ }, [listAPIParameter]);
+
const searchInputChange = (e: ChangeEvent) => {
setListAPIParameter({
...listAPIParameter,
@@ -62,6 +73,13 @@ const ConnectionList = (props: {
const { data } = response as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
setTotalItem(data?.data.totalItems);
+ const { totalItems, nextPage, lastPage } = data.data;
+
+ setPageInfo({
+ totalItem: totalItems,
+ nextPage: nextPage,
+ lastPage: lastPage,
+ });
const connections = data?.data?.data?.map(
(ele: IConnectionList) => {
const userName = ele?.theirLabel
@@ -163,6 +181,21 @@ const ConnectionList = (props: {
}
};
+ const searchSortByValue = (value: any) => {
+ setListAPIParameter({
+ ...listAPIParameter,
+ page: 1,
+ sortingOrder: value,
+ });
+ };
+
+
+ const refreshPage = () => {
+ setSelectedConnectionList([]);
+ getConnectionsVerification(listAPIParameter);
+ };
+
+
useEffect(() => {
props.selectConnection(selectedConnectionList);
}, [selectedConnectionList]);
@@ -179,9 +212,6 @@ const ConnectionList = (props: {
Connection List
-
-
-
-
-
-
- {Math.ceil(totalItem / listAPIParameter?.itemPerPage) > 1 && (
-
-
{
- setListAPIParameter((prevState) => ({
- ...prevState,
- page,
- }));
- }}
- totalPages={Math.ceil(totalItem / listAPIParameter?.itemPerPage)}
- />
-
- )}
+ {
+ setListAPIParameter((prevState) => ({
+ ...prevState,
+ page,
+ }));
+ }}
+ totalPages={Math.ceil(totalItem / listAPIParameter?.itemPerPage)}
+ pageInfo={pageInfo}
+ searchSortByValue={searchSortByValue}
+ isHeader={true}
+ isSearch={true}
+ isRefresh={true}
+ isSort={true}
+ isPagination={true}
+ message={'No Connections'}
+ discription={"You don't have any connections yet"}
+ >
);
};
diff --git a/src/components/Verification/ProofRequestPopup.tsx b/src/components/Verification/ProofRequestPopup.tsx
index 170225a95..83d0af8c9 100644
--- a/src/components/Verification/ProofRequestPopup.tsx
+++ b/src/components/Verification/ProofRequestPopup.tsx
@@ -14,6 +14,7 @@ const ProofRequest = (props: IProofRrquestDetails) => {
const [navigation, setNavigation] = useState(false);
const [succesMsg, setSuccesMsg] = useState('');
const [error, setError] = useState('');
+
const handleConfirmClick = async (id: string) => {
try {
setButtonLoader(true);
@@ -85,7 +86,7 @@ const ProofRequest = (props: IProofRrquestDetails) => {
{' '}
Verification Details
- {!props.userData ? (
+ {props.verifyLoading ? (
@@ -189,7 +190,7 @@ const ProofRequest = (props: IProofRrquestDetails) => {
Verified Details
- {!props.userData ? (
+ {props.verifyLoading ? (
@@ -206,16 +207,17 @@ const ProofRequest = (props: IProofRrquestDetails) => {
)}
- {
setButtonLoader(false);
props.closeModal(false, '', false);
}}
+ disabled={props.verifyLoading}
className="py-1 px-2 medium text-center text-white bg-primary-700 hover:!bg-primary-800 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800"
style={{ height: '2.5rem', minWidth: '100px' }}
>
Close
-
+
diff --git a/src/components/Verification/VerificationCredentialList.tsx b/src/components/Verification/VerificationCredentialList.tsx
index 9263aa087..b88477837 100644
--- a/src/components/Verification/VerificationCredentialList.tsx
+++ b/src/components/Verification/VerificationCredentialList.tsx
@@ -36,7 +36,7 @@ const initialPageState = {
page: 1,
search: '',
sortBy: 'createDateTime',
- sortingOrder: 'DESC',
+ sortingOrder: 'desc',
allSearch: '',
};
@@ -47,13 +47,13 @@ const VerificationCredentialList = () => {
const [requestId, setRequestId] = useState('');
const [errMsg, setErrMsg] = useState(null);
const [proofReqSuccess, setProofReqSuccess] = useState('');
- const [verifyLoader, setVerifyloader] = useState(false);
const [userData, setUserData] = useState(null);
const [view, setView] = useState(false);
const [walletCreated, setWalletCreated] = useState(false);
const [listAPIParameter, setListAPIParameter] =
useState(initialPageState);
const [totalItem, setTotalItem] = useState(0);
+ const [verifyLoading, setVerifyLoading]= useState(true)
const [pageInfo, setPageInfo] = useState({
totalItem: '',
nextPage: '',
@@ -62,14 +62,17 @@ const VerificationCredentialList = () => {
const getProofPresentationData = async (proofId: string) => {
try {
+ setVerifyLoading(true)
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const response = await getVerifiedProofDetails(proofId, orgId);
const { data } = response as AxiosResponse;
if (data?.statusCode === apiStatusCodes?.API_STATUS_SUCCESS) {
setUserData(data?.data);
+ setVerifyLoading(false)
} else {
setErrMsg(response as string);
+ setVerifyLoading(false)
}
} catch (error) {
throw error;
@@ -104,8 +107,6 @@ const VerificationCredentialList = () => {
const { data } = response as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const { totalItems, nextPage, lastPage } = data.data;
- console.log('data.data', data.data);
-
setPageInfo({
totalItem: totalItems,
nextPage: nextPage,
@@ -263,14 +264,14 @@ const VerificationCredentialList = () => {
if (data?.statusCode === apiStatusCodes?.API_STATUS_CREATED) {
setOpenModal(false);
setProofReqSuccess(data.message);
- setVerifyloader(false);
+ setVerifyLoading(false);
setTimeout(() => {
getproofRequestList(listAPIParameter);
}, 2000);
} else {
setOpenModal(false);
setErrMsg(response as string);
- setVerifyloader(false);
+ setVerifyLoading(false);
}
setTimeout(() => {
setProofReqSuccess('');
@@ -278,7 +279,7 @@ const VerificationCredentialList = () => {
}, 4000);
} catch (error) {
setOpenModal(false);
- setVerifyloader(false);
+ setVerifyLoading(false);
console.error('An error occurred:', error);
setErrMsg('An error occurred while processing the presentation.');
}
@@ -437,11 +438,12 @@ const VerificationCredentialList = () => {
{userData && (
openProofRequestModel(false, '', '')}
+ closeModal={() => {openProofRequestModel(false, '', '')}}
onSucess={requestProof}
requestId={requestId}
userData={userData}
view={view}
+ verifyLoading={verifyLoading}
/>
)}
diff --git a/src/components/Verification/interface.ts b/src/components/Verification/interface.ts
index a49940da6..7bb0d1ea1 100644
--- a/src/components/Verification/interface.ts
+++ b/src/components/Verification/interface.ts
@@ -38,6 +38,7 @@ export interface SchemaDetails {
}
export interface IProofRrquestDetails {
+ verifyLoading: boolean;
openModal: boolean;
closeModal: (flag: boolean, id: string, state: boolean) => void;
onSucess: (verifyPresentationId: string) => void;
diff --git a/src/components/organization/Dashboard.tsx b/src/components/organization/Dashboard.tsx
index 89ab9a7e6..f8d45615a 100644
--- a/src/components/organization/Dashboard.tsx
+++ b/src/components/organization/Dashboard.tsx
@@ -2,7 +2,6 @@ import type { OrgDashboard, Organisation } from './interfaces';
import { apiStatusCodes, storageKeys } from '../../config/CommonConstant';
import { getOrgDashboard, getOrganizationById } from '../../api/organization';
import { useEffect, useState } from 'react';
-
import { Alert } from 'flowbite-react';
import type { AxiosResponse } from 'axios';
import BreadCrumbs from '../BreadCrumbs';
@@ -19,28 +18,22 @@ import { getFromLocalStorage } from '../../api/Auth';
import { getOrganizationById } from '../../api/organization';
import { pathRoutes } from '../../config/pathRoutes';
import DashboardCard from '../../commonComponents/DashboardCard';
+import { AlertComponent } from '../AlertComponent';
+import React from 'react';
const Dashboard = () => {
const [orgData, setOrgData] = useState(null);
-
const [walletStatus, setWalletStatus] = useState(false);
-
const [orgDashboard, setOrgDashboard] = useState(null);
const [success, setSuccess] = useState(null);
const [failure, setFailure] = useState(null);
-
const [loading, setLoading] = useState(true);
const [userRoles, setUserRoles] = useState([]);
-
+ const [orgSuccess, setOrgSuccess] = useState(null);
const [openModal, setOpenModal] = useState(false);
- const props = { openModal, setOpenModal };
const EditOrgDetails = () => {
- props.setOpenModal(true);
- };
-
- const updateOrganizationData = (updatedData: Organisation) => {
- setOrgData(updatedData);
+ setOpenModal(true);
};
const getUserRoles = async () => {
@@ -55,11 +48,8 @@ const Dashboard = () => {
const fetchOrganizationDetails = async () => {
setLoading(true);
-
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
-
const response = await getOrganizationById(orgId as string);
-
const { data } = response as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
@@ -75,11 +65,8 @@ const Dashboard = () => {
const fetchOrganizationDashboard = async () => {
setLoading(true);
-
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
-
const response = await getOrgDashboard(orgId as string);
-
const { data } = response as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
@@ -95,6 +82,11 @@ const Dashboard = () => {
fetchOrganizationDashboard();
}, []);
+ const handleEditModalClose = () => {
+ setOpenModal(false);
+ fetchOrganizationDetails();
+ };
+
useEffect(() => {
setTimeout(() => {
setSuccess(null);
@@ -102,10 +94,6 @@ const Dashboard = () => {
}, 3000);
}, [success !== null, failure !== null]);
- const redirectDashboardInvitations = () => {
- window.location.href = '/organizations/invitations';
- };
-
const setWalletSpinupStatus = (status: boolean) => {
setSuccess('Wallet created successfully');
fetchOrganizationDetails();
@@ -120,6 +108,19 @@ const Dashboard = () => {
+
+ {orgSuccess && (
+
+
{
+ setOrgSuccess(null);
+ }}
+ />
+
+ )}
+
@@ -181,13 +182,13 @@ const Dashboard = () => {
{
- throw new Error('Function not implemented.');
+ setOrgSuccess(message);
}}
+ orgData={orgData}
/>
diff --git a/src/components/organization/EditOrgdetailsModal.tsx b/src/components/organization/EditOrgdetailsModal.tsx
index b7d528f99..24aba5a4b 100644
--- a/src/components/organization/EditOrgdetailsModal.tsx
+++ b/src/components/organization/EditOrgdetailsModal.tsx
@@ -2,36 +2,16 @@ import * as yup from 'yup';
import { Avatar, Button, Label, Modal } from 'flowbite-react';
import { Field, Form, Formik, FormikHelpers } from 'formik';
import {
- IMG_MAX_HEIGHT,
- IMG_MAX_WIDTH,
apiStatusCodes,
- imageSizeAccepted,
} from '../../config/CommonConstant';
-import { calculateSize, dataURItoBlob } from '../../utils/CompressImage';
import React, { useEffect, useState } from 'react';
import { AlertComponent } from '../AlertComponent';
import type { AxiosResponse } from 'axios';
import { updateOrganization } from '../../api/organization';
-import type { Organisation } from './interfaces';
+import type { EditOrgdetailsModalProps, ILogoImage, Organisation, Values } from './interfaces';
import defaultUserIcon from '../../../public/images/person_FILL1_wght400_GRAD0_opsz24.svg';
-
-interface Values {
- website: any;
- name: string;
- description: string;
-}
-interface ILogoImage {
- logoFile: string | File;
- imagePreviewUrl: string | ArrayBuffer | null | File;
- fileName: string;
-}
-interface EditOrgdetailsModalProps {
- openModal: boolean;
- setMessage: (message: string) => void;
- setOpenModal: (flag: boolean) => void;
- onEditSucess?: () => void;
- orgData: Organisation | null;
-}
+import { processImage } from '../../utils/processImage';
+import FormikErrorMessage from '../../commonComponents/formikerror/index'
const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
const [logoImage, setLogoImage] = useState
({
@@ -48,7 +28,7 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
});
useEffect(() => {
- if (props.orgData) {
+ if (props.openModal && props.orgData) {
setInitialOrgData({
name: props.orgData.name ?? '',
description: props.orgData.description ?? '',
@@ -63,14 +43,14 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
setIsPublic(props?.orgData?.publicProfile);
}
- }, [props]);
+ }, [props.orgData, props.openModal]);
const [erroMsg, setErrMsg] = useState(null);
const [imgError, setImgError] = useState('');
useEffect(() => {
- if (props.openModal === false) {
+ if (!props.openModal) {
setInitialOrgData({
name: '',
description: '',
@@ -85,86 +65,20 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
}
}, [props.openModal]);
- const ProcessImg = (e: any): string | undefined => {
- const file = e?.target.files[0];
- if (!file) {
- return;
- }
-
- const reader = new FileReader();
- reader.readAsDataURL(file);
-
- reader.onload = (event): void => {
- const imgElement = document.createElement('img');
- if (imgElement) {
- imgElement.src =
- typeof event?.target?.result === 'string' ? event.target.result : '';
- imgElement.onload = (e): void => {
- let fileUpdated: File | string = file;
- let srcEncoded = '';
- const canvas = document.createElement('canvas');
-
- const { width, height, ev } = calculateSize(
- imgElement,
- IMG_MAX_WIDTH,
- IMG_MAX_HEIGHT,
- );
- canvas.width = width;
- canvas.height = height;
-
- const ctx = canvas.getContext('2d');
- if (ctx && e?.target) {
- ctx.imageSmoothingEnabled = true;
- ctx.imageSmoothingQuality = 'high';
- ctx.drawImage(ev, 0, 0, canvas.width, canvas.height);
- srcEncoded = ctx.canvas.toDataURL(ev, file.type);
- const blob = dataURItoBlob(srcEncoded, file.type);
- fileUpdated = new File([blob], file.name, {
- type: file.type,
- lastModified: new Date().getTime(),
- });
- setLogoImage({
- logoFile: fileUpdated,
- imagePreviewUrl: srcEncoded,
- fileName: file.name,
- });
- }
- };
- }
- };
- };
-
- const isEmpty = (object: any): boolean => {
- for (const property in object) {
- return false;
- }
- return true;
- };
const handleImageChange = (event: any): void => {
- setImgError('');
- const reader = new FileReader();
- const file = event?.target?.files;
-
- const fieSize = Number((file[0]?.size / 1024 / 1024)?.toFixed(2));
- const extension = file[0]?.name
- ?.substring(file[0]?.name?.lastIndexOf('.') + 1)
- ?.toLowerCase();
- if (extension === 'png' || extension === 'jpeg' || extension === 'jpg') {
- if (fieSize <= imageSizeAccepted) {
- reader.onloadend = (): void => {
- ProcessImg(event);
- isEmpty(reader.result);
- };
- reader.readAsDataURL(file[0]);
- event.preventDefault();
- } else {
- setImgError('Please check image size');
- }
- } else {
- setImgError('Invalid image type');
- }
- };
-
+ setImgError('');
+ processImage(event, (result, error) => {
+ if (result) {
+ setLogoImage({
+ logoFile: '',
+ imagePreviewUrl: result,
+ fileName: event.target.files[0].name,
+ });
+ } else {
+ setImgError(error || 'An error occurred while processing the image.');
+ }
+ });
+ };
const submitUpdateOrganization = async (values: Values) => {
setLoading(true);
@@ -176,22 +90,26 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
website: values.website,
isPublic: isPublic,
};
-
- const resUpdateOrg = await updateOrganization(
- orgData,
- orgData.orgId?.toString() as string,
- );
-
- const { data } = resUpdateOrg as AxiosResponse;
- setLoading(false);
-
- if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
- if (props?.onEditSucess) {
- props?.onEditSucess();
+ try {
+ const response = await updateOrganization(
+ orgData,
+ orgData.orgId?.toString() as string,
+ );
+ const { data } = response as AxiosResponse;
+ if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
+ if (props?.onEditSucess) {
+ props?.onEditSucess();
+ }
+ props.setOpenModal(false);
+ props.setMessage(data?.message);
+ setLoading(false);
+ } else {
+ setErrMsg(response as string);
+ setLoading(false);
}
- props.setOpenModal(false);
- } else {
- setErrMsg(resUpdateOrg as string);
+ } catch (error) {
+ console.error('An error occurred:', error);
+ setLoading(false);
}
};
@@ -204,6 +122,11 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
imagePreviewUrl: '',
fileName: '',
});
+ setInitialOrgData({
+ name: props?.orgData?.name ?? '',
+ description: props?.orgData?.description ?? '',
+ website: props?.orgData?.website ?? '',
+ });
props.setOpenModal(false);
}}
>
@@ -239,18 +162,16 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
{ resetForm }: FormikHelpers,
) => {
submitUpdateOrganization(values);
- window.location.reload();
}}
>
{(formikHandlers): JSX.Element => (
- {typeof logoImage.logoFile === 'string' &&
- props?.orgData?.logoUrl ? (
+ {logoImage?.imagePreviewUrl ? (
) : typeof logoImage.logoFile === 'string' ? (
@@ -321,13 +242,10 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
}
}}
/>
- {formikHandlers?.errors &&
- formikHandlers?.errors?.name &&
- formikHandlers?.touched?.name && (
-
- {formikHandlers?.errors?.name}
-
- )}
+
@@ -358,14 +276,10 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
}
}}
/>
- {formikHandlers?.errors &&
- formikHandlers?.errors?.description &&
- formikHandlers?.touched &&
- formikHandlers?.touched?.description && (
-
- {formikHandlers?.errors?.description}
-
- )}
+
diff --git a/src/components/organization/interfaces/index.ts b/src/components/organization/interfaces/index.ts
index 0d7cf3e33..799113826 100644
--- a/src/components/organization/interfaces/index.ts
+++ b/src/components/organization/interfaces/index.ts
@@ -188,4 +188,20 @@ export interface IOrgData {
export interface IExploreOrg {
orgData: IOrgData
}
-
+export interface Values {
+ website: any;
+ name: string;
+ description: string;
+}
+export interface ILogoImage {
+ logoFile: string | File;
+ imagePreviewUrl: string | ArrayBuffer | null | File;
+ fileName: string;
+}
+export interface EditOrgdetailsModalProps {
+ openModal: boolean;
+ setMessage: (message: string) => void;
+ setOpenModal: (flag: boolean) => void;
+ onEditSucess?: () => void;
+ orgData: Organisation | null;
+}
diff --git a/src/utils/processImage.ts b/src/utils/processImage.ts
new file mode 100644
index 000000000..3939e193a
--- /dev/null
+++ b/src/utils/processImage.ts
@@ -0,0 +1,29 @@
+import type { ChangeEvent } from 'react';
+import {
+ imageSizeAccepted,
+} from '../config/CommonConstant';
+
+export const processImage = (event: ChangeEvent, callback:any) => {
+ const reader = new FileReader();
+ const file = event?.target?.files;
+if(file){
+ const fileSize = Number((file[0]?.size / 1024 / 1024)?.toFixed(2));
+ const extension = file[0]?.name
+ ?.substring(file[0]?.name?.lastIndexOf('.') + 1)
+ ?.toLowerCase();
+
+ if (
+ (extension === 'png' || extension === 'jpeg' || extension === 'jpg') &&
+ fileSize <= imageSizeAccepted
+ ) {
+ reader.onloadend = () => {
+ callback(reader.result);
+ };
+ reader.readAsDataURL(file[0]);
+ event.preventDefault();
+ } else {
+ callback(null, extension === 'png' || extension === 'jpeg' || extension === 'jpg' ? 'Please check image size' : 'Invalid image type');
+ }
+}
+
+};