Add /teams/:teamId/sites/:siteId/stories client-side

This commit is contained in:
Jerko Steiner 2019-04-06 14:01:16 +08:00
parent 89af2f0845
commit e18fa89b26
2 changed files with 58 additions and 30 deletions

View File

@ -5,41 +5,64 @@ import {Link} from '../components'
export interface ICRUDListProps<T> { export interface ICRUDListProps<T> {
nameKey: keyof T nameKey: keyof T
editLink: (item: T) => string editLink?: (item: T) => string
itemIds: ReadonlyArray<number> itemIds: ReadonlyArray<number>
itemsById: Record<number, T> itemsById: Record<number, T>
newLink: string newLink?: string
onRemove: (t: T) => void onRemove?: (t: T) => void
title: string title: string
Info?: React.ComponentType<ICRUDItemInfoProps<T>>
} }
export interface ICRUDItemRowProps<T> { export interface ICRUDItemRowProps<T> {
Info?: React.ComponentType<ICRUDItemInfoProps<T>>
nameKey: keyof T nameKey: keyof T
editLink: string editLink?: string
item: T item: T
onRemove: (t: T) => void onRemove?: (t: T) => void
}
export interface ICRUDItemInfoProps<T> {
item: T
nameKey: keyof T
}
export class CRUDItemInfo<T>
extends React.PureComponent<ICRUDItemInfoProps<T>> {
render() {
const {item, nameKey} = this.props
return <span>{item[nameKey]}</span>
}
} }
export class CRUDItemRow<T> extends React.PureComponent<ICRUDItemRowProps<T>> { export class CRUDItemRow<T> extends React.PureComponent<ICRUDItemRowProps<T>> {
handleRemove = () => { handleRemove = () => {
const {onRemove, item} = this.props const {onRemove, item} = this.props
if (onRemove) {
onRemove(item) onRemove(item)
} }
}
render() { render() {
const {nameKey, editLink, item} = this.props const {nameKey, editLink, item} = this.props
return ( return (
<React.Fragment> <React.Fragment>
<div className='item-info'> <div className='item-info'>
{item[nameKey]} {this.props.Info
? <this.props.Info item={item} nameKey={nameKey} />
: <CRUDItemInfo<T> item={item} nameKey={nameKey} />
}
</div> </div>
<div className='ml-auto'> <div className='ml-auto'>
{!!editLink && (
<Link to={editLink}> <Link to={editLink}>
<Button isInverted isColor='link' aria-label='Edit'> <Button isInverted isColor='link' aria-label='Edit'>
<FaEdit /> <FaEdit />
</Button> </Button>
</Link> </Link>
)}
&nbsp; &nbsp;
{!!this.props.onRemove && (
<Button <Button
aria-label='Remove' aria-label='Remove'
onClick={this.handleRemove} onClick={this.handleRemove}
@ -48,6 +71,7 @@ export class CRUDItemRow<T> extends React.PureComponent<ICRUDItemRowProps<T>> {
> >
<FaTimes /> <FaTimes />
</Button> </Button>
)}
</div> </div>
</React.Fragment> </React.Fragment>
) )
@ -63,12 +87,14 @@ export class CRUDList<T> extends React.PureComponent<ICRUDListProps<T>> {
<PanelHeading> <PanelHeading>
<span className='is-flex v-centered'> <span className='is-flex v-centered'>
<span>{title}</span> <span>{title}</span>
{!!newLink && (
<Link <Link
className='ml-auto button is-link is-small' className='ml-auto button is-link is-small'
to={newLink} to={newLink}
> >
<FaPlus />&nbsp; New <FaPlus />&nbsp; New
</Link> </Link>
)}
</span> </span>
</PanelHeading> </PanelHeading>
{itemIds.map(itemId => { {itemIds.map(itemId => {
@ -76,8 +102,9 @@ export class CRUDList<T> extends React.PureComponent<ICRUDListProps<T>> {
return ( return (
<PanelBlock key={itemId}> <PanelBlock key={itemId}>
<CRUDItemRow<T> <CRUDItemRow<T>
Info={this.props.Info}
nameKey={nameKey} nameKey={nameKey}
editLink={editLink(item)} editLink={editLink && editLink(item)}
item={item} item={item}
onRemove={this.props.onRemove} onRemove={this.props.onRemove}
/> />

View File

@ -23,10 +23,11 @@ export function Login(
// sync actions // sync actions
case 'LOGIN_REDIRECT_SET': case 'LOGIN_REDIRECT_SET':
return {...state, redirectTo: action.payload.redirectTo} return {...state, redirectTo: action.payload.redirectTo}
default: case 'LOGIN':
case 'LOGIN_LOGOUT':
case 'LOGIN_REGISTER':
// async actions // async actions
switch (action.status) { switch (action.status) {
// FIXME this will trigger for all async actions with status pending
case 'pending': case 'pending':
return { return {
...state, ...state,
@ -48,6 +49,6 @@ export function Login(
return {...state, user: action.payload, error: ''} return {...state, user: action.payload, error: ''}
} }
} }
return state
} }
return state
} }