mirror of
https://github.com/optim-enterprises-bv/OptimCloud-gw-ui.git
synced 2025-10-30 17:57:46 +00:00
[WIFI-11392] Refetch all endpoints on System page
Signed-off-by: Charles <charles.bourque96@gmail.com>
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ucentral-client",
|
"name": "ucentral-client",
|
||||||
"version": "2.8.0(2)",
|
"version": "2.8.0(3)",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ucentral-client",
|
"name": "ucentral-client",
|
||||||
"version": "2.8.0(2)",
|
"version": "2.8.0(3)",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@chakra-ui/icons": "^2.0.11",
|
"@chakra-ui/icons": "^2.0.11",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ucentral-client",
|
"name": "ucentral-client",
|
||||||
"version": "2.8.0(2)",
|
"version": "2.8.0(3)",
|
||||||
"description": "",
|
"description": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "index.tsx",
|
"main": "index.tsx",
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { useToast } from '@chakra-ui/react';
|
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { axiosGw, axiosProv, axiosSec } from 'constants/axiosInstances';
|
import { axiosGw, axiosProv, axiosSec } from 'constants/axiosInstances';
|
||||||
import { AxiosError } from 'models/Axios';
|
|
||||||
|
|
||||||
export type EndpointApiResponse = {
|
export type EndpointApiResponse = {
|
||||||
authenticationType: string;
|
authenticationType: string;
|
||||||
@@ -12,11 +9,8 @@ export type EndpointApiResponse = {
|
|||||||
vendor: string;
|
vendor: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetEndpoints = ({ onSuccess }: { onSuccess: (data: EndpointApiResponse[]) => void }) => {
|
export const useGetEndpoints = ({ onSuccess }: { onSuccess: (data: EndpointApiResponse[]) => void }) =>
|
||||||
const { t } = useTranslation();
|
useQuery(
|
||||||
const toast = useToast();
|
|
||||||
|
|
||||||
return useQuery(
|
|
||||||
['get-endpoints'],
|
['get-endpoints'],
|
||||||
() =>
|
() =>
|
||||||
axiosSec
|
axiosSec
|
||||||
@@ -26,21 +20,8 @@ export const useGetEndpoints = ({ onSuccess }: { onSuccess: (data: EndpointApiRe
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
onError: (e: AxiosError) => {
|
|
||||||
if (!toast.isActive('endpoints-fetching-error'))
|
|
||||||
toast({
|
|
||||||
id: 'user-fetching-error',
|
|
||||||
title: t('common.error'),
|
|
||||||
description: t('user.error_fetching', { e: e?.response?.data?.ErrorDescription }),
|
|
||||||
status: 'error',
|
|
||||||
duration: 5000,
|
|
||||||
isClosable: true,
|
|
||||||
position: 'top-right',
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
export const useGetGatewayUi = () =>
|
export const useGetGatewayUi = () =>
|
||||||
useQuery(['get-gw-ui'], () => axiosGw.get('system?command=info').then(({ data }) => data.UI), {
|
useQuery(['get-gw-ui'], () => axiosGw.get('system?command=info').then(({ data }) => data.UI), {
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Flex, SimpleGrid } from '@chakra-ui/react';
|
import { Flex, Heading, SimpleGrid, Spacer } from '@chakra-ui/react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import SystemTile from './SystemTile';
|
import SystemTile from './SystemTile';
|
||||||
|
import { RefreshButton } from 'components/Buttons/RefreshButton';
|
||||||
|
import { Card } from 'components/Containers/Card';
|
||||||
|
import { CardHeader } from 'components/Containers/Card/CardHeader';
|
||||||
import { axiosSec } from 'constants/axiosInstances';
|
import { axiosSec } from 'constants/axiosInstances';
|
||||||
import { useAuth } from 'contexts/AuthProvider';
|
import { useAuth } from 'contexts/AuthProvider';
|
||||||
import { useGetEndpoints } from 'hooks/Network/Endpoints';
|
import { useGetEndpoints } from 'hooks/Network/Endpoints';
|
||||||
|
|
||||||
const SystemPage = () => {
|
const SystemPage = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { token, isUserLoaded } = useAuth();
|
const { token, isUserLoaded } = useAuth();
|
||||||
const { data: endpoints } = useGetEndpoints({ onSuccess: () => {} });
|
const { data: endpoints, refetch, isFetching } = useGetEndpoints({ onSuccess: () => {} });
|
||||||
|
|
||||||
const endpointsList = React.useMemo(() => {
|
const endpointsList = React.useMemo(() => {
|
||||||
if (!endpoints || !token || !isUserLoaded) return null;
|
if (!endpoints || !token || !isUserLoaded) return null;
|
||||||
@@ -35,11 +40,19 @@ const SystemPage = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex flexDirection="column" pt="75px">
|
<Flex flexDirection="column" pt="75px">
|
||||||
|
<Card mb={4} py={2} px={4}>
|
||||||
|
<CardHeader>
|
||||||
|
<Heading size="md" my="auto">
|
||||||
|
{t('controller.firmware.endpoints')} ({endpoints?.length ?? 0})
|
||||||
|
</Heading>
|
||||||
|
<Spacer />
|
||||||
|
<RefreshButton onClick={refetch} isFetching={isFetching} />
|
||||||
|
</CardHeader>
|
||||||
|
</Card>
|
||||||
<SimpleGrid minChildWidth="500px" spacing="20px" mb={3}>
|
<SimpleGrid minChildWidth="500px" spacing="20px" mb={3}>
|
||||||
{endpointsList}
|
{endpointsList}
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SystemPage;
|
export default SystemPage;
|
||||||
|
|||||||
Reference in New Issue
Block a user