Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ui.inlineCreate for relationships submitting the parent form of nested relationship fields #8914

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-inline-create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Fix ui.inlineCreate: { ... } for relationships submitting the parent form of nested relationship fields
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsxRuntime classic */
/** @jsx jsx */

import { type FormEvent, useState } from 'react'
import { useState } from 'react'
import { jsx, Stack } from '@keystone-ui/core'
import isDeepEqual from 'fast-deep-equal'
import { useToasts } from '@keystone-ui/toast'
Expand Down Expand Up @@ -53,11 +53,9 @@ export function InlineCreate ({
})

const invalidFields = useInvalidFields(fields, value)

const [forceValidation, setForceValidation] = useState(false)

const onSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault()
const onSubmit = () => {
const newForceValidation = invalidFields.size !== 0
setForceValidation(newForceValidation)

Expand Down Expand Up @@ -106,7 +104,7 @@ export function InlineCreate ({
}

return (
<form onSubmit={onSubmit}>
<section>
<Stack gap="xlarge">
{error && (
<GraphQLErrorNotice networkError={error?.networkError} errors={error?.graphQLErrors} />
Expand All @@ -119,14 +117,14 @@ export function InlineCreate ({
value={value}
/>
<Stack gap="small" across>
<Button isLoading={loading} size="small" tone="positive" weight="bold" type="submit">
<Button onClick={onSubmit} isLoading={loading} size="small" tone="positive" weight="bold">
Create {list.singular}
</Button>
<Button size="small" weight="none" onClick={onCancel}>
Cancel
</Button>
</Stack>
</Stack>
</form>
</section>
)
}