fixes
This commit is contained in:
1 parent
e97c7cd0f4
commit
95315d1453
8 files changed
+90
-72
No files matched your search
@@ -4,19 +4,18 @@ namespace App\Livewire;
|
||||
|
||||
use App\Mail\UserNotification;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\Concerns\InteractsWithActions;
|
||||
use Filament\Actions\Contracts\HasActions;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Component;
|
||||
@@ -27,53 +26,53 @@ class UserNotifications extends Component implements HasActions, HasSchemas, Has
|
||||
use InteractsWithSchemas;
|
||||
use InteractsWithTable;
|
||||
|
||||
protected Table $table2;
|
||||
public ?array $data = [];
|
||||
|
||||
public function table(Table $table): Table
|
||||
public function mount(): void
|
||||
{
|
||||
return $table
|
||||
->query(User::query()->where('client_id', auth()->user()->client_id)->orwhereIn('id', [1, 2]))
|
||||
->description('Send a message to one of the user listed')
|
||||
->columns([
|
||||
TextColumn::make('name')->icon('phosphor-user-duotone')->searchable(),
|
||||
TextColumn::make('email')->icon('phosphor-envelope-duotone'),
|
||||
$this->form->fill();
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('recipient')
|
||||
->placeholder('Select an recipient')
|
||||
->required()
|
||||
->options(fn () => User::query()->where('client_id', auth()->user()->client_id)->orwhereIn('id', [1, 2])->pluck('name', 'id')),
|
||||
Toggle::make('notify_by_email')->label('Send also as E-Mail'),
|
||||
TextInput::make('subject')
|
||||
->required(),
|
||||
MarkdownEditor::make('message')
|
||||
->required(),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('notification')
|
||||
->icon('phosphor-note-pencil-duotone')
|
||||
->tooltip('Create a notification')
|
||||
->modalHeading(fn ($record) => 'Send a notification to '.$record->name)
|
||||
->iconButton()
|
||||
->modalWidth(Width::Large)
|
||||
// ->modalDescription('Send a notification')
|
||||
->modalSubmitActionLabel('Send')
|
||||
->modalIcon('phosphor-envelope-duotone')
|
||||
->schema([
|
||||
Textarea::make('message')
|
||||
->required()
|
||||
->rows(4),
|
||||
Toggle::make('notify_by_email')->label('Send also as email')
|
||||
// ->belowContent('Notify me also by e-mail')
|
||||
->onColor('info')
|
||||
->offColor('gray'),
|
||||
])->action(function (array $data, $record) {
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
if ($data['notify_by_email']) {
|
||||
Mail::to($record)
|
||||
->send(new UserNotification($data['message']));
|
||||
}
|
||||
Notification::make()
|
||||
->title('Notification from '.$record->name)
|
||||
->icon('phosphor-envelope-duotone')
|
||||
->body($data['message'])
|
||||
->sendToDatabase($record);
|
||||
public function create(): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
|
||||
Notification::make()
|
||||
->title('Message send successfully')
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
]);
|
||||
$recipient = User::find((int) $data['recipient']);
|
||||
|
||||
if ($recipient) {
|
||||
if ($data['notify_by_email']) {
|
||||
Mail::to($recipient)->send(new UserNotification($data['subject'], $data['message']));
|
||||
}
|
||||
Notification::make()
|
||||
->title($data['subject'])
|
||||
->icon('phosphor-envelope-duotone')
|
||||
->body($data['message'])
|
||||
->sendToDatabase($recipient);
|
||||
|
||||
Notification::make()
|
||||
->title('Message send successfully')
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$this->dispatch('close-modal', id: 'send_message_modal');
|
||||
}
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
|
||||
Reference in new issue
Block a user