mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
* chore: paginate user content * progress * loading states * add load more buttons to private snippets * working pagination * fix some types * always show snippet counts * support new api parameters * favorite snippets * progress * searching * paginate root folder * fix renaming snippets * fix ts * removed unused prop * Shift sharing/unsharing query logic outside of valtio to leverage on RQ only * Fix invalidation on an unsaved snippet * Clean up * Fix * Clean up * Update API type * Update API * fix duplicate snippets error after moving a snippet * add currently selected snippet * Fix unsharing a snippet that has yet to be opened * i'm dumb * fix sharing a snippet * fix sharing and unsharing * show favorite or shared snippet in list even if it's in another page * Fix wrong import for debounce * Fix false positive toast error when creating custom report * Update API type * Change create new snippet CTA to link back to /new with skip flag * Fix saving logs explorer query * Bump page number --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
111 lines
3.0 KiB
TypeScript
111 lines
3.0 KiB
TypeScript
import { useRouter } from 'next/router'
|
|
import { toast } from 'sonner'
|
|
|
|
import { useContentInsertMutation } from 'data/content/content-insert-mutation'
|
|
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
|
|
import { uuidv4 } from 'lib/helpers'
|
|
import { Button, Form, Input, Modal } from 'ui'
|
|
|
|
type CustomReport = { name: string; description?: string }
|
|
export interface CreateReportModal {
|
|
visible: boolean
|
|
onCancel: () => void
|
|
afterSubmit: () => void
|
|
}
|
|
|
|
export const CreateReportModal = ({ visible, onCancel, afterSubmit }: CreateReportModal) => {
|
|
const router = useRouter()
|
|
const project = useSelectedProject()
|
|
const ref = project?.ref ?? 'default'
|
|
|
|
const { mutate: insertReport, isLoading: isCreating } = useContentInsertMutation({
|
|
onSuccess: (data) => {
|
|
toast.success('Successfully created new report')
|
|
const newReportId = data.id
|
|
router.push(`/project/${ref}/reports/${newReportId}`)
|
|
afterSubmit()
|
|
},
|
|
onError: (error) => {
|
|
toast.error(`Failed to create report: ${error.message}`)
|
|
},
|
|
})
|
|
|
|
async function createCustomReport({ name, description }: { name: string; description?: string }) {
|
|
if (!ref) return
|
|
|
|
insertReport({
|
|
projectRef: ref,
|
|
payload: {
|
|
id: uuidv4(),
|
|
type: 'report',
|
|
name,
|
|
description: description || '',
|
|
visibility: 'project',
|
|
content: {
|
|
schema_version: 1,
|
|
period_start: {
|
|
time_period: '7d',
|
|
date: '',
|
|
},
|
|
period_end: {
|
|
time_period: 'today',
|
|
date: '',
|
|
},
|
|
interval: '1d',
|
|
layout: [],
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
return (
|
|
<Modal
|
|
visible={visible}
|
|
onCancel={onCancel}
|
|
hideFooter
|
|
header="Create a custom report"
|
|
size="small"
|
|
>
|
|
<Form
|
|
onReset={onCancel}
|
|
validateOnBlur
|
|
initialValues={{ name: '', description: '' }}
|
|
validate={(vals) => {
|
|
const errors: Partial<CustomReport> = {}
|
|
|
|
if (!vals.name) {
|
|
errors.name = 'Required'
|
|
}
|
|
|
|
return errors
|
|
}}
|
|
onSubmit={(newVals) => createCustomReport(newVals)}
|
|
>
|
|
{() => (
|
|
<>
|
|
<Modal.Content className="space-y-4">
|
|
<Input label="Name" id="name" name="name" />
|
|
<Input.TextArea
|
|
label="Description"
|
|
id="description"
|
|
placeholder="Describe your custom report"
|
|
size="medium"
|
|
textAreaClassName="resize-none"
|
|
/>
|
|
</Modal.Content>
|
|
<Modal.Separator />
|
|
<Modal.Content className="flex items-center justify-end gap-2">
|
|
<Button htmlType="reset" type="default" onClick={onCancel} disabled={isCreating}>
|
|
Cancel
|
|
</Button>
|
|
<Button htmlType="submit" loading={isCreating} disabled={isCreating}>
|
|
Create report
|
|
</Button>
|
|
</Modal.Content>
|
|
</>
|
|
)}
|
|
</Form>
|
|
</Modal>
|
|
)
|
|
}
|