Added ability to delete reports.
This commit is contained in:
@@ -1,10 +1,23 @@
|
||||
import { useState } from 'react';
|
||||
import useApi from './useApi';
|
||||
|
||||
export function useReports(websiteId) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { data, error, isLoading } = useQuery(['reports'], () => get(`/reports`, { websiteId }));
|
||||
const [modified, setModified] = useState(Date.now());
|
||||
const { get, useQuery, del, useMutation } = useApi();
|
||||
const { mutate } = useMutation(reportId => del(`/reports/${reportId}`));
|
||||
const { data, error, isLoading } = useQuery(['reports:website', { websiteId, modified }], () =>
|
||||
get(`/reports`, { websiteId }),
|
||||
);
|
||||
|
||||
return { reports: data, error, isLoading };
|
||||
const deleteReport = id => {
|
||||
mutate(id, {
|
||||
onSuccess: () => {
|
||||
setModified(Date.now());
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return { reports: data, error, isLoading, deleteReport };
|
||||
}
|
||||
|
||||
export default useReports;
|
||||
|
||||
Reference in New Issue
Block a user