|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Filament\App\Resources\WhatsappInstanceResource\RelationManagers; |
| 4 | + |
| 5 | +use App\Enums\Evolution\Typebot\{TriggerOperatorEnum, TriggerTypeEnum}; |
| 6 | +use Filament\Forms\Components\ToggleButtons; |
| 7 | +use Filament\Forms\Components\{Section, Select, TextInput}; |
| 8 | +use Filament\Forms\Form; |
| 9 | +use Filament\Resources\RelationManagers\RelationManager; |
| 10 | +use Filament\Tables\Columns\{TextColumn, ToggleColumn}; |
| 11 | +use Filament\Tables\Table; |
| 12 | +use Filament\{Tables}; |
| 13 | + |
| 14 | +class InstanceTypebotsRelationManager extends RelationManager |
| 15 | +{ |
| 16 | + protected static string $relationship = 'InstanceTypebots'; |
| 17 | + |
| 18 | + protected static ?string $modelLabel = 'Robô TypeBot'; |
| 19 | + |
| 20 | + protected static ?string $modelLabelPlural = "TypeBots"; |
| 21 | + |
| 22 | + protected static ?string $title = 'Robôs TypeBot'; |
| 23 | + |
| 24 | + public function form(Form $form): Form |
| 25 | + { |
| 26 | + return $form |
| 27 | + ->schema([ |
| 28 | + Section::make('Dados Basicos do typebot') |
| 29 | + ->schema([ |
| 30 | + |
| 31 | + TextInput::make('name') |
| 32 | + ->label('Descrição do Robô') |
| 33 | + ->prefixIcon('fas-id-card') |
| 34 | + ->required() |
| 35 | + ->maxLength(255), |
| 36 | + |
| 37 | + TextInput::make('url') |
| 38 | + ->label('URL do typebot') |
| 39 | + ->prefix('https://') |
| 40 | + ->required() |
| 41 | + ->maxLength(255), |
| 42 | + |
| 43 | + TextInput::make('type_bot') |
| 44 | + ->prefixIcon('fas-robot') |
| 45 | + ->label('Typebot') |
| 46 | + ->required() |
| 47 | + ->maxLength(255), |
| 48 | + |
| 49 | + ])->columns(3), |
| 50 | + |
| 51 | + Section::make('Dados de Disparo') |
| 52 | + ->schema([ |
| 53 | + |
| 54 | + Select::make('trigger_type') |
| 55 | + ->label('Tipo de Gatilho') |
| 56 | + ->required() |
| 57 | + ->reactive() |
| 58 | + ->live() |
| 59 | + ->options(TriggerTypeEnum::class), |
| 60 | + |
| 61 | + Select::make('trigger_operator') |
| 62 | + ->hidden(fn ($get) => $get('trigger_type') != 'keyword') |
| 63 | + ->required() |
| 64 | + ->reactive() |
| 65 | + ->label('Operador de Gatilho') |
| 66 | + ->options(TriggerOperatorEnum::class), |
| 67 | + |
| 68 | + TextInput::make('trigger_value') |
| 69 | + ->hidden(fn ($get) => !in_array($get('trigger_type'), ['advanced', 'keyword'])) |
| 70 | + ->label('Valor do Gatilho') |
| 71 | + ->prefixIcon('fas-keyboard') |
| 72 | + ->reactive() |
| 73 | + ->required() |
| 74 | + ->maxLength(255), |
| 75 | + |
| 76 | + ])->columns(3), |
| 77 | + |
| 78 | + Section::make('Configurações Gerais') |
| 79 | + ->schema([ |
| 80 | + |
| 81 | + TextInput::make('expire') |
| 82 | + ->label('Expirar em minutos') |
| 83 | + ->prefixIcon('fas-clock') |
| 84 | + ->numeric() |
| 85 | + ->required(), |
| 86 | + |
| 87 | + TextInput::make('keyword_finish') |
| 88 | + ->label('Palavra-chave de Finalização') |
| 89 | + ->prefixIcon('fas-arrow-right-from-bracket') |
| 90 | + ->required() |
| 91 | + ->maxLength(255), |
| 92 | + |
| 93 | + TextInput::make('delay_message') |
| 94 | + ->label('Atraso Padrão (Milisegundos)') |
| 95 | + ->prefixIcon('fas-clock') |
| 96 | + ->required() |
| 97 | + ->numeric(), |
| 98 | + |
| 99 | + TextInput::make('unknown_message') |
| 100 | + ->label('Mensagem Desconhecida') |
| 101 | + ->prefixIcon('fas-question') |
| 102 | + ->required() |
| 103 | + ->maxLength(30), |
| 104 | + |
| 105 | + TextInput::make('debounce_time') |
| 106 | + ->label('Tempo de Debounce') |
| 107 | + ->prefixIcon('fas-clock') |
| 108 | + ->required() |
| 109 | + ->numeric(), |
| 110 | + |
| 111 | + ])->columns(3), |
| 112 | + |
| 113 | + Section::make('Opções Gerais') |
| 114 | + ->schema([ |
| 115 | + |
| 116 | + ToggleButtons::make('listening_from_me') |
| 117 | + ->label('Ouvindo de mim') |
| 118 | + ->inline() |
| 119 | + ->boolean() |
| 120 | + ->required(), |
| 121 | + |
| 122 | + ToggleButtons::make('stop_bot_from_me') |
| 123 | + ->label('Parar bot por mim') |
| 124 | + ->inline() |
| 125 | + ->boolean() |
| 126 | + ->required(), |
| 127 | + |
| 128 | + ToggleButtons::make('keep_open') |
| 129 | + ->label('Manter aberto') |
| 130 | + ->inline() |
| 131 | + ->boolean() |
| 132 | + ->required(), |
| 133 | + |
| 134 | + ])->columns(3), |
| 135 | + |
| 136 | + ]); |
| 137 | + } |
| 138 | + |
| 139 | + public function table(Table $table): Table |
| 140 | + { |
| 141 | + return $table |
| 142 | + ->columns([ |
| 143 | + |
| 144 | + TextColumn::make('name') |
| 145 | + ->label('Descrição do'), |
| 146 | + |
| 147 | + TextColumn::make('url') |
| 148 | + ->label('URL'), |
| 149 | + |
| 150 | + TextColumn::make('type_bot') |
| 151 | + ->label('Codigo do Typebot'), |
| 152 | + |
| 153 | + TextColumn::make('id_typebot') |
| 154 | + ->label('Id do Bot'), |
| 155 | + |
| 156 | + ToggleColumn::make('is_active') |
| 157 | + ->label('Ativo') |
| 158 | + ->alignCenter(), |
| 159 | + |
| 160 | + ]) |
| 161 | + ->filters([ |
| 162 | + // |
| 163 | + ]) |
| 164 | + ->headerActions([ |
| 165 | + Tables\Actions\CreateAction::make(), |
| 166 | + ]) |
| 167 | + ->actions([ |
| 168 | + Tables\Actions\EditAction::make(), |
| 169 | + Tables\Actions\DeleteAction::make(), |
| 170 | + ]) |
| 171 | + ->bulkActions([ |
| 172 | + Tables\Actions\BulkActionGroup::make([ |
| 173 | + Tables\Actions\DeleteBulkAction::make(), |
| 174 | + ]), |
| 175 | + ]); |
| 176 | + } |
| 177 | +} |
0 commit comments