mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
## Context Enforce `noUnusedLocals` and `noUnusedParameters` in tsconfig.json + fix all related issues
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { useMutation } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { del, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
type DeleteBucketObjectParams = {
|
|
projectRef: string
|
|
bucketId?: string
|
|
paths: string[]
|
|
}
|
|
export const deleteBucketObject = async (
|
|
{ projectRef, bucketId, paths }: DeleteBucketObjectParams,
|
|
signal?: AbortSignal
|
|
) => {
|
|
if (!bucketId) throw new Error('bucketId is required')
|
|
|
|
const { data, error } = await del('/platform/storage/{ref}/buckets/{id}/objects', {
|
|
params: {
|
|
path: {
|
|
ref: projectRef,
|
|
id: bucketId,
|
|
},
|
|
},
|
|
body: {
|
|
paths,
|
|
},
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type BucketObjectDeleteData = Awaited<ReturnType<typeof deleteBucketObject>>
|
|
|
|
export const useBucketObjectDeleteMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<BucketObjectDeleteData, ResponseError, DeleteBucketObjectParams>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
return useMutation<BucketObjectDeleteData, ResponseError, DeleteBucketObjectParams>({
|
|
mutationFn: (vars) => deleteBucketObject(vars),
|
|
async onSuccess(data, variables, context) {
|
|
// [Joshen] TODO figure out what queries to invalidate
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to delete bucket object: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|