more alova ports

This commit is contained in:
Proddy
2023-06-17 13:06:31 +02:00
parent 2ae45ecd6e
commit ed55a96b80
31 changed files with 868 additions and 931 deletions

View File

@@ -1,30 +1,14 @@
import { useCallback, useEffect, useState } from 'react';
import { useRequest } from 'alova';
import { FeaturesContext } from '.';
import type { FC } from 'react';
import type { Features } from 'types';
import type { RequiredChildrenProps } from 'utils';
import * as FeaturesApi from 'api/features';
import { ApplicationError, LoadingSpinner } from 'components';
import { extractErrorMessage } from 'utils';
const FeaturesLoader: FC<RequiredChildrenProps> = (props) => {
const [errorMessage, setErrorMessage] = useState<string>();
const [features, setFeatures] = useState<Features>();
const loadFeatures = useCallback(async () => {
try {
const response = await FeaturesApi.readFeatures();
setFeatures(response.data);
} catch (error) {
setErrorMessage(extractErrorMessage(error, 'Failed to fetch application details.'));
}
}, []);
useEffect(() => {
void loadFeatures();
}, [loadFeatures]);
const { data: features, error } = useRequest(FeaturesApi.readFeatures);
if (features) {
return (
@@ -38,8 +22,8 @@ const FeaturesLoader: FC<RequiredChildrenProps> = (props) => {
);
}
if (errorMessage) {
return <ApplicationError message={errorMessage} />;
if (error) {
return <ApplicationError message={error?.message} />;
}
return <LoadingSpinner height="100vh" />;