-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crashing caused by missing data (#105)
- Loading branch information
1 parent
932b0a6
commit 6cccc3d
Showing
4 changed files
with
161 additions
and
90 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
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,65 @@ | ||
import React from 'react' | ||
|
||
import ListItem from 'components/ListItem' | ||
import { actionTypes } from 'components/Actions' | ||
import { ITEM_TYPES } from '../../consts' | ||
import { getActivityGroupIcon, getItemId } from '../../helpers' | ||
|
||
export const LIST_ITEM_TYPES = { | ||
ACTIVE_LIST_ITEM: 'activeListItem', | ||
COMPLETION_REQUEST_LIST_ITEM: 'completionRequestItem', | ||
} | ||
|
||
const ActiveListItem = ({ task, parent }) => ( | ||
<ListItem | ||
key={getItemId(task.item)} | ||
guid={task.id} | ||
title={task.item.title} | ||
subTitle={parent.title} | ||
icon={getActivityGroupIcon(parent)} | ||
itemType={ITEM_TYPES.TASK} | ||
actionsComponent={actionTypes.groupLeaderActions} | ||
/> | ||
) | ||
|
||
const CompletionRequestedItem = ({ task, parent, groupId, memberId }) => ( | ||
<ListItem | ||
key={getItemId(task.item)} | ||
guid={task.id} | ||
groupGuid={Number(groupId)} | ||
userGuid={Number(memberId)} | ||
title={task.item.title} | ||
icon={getActivityGroupIcon(parent)} | ||
subTitle={parent.title} | ||
itemType={ITEM_TYPES.TASK} | ||
actionsComponent={actionTypes.groupLeaderActions} | ||
showActions | ||
/> | ||
) | ||
|
||
const LIST_ITEMS = { | ||
[LIST_ITEM_TYPES.ACTIVE_LIST_ITEM]: ActiveListItem, | ||
[LIST_ITEM_TYPES.COMPLETION_REQUEST_LIST_ITEM]: CompletionRequestedItem, | ||
} | ||
|
||
const MemberTaskListItem = ({ | ||
itemsByGuid, | ||
taskGuid, | ||
activityGroups, | ||
language, | ||
type, | ||
...props | ||
}) => { | ||
const task = itemsByGuid[taskGuid] | ||
|
||
if (!task || !task.item || task.item.locale !== language) return null | ||
|
||
const parent = activityGroups[task.item.activity_group] | ||
if (!parent) return null | ||
|
||
const Component = LIST_ITEMS[type] | ||
|
||
return Component ? <Component {...props} task={task} parent={parent} /> : null | ||
} | ||
|
||
export default MemberTaskListItem |