Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 27x |
import { useMutation, useQueryClient } from 'react-query';
import { useOkapiKy } from '@folio/stripes/core';
import { modConfigEntriesQueryKey } from '../utils';
import { MOD_SETTINGS_ENDPOINT } from '../constants/endpoints';
// This will simply take in some information and decide whether to mutate via POST or via PUT
// DEPRECATED -- As far as I can see this is now unused anyway
// KInt modules are swapping to AppSettings instead of mod-settings, so no centralised components should be needed
const useMutateModConfigEntry = ({
configName,
moduleName,
id
}) => {
// eslint-disable-next-line no-console
console.warn('useMutateModConfigEntry is deprecated, as it utilises mod-config');
const ky = useOkapiKy();
const queryClient = useQueryClient();
const baseNamespace = modConfigEntriesQueryKey({
configName,
moduleName
});
const putQueryObject = useMutation(
[...baseNamespace, 'putConfigEntry', id],
async (data) => ky.put(
`${MOD_SETTINGS_ENDPOINT}/${id}`,
{ json: data }
).json()
.then(() => {
queryClient.invalidateQueries(baseNamespace);
})
);
const postQueryObject = useMutation(
[...baseNamespace, 'postConfigEntry'],
async (data) => ky.post(
`${MOD_SETTINGS_ENDPOINT}`,
{ json: data }
).json()
.then(() => {
queryClient.invalidateQueries(baseNamespace);
})
);
if (id) {
return putQueryObject;
}
return postQueryObject;
};
export default useMutateModConfigEntry;
|