Files
supabase/apps/studio/data/storage/bucket-object-delete-mutation.ts
Joshen Lim 7f5865872a Enforce noUnusedLocals and noUnusedParameters in tsconfig.json + fix all related issues (#45264)
## Context

Enforce `noUnusedLocals` and `noUnusedParameters` in tsconfig.json + fix
all related issues
2026-04-27 17:42:34 +08:00

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,
})
}