/** @jsxRuntime classic */ /** @jsx jsx */ import { jsx, Box } from '@keystone-ui/core' import { Drawer } from '@keystone-ui/modals' import { LoadingDots } from '@keystone-ui/loading' import { useKeystone, useList } from '../context' import { Fields } from '../utils/Fields' import { useCreateItem } from '../utils/useCreateItem' import { GraphQLErrorNotice } from './GraphQLErrorNotice' export function CreateItemDrawer ({ listKey, onClose, onCreate, }: { listKey: string onClose: () => void onCreate: (item: { id: string, label: string }) => void }) { const { createViewFieldModes } = useKeystone() const list = useList(listKey) const createItemState = useCreateItem(list) return ( { const item = await createItemState.create() if (item) { onCreate({ id: item.id, label: item.label || item.id }) } }, }, cancel: { label: 'Cancel', action: () => { if ( !createItemState.shouldPreventNavigation || window.confirm('There are unsaved changes, are you sure you want to exit?') ) { onClose() } }, }, }} > {createViewFieldModes.state === 'error' && ( )} {createViewFieldModes.state === 'loading' && } {createItemState.error && ( )} ) }