diff --git a/src/components/Resources/Schema/SchemasList.tsx b/src/components/Resources/Schema/SchemasList.tsx index 782d3228d..e93de74fc 100644 --- a/src/components/Resources/Schema/SchemasList.tsx +++ b/src/components/Resources/Schema/SchemasList.tsx @@ -1,6 +1,6 @@ 'use client'; -import { Button, Card, Pagination, Spinner, Table, } from 'flowbite-react'; +import { Alert, Button, Card, Pagination, Spinner, Table, } from 'flowbite-react'; import { ChangeEvent, useEffect, useState } from 'react'; import type { GetAllSchemaListParameter, PaginationData } from './interfaces'; import { apiStatusCodes, storageKeys } from '../../../config/CommonConstant'; @@ -11,9 +11,11 @@ import SearchInput from '../../SearchInput'; import { getAllSchemas } from '../../../api/Schema'; import { getFromLocalStorage } from '../../../api/Auth'; import { pathRoutes } from '../../../config/pathRoutes'; +import { EmptyListMessage } from '../../EmptyListComponent'; const SchemaList = (props: { schemaSelectionCallback: (schemaId: string) => void; }) => { const [schemaList, setSchemaList] = useState([]) + const [schemaListErr, setSchemaListErr] = useState('') const [loading, setLoading] = useState(true) const [orgId, setOrgId] = useState('') const [schemaListAPIParameter, setSchemaListAPIParameter] = useState({ @@ -25,24 +27,41 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string) => void }) const getSchemaList = async (schemaListAPIParameter: GetAllSchemaListParameter) => { - const organizationId = await getFromLocalStorage(storageKeys.ORG_ID) - setOrgId(organizationId) - setLoading(true) - - const schemaList = await getAllSchemas(schemaListAPIParameter, organizationId); - const { data } = schemaList as AxiosResponse - - if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { - if (data?.data?.data) { - setSchemaList(data?.data?.data) - setLoading(false) + try { + const organizationId = await getFromLocalStorage(storageKeys.ORG_ID); + setOrgId(organizationId); + setLoading(true); + + const schemaList = await getAllSchemas(schemaListAPIParameter, organizationId); + const { data } = schemaList as AxiosResponse; + if (schemaList === 'Schema records not found') { + setLoading(false); + setSchemaList([]); + } + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + if (data?.data?.data?.length === 0) { + setSchemaListErr('No Data Found'); + } + if (data?.data?.data) { + setSchemaList(data?.data?.data); + setLoading(false); + } else { + setLoading(false); + setSchemaListErr(schemaList as string) + } } else { - setLoading(false) + setLoading(false); + setSchemaListErr(schemaList as string) } - } else { - setLoading(false) + setTimeout(() => { + setSchemaListErr('') + }, 3000) + } catch (error) { + console.error('Error while fetching schema list:', error); + setLoading(false); + } - } + }; useEffect(() => { @@ -84,8 +103,8 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string) => void
-
-
+
+
@@ -100,37 +119,61 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string) => void Create Schema
+ { + schemaListErr && + setSchemaListErr(null)} + > + +

+ {schemaListErr} +

+
+
+ } {loading - ?
+ ? (
-
+
) : -
-
- {schemaList && schemaList.length > 0 && - schemaList.map((element, key) => ( -
- -
- ))} -
-
- - { - setSchemaListAPIParameter(prevState => ({ - ...prevState, - page: page - })); - }} - totalPages={0} - /> -
-
+ schemaList && schemaList.length > 0 ? ( +
+
+ {schemaList && schemaList.length > 0 && + schemaList.map((element, key) => ( +
+ +
+ ))} +
+
+ + { + setSchemaListAPIParameter(prevState => ({ + ...prevState, + page: page + })); + }} + totalPages={0} + /> +
+
) : ( + + } + onClick={()=>{ + window.location.href = `${pathRoutes.organizations.createSchema}?OrgId=${orgId}` + }} + />) }