Skip to content

Commit

Permalink
chore: refactored the code
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramkanakam87 committed Oct 7, 2024
1 parent f56ef21 commit 0dc5535
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/Filament/Dashboard/Resources/MoleculeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ public static function table(Table $table): Table
}),
])
->action(function (array $data, Molecule $record): void {
$record->active = ! $record->active;
$record->active ? $record->status = 'APPROVED' : $record->status = 'REVOKED';
self::saveComment($record, $data['reason']);
self::changeMoleculeStatus($record, $data['reason']);
})
->modalHidden(function (Molecule $record) {
return ! $record['active'];
Expand All @@ -144,9 +142,7 @@ public static function table(Table $table): Table
])
->action(function (array $data, Collection $records): void {
foreach ($records as $record) {
$record->active = ! $record->active;
$record->active ? $record->status = 'APPROVED' : $record->status = 'REVOKED';
self::saveComment($record, $data['reason']);
self::changeMoleculeStatus($record, $data['reason']);
}
})
// ->modalHidden(function (Molecule $record) {
Expand Down Expand Up @@ -210,8 +206,11 @@ public static function getNavigationBadge(): ?string
return Cache::get('stats.molecules');
}

public static function saveComment($record, $reason)
public static function changeMoleculeStatus($record, $reason)
{
$record->active = ! $record->active;
$record->active ? $record->status = 'APPROVED' : $record->status = 'REVOKED';

$record->comment = [[
'timestamp' => now(),
'changed_by' => auth()->user()->id,
Expand Down

0 comments on commit 0dc5535

Please sign in to comment.