@postxl/generator 0.25.1 → 0.27.0
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.
|
@@ -48,12 +48,35 @@ type CreateInputData = {
|
|
|
48
48
|
* A modal component that lets the user create a new ${meta.userFriendlyName} instance.
|
|
49
49
|
*/
|
|
50
50
|
export const ${modals.createComponentName} = ({ show, onHide }: { show: boolean; onHide: () => void }) => {
|
|
51
|
+
const Typed = React.useMemo(
|
|
52
|
+
() => createTypedForm<CreateInputData>().with({ ${(() => {
|
|
53
|
+
const components = new Set();
|
|
54
|
+
for (const field of fields.values()) {
|
|
55
|
+
switch (field.kind) {
|
|
56
|
+
case 'enum': {
|
|
57
|
+
const enumMeta = (0, meta_1.getEnumMetadata)({ enumerator: field.enumerator });
|
|
58
|
+
components.add(enumMeta.react.selectFieldName);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case 'relation': {
|
|
62
|
+
const refMeta = (0, meta_1.getModelMetadata)({ model: field.relationToModel });
|
|
63
|
+
components.add(refMeta.react.components.forms.searchFieldName);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
default:
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return [...components].join(', ');
|
|
71
|
+
})()} }),
|
|
72
|
+
[]
|
|
73
|
+
)
|
|
51
74
|
const cache = trpc.useContext()
|
|
52
75
|
const mutation = trpc.${trpc.create.reactQueryMethod}.useMutation()
|
|
53
76
|
|
|
54
77
|
return (
|
|
55
78
|
<ModalWithNavigationContainer label="Create new ${meta.userFriendlyName}" show={show} onHide={onHide} fixed wide>
|
|
56
|
-
<Formik
|
|
79
|
+
<Typed.Formik
|
|
57
80
|
initialValues={{
|
|
58
81
|
${fields
|
|
59
82
|
.filter((f) => f.kind !== 'id')
|
|
@@ -109,7 +132,7 @@ export const ${modals.createComponentName} = ({ show, onHide }: { show: boolean;
|
|
|
109
132
|
${getFormFieldComponents({ model })}
|
|
110
133
|
</ModalWithActions>
|
|
111
134
|
)}
|
|
112
|
-
</Formik>
|
|
135
|
+
</Typed.Formik>
|
|
113
136
|
</ModalWithNavigationContainer>
|
|
114
137
|
)
|
|
115
138
|
}
|
|
@@ -141,12 +164,35 @@ export const ${components.modals.editComponentName} = ({
|
|
|
141
164
|
show,
|
|
142
165
|
onHide
|
|
143
166
|
}: { data: ${model.typeName}; show: boolean; onHide: () => void }) => {
|
|
167
|
+
const Typed = React.useMemo(
|
|
168
|
+
() => createTypedForm<EditInputData>().with({ ${(() => {
|
|
169
|
+
const components = new Set();
|
|
170
|
+
for (const field of fields.values()) {
|
|
171
|
+
switch (field.kind) {
|
|
172
|
+
case 'enum': {
|
|
173
|
+
const enumMeta = (0, meta_1.getEnumMetadata)({ enumerator: field.enumerator });
|
|
174
|
+
components.add(enumMeta.react.selectFieldName);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case 'relation': {
|
|
178
|
+
const refMeta = (0, meta_1.getModelMetadata)({ model: field.relationToModel });
|
|
179
|
+
components.add(refMeta.react.components.forms.searchFieldName);
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
default:
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return [...components].join(', ');
|
|
187
|
+
})()} }),
|
|
188
|
+
[]
|
|
189
|
+
)
|
|
144
190
|
const cache = trpc.useContext()
|
|
145
191
|
const mutation = trpc.${trpc.update.reactQueryMethod}.useMutation()
|
|
146
192
|
|
|
147
193
|
return (
|
|
148
194
|
<ModalWithNavigationContainer label="Edit ${meta.userFriendlyName}" show={show} onHide={onHide} fixed wide>
|
|
149
|
-
<Formik
|
|
195
|
+
<Typed.Formik
|
|
150
196
|
initialValues={{
|
|
151
197
|
${fields
|
|
152
198
|
.map((field) => {
|
|
@@ -213,7 +259,7 @@ export const ${components.modals.editComponentName} = ({
|
|
|
213
259
|
${getFormFieldComponents({ model })}
|
|
214
260
|
</ModalWithActions>
|
|
215
261
|
)}
|
|
216
|
-
</Formik>
|
|
262
|
+
</Typed.Formik>
|
|
217
263
|
</ModalWithNavigationContainer>
|
|
218
264
|
)
|
|
219
265
|
}
|
|
@@ -323,13 +369,10 @@ function getFormImports({ model, meta }) {
|
|
|
323
369
|
return `
|
|
324
370
|
import React from 'react'
|
|
325
371
|
import { toast } from 'react-hot-toast'
|
|
326
|
-
import {
|
|
372
|
+
import { FormikErrors } from 'formik'
|
|
327
373
|
|
|
328
|
-
import {
|
|
374
|
+
import { createTypedForm } from '@components/atoms/Form'
|
|
329
375
|
import { ConfirmButton, ModalWithNavigationContainer, Label, ModalWithActions } from '@components/atoms/Modal'
|
|
330
|
-
import { TextAreaField } from '@components/atoms/TextAreaInput'
|
|
331
|
-
import { TextField } from '@components/atoms/TextInput'
|
|
332
|
-
import { NumberField } from '@components/atoms/NumberInput'
|
|
333
376
|
|
|
334
377
|
import { trpc } from '@lib/trpc'
|
|
335
378
|
|
|
@@ -491,7 +534,7 @@ function getFormFieldComponents({ model }) {
|
|
|
491
534
|
form.append(`
|
|
492
535
|
<div>
|
|
493
536
|
<Label>${label}</Label>
|
|
494
|
-
<TextField placeholder="Type..." name="${formikFieldName}" />
|
|
537
|
+
<Typed.TextField placeholder="Type..." name="${formikFieldName}" />
|
|
495
538
|
</div>
|
|
496
539
|
`);
|
|
497
540
|
break scalar;
|
|
@@ -504,7 +547,7 @@ function getFormFieldComponents({ model }) {
|
|
|
504
547
|
form.append(`
|
|
505
548
|
<div>
|
|
506
549
|
<Label>${label}</Label>
|
|
507
|
-
<NumberField placeholder="2511" name="${formikFieldName}" decimals={${decimals}}/>
|
|
550
|
+
<Typed.NumberField placeholder="2511" name="${formikFieldName}" decimals={${decimals}}/>
|
|
508
551
|
</div>
|
|
509
552
|
`);
|
|
510
553
|
break scalar;
|
|
@@ -513,7 +556,7 @@ function getFormFieldComponents({ model }) {
|
|
|
513
556
|
form.append(`
|
|
514
557
|
<div>
|
|
515
558
|
<Label>Is ${label}</Label>
|
|
516
|
-
<CheckBoxField label="${label}" name="${formikFieldName}" />
|
|
559
|
+
<Typed.CheckBoxField label="${label}" name="${formikFieldName}" />
|
|
517
560
|
</div>
|
|
518
561
|
`);
|
|
519
562
|
break scalar;
|
|
@@ -534,7 +577,7 @@ function getFormFieldComponents({ model }) {
|
|
|
534
577
|
form.append(`
|
|
535
578
|
<div>
|
|
536
579
|
<Label>${refMeta.userFriendlyName}</Label>
|
|
537
|
-
|
|
580
|
+
<Typed.${refMeta.react.components.forms.searchFieldName} name="${formikFieldName}" placeholder="Search..." />
|
|
538
581
|
</div>
|
|
539
582
|
`);
|
|
540
583
|
break;
|
|
@@ -544,7 +587,7 @@ function getFormFieldComponents({ model }) {
|
|
|
544
587
|
form.append(`
|
|
545
588
|
<div>
|
|
546
589
|
<Label>${label}</Label>
|
|
547
|
-
|
|
590
|
+
<Typed.${enumMeta.react.selectFieldName} name="${formikFieldName}" placeholder="Search..." />
|
|
548
591
|
</div>
|
|
549
592
|
`);
|
|
550
593
|
break;
|