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 2 commits
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: 1 addition & 9 deletions app/Filament/Resources/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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 @@ -115,14 +114,7 @@ public static function table(Table $table): Table
->url(fn (Article $record) => route('articles.show', $record))
->openUrlInNewTab()
->label('Afficher'),
Tables\Actions\DeleteAction::make()
->after(
function ($record): void {
if ($record->isApproved()) {
undoPoint(new ArticleDeleted($record));
}
}
),
Tables\Actions\DeleteAction::make(),
]),
])
->bulkActions([
Expand Down
4 changes: 1 addition & 3 deletions app/Filament/Resources/DiscussionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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 @@ -62,8 +61,7 @@ public static function table(Table $table): Table
->url(fn (Discussion $record) => route('discussions.show', $record))
->openUrlInNewTab(),
Tables\Actions\DeleteAction::make()
->iconButton()
->after(fn ($record) => undoPoint(new DiscussionDeleted($record))),
->iconButton(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
4 changes: 1 addition & 3 deletions app/Filament/Resources/ThreadResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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 @@ -63,8 +62,7 @@ public static function table(Table $table): Table
->color('success')
->url(fn (Thread $record): string => route('forum.show', $record))
->openUrlInNewTab(),
Tables\Actions\DeleteAction::make()
->after(fn ($record) => undoPoint(new ThreadDeleted($record))),
Tables\Actions\DeleteAction::make(),
]),
])
->bulkActions([
Expand Down
20 changes: 0 additions & 20 deletions app/Gamify/Points/ArticleDeleted.php

This file was deleted.

21 changes: 0 additions & 21 deletions app/Gamify/Points/DiscussionDeleted.php

This file was deleted.

20 changes: 0 additions & 20 deletions app/Gamify/Points/ThreadDeleted.php

This file was deleted.

16 changes: 13 additions & 3 deletions app/Livewire/Pages/Discussions/SingleDiscussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace App\Livewire\Pages\Discussions;

use App\Actions\Discussion\ConvertDiscussionToThreadAction;
use App\Gamify\Points\DiscussionDeleted;
use App\Gamify\Points\DiscussionCreated;
use App\Models\Discussion;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
Expand All @@ -14,6 +14,7 @@
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\DB;
use Livewire\Component;

final class SingleDiscussion extends Component implements HasActions, HasForms
Expand Down Expand Up @@ -81,8 +82,17 @@ public function deleteAction(): Action
->authorize('delete', $this->discussion)
->requiresConfirmation()
->successNotificationTitle(__('notifications.discussion.deleted'))
->successRedirectUrl(route('discussions.index'))
->after(fn ($record) => undoPoint(new DiscussionDeleted($record)));
->action(function (): void {
DB::beginTransaction();

undoPoint(new DiscussionCreated($this->discussion));

$this->discussion->delete();

DB::commit();

$this->redirectRoute('discussions.index', navigate: true);
});
}

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

namespace App\Livewire\Pages\Forum;

use App\Gamify\Points\ThreadDeleted;
use App\Gamify\Points\ThreadCreated;
use App\Models\Thread;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\DB;
use Livewire\Attributes\Layout;
use Livewire\Attributes\On;
use Livewire\Component;
Expand Down Expand Up @@ -54,9 +55,12 @@ public function deleteAction(): Action
->authorize('delete', $this->thread)
->requiresConfirmation()
->action(function (): void {
DB::beginTransaction();

undoPoint(new ThreadCreated($this->thread));
$this->thread->delete();

undoPoint(new ThreadDeleted($this->thread));
DB::commit();

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