diff --git a/src/components/User/UserDashBoard.tsx b/src/components/User/UserDashBoard.tsx index 7aa739e55..14bfd609b 100644 --- a/src/components/User/UserDashBoard.tsx +++ b/src/components/User/UserDashBoard.tsx @@ -1,24 +1,27 @@ -import { useEffect, useState } from 'react'; -import { AlertComponent } from '../AlertComponent'; -import type { AxiosResponse } from 'axios'; -import CustomAvatar from '../Avatar/index'; -import type { Organisation } from '../organization/interfaces'; -import type { UserActivity } from './interfaces'; +import { Button, Tooltip } from 'flowbite-react'; +import { getAllCredDef, getAllSchemasByOrgId } from '../../api/Schema'; +import { getFromLocalStorage, setToLocalStorage } from '../../api/Auth'; + import { apiStatusCodes, itemPerPage, storageKeys } from '../../config/CommonConstant'; import { getOrganizationById, getOrganizations } from '../../api/organization'; -import { getUserActivity } from '../../api/users'; import { getUserEcosystemInvitations, getUserInvitations, } from '../../api/invitations'; -import { pathRoutes } from '../../config/pathRoutes'; -import { getFromLocalStorage, setToLocalStorage } from '../../api/Auth'; -import { dateConversion } from '../../utils/DateConversion'; +import { useEffect, useState } from 'react'; + +import { AlertComponent } from '../AlertComponent'; +import type { AxiosResponse } from 'axios'; +import CustomAvatar from '../Avatar/index'; import DateTooltip from '../Tooltip'; -import { Roles } from '../../utils/enums/roles'; -import { Button, Tooltip } from 'flowbite-react'; -import { getAllCredDef, getAllSchemasByOrgId } from '../../api/Schema'; import type { GetAllSchemaListParameter } from '../Resources/Schema/interfaces'; +import type { Organisation } from '../organization/interfaces'; + +import { Roles } from '../../utils/enums/roles'; +import type { UserActivity } from './interfaces'; +import { dateConversion } from '../../utils/DateConversion'; +import { getUserActivity } from '../../api/users'; +import { pathRoutes } from '../../config/pathRoutes'; import React from 'react'; import { OrganizationRoles, @@ -50,10 +53,10 @@ interface ICredDef { } const UserDashBoard = () => { - const [message, setMessage] = useState(null); - const [ecoMessage, setEcoMessage] = useState(null); + const [message, setMessage] = useState(''); + const [ecoMessage, setEcoMessage] = useState(''); const [viewButton, setViewButton] = useState(false); - const [error, setError] = useState(null); + const [error, setError] = useState(''); const [currentPage, setCurrentPage] = useState(initialPageState); const [organizationsList, setOrganizationList] = useState | null>(null); @@ -85,6 +88,7 @@ const UserDashBoard = () => { const getAllInvitations = async () => { setLoading(true); + try { const response = await getUserInvitations( currentPage.pageNumber, currentPage.pageSize, @@ -106,9 +110,11 @@ const UserDashBoard = () => { } else { setError(response as string); } + } catch(err) { + setError('An unexpected error occurred'); + } setLoading(false); }; - //Fetch the user organization list const getAllOrganizations = async () => { setOrgLoading(true); const response = await getOrganizations( @@ -128,6 +134,40 @@ const UserDashBoard = () => { } setOrgLoading(false); }; + const getAllEcosystemInvitations = async () => { + setLoading(true); + try { + const response = await getUserEcosystemInvitations( + currentPage.pageNumber, + currentPage.pageSize, + '', + ); + const { data } = response as AxiosResponse; + + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + const totalPages = data?.data?.totalPages; + const invitationPendingList = + data?.data?.invitations && + data?.data?.invitations?.filter((invitation: { status: string }) => { + return invitation.status === 'pending'; + }); + if (invitationPendingList && invitationPendingList.length > 0) { + setEcoMessage(`You have received invitation to join ecosystem `); + setViewButton(true); + } + setCurrentPage({ + ...currentPage, + total: totalPages, + }); + } else { + setError(response as string); + } + } + catch(err){ + setError('An unexpected error occurred.'); + } + setLoading(false); + }; const getAllEcosystemInvitations = async () => { setLoading(true); @@ -437,31 +477,39 @@ const UserDashBoard = () => { }; return ( + <>
- 0 && + + { - setMessage(null); - setError(null); + setMessage(''); + setError(''); }} - /> + /> + } + +
- { - setEcoMessage(null); - setError(null); - }} - /> + {ecoMessage && ecoMessage.length > 0 && + { + setEcoMessage(''); + setError(''); + }} + /> +} +
{walletData && walletData.length > 0 ? ( <> @@ -572,7 +620,7 @@ const UserDashBoard = () => { ); org.roles = roles; return ( - @@ -603,12 +651,12 @@ const UserDashBoard = () => { )} - {org?.name} + {org?.name} {org.roles.includes( OrganizationRoles.organizationOwner, ) ? ( - + { OrganizationRoles.organizationIssuer, ) ? ( {
- + ); })} {organizationsList && organizationsList?.length > 0 && ( @@ -941,10 +986,10 @@ const UserDashBoard = () => { className="flex items-center space-x-2 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white rounded-md" > - {schema?.name} + {schema?.name || ''} - {schema?.version} + {schema?.version || ''} @@ -1040,10 +1085,10 @@ const UserDashBoard = () => { className="flex items-center space-x-2 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white rounded-md" > - {cred?.tag} + {cred?.tag || ''} - {cred?.credentialDefinitionId} + {cred?.credentialDefinitionId || ''} @@ -1111,6 +1156,7 @@ const UserDashBoard = () => { + ); }; export default UserDashBoard;