diff --git a/src/components/ConnectionsList/index.tsx b/src/components/ConnectionsList/index.tsx index da6c8b87f..f0e1b2d6b 100644 --- a/src/components/ConnectionsList/index.tsx +++ b/src/components/ConnectionsList/index.tsx @@ -1,60 +1,74 @@ '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 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([]) - const [loading, setLoading] = useState(false) - const [error, setError] = useState(null) + const [connectionList, setConnectionList] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); useEffect(() => { - getConnections() - }, []) + getConnections(); + }, []); const getConnections = async () => { - setLoading(true) + setLoading(true); const response = await getConnectionsByOrg(); - const { data } = response as AxiosResponse + 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: {dateConversion(createdOn)} }, - ] - } - }) - setConnectionList(connections) + 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: ( + + {' '} + {dateConversion(createdOn)}{' '} + + ), + }, + ], + }; + }, + ); + setConnectionList(connections); } else { - setError(response as string) + setError(response as string); } - setLoading(false) - } + setLoading(false); + }; const header = [ { columnName: 'User' }, { columnName: 'Connection ID' }, - { columnName: 'Created on' } - ] + { columnName: 'Created on' }, + ]; return ( -
- -
+
+ +

Connections

@@ -63,15 +77,35 @@ const ConnectionList = () => { message={error} type={'failure'} onAlertClose={() => { - setError(null) + setError(null); }} /> -
- -
+ + {loading ? ( +
+ +
+ ) : connectionList && connectionList?.length > 0 ? ( +
+ +
+ ) : ( +
+ +
+ )}
- ) -} + ); +}; -export default ConnectionList +export default ConnectionList;