-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user-multi-selection): add component
- Loading branch information
Tobias Pickel
committed
Jan 9, 2019
1 parent
61c1742
commit 62942d4
Showing
2 changed files
with
91 additions
and
71 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
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,48 @@ | ||
import { MultiSelectionBox } from 'bricks-of-sand'; | ||
import * as React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { AppState } from '../../store'; | ||
import { User, UsersState } from '../../store/reducers'; | ||
|
||
interface OwnProps { | ||
placeholder: string; | ||
validation: { [userId: number]: string }; | ||
onSelect(selection: UsersState): void; | ||
} | ||
|
||
interface StateProps { | ||
users: UsersState; | ||
} | ||
|
||
interface ActionProps {} | ||
|
||
export type UserMultiSelectionProps = ActionProps & StateProps & OwnProps; | ||
|
||
export function UserMultiSelection({ | ||
placeholder, | ||
onSelect, | ||
users, | ||
validation, | ||
}: UserMultiSelectionProps): JSX.Element | null { | ||
return ( | ||
<MultiSelectionBox | ||
errorMessageMap={validation} | ||
getItemIndex={user => (user ? user.id : 0)} | ||
itemToString={user => user.name} | ||
items={users} | ||
onSelect={onSelect} | ||
placeholder={placeholder} | ||
/> | ||
); | ||
} | ||
|
||
const mapStateToProps = (state: AppState): StateProps => ({ | ||
users: state.user, | ||
}); | ||
|
||
const mapDispatchToProps = {}; | ||
|
||
export const ConnectedUserMultiSelection = connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(UserMultiSelection); |