muffin-admin 3.7.0 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "3.7.0",
3
+ "version": "3.7.1",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
package/src/buildRA.tsx CHANGED
@@ -90,8 +90,6 @@ export function buildRAComponent(name, props) {
90
90
  delete props.required
91
91
  }
92
92
 
93
- props.fullWidth = props.fullWidth ?? true
94
-
95
93
  if (props.children) props.children = buildRA(props.children)[0]
96
94
 
97
95
  return <Item key={props.source} {...props} />
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  Button,
3
- Form,
3
+ FormGroupsProvider,
4
+ useAugmentedForm,
4
5
  useListContext,
5
6
  useRecordContext,
6
7
  useResourceContext,
7
8
  useTranslate,
8
9
  } from "react-admin"
10
+ import { FormProvider } from "react-hook-form"
9
11
 
10
12
  import { useState } from "react"
11
13
  import { buildRA } from "../buildRA"
@@ -56,29 +58,6 @@ export function BulkActionButton({ paths, confirm, ...props }: AdminAction) {
56
58
  return <ActionButtonBase {...props} onHandle={onHandle} isPending={isPending} />
57
59
  }
58
60
 
59
- export function CommonPayload({ active, onClose, onHandle, schema, title }) {
60
- const inputs = buildRA(schema)
61
- const translate = useTranslate()
62
- return (
63
- <AdminModal
64
- maxWidth="sm"
65
- open={active}
66
- onClose={onClose}
67
- title={translate(title, { _: title })}
68
- >
69
- <Form
70
- onSubmit={(data) => {
71
- onClose()
72
- onHandle(data)
73
- }}
74
- >
75
- {inputs}
76
- <PayloadButtons onClose={onClose} />
77
- </Form>
78
- </AdminModal>
79
- )
80
- }
81
-
82
61
  function ActionButtonBase({
83
62
  label,
84
63
  title,
@@ -122,3 +101,35 @@ function ActionButtonBase({
122
101
  </>
123
102
  )
124
103
  }
104
+
105
+ export function CommonPayload({ active, onClose, onHandle, schema, title }) {
106
+ schema[0][1] = { ...schema[0][1], autoFocus: true }
107
+ const inputs = buildRA(schema)
108
+ const translate = useTranslate()
109
+ const { form, formHandleSubmit } = useAugmentedForm({
110
+ onSubmit: (data) => {
111
+ onClose()
112
+ onHandle(data)
113
+ form.reset()
114
+ },
115
+ record: {},
116
+ })
117
+
118
+ return (
119
+ <AdminModal
120
+ maxWidth="sm"
121
+ open={active}
122
+ onClose={onClose}
123
+ title={translate(title, { _: title })}
124
+ >
125
+ <FormProvider {...form}>
126
+ <FormGroupsProvider>
127
+ <form onSubmit={formHandleSubmit}>
128
+ {inputs}
129
+ <PayloadButtons onClose={onClose} />
130
+ </form>
131
+ </FormGroupsProvider>
132
+ </FormProvider>
133
+ </AdminModal>
134
+ )
135
+ }