Pass config request through to subscription edit

This commit is contained in:
mabashian 2021-05-10 17:05:11 -04:00
parent 91134b2537
commit 0d17dfcd87
3 changed files with 8 additions and 23 deletions

View File

@ -22,13 +22,7 @@ export const useConfig = () => {
};
export const ConfigProvider = ({ children }) => {
const {
error: configError,
isLoading,
request,
result: config,
setValue: setConfig,
} = useRequest(
const { error: configError, isLoading, request, result: config } = useRequest(
useCallback(async () => {
const [
{ data },
@ -55,10 +49,10 @@ export const ConfigProvider = ({ children }) => {
}
}, [error]);
const value = useMemo(() => ({ ...config, isLoading, setConfig }), [
const value = useMemo(() => ({ ...config, request, isLoading }), [
config,
request,
isLoading,
setConfig,
]);
return (

View File

@ -12,7 +12,7 @@ import {
WizardContextConsumer,
WizardFooter,
} from '@patternfly/react-core';
import { ConfigAPI, SettingsAPI, MeAPI, RootAPI } from '../../../../api';
import { ConfigAPI, SettingsAPI, RootAPI } from '../../../../api';
import useRequest, { useDismissableError } from '../../../../util/useRequest';
import ContentLoading from '../../../../components/ContentLoading';
import ContentError from '../../../../components/ContentError';
@ -91,7 +91,7 @@ const CustomFooter = ({ isSubmitLoading }) => {
function SubscriptionEdit() {
const history = useHistory();
const { license_info, setConfig } = useConfig();
const { request: updateConfig, license_info } = useConfig();
const hasValidKey = Boolean(license_info?.valid_key);
const subscriptionMgmtRoute = useRouteMatch({
path: '/subscription_management',
@ -164,16 +164,7 @@ function SubscriptionEdit() {
}
}
const [
{ data },
{
data: {
results: [me],
},
},
] = await Promise.all([ConfigAPI.read(), MeAPI.read()]);
const newConfig = { ...data, me };
setConfig(newConfig);
await updateConfig();
return true;
}, []) // eslint-disable-line react-hooks/exhaustive-deps

View File

@ -52,7 +52,7 @@ const emptyConfig = {
license_info: {
valid_key: false,
},
setConfig: jest.fn(),
request: jest.fn(),
};
describe('<SubscriptionEdit />', () => {
@ -268,7 +268,7 @@ describe('<SubscriptionEdit />', () => {
context: {
config: {
mockConfig,
setConfig: jest.fn(),
request: jest.fn(),
},
me: {
is_superuser: true,