diff --git a/packages/client/src/crud/CRUDList.tsx b/packages/client/src/crud/CRUDList.tsx new file mode 100644 index 0000000..82466fa --- /dev/null +++ b/packages/client/src/crud/CRUDList.tsx @@ -0,0 +1,90 @@ +import React from 'react' +import {Button, Panel, PanelHeading, PanelBlock} from 'bloomer' +import {FaPlus, FaEdit, FaTimes} from 'react-icons/fa' +import {Link} from 'react-router-dom' + +export interface ICRUDListProps { + nameKey: keyof T + editLink: (item: T) => string + itemIds: number[] + itemsById: Record + newLink: string + onRemove: (t: T) => void + title: string +} + +export interface ICRUDItemRowProps { + nameKey: keyof T + editLink: string + item: T + onRemove: (t: T) => void +} + +export class CRUDItemRow extends React.PureComponent> { + handleRemove = () => { + const {onRemove, item} = this.props + onRemove(item) + } + render() { + const {nameKey, editLink, item} = this.props + + return ( + +
+ {item[nameKey]} +
+
+ + + +   + +
+
+ ) + } +} + +export class CRUDList extends React.PureComponent> { + render() { + const {nameKey, editLink, itemIds, itemsById, newLink, title} = this.props + + return ( + + + + {title} + +   New + + + + {itemIds.map(itemId => { + const item = itemsById[itemId] + return ( + + + nameKey={nameKey} + editLink={editLink(item)} + item={item} + onRemove={this.props.onRemove} + /> + + ) + })} + + ) + } +} diff --git a/packages/client/src/crud/index.ts b/packages/client/src/crud/index.ts index 00db918..49c1af7 100644 --- a/packages/client/src/crud/index.ts +++ b/packages/client/src/crud/index.ts @@ -1,4 +1,5 @@ export * from './CRUDActions' +export * from './CRUDList' export * from './CRUDReducer' export * from './TCRUDAction' export * from './TCRUDMethod'