-
-
Notifications
You must be signed in to change notification settings - Fork 15
Feature/lar 111 create edit discussion #236
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
StevyMarlino
merged 11 commits into
develop
from
feature/LAR-111-create-edit-discussion
Dec 17, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0cdefaf
wip
mckenziearts c4fc906
feat:(LAR-111) adding create and edit feature with slideover
StevyMarlino 36bfecf
feat:(LAR-111) remove unecessary view and route
StevyMarlino 0c034fe
feat:(LAR-111) remove old discussionTest file
StevyMarlino e6033c1
fix(lint):(LAR-111) fix lint error
StevyMarlino 8a1a103
refact: (LAR-111) refactoring DiscussionForm and adding an acation
StevyMarlino 12e1762
refact: (LAR-111) refactoring filter displaying of tags by discussion
StevyMarlino c9479dc
refact:(LAR-11) refactoring route formDiscussion and type action
StevyMarlino 7a04fa2
fix:(LAR-111) fixing type of form action
StevyMarlino 7d4755b
feat: [LAR-111] updatec
mckenziearts 6e2c24f
chore: [LAR-111] apply composer lint and upgrade dependencies
mckenziearts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\Discussion; | ||
|
||
use App\Gamify\Points\DiscussionCreated; | ||
use App\Models\Discussion; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
final class CreateOrUpdateDiscussionAction | ||
{ | ||
public function handle(array $formValues, ?int $discussionId = null): Discussion | ||
{ | ||
return DB::transaction(function () use ($formValues, $discussionId) { | ||
/** @var Discussion $discussion */ | ||
$discussion = Discussion::query()->updateOrCreate( | ||
['id' => $discussionId], | ||
$formValues | ||
); | ||
|
||
if (! $discussionId) { | ||
givePoint(new DiscussionCreated($discussion)); | ||
} | ||
|
||
return $discussion; | ||
}); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,148 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Livewire\Components\Slideovers; | ||
|
||
use App\Actions\Discussion\CreateOrUpdateDiscussionAction; | ||
use App\Exceptions\UnverifiedUserException; | ||
use App\Livewire\Traits\WithAuthenticatedUser; | ||
use App\Models\Discussion; | ||
use Filament\Forms; | ||
use Filament\Forms\Concerns\InteractsWithForms; | ||
use Filament\Forms\Contracts\HasForms; | ||
use Filament\Forms\Form; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Blade; | ||
use Illuminate\Support\HtmlString; | ||
use Illuminate\Support\Str; | ||
use Laravelcm\LivewireSlideOvers\SlideOverComponent; | ||
|
||
/** | ||
* @property Form $form | ||
*/ | ||
final class DiscussionForm extends SlideOverComponent implements HasForms | ||
{ | ||
use InteractsWithForms; | ||
use WithAuthenticatedUser; | ||
|
||
public ?Discussion $discussion = null; | ||
|
||
public ?array $data = []; | ||
|
||
public function mount(?int $discussionId = null): void | ||
{ | ||
// @phpstan-ignore-next-line | ||
$this->discussion = $discussionId | ||
? Discussion::query()->findOrFail($discussionId) | ||
: new Discussion; | ||
|
||
$this->form->fill(array_merge( | ||
$this->discussion->toArray(), | ||
['user_id' => $this->discussion->user_id ?? Auth::id()] | ||
)); | ||
} | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\Hidden::make('user_id'), | ||
Forms\Components\TextInput::make('title') | ||
->label(__('validation.attributes.title')) | ||
->helperText(__('pages/discussion.min_discussion_length')) | ||
->required() | ||
->live(onBlur: true) | ||
->afterStateUpdated(function (string $operation, $state, Forms\Set $set): void { | ||
$set('slug', Str::slug($state)); | ||
}) | ||
->minLength(10), | ||
Forms\Components\Hidden::make('slug'), | ||
Forms\Components\Select::make('tags') | ||
->multiple() | ||
->relationship( | ||
name: 'tags', | ||
titleAttribute: 'name', | ||
modifyQueryUsing: fn ($query) => $query->whereJsonContains('concerns', 'discussion') | ||
) | ||
->required() | ||
->minItems(1) | ||
->maxItems(3) | ||
->preload(), | ||
Forms\Components\MarkdownEditor::make('body') | ||
->toolbarButtons([ | ||
'blockquote', | ||
'bold', | ||
'bulletList', | ||
'codeBlock', | ||
'link', | ||
]) | ||
->label(__('validation.attributes.content')) | ||
->maxHeight('18.25rem') | ||
->required() | ||
->minLength(20), | ||
Forms\Components\Placeholder::make('') | ||
->content(fn () => new HtmlString(Blade::render(<<<'Blade' | ||
<x-torchlight /> | ||
Blade))), | ||
]) | ||
->statePath('data') | ||
->model($this->discussion); | ||
} | ||
|
||
public function save(): void | ||
{ | ||
// @phpstan-ignore-next-line | ||
if (! Auth::user()->hasVerifiedEmail()) { | ||
throw new UnverifiedUserException( | ||
message: __('notifications.exceptions.unverified_user') | ||
); | ||
} | ||
|
||
if ($this->discussion?->id) { | ||
$this->authorize('update', $this->discussion); | ||
} | ||
|
||
$this->validate(); | ||
|
||
$discussion = app(CreateOrUpdateDiscussionAction::class)->handle( | ||
formValues : $this->form->getState(), | ||
discussionId: $this->discussion?->id | ||
); | ||
|
||
$this->form->model($discussion)->saveRelationships(); | ||
|
||
Notification::make() | ||
->title( | ||
$this->discussion?->id | ||
? __('notifications.discussion.updated') | ||
: __('notifications.discussion.created'), | ||
) | ||
->success() | ||
->send(); | ||
|
||
$this->redirect(route('discussions.show', ['discussion' => $discussion]), navigate: true); | ||
} | ||
|
||
public static function panelMaxWidth(): string | ||
{ | ||
return '2xl'; | ||
} | ||
|
||
public static function closePanelOnEscape(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public static function closePanelOnClickAway(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.components.slideovers.discussion-form'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.