diff --git a/packages/client/src/crud/CRUDList.tsx b/packages/client/src/crud/CRUDList.tsx index db02f42..113b8a9 100644 --- a/packages/client/src/crud/CRUDList.tsx +++ b/packages/client/src/crud/CRUDList.tsx @@ -5,25 +5,42 @@ import {Link} from '../components' export interface ICRUDListProps { nameKey: keyof T - editLink: (item: T) => string + editLink?: (item: T) => string itemIds: ReadonlyArray itemsById: Record - newLink: string - onRemove: (t: T) => void + newLink?: string + onRemove?: (t: T) => void title: string + Info?: React.ComponentType> } export interface ICRUDItemRowProps { + Info?: React.ComponentType> nameKey: keyof T - editLink: string + editLink?: string item: T - onRemove: (t: T) => void + onRemove?: (t: T) => void +} + +export interface ICRUDItemInfoProps { + item: T + nameKey: keyof T +} + +export class CRUDItemInfo +extends React.PureComponent> { + render() { + const {item, nameKey} = this.props + return {item[nameKey]} + } } export class CRUDItemRow extends React.PureComponent> { handleRemove = () => { const {onRemove, item} = this.props - onRemove(item) + if (onRemove) { + onRemove(item) + } } render() { const {nameKey, editLink, item} = this.props @@ -31,23 +48,30 @@ export class CRUDItemRow extends React.PureComponent> { return (
- {item[nameKey]} + {this.props.Info + ? + : item={item} nameKey={nameKey} /> + }
- - - + {!!editLink && ( + + + + )}   - + {!!this.props.onRemove && ( + + )}
) @@ -63,12 +87,14 @@ export class CRUDList extends React.PureComponent> { {title} - -   New - + {!!newLink && ( + +   New + + )} {itemIds.map(itemId => { @@ -76,8 +102,9 @@ export class CRUDList extends React.PureComponent> { return ( + Info={this.props.Info} nameKey={nameKey} - editLink={editLink(item)} + editLink={editLink && editLink(item)} item={item} onRemove={this.props.onRemove} /> diff --git a/packages/client/src/login/LoginReducer.ts b/packages/client/src/login/LoginReducer.ts index 4a5a32a..dc28ba5 100644 --- a/packages/client/src/login/LoginReducer.ts +++ b/packages/client/src/login/LoginReducer.ts @@ -23,10 +23,11 @@ export function Login( // sync actions case 'LOGIN_REDIRECT_SET': return {...state, redirectTo: action.payload.redirectTo} - default: + case 'LOGIN': + case 'LOGIN_LOGOUT': + case 'LOGIN_REGISTER': // async actions switch (action.status) { - // FIXME this will trigger for all async actions with status pending case 'pending': return { ...state, @@ -48,6 +49,6 @@ export function Login( return {...state, user: action.payload, error: ''} } } - return state } + return state }