- Introduced `ApiErrorTranslator` to normalize and translate API error messages, providing clearer feedback in French. - Updated all Filament pages (Articles, Documents, Divers, Journaux, Tiers, TablesExplorer) to utilize the new error translation mechanism, improving user experience during API interactions. - Added validation for required fields before API calls, ensuring users receive immediate feedback when mandatory inputs are missing. - Implemented tracking properties to distinguish between "never searched" and "searched without results," enhancing the user interface. - Removed the obsolete `$results` property from the Articles page and added a new `$barcode` property to align with API requirements. - Updated documentation to reflect changes in API behavior and error handling, including new metadata returned by the `art_list` endpoint. - Added new tests to verify the functionality of the barcode handling and validation logic.
74 lines
1.9 KiB
PHP
74 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Exceptions\LogisticsApiException;
|
|
use App\Services\LogisticsService;
|
|
use App\Support\ApiErrorTranslator;
|
|
use Filament\Pages\Page;
|
|
use Filament\Support\Icons\Heroicon;
|
|
|
|
class Journaux extends Page
|
|
{
|
|
protected static string|\BackedEnum|null $navigationIcon = Heroicon::OutlinedBookOpen;
|
|
|
|
protected static ?string $navigationLabel = 'Journaux';
|
|
|
|
protected static ?string $title = 'Journaux';
|
|
|
|
protected static ?int $navigationSort = 4;
|
|
|
|
protected string $view = 'filament.pages.journaux';
|
|
|
|
public string $mode = 'read';
|
|
|
|
public string $select = '';
|
|
|
|
public int $results = 10;
|
|
|
|
public string $type = '';
|
|
|
|
public array $data = [];
|
|
|
|
public ?array $metadata = null;
|
|
|
|
public ?string $errorMessage = null;
|
|
|
|
public bool $hasSearched = false;
|
|
|
|
public function searchJournaux(): void
|
|
{
|
|
$this->errorMessage = null;
|
|
|
|
if (blank($this->type)) {
|
|
$this->errorMessage = 'Le champ type de journal (TYPE) est obligatoire.';
|
|
|
|
return;
|
|
}
|
|
|
|
$this->hasSearched = true;
|
|
|
|
try {
|
|
$service = app(LogisticsService::class);
|
|
|
|
$params = array_filter([
|
|
'select' => $this->select,
|
|
'results' => $this->results,
|
|
'TYPE' => $this->type,
|
|
]);
|
|
|
|
$response = $service->jnlList($params);
|
|
|
|
$this->data = $response['data'] ?? [];
|
|
$this->metadata = $response['metadata'] ?? null;
|
|
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
|
|
} catch (LogisticsApiException $e) {
|
|
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
|
|
$this->data = [];
|
|
} catch (\Throwable $e) {
|
|
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
|
|
$this->data = [];
|
|
}
|
|
}
|
|
}
|