Last active
October 5, 2016 10:10
-
-
Save jacobjuul/484a17f7869ed2510b712f4ee216a925 to your computer and use it in GitHub Desktop.
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
// ActivityView.js | |
notificationSender(notificationTypes.USER_UNJOINED_ACTIVITY_USER, { | |
payload: { activity }, | |
sender: userId | |
}); | |
notificationSender(notificationTypes.USER_UNJOINED_ACTIVITY_COACH, { | |
payload: { activityId: activity._id }, | |
sender: userId, | |
reciever: activity.coachId | |
}); | |
// notficationHandler.js | |
export const notificationSender = (notificationType, { sender, reciever, payload }) => { | |
switch(notificationType) { | |
case types.USER_JOINED_ACTIVITY_COACH: | |
break; | |
case types.USER_JOINED_ACTIVITY_USER: | |
break; | |
case types.USER_UNJOINED_ACTIVITY_COACH: | |
userUnjoinedActivity(notificationType, { sender, reciever, payload }); | |
break; | |
case types.USER_UNJOINED_ACTIVITY_USER: | |
userUnjoinedActivity(notificationType, { sender, reciever, payload }); | |
break; | |
case types.USER_ENQUIRED_PACKAGE_COACH: | |
break; | |
default: | |
break; | |
} | |
}; | |
// notificationMethods.js | |
export function userUnjoinedActivity(notificationType, { sender, reciever, payload }) { | |
const userId = user._id; | |
if (notificationType === types.USER_UNJOINED_ACTIVITY_USER) | |
// send notification to user | |
Notification.insert({ | |
createdBy: sender, | |
targetId: sender, | |
type: notificationType, | |
data: payload.activity, | |
message: `Du har afmeldt dig fra ${payload.activity.title}`, | |
activityId: payload.activity._id | |
}); | |
} else { | |
// send notification to coach | |
Notification.insert({ | |
createdBy: sender, | |
targetId: reciever, | |
type: notificationType, | |
data: payload.activity, | |
message: `Du har afmeldt dig fra ${payload.activity.title}`, | |
activityId: payload.activity._id | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment