-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bb5aa1
commit dccbb8e
Showing
7 changed files
with
221 additions
and
25 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Button from '@mui/material/Button'; | ||
import Grid from '@mui/material/Grid2'; | ||
import TextField from '@mui/material/TextField'; | ||
import { CRUDFields, DataModel } from './shared'; | ||
|
||
export interface CreateProps<D extends DataModel> { | ||
/** | ||
* Fields to show. | ||
*/ | ||
fields: CRUDFields; | ||
/** | ||
* Methods to interact with server-side data. | ||
*/ | ||
methods: { | ||
createOne: (data: Omit<D, 'id'>) => Promise<D>; | ||
}; | ||
} | ||
|
||
function Create<D extends DataModel>(props: CreateProps<D>) { | ||
const { fields, methods } = props; | ||
const { createOne } = methods; | ||
|
||
return ( | ||
<Box component="form" noValidate autoComplete="off"> | ||
<Grid container spacing={2} sx={{ mb: 2 }}> | ||
{fields.map((field) => ( | ||
<Grid key={field.field} size={6}> | ||
<TextField id={field.field} label={field.headerName} sx={{ width: '100%' }} /> | ||
</Grid> | ||
))} | ||
</Grid> | ||
<Button type="submit" variant="contained"> | ||
Contained | ||
</Button> | ||
</Box> | ||
); | ||
} | ||
|
||
export { Create }; |
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,2 +1,3 @@ | ||
export * from './List'; | ||
export * from './Show'; | ||
export * from './Create'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from 'react'; | ||
import { Create } from '@toolpad/core/CRUD'; | ||
|
||
interface Order extends Record<string, unknown> { | ||
id: number; | ||
name: string; | ||
status: string; | ||
} | ||
|
||
const orderFields = [ | ||
{ field: 'id', headerName: 'ID' }, | ||
{ field: 'name', headerName: 'Name' }, | ||
{ field: 'status', headerName: 'Status' }, | ||
]; | ||
|
||
export default function OrderPage() { | ||
return ( | ||
<Create<Order> | ||
fields={orderFields} | ||
methods={{ | ||
createOne: () => { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
id: 69, | ||
name: 'Order 69', | ||
status: 'pending', | ||
}); | ||
}, 1500); | ||
}); | ||
}, | ||
}} | ||
/> | ||
); | ||
} |
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.