You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConfigureCompanyDefault.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Listeners;
  3. use App\Enums\DateFormat;
  4. use App\Enums\Font;
  5. use App\Enums\ModalWidth;
  6. use App\Enums\PrimaryColor;
  7. use App\Enums\RecordsPerPage;
  8. use App\Enums\TableSortDirection;
  9. use App\Enums\WeekStart;
  10. use App\Events\CompanyConfigured;
  11. use App\Utilities\Currency\ConfigureCurrencies;
  12. use Filament\Actions\MountableAction;
  13. use Filament\Facades\Filament;
  14. use Filament\Forms\Components\DatePicker;
  15. use Filament\Forms\Components\Section;
  16. use Filament\Forms\Components\Tabs\Tab;
  17. use Filament\Resources\Components\Tab as ResourcesTab;
  18. use Filament\Support\Facades\FilamentColor;
  19. use Filament\Tables\Table;
  20. class ConfigureCompanyDefault
  21. {
  22. /**
  23. * Handle the event.
  24. */
  25. public function handle(CompanyConfigured $event): void
  26. {
  27. $company = $event->company;
  28. $paginationPageOptions = RecordsPerPage::caseValues();
  29. $defaultPaginationPageOption = $company->appearance->records_per_page->value ?? RecordsPerPage::DEFAULT;
  30. $defaultSort = $company->appearance->table_sort_direction->value ?? TableSortDirection::DEFAULT;
  31. $stripedTables = $company->appearance->is_table_striped ?? false;
  32. $defaultPrimaryColor = $company->appearance->primary_color ?? PrimaryColor::from(PrimaryColor::DEFAULT);
  33. $modalWidth = $company->appearance->modal_width->value ?? ModalWidth::DEFAULT;
  34. $defaultFont = $company->appearance->font->value ?? Font::DEFAULT;
  35. $default_language = $company->locale->language ?? config('transmatic.source_locale');
  36. $defaultTimezone = $company->locale->timezone ?? config('app.timezone');
  37. $dateFormat = $company->locale->date_format->value ?? DateFormat::DEFAULT;
  38. $weekStart = $company->locale->week_start->value ?? WeekStart::DEFAULT;
  39. app()->setLocale($default_language);
  40. locale_set_default($default_language);
  41. config(['app.timezone' => $defaultTimezone]);
  42. date_default_timezone_set($defaultTimezone);
  43. Table::configureUsing(static function (Table $table) use ($paginationPageOptions, $defaultSort, $stripedTables, $defaultPaginationPageOption): void {
  44. $table
  45. ->paginationPageOptions($paginationPageOptions)
  46. ->defaultSort(column: 'id', direction: $defaultSort)
  47. ->striped($stripedTables)
  48. ->defaultPaginationPageOption($defaultPaginationPageOption);
  49. }, isImportant: true);
  50. MountableAction::configureUsing(static function (MountableAction $action) use ($modalWidth): void {
  51. $actionOperation = $action->getName();
  52. if (in_array($actionOperation, ['delete', 'restore', 'forceDelete', 'detach'])) {
  53. $action->modalWidth($modalWidth);
  54. }
  55. }, isImportant: true);
  56. FilamentColor::register([
  57. 'primary' => $defaultPrimaryColor->getColor(),
  58. ]);
  59. Filament::getPanel('company')
  60. ->font($defaultFont)
  61. ->brandName($company->name);
  62. DatePicker::configureUsing(static function (DatePicker $component) use ($dateFormat, $weekStart) {
  63. $component
  64. ->displayFormat($dateFormat)
  65. ->firstDayOfWeek($weekStart);
  66. });
  67. Tab::configureUsing(static function (Tab $tab) {
  68. $label = $tab->getLabel();
  69. $translatedLabel = translate($label);
  70. $tab->label(ucwords($translatedLabel));
  71. }, isImportant: true);
  72. Section::configureUsing(static function (Section $section): void {
  73. $heading = $section->getHeading();
  74. $translatedHeading = translate($heading);
  75. $section->heading(ucfirst($translatedHeading));
  76. }, isImportant: true);
  77. ResourcesTab::configureUsing(static function (ResourcesTab $tab): void {
  78. $tab->localizeLabel();
  79. }, isImportant: true);
  80. ConfigureCurrencies::syncCurrencies();
  81. }
  82. }