From d88fdd4c3863350eb29a2d40b5c18ac42640472a Mon Sep 17 00:00:00 2001 From: Alec Ritson Date: Wed, 3 Jan 2024 13:37:22 +0000 Subject: [PATCH] Status editing updates --- composer.json | 3 +- packages/admin/composer.json | 3 +- packages/admin/resources/lang/en/product.php | 27 ++++++++++++++++ .../Filament/Resources/ProductResource.php | 31 ++++++++++++------- .../ProductResource/Pages/EditProduct.php | 20 ++++++++++++ 5 files changed, 70 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index af306af5ad..8164e49848 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "spatie/laravel-blink": "^1.6", "spatie/laravel-medialibrary": "^10.0.0", "spatie/laravel-permission": "^5.10", - "technikermathe/blade-lucide-icons": "^v2.24.0" + "technikermathe/blade-lucide-icons": "^v2.24.0", + "awcodes/shout": "2.x-dev" }, "require-dev": { "laravel/pint": "1.13.1", diff --git a/packages/admin/composer.json b/packages/admin/composer.json index 6358eaf194..9b5494b2ac 100644 --- a/packages/admin/composer.json +++ b/packages/admin/composer.json @@ -21,7 +21,8 @@ "barryvdh/laravel-dompdf": "^2.0", "technikermathe/blade-lucide-icons": "^v2.24.0", "marvinosswald/filament-input-select-affix": "^0.1.0", - "leandrocfe/filament-apex-charts": "^3.0" + "leandrocfe/filament-apex-charts": "^3.0", + "awcodes/shout": "2.x-dev" }, "extra": { "laravel": { diff --git a/packages/admin/resources/lang/en/product.php b/packages/admin/resources/lang/en/product.php index 4e21eae6d7..a34ae0e2e6 100644 --- a/packages/admin/resources/lang/en/product.php +++ b/packages/admin/resources/lang/en/product.php @@ -6,6 +6,16 @@ 'plural_label' => 'Products', + 'status' => [ + 'unpublished' => [ + 'content' => 'Currently in draft status, this product is concealed across all channels and customer groups.', + ], + 'availability' => [ + 'customer_groups' => 'This product is currently unavailable for all customer groups.', + 'channels' => 'This product is currently unavailable for all channels.', + ], + ], + 'table' => [ 'status' => [ 'label' => 'Status', @@ -27,6 +37,13 @@ ], ], + 'actions' => [ + 'edit_status' => [ + 'label' => 'Update Status', + 'heading' => 'Update Status', + ], + ], + 'form' => [ 'name' => [ 'label' => 'Name', @@ -42,6 +59,16 @@ ], 'status' => [ 'label' => 'Status', + 'options' => [ + 'published' => [ + 'label' => 'Published', + 'description' => 'This product will be available across all enabled customer groups and channels', + ], + 'draft' => [ + 'label' => 'Draft', + 'description' => 'This product will be hidden across all channels and customer groups', + ], + ], ], 'tags' => [ 'label' => 'Tags', diff --git a/packages/admin/src/Filament/Resources/ProductResource.php b/packages/admin/src/Filament/Resources/ProductResource.php index 21369703ef..50a141bd3d 100644 --- a/packages/admin/src/Filament/Resources/ProductResource.php +++ b/packages/admin/src/Filament/Resources/ProductResource.php @@ -2,6 +2,7 @@ namespace Lunar\Admin\Filament\Resources; +use Awcodes\Shout\Components\Shout; use Filament\Forms; use Filament\Forms\Components\Component; use Filament\Forms\Form; @@ -76,6 +77,24 @@ public static function getDefaultForm(Form $form): Form { return $form ->schema([ + Shout::make('product-status') + ->content( + __('lunarpanel::product.status.unpublished.content') + )->type('danger')->hidden( + fn (Model $record) => $record?->status == 'published' + ), + Shout::make('product-customer-groups') + ->content( + __('lunarpanel::product.status.availability.customer_groups') + )->type('danger')->hidden(function (Model $record) { + return $record->customerGroups()->where('enabled', true)->count(); + }), + Shout::make('product-channels') + ->content( + __('lunarpanel::product.status.availability.channels') + )->type('danger')->hidden(function (Model $record) { + return $record->channels()->where('enabled', true)->count(); + }), Forms\Components\Section::make() ->schema( static::getMainFormComponents(), @@ -90,7 +109,6 @@ protected static function getMainFormComponents(): array return [ static::getBrandFormComponent(), static::getProductTypeFormComponent(), - static::getStatusFormComponent(), static::getTagsFormComponent(), ]; } @@ -162,17 +180,6 @@ public static function getProductTypeFormComponent(): Component ->required(); } - protected static function getStatusFormComponent(): Component - { - return Forms\Components\Select::make('status') - ->label(__('lunarpanel::product.form.status.label')) - ->options([ - 'draft' => 'Draft', - 'published' => 'Published', - ]) - ->selectablePlaceholder(false); - } - protected static function getTagsFormComponent(): Component { return Forms\Components\TextInput::make('tags') diff --git a/packages/admin/src/Filament/Resources/ProductResource/Pages/EditProduct.php b/packages/admin/src/Filament/Resources/ProductResource/Pages/EditProduct.php index 156819f2cc..4e37868b17 100644 --- a/packages/admin/src/Filament/Resources/ProductResource/Pages/EditProduct.php +++ b/packages/admin/src/Filament/Resources/ProductResource/Pages/EditProduct.php @@ -3,6 +3,7 @@ namespace Lunar\Admin\Filament\Resources\ProductResource\Pages; use Filament\Actions; +use Filament\Forms; use Filament\Support\Facades\FilamentIcon; use Lunar\Admin\Filament\Resources\ProductResource; use Lunar\Admin\Support\Pages\BaseEditRecord; @@ -23,6 +24,25 @@ public static function getNavigationIcon(): ?string protected function getDefaultHeaderActions(): array { return [ + Actions\EditAction::make('update_status') + ->label( + __('lunarpanel::product.actions.edit_status.label') + ) + ->modalHeading( + __('lunarpanel::product.actions.edit_status.heading') + ) + ->record( + $this->record + )->form([ + Forms\Components\Radio::make('status')->options([ + 'published' => __('lunarpanel::product.form.status.options.published.label'), + 'draft' => __('lunarpanel::product.form.status.options.draft.label'), + ]) + ->descriptions([ + 'published' => __('lunarpanel::product.form.status.options.published.description'), + 'draft' => __('lunarpanel::product.form.status.options.draft.description'), + ])->live(), + ]), Actions\DeleteAction::make(), ]; }