mirror of
https://github.com/strapi/strapi.git
synced 2025-11-07 05:38:13 +00:00
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
import { useQuery, useMutation, useQueryClient } from 'react-query';
|
|
import { useNotification } from '@strapi/helper-plugin';
|
|
import { fetchData, deleteDoc, regenerateDoc, submit } from './utils/api';
|
|
import getTrad from '../../utils/getTrad';
|
|
|
|
const useHomePage = () => {
|
|
const queryClient = useQueryClient();
|
|
const toggleNotification = useNotification();
|
|
const { isLoading, data } = useQuery('get-documentation', () => fetchData(toggleNotification));
|
|
|
|
const handleError = err => {
|
|
toggleNotification({
|
|
type: 'warning',
|
|
message: err.response.payload.message,
|
|
});
|
|
};
|
|
|
|
const deleteMutation = useMutation(deleteDoc, {
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries('get-documentation');
|
|
toggleNotification({
|
|
type: 'info',
|
|
message: { id: getTrad('notification.delete.success') },
|
|
});
|
|
},
|
|
onError: handleError,
|
|
});
|
|
|
|
const submitMutation = useMutation(submit, {
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries('get-documentation');
|
|
|
|
toggleNotification({
|
|
type: 'success',
|
|
message: { id: getTrad('notification.update.success') },
|
|
});
|
|
},
|
|
onError: handleError,
|
|
});
|
|
|
|
const regenerateDocMutation = useMutation(regenerateDoc, {
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries('get-documentation');
|
|
|
|
toggleNotification({
|
|
type: 'info',
|
|
message: { id: getTrad('notification.generate.success') },
|
|
});
|
|
},
|
|
onError: handleError,
|
|
});
|
|
|
|
return { data, isLoading, deleteMutation, submitMutation, regenerateDocMutation };
|
|
};
|
|
|
|
export default useHomePage;
|