Skip to content

Commit fd32c9c

Browse files
style: Fix code style with Laravel Pint
1 parent 69767d7 commit fd32c9c

25 files changed

+1075
-32
lines changed

.env.example

+6
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,9 @@ STRIPE_SECRET=
7676
STRIPE_WEBHOOK_SECRET=
7777
STRIPE_DEVICE_NAME="${APP_NAME}"
7878

79+
#Keys Evolution API
80+
EVOLUTION_API_KEY= "KEY DE LOGIN GERADA NO ARQUIVO DA EVOLUTION"
81+
EVOLUTION_URL="ATENÇÃO SEU IP LOCAL "IP DA MAQUINA" :8080"
82+
EVOLUTION_URL_WEBHOOK="ATENÇÃO SEU IP LOCAL "IP DA MAQUINA" /evolution/webhook"
83+
84+

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ yarn-error.log
2121
/.nova
2222
/.vscode
2323
/.zed
24-
.docker
24+
.docker
25+
.docker-compose copy.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Enums\Evolution;
4+
5+
use Filament\Support\Contracts\{HasColor, HasLabel};
6+
7+
enum StatusConnectionEnum: string implements HasLabel, HasColor
8+
{
9+
case CLOSE = 'close';
10+
case OPEN = 'open';
11+
case CONNECTING = 'connecting';
12+
case REFUSED = 'refused';
13+
14+
public function getLabel(): string
15+
{
16+
return match ($this) {
17+
self::OPEN => 'Conectado',
18+
self::CONNECTING => 'Conectando',
19+
self::CLOSE => 'Desconectado',
20+
self::REFUSED => 'Recusado',
21+
};
22+
}
23+
public function getColor(): string|array|null
24+
{
25+
return match ($this) {
26+
self::OPEN => 'success',
27+
self::CONNECTING => 'warning',
28+
self::CLOSE => 'danger',
29+
self::REFUSED => 'danger',
30+
};
31+
}
32+
33+
34+
}

app/Filament/Admin/Resources/ProductResource.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@ public static function form(Form $form): Form
4343
TextInput::make('stripe_id')
4444
->label('Id Plano Stripe')
4545
->readOnly(),
46-
]),
4746

48-
Fieldset::make('Label')
49-
->schema([
5047
TextInput::make('name')
5148
->label('Nome do Plano')
5249
->required()
5350
->maxLength(255),
51+
5452
TextInput::make('description')
5553
->label('Descrição do Plano')
5654
->required()
5755
->maxLength(255),
58-
])->columns(2),
56+
57+
])->columns(3),
5958

6059
Fieldset::make('Imagem do Plano')
6160
->schema([
6261
FileUpload::make('image')
6362
->label('Imagem do Plano')
6463
->image()
65-
->imageEditor(),
64+
->imageEditor()
65+
->columnSpanFull(),
6666
]),
6767
]);
6868
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
<?php
2+
3+
namespace App\Filament\App\Resources;
4+
5+
use Exception;
6+
use Filament\Tables;
7+
use Filament\Forms\Form;
8+
use Filament\Tables\Table;
9+
use Filament\Facades\Filament;
10+
use App\Models\WhatsappInstance;
11+
use Filament\Resources\Resource;
12+
use Illuminate\Support\HtmlString;
13+
use Filament\Tables\Actions\Action;
14+
use Filament\Forms\Components\Section;
15+
use Filament\Tables\Actions\EditAction;
16+
use Filament\Tables\Actions\ViewAction;
17+
use Filament\Forms\Components\TextInput;
18+
use Filament\Notifications\Notification;
19+
use Filament\Tables\Actions\ActionGroup;
20+
use Filament\Tables\Actions\DeleteAction;
21+
use Illuminate\Database\Eloquent\Builder;
22+
use Filament\Forms\Components\ToggleButtons;
23+
use Leandrocfe\FilamentPtbrFormFields\PhoneNumber;
24+
use Illuminate\Database\Eloquent\SoftDeletingScope;
25+
use App\Filament\App\Resources\WhatsappInstanceResource\Pages;
26+
use App\Services\Evolution\Instance\DeleteEvolutionInstanceService;
27+
use App\Services\Evolution\Instance\LogOutEvolutionInstanceService;
28+
use App\Services\Evolution\Instance\ConnectEvolutionInstanceService;
29+
use App\Services\Evolution\Instance\RestartEvolutionInstanceService;
30+
use App\Filament\App\Resources\WhatsappInstanceResource\RelationManagers;
31+
32+
33+
class WhatsappInstanceResource extends Resource
34+
{
35+
protected static ?string $model = WhatsappInstance::class;
36+
37+
protected static ?string $navigationIcon = 'fab-whatsapp';
38+
39+
protected static ?string $navigationGroup = 'Administração';
40+
41+
protected static ?string $navigationLabel = 'Instâncias WhatsApp';
42+
43+
protected static ?string $modelLabel = 'Instâncias WhatsApp';
44+
45+
protected static ?string $modelLabelPlural = "Instâncias WhatsApp";
46+
47+
protected static ?int $navigationSort = 3;
48+
49+
protected static bool $isScopedToTenant = true;
50+
51+
public static function form(Form $form): Form
52+
{
53+
return $form
54+
->schema([
55+
Section::make('Dados da Instância')
56+
->schema([
57+
58+
TextInput::make('name')
59+
->label('Nome da Instância')
60+
->unique(WhatsappInstance::class, 'name', ignoreRecord: true)
61+
->default(fn () => Filament::getTenant()?->slug ?? '')
62+
->required()
63+
->prefixIcon('fas-id-card')
64+
->validationMessages([
65+
'unique' => 'Nome da instância já cadastrada.',
66+
])
67+
->maxLength(20),
68+
69+
PhoneNumber::make('number')
70+
->label('Número WhatsApp')
71+
->unique(WhatsappInstance::class, 'number', ignoreRecord: true)
72+
->mask('+55 (99) 99999-9999')
73+
->placeholder('+55 (99) 99999-9999')
74+
->required()
75+
->prefixIcon('fas-phone')
76+
->validationMessages([
77+
'unique' => 'Número já cadastrado.',
78+
]),
79+
80+
])->columns(2),
81+
82+
Section::make('Dados da Instância')
83+
->schema([
84+
ToggleButtons::make('groups_ignore')
85+
->label('Ignorar Grupos')
86+
->inline()
87+
->boolean()
88+
->required(),
89+
90+
ToggleButtons::make('always_online')
91+
->label('Status Sempre Online')
92+
->inline()
93+
->boolean()
94+
->required(),
95+
96+
ToggleButtons::make('read_messages')
97+
->label('Marcar Mensagens como Lidas')
98+
->inline()
99+
->boolean()
100+
->required(),
101+
102+
ToggleButtons::make('read_status')
103+
->label('Marcar Status como Lido')
104+
->inline()
105+
->boolean()
106+
->required(),
107+
108+
ToggleButtons::make('sync_full_history')
109+
->label('Sincronizar Histórico')
110+
->inline()
111+
->boolean()
112+
->required(),
113+
114+
ToggleButtons::make('reject_call')
115+
->label('Rejeitar Chamadas')
116+
->inline()
117+
->boolean()
118+
->live()
119+
->reactive()
120+
->required(),
121+
122+
TextInput::make('msg_call')
123+
->label('Mensagem para Chamadas Rejeitadas')
124+
->required()
125+
->hidden(fn ($get) => $get('reject_call') == false)
126+
->maxLength(255),
127+
128+
])->columns(4),
129+
]);
130+
}
131+
132+
public static function table(Table $table): Table
133+
{
134+
return $table
135+
->columns([
136+
Tables\Columns\TextColumn::make('status')
137+
->label('Status')
138+
->alignCenter()
139+
->badge()
140+
->searchable(),
141+
Tables\Columns\TextColumn::make('name')
142+
->label('Nome da Instância')
143+
->searchable(),
144+
Tables\Columns\TextColumn::make('number')
145+
->label('Número')
146+
->searchable(),
147+
Tables\Columns\TextColumn::make('instance_id')
148+
->label('ID da Instância')
149+
->searchable(),
150+
Tables\Columns\TextColumn::make('created_at')
151+
->dateTime()
152+
->sortable()
153+
->toggleable(isToggledHiddenByDefault: true),
154+
Tables\Columns\TextColumn::make('updated_at')
155+
->dateTime()
156+
->sortable()
157+
->toggleable(isToggledHiddenByDefault: true),
158+
])
159+
->filters([
160+
//
161+
])
162+
->actions([
163+
Action::make('showQr')
164+
->label('QR Code')
165+
->icon('heroicon-o-qr-code')
166+
->color('success')
167+
->modalHeading('Qr Code WhatsApp')
168+
->modalSubmitAction(false)
169+
->modalCancelAction(
170+
\Filament\Actions\Action::make('close')
171+
->label('FECHAR')
172+
->color('danger') // Cores: primary, secondary, success, danger, warning, gray
173+
->extraAttributes(['class' => 'w-full']) // Largura total
174+
->close()
175+
)
176+
->modalWidth('md') // ou sm, lg, xl, 2xl, 3xl, 4xl, 5xl, 6xl, 7xl
177+
->modalContent(fn ($record) => view('evolution.qr-code-modal', [
178+
'qrCode' => str_replace('\/', '/', $record->getRawOriginal('qr_code'))
179+
])),
180+
181+
ActionGroup::make([
182+
Action::make('RestartInstance')
183+
->label('Reconectar Instância')
184+
->icon('fas-sign-in-alt')
185+
->color('info')
186+
->action(function ($record) {
187+
$service = new ConnectEvolutionInstanceService();
188+
$response = $service->connectInstance($record->name);
189+
190+
if (isset($response['error'])) {
191+
Notification::make()
192+
->title('Erro ao reconectar')
193+
->danger()
194+
->send();
195+
} else {
196+
Notification::make()
197+
->title('Instância reconectada')
198+
->success()
199+
->send();
200+
}
201+
}),
202+
203+
ViewAction::make()
204+
->color('primary'),
205+
EditAction::make()
206+
->color('secondary'),
207+
DeleteAction::make()
208+
->action(function ($record) {
209+
210+
$service = new DeleteEvolutionInstanceService();
211+
$response = $service->deleteInstance($record->name);
212+
213+
// Deleta o registro local após sucesso na API
214+
$record->delete();
215+
216+
}),
217+
])
218+
->icon('fas-sliders')
219+
->color('warning'),
220+
])
221+
->bulkActions([
222+
223+
]);
224+
}
225+
226+
public static function getRelations(): array
227+
{
228+
return [
229+
//
230+
];
231+
}
232+
233+
public static function getPages(): array
234+
{
235+
return [
236+
'index' => Pages\ListWhatsappInstances::route('/'),
237+
'create' => Pages\CreateWhatsappInstance::route('/create'),
238+
'view' => Pages\ViewWhatsappInstance::route('/{record}'),
239+
'edit' => Pages\EditWhatsappInstance::route('/{record}/edit'),
240+
];
241+
}
242+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Filament\App\Resources\WhatsappInstanceResource\Pages;
4+
5+
use Filament\Resources\Pages\CreateRecord;
6+
use App\Filament\App\Resources\WhatsappInstanceResource;
7+
use App\Services\Evolution\Instance\CreateEvolutionInstanceService;
8+
9+
class CreateWhatsappInstance extends CreateRecord
10+
{
11+
protected static string $resource = WhatsappInstanceResource::class;
12+
13+
protected function mutateFormDataBeforeCreate(array $data): array
14+
{
15+
$service = new CreateEvolutionInstanceService();
16+
$result = $service->createInstance($data);
17+
18+
// Inclui os dados retornados no array de dados do formulário
19+
return array_merge($data, $result);
20+
}
21+
22+
protected function getRedirectUrl(): string
23+
{
24+
return $this->getResource()::getUrl('index');
25+
}
26+
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Filament\App\Resources\WhatsappInstanceResource\Pages;
4+
5+
use App\Filament\App\Resources\WhatsappInstanceResource;
6+
use Filament\Actions;
7+
use Filament\Resources\Pages\EditRecord;
8+
9+
class EditWhatsappInstance extends EditRecord
10+
{
11+
protected static string $resource = WhatsappInstanceResource::class;
12+
13+
protected function getHeaderActions(): array
14+
{
15+
return [
16+
Actions\ViewAction::make(),
17+
Actions\DeleteAction::make(),
18+
];
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Filament\App\Resources\WhatsappInstanceResource\Pages;
4+
5+
use App\Filament\App\Resources\WhatsappInstanceResource;
6+
use Filament\Actions;
7+
use Filament\Resources\Pages\ListRecords;
8+
9+
class ListWhatsappInstances extends ListRecords
10+
{
11+
protected static string $resource = WhatsappInstanceResource::class;
12+
13+
protected function getHeaderActions(): array
14+
{
15+
return [
16+
Actions\CreateAction::make(),
17+
];
18+
}
19+
}

0 commit comments

Comments
 (0)