Skip to content

Commit

Permalink
Slack notifications for earned badges
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyiliev committed Dec 30, 2020
1 parent b47b096 commit 6f98c62
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 0 additions & 2 deletions app/Http/Livewire/Badges.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ public function delete($id)
$badge->delete();
$this->dispatchBrowserEvent('notification', ['type' => 'warning', 'message' => 'You have deleted the badge!']);

$notification = new Notification;
$notification->notify('Dadge Deleted', $badge->name);
} else {
$this->dispatchBrowserEvent('notification', ['type' => 'error', 'message' => 'You do not have permissions to delete badges!']);
}
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Livewire/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function store()
$this->resetInputFields();

$notification = new Notification;
$notification->notify('New Post Added', $post->name);
$notification->notify('New Post Added', $post->body);
} else {
$this->dispatchBrowserEvent('notification', ['type' => 'error', 'message' => 'You do not have permissions to add posts to this team!']);
}
Expand All @@ -64,9 +64,6 @@ public function delete($id)
if(auth()->user()->id == $post->user_id) {
$post->delete();
$this->dispatchBrowserEvent('notification', ['type' => 'warning', 'message' => 'You have deleted the post!']);

$notification = new Notification;
$notification->notify('Post Deleted', $post->name);
} else {
$this->dispatchBrowserEvent('notification', ['type' => 'error', 'message' => 'You do not have permissions to delete this post!']);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Tasks extends Component
public $updateMode = false;
public $numResults = 10;
public $sortField = 'created_at';
public $sortAsc = true;
public $sortAsc = false;
public $taskStatus = ['To Do', 'Completed', 'In Progress'];
public $search = '';

Expand Down
9 changes: 9 additions & 0 deletions app/Models/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Models\Notification;
use App\Events\BadgeEarned;
use Illuminate\Database\Eloquent\Model;

Expand Down Expand Up @@ -48,13 +49,17 @@ public static function checkIfUserEarnedBadge()
public function checkTeamBadge($badge)
{
if ($badge->requirement_value <= auth()->user()->allTeams()->count() ) {
$notification = new Notification;
$notification->notify('The user won a new badge: ', $badge->name);
event(new BadgeEarned($badge));
}
}

public function checkTaskBadge($badge)
{
if ($badge->requirement_value <= auth()->user()->completedTasks()->count() ) {
$notification = new Notification;
$notification->notify('The user won a new badge: ', $badge->name);
event(new BadgeEarned($badge));
}
}
Expand All @@ -64,6 +69,8 @@ public function checkShiftBadge($badge)
$total_hours = auth()->user()->shifts()->first();
if($total_hours){
if ($badge->requirement_value <= $total_hours->total_hours ) {
$notification = new Notification;
$notification->notify('The user won a new badge: ', $badge->name);
event(new BadgeEarned($badge));
}
}
Expand All @@ -72,6 +79,8 @@ public function checkShiftBadge($badge)
public function checkFeedBadge($badge)
{
if ($badge->requirement_value <= auth()->user()->posts()->count() ) {
$notification = new Notification;
$notification->notify('The user won a new badge: ', $badge->name);
event(new BadgeEarned($badge));
}
}
Expand Down
4 changes: 2 additions & 2 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22008,8 +22008,8 @@ window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! /Users/tony/Sites/guild/resources/js/app.js */"./resources/js/app.js");
module.exports = __webpack_require__(/*! /Users/tony/Sites/guild/resources/css/app.css */"./resources/css/app.css");
__webpack_require__(/*! /var/www/guild/resources/js/app.js */"./resources/js/app.js");
module.exports = __webpack_require__(/*! /var/www/guild/resources/css/app.css */"./resources/css/app.css");


/***/ })
Expand Down

0 comments on commit 6f98c62

Please sign in to comment.