File size: 881 Bytes
1e92f2d |
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 |
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useCallback } from 'react';
import wp from 'calypso/lib/wp';
function useRemoveFollowerMutation() {
const queryClient = useQueryClient();
const mutation = useMutation( {
mutationFn: ( { siteId, type, followerId } ) => {
const typeSlug = type === 'email' ? 'email-followers' : 'followers';
return wp.req.post( `/sites/${ siteId }/${ typeSlug }/${ followerId }/delete` );
},
onSuccess( data, variables ) {
const { siteId, type } = variables;
queryClient.invalidateQueries( {
queryKey: [ 'followers', siteId, type ],
} );
},
} );
const { mutate } = mutation;
const removeFollower = useCallback(
( siteId, type, followerId ) => mutate( { siteId, type, followerId } ),
[ mutate ]
);
return { removeFollower, ...mutation };
}
export default useRemoveFollowerMutation;
|