-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #388 from credebl/refactor-connection-list
Refactor connection list
- Loading branch information
Showing
4 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
'use client'; | ||
|
||
import type { AxiosResponse } from 'axios'; | ||
import { useEffect, useState } from 'react'; | ||
import { 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 BreadCrumbs from '../BreadCrumbs'; | ||
import CustomSpinner from '../CustomSpinner'; | ||
import { EmptyListMessage } from '../EmptyListComponent'; | ||
|
||
const ConnectionList = () => { | ||
const [connectionList, setConnectionList] = useState<TableData[]>([]); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
getConnections(); | ||
}, []); | ||
|
||
const getConnections = async () => { | ||
setLoading(true); | ||
const response = await getConnectionsByOrg(); | ||
const { data } = response as AxiosResponse; | ||
|
||
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { | ||
const connections = data?.data?.map( | ||
(ele: { theirLabel: string; id: string; createdAt: string }) => { | ||
const userName = ele?.theirLabel ? ele.theirLabel : 'Not available'; | ||
const connectionId = ele.id ? ele.id : 'Not available'; | ||
const createdOn = ele?.createdAt ? ele?.createdAt : 'Not available'; | ||
return { | ||
data: [ | ||
{ data: userName }, | ||
{ data: connectionId }, | ||
{ | ||
data: ( | ||
<DateTooltip date={createdOn} id="issuance_connection_list"> | ||
{' '} | ||
{dateConversion(createdOn)}{' '} | ||
</DateTooltip> | ||
), | ||
}, | ||
], | ||
}; | ||
}, | ||
); | ||
setConnectionList(connections); | ||
} else { | ||
setError(response as string); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
const header = [ | ||
{ columnName: 'User' }, | ||
{ columnName: 'Connection ID' }, | ||
{ columnName: 'Created on' }, | ||
]; | ||
|
||
return ( | ||
<div className="p-4" id="connection_list"> | ||
<BreadCrumbs /> | ||
<div | ||
className="flex items-center justify-between mb-4" | ||
id="connection-list" | ||
> | ||
<h1 className="ml-1 text-xl font-semibold text-gray-900 sm:text-2xl dark:text-white"> | ||
Connections | ||
</h1> | ||
</div> | ||
<AlertComponent | ||
message={error} | ||
type={'failure'} | ||
onAlertClose={() => { | ||
setError(null); | ||
}} | ||
/> | ||
|
||
{loading ? ( | ||
<div className="flex items-center justify-center mt-36 mb-4"> | ||
<CustomSpinner /> | ||
</div> | ||
) : connectionList && connectionList?.length > 0 ? ( | ||
<div | ||
id="issuance_datatable" | ||
className="p-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" | ||
> | ||
<DataTable | ||
header={header} | ||
data={connectionList} | ||
loading={loading} | ||
></DataTable> | ||
</div> | ||
) : ( | ||
<div className="bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800"> | ||
<EmptyListMessage | ||
message={'No Connections'} | ||
description={"You don't have any connection"} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ConnectionList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
import LayoutSidebar from "../app/LayoutSidebar.astro"; | ||
import ConnectionsList from "../components/ConnectionsList"; | ||
--- | ||
|
||
<LayoutSidebar> | ||
<ConnectionsList client:load /> | ||
</LayoutSidebar> |