mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-01 10:52:02 +08:00
fix: onApply data is updated (#1655)
This commit is contained in:
parent
4c0d573760
commit
d5bd991417
@ -1,15 +1,30 @@
|
|||||||
import { Button, Input, notification } from 'antd';
|
import { Button, Input, notification } from 'antd';
|
||||||
import FormItem from 'antd/lib/form/FormItem';
|
import FormItem from 'antd/lib/form/FormItem';
|
||||||
|
import getFeaturesFlags from 'api/features/getFeatureFlags';
|
||||||
import apply from 'api/licenses/apply';
|
import apply from 'api/licenses/apply';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { QueryObserverResult, RefetchOptions, useQuery } from 'react-query';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { Dispatch } from 'redux';
|
||||||
|
import { AppAction, UPDATE_FEATURE_FLAGS } from 'types/actions/app';
|
||||||
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
||||||
|
import { PayloadProps } from 'types/api/licenses/getAll';
|
||||||
|
|
||||||
import { ApplyForm, ApplyFormContainer, LicenseInput } from './applyFormStyles';
|
import { ApplyForm, ApplyFormContainer, LicenseInput } from './styles';
|
||||||
|
|
||||||
function ApplyLicenseForm(): JSX.Element {
|
function ApplyLicenseForm({
|
||||||
|
licenseRefetch,
|
||||||
|
}: ApplyLicenseFormProps): JSX.Element {
|
||||||
const { t } = useTranslation(['licenses']);
|
const { t } = useTranslation(['licenses']);
|
||||||
const [key, setKey] = useState('');
|
const [key, setKey] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const dispatch = useDispatch<Dispatch<AppAction>>();
|
||||||
|
const { refetch } = useQuery({
|
||||||
|
queryFn: getFeaturesFlags,
|
||||||
|
queryKey: 'getFeatureFlags',
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
const onFinish = async (values: unknown | { key: string }): Promise<void> => {
|
const onFinish = async (values: unknown | { key: string }): Promise<void> => {
|
||||||
const params = values as { key: string };
|
const params = values as { key: string };
|
||||||
@ -28,6 +43,16 @@ function ApplyLicenseForm(): JSX.Element {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.statusCode === 200) {
|
if (response.statusCode === 200) {
|
||||||
|
const [featureFlagsResponse] = await Promise.all([
|
||||||
|
refetch(),
|
||||||
|
licenseRefetch(),
|
||||||
|
]);
|
||||||
|
if (featureFlagsResponse.data?.payload) {
|
||||||
|
dispatch({
|
||||||
|
type: UPDATE_FEATURE_FLAGS,
|
||||||
|
payload: featureFlagsResponse.data.payload,
|
||||||
|
});
|
||||||
|
}
|
||||||
notification.success({
|
notification.success({
|
||||||
message: 'Success',
|
message: 'Success',
|
||||||
description: t('license_applied'),
|
description: t('license_applied'),
|
||||||
@ -74,4 +99,12 @@ function ApplyLicenseForm(): JSX.Element {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ApplyLicenseFormProps {
|
||||||
|
licenseRefetch: (
|
||||||
|
options?: RefetchOptions,
|
||||||
|
) => Promise<
|
||||||
|
QueryObserverResult<SuccessResponse<PayloadProps> | ErrorResponse, unknown>
|
||||||
|
>;
|
||||||
|
}
|
||||||
|
|
||||||
export default ApplyLicenseForm;
|
export default ApplyLicenseForm;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable react/display-name */
|
|
||||||
import { Table } from 'antd';
|
import { Table } from 'antd';
|
||||||
import { ColumnsType } from 'antd/lib/table';
|
import { ColumnsType } from 'antd/lib/table';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { Tabs, Typography } from 'antd';
|
import { Tabs, Typography } from 'antd';
|
||||||
import getAll from 'api/licenses/getAll';
|
import getAll from 'api/licenses/getAll';
|
||||||
import Spinner from 'components/Spinner';
|
import Spinner from 'components/Spinner';
|
||||||
import useFetch from 'hooks/useFetch';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useQuery } from 'react-query';
|
||||||
|
|
||||||
import ApplyLicenseForm from './ApplyLicenseForm';
|
import ApplyLicenseForm from './ApplyLicenseForm';
|
||||||
import ListLicenses from './ListLicenses';
|
import ListLicenses from './ListLicenses';
|
||||||
@ -12,29 +12,31 @@ const { TabPane } = Tabs;
|
|||||||
|
|
||||||
function Licenses(): JSX.Element {
|
function Licenses(): JSX.Element {
|
||||||
const { t } = useTranslation(['licenses']);
|
const { t } = useTranslation(['licenses']);
|
||||||
const { loading, payload, error, errorMessage } = useFetch(getAll);
|
const { data, isError, isLoading, refetch } = useQuery({
|
||||||
|
queryFn: getAll,
|
||||||
|
queryKey: 'getAllLicenses',
|
||||||
|
});
|
||||||
|
|
||||||
if (error) {
|
if (isError || data?.error) {
|
||||||
return <Typography>{errorMessage}</Typography>;
|
return <Typography>{data?.error}</Typography>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading || payload === undefined) {
|
if (isLoading || data?.payload === undefined) {
|
||||||
return <Spinner tip={t('loading_licenses')} height="90vh" />;
|
return <Spinner tip={t('loading_licenses')} height="90vh" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const allValidLicense =
|
||||||
|
data?.payload?.filter((license) => license.isCurrent) || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs destroyInactiveTabPane defaultActiveKey="licenses">
|
<Tabs destroyInactiveTabPane defaultActiveKey="licenses">
|
||||||
<TabPane tabKey="licenses" tab={t('tab_current_license')} key="licenses">
|
<TabPane tabKey="licenses" tab={t('tab_current_license')} key="licenses">
|
||||||
<ApplyLicenseForm />
|
<ApplyLicenseForm licenseRefetch={refetch} />
|
||||||
<ListLicenses
|
<ListLicenses licenses={allValidLicense} />
|
||||||
licenses={payload ? payload.filter((l) => l.isCurrent === true) : []}
|
|
||||||
/>
|
|
||||||
</TabPane>
|
</TabPane>
|
||||||
|
|
||||||
<TabPane tabKey="history" tab={t('tab_license_history')} key="history">
|
<TabPane tabKey="history" tab={t('tab_license_history')} key="history">
|
||||||
<ListLicenses
|
<ListLicenses licenses={allValidLicense} />
|
||||||
licenses={payload ? payload.filter((l) => l.isCurrent === false) : []}
|
|
||||||
/>
|
|
||||||
</TabPane>
|
</TabPane>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user