Skip to content

feat:[lar-140] Remove point after deleted article ,thread and discussion #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/Filament/Resources/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Filament\Resources;

use App\Filament\Resources\ArticleResource\Pages;
use App\Gamify\Points\ArticleDeleted;
use App\Gamify\Points\ArticlePublished;
use App\Models\Article;
use Filament\Resources\Resource;
Expand Down Expand Up @@ -114,7 +115,14 @@ public static function table(Table $table): Table
->url(fn (Article $record) => route('articles.show', $record))
->openUrlInNewTab()
->label('Afficher'),
Tables\Actions\DeleteAction::make(),
Tables\Actions\DeleteAction::make()
->after(
function ($record): void {
if ($record->isApproved()) {
undoPoint(new ArticleDeleted($record));
}
}
),
]),
])
->bulkActions([
Expand Down
4 changes: 3 additions & 1 deletion app/Filament/Resources/DiscussionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Filament\Resources;

use App\Filament\Resources\DiscussionResource\Pages;
use App\Gamify\Points\DiscussionDeleted;
use App\Models\Discussion;
use Filament\Resources\Resource;
use Filament\Tables;
Expand Down Expand Up @@ -61,7 +62,8 @@ public static function table(Table $table): Table
->url(fn (Discussion $record) => route('discussions.show', $record))
->openUrlInNewTab(),
Tables\Actions\DeleteAction::make()
->iconButton(),
->iconButton()
->after(fn ($record) => undoPoint(new DiscussionDeleted($record))),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
4 changes: 3 additions & 1 deletion app/Filament/Resources/ThreadResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Filament\Resources;

use App\Filament\Resources\ThreadResource\Pages;
use App\Gamify\Points\ThreadDeleted;
use App\Models\Thread;
use Filament\Resources\Resource;
use Filament\Tables;
Expand Down Expand Up @@ -62,7 +63,8 @@ public static function table(Table $table): Table
->color('success')
->url(fn (Thread $record): string => route('forum.show', $record))
->openUrlInNewTab(),
Tables\Actions\DeleteAction::make(),
Tables\Actions\DeleteAction::make()
->after(fn ($record) => undoPoint(new ThreadDeleted($record))),
]),
])
->bulkActions([
Expand Down
20 changes: 20 additions & 0 deletions app/Gamify/Points/ArticleDeleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Gamify\Points;

use App\Models\Article;
use QCod\Gamify\PointType;

final class ArticleDeleted extends PointType
{
public int $points = 50;

protected string $payee = 'user';

public function __construct(Article $subject)
{
$this->subject = $subject;
}
}
21 changes: 21 additions & 0 deletions app/Gamify/Points/DiscussionDeleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Gamify\Points;

use App\Models\Discussion;
use QCod\Gamify\PointType;

final class DiscussionDeleted extends PointType
{
public int $points = 20;

protected string $payee = 'user';

public function __construct(Discussion $subject)
{
$this->subject = $subject;
dd($subject);
}
}
20 changes: 20 additions & 0 deletions app/Gamify/Points/ThreadDeleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Gamify\Points;

use App\Models\Thread;
use QCod\Gamify\PointType;

final class ThreadDeleted extends PointType
{
public int $points = 55;

protected string $payee = 'user';

public function __construct(Thread $subject)
{
$this->subject = $subject;
}
}
4 changes: 3 additions & 1 deletion app/Livewire/Pages/Discussions/SingleDiscussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Livewire\Pages\Discussions;

use App\Actions\Discussion\ConvertDiscussionToThreadAction;
use App\Gamify\Points\DiscussionDeleted;
use App\Models\Discussion;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
Expand Down Expand Up @@ -80,7 +81,8 @@ public function deleteAction(): Action
->authorize('delete', $this->discussion)
->requiresConfirmation()
->successNotificationTitle(__('notifications.discussion.deleted'))
->successRedirectUrl(route('discussions.index'));
->successRedirectUrl(route('discussions.index'))
->after(fn ($record) => undoPoint(new DiscussionDeleted($record)));
}

public function render(): View
Expand Down
3 changes: 3 additions & 0 deletions app/Livewire/Pages/Forum/DetailThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Livewire\Pages\Forum;

use App\Gamify\Points\ThreadDeleted;
use App\Models\Thread;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
Expand Down Expand Up @@ -55,6 +56,8 @@ public function deleteAction(): Action
->action(function (): void {
$this->thread->delete();

undoPoint(new ThreadDeleted($this->thread));

$this->redirectRoute('forum.index', navigate: true);
});
}
Expand Down
Loading