mirror of
https://github.com/supabase/supabase.git
synced 2026-09-06 09:59:03 +08:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Minor remove any to fix ratchet baseline rules <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved error handling when making a report snippet public, so error messages are only shown when a valid error message is available. * Reduced the chance of unexpected failures from non-standard error values during this action. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
86 lines
2.6 KiB
TypeScript
86 lines
2.6 KiB
TypeScript
import { Eye, Unlock } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
|
|
import { getContentById } from '@/data/content/content-id-query'
|
|
import { useContentUpsertMutation } from '@/data/content/content-upsert-mutation'
|
|
|
|
type ReportSnippet = { id: string; name: string }
|
|
|
|
export const MakeReportSnippetPublicModal = ({
|
|
projectRef,
|
|
snippet,
|
|
onCancel,
|
|
onConfirm,
|
|
}: {
|
|
projectRef?: string
|
|
snippet?: ReportSnippet
|
|
onCancel: () => void
|
|
onConfirm: (snippet: ReportSnippet) => void
|
|
}) => {
|
|
const [isPreparing, setIsPreparing] = useState(false)
|
|
|
|
const { mutate: upsertContent, isPending: isUpserting } = useContentUpsertMutation({
|
|
onError: (error) => {
|
|
toast.error(`Failed to share snippet: ${error.message}`)
|
|
},
|
|
})
|
|
|
|
const onMakePublic = async () => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
if (!snippet) return console.error('Snippet is required')
|
|
|
|
setIsPreparing(true)
|
|
try {
|
|
const item = await getContentById({ projectRef, id: snippet.id })
|
|
upsertContent(
|
|
{
|
|
projectRef,
|
|
payload: { ...item, visibility: 'project', folder_id: null },
|
|
},
|
|
{
|
|
onSuccess: () => {
|
|
toast.success('Snippet is now shared to the project')
|
|
onConfirm(snippet)
|
|
},
|
|
}
|
|
)
|
|
} catch (error: unknown) {
|
|
if (error instanceof Error) {
|
|
toast.error(`Failed to share snippet: ${error.message}`)
|
|
}
|
|
} finally {
|
|
setIsPreparing(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<ConfirmationModal
|
|
size="medium"
|
|
loading={isPreparing || isUpserting}
|
|
title={`Share snippet with the team: ${snippet?.name}`}
|
|
confirmLabel="Share and add to report"
|
|
confirmLabelLoading="Sharing snippet"
|
|
visible={snippet !== undefined}
|
|
onCancel={onCancel}
|
|
onConfirm={onMakePublic}
|
|
alert={{
|
|
title: 'This snippet will become visible to all project members',
|
|
description: 'Snippets added to the report must be shared so the team can view them',
|
|
}}
|
|
>
|
|
<ul className="text-sm text-foreground-light space-y-5">
|
|
<li className="flex gap-3 items-center">
|
|
<Eye size={16} />
|
|
<span>Project members will have read-only access to this snippet.</span>
|
|
</li>
|
|
<li className="flex gap-3 items-center">
|
|
<Unlock size={16} />
|
|
<span>Project members can duplicate it to their personal snippets.</span>
|
|
</li>
|
|
</ul>
|
|
</ConfirmationModal>
|
|
)
|
|
}
|