-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: switch to native @mantine/forms
- Loading branch information
Showing
15 changed files
with
439 additions
and
356 deletions.
There are no files selected for viewing
324 changes: 200 additions & 124 deletions
324
libs/tools/src/generators/web-crud/__snapshots__/web-crud-generator.spec.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 8 additions & 9 deletions
17
...rc/lib/web-crud/files/feature/lib/__actorFileName__-__modelFileName__.routes.tsx.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import { lazy } from 'react' | ||
import { useRoutes } from 'react-router-dom' | ||
import { <%= actor.className %><%= model.className %>DetailFeature } from './<%= actor.propertyName %>-<%= model.fileName %>-detail.feature' | ||
import { <%= actor.className %><%= model.className %>CreateFeature } from './<%= actor.propertyName %>-<%= model.fileName %>-create.feature' | ||
import { <%= actor.className %><%= model.className %>ListFeature } from './<%= actor.propertyName %>-<%= model.fileName %>-list.feature' | ||
|
||
const Create = lazy(() => import('./<%= actor.fileName %>-<%= model.fileName %>-create.feature')) | ||
const Detail = lazy(() => import('./<%= actor.fileName %>-<%= model.fileName %>-detail.feature')) | ||
const List = lazy(() => import('./<%= actor.fileName %>-<%= model.fileName %>-list.feature')) | ||
|
||
export default function <%= actor.className %><%= model.className %>Routes(<% if(ownerId && actor.className === 'Admin'){ %>{ <%= ownerId %> }: { <%= ownerId %>: string } <% } %>) { | ||
return useRoutes([ | ||
{ path: '', element: <<%= actor.className %><%= model.className %>ListFeature <% if(ownerId && actor.className === 'Admin'){ %><%= ownerId %>={<%= ownerId %>}<% } %> /> }, | ||
{ | ||
path: 'create', | ||
element: <<%= actor.className %><%= model.className %>CreateFeature <% if(ownerId && actor.className === 'Admin'){ %><%= ownerId %>={<%= ownerId %>}<% } %> />, | ||
}, | ||
{ path: ':<%= model.propertyName %>Id/*', element: <<%= actor.className %><%= model.className %>DetailFeature /> }, | ||
{ path: '', element: <List <% if(ownerId && actor.className === 'Admin'){ %><%= ownerId %>={<%= ownerId %>}<% } %> /> }, | ||
{ path: 'create', element: <Create <% if(ownerId && actor.className === 'Admin'){ %><%= ownerId %>={<%= ownerId %>}<% } %> /> }, | ||
{ path: ':<%= model.propertyName %>Id/*', element: <Detail /> }, | ||
]) | ||
} |
43 changes: 23 additions & 20 deletions
43
...lib/web-crud/files/ui/lib/__actorFileName__-__modelFileName__-ui-create-form.tsx.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
import { Button, Group } from '@mantine/core' | ||
import { Button, Group, TextInput } from '@mantine/core' | ||
import { useForm } from '@mantine/form' | ||
import { <%= model.className %><%= actor.className %>CreateInput } from '@<%= npmScope %>/sdk' | ||
import { formFieldText, UiForm, UiFormField } from '@pubkey-ui/core' | ||
import { UiStack } from '@pubkey-ui/core' | ||
|
||
export function <%= actor.className %><%= model.className %>UiCreateForm({ submit }: { submit: (res: <%= model.className %><%= actor.className %>CreateInput) => Promise<boolean> }) { | ||
const model: <%= model.className %><%= actor.className %>CreateInput = { | ||
<% for (let field of fields){ %> | ||
<%= field.name %>: '', | ||
<% } %> | ||
<% if(ownerId && actor.className === 'Admin'){ %> | ||
<%= ownerId %>: '', | ||
<% } %> | ||
} | ||
const form = useForm<<%= model.className %><%= actor.className %>CreateInput>({ | ||
initialValues: { | ||
<% for (let field of fields){ %> | ||
<%= field.name %>: '', | ||
<% } %> | ||
<% if(ownerId && actor.className === 'Admin'){ %> | ||
<%= ownerId %>: '', | ||
<% } %> | ||
}, | ||
}) | ||
|
||
const fields: UiFormField<<%= model.className %><%= actor.className %>CreateInput>[] = [ | ||
<% for (let field of fields){ %> | ||
formFieldText('<%= field.name %>', { label: '<%= field.name %>', required: true, }), | ||
<% } %> | ||
] | ||
return ( | ||
<UiForm model={model} fields={fields} submit={(res) => submit(res as <%= model.className %><%= actor.className %>CreateInput)}> | ||
<Group justify="right"> | ||
<Button type="submit">Create</Button> | ||
</Group> | ||
</UiForm> | ||
<form onSubmit={form.onSubmit((values) => submit(values))}> | ||
<UiStack> | ||
<% for (let field of fields){ %> | ||
<TextInput required name="<%= field.name %>" label="<%= field.name %>" {...form.getInputProps('<%= field.name %>')} /> | ||
<% } %> | ||
<Group justify="right"> | ||
<Button type="submit">Save</Button> | ||
</Group> | ||
</UiStack> | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.