Set the calendar's daily capacity in the company details
The task calendar's daily maximum moves from the hidden setting jobs.daily_capacity_hours to shared.daily_capacity_hours, edited by the admin on the company details page. An empty field means 7.5 hours. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -2,15 +2,18 @@
|
||||
|
||||
use App\Modules\Shared\Application\DTOs\CompanyDetails;
|
||||
use App\Modules\Shared\Application\UseCases\CompanyDetailsStore;
|
||||
use App\Modules\Shared\Application\UseCases\DailyCapacity;
|
||||
use App\Modules\Shared\Domain\Exceptions\CompanyNameRequired;
|
||||
use App\Modules\Shared\Domain\Exceptions\InvalidBusinessId;
|
||||
use App\Modules\Shared\Domain\Exceptions\InvalidDailyCapacity;
|
||||
use App\Modules\Shared\Domain\Exceptions\InvalidEmailAddress;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* The company's own details (Yritystiedot) for receipts and other
|
||||
* documents. Only admins change settings (spec 2).
|
||||
* documents, and the task calendar's daily capacity. Only admins change
|
||||
* settings (spec 2).
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
@@ -26,13 +29,17 @@ new class extends Component
|
||||
|
||||
public string $email = '';
|
||||
|
||||
public string $daily_capacity_hours = '';
|
||||
|
||||
#[Locked]
|
||||
public string $statusMessage = '';
|
||||
|
||||
public function mount(CompanyDetailsStore $store): void
|
||||
public function mount(CompanyDetailsStore $store, DailyCapacity $capacity): void
|
||||
{
|
||||
$this->authorize('settings.manage');
|
||||
|
||||
$this->daily_capacity_hours = $capacity->hours() ?? '';
|
||||
|
||||
$details = $store->get();
|
||||
|
||||
if ($details !== null) {
|
||||
@@ -45,7 +52,7 @@ new class extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function save(CompanyDetailsStore $store): void
|
||||
public function save(CompanyDetailsStore $store, DailyCapacity $capacity): void
|
||||
{
|
||||
$this->authorize('settings.manage');
|
||||
$this->statusMessage = '';
|
||||
@@ -57,6 +64,7 @@ new class extends Component
|
||||
'address' => ['nullable', 'string', 'max:500'],
|
||||
'phone' => ['nullable', 'string', 'max:50'],
|
||||
'email' => ['nullable', 'string', 'max:255'],
|
||||
'daily_capacity_hours' => ['nullable', 'string', 'max:10'],
|
||||
], [
|
||||
'name.required' => __('company.errors.name'),
|
||||
'name.max' => __('company.errors.name'),
|
||||
@@ -66,10 +74,22 @@ new class extends Component
|
||||
'address.max' => __('company.errors.address'),
|
||||
'phone.max' => __('company.errors.phone'),
|
||||
'email.max' => __('company.errors.email'),
|
||||
'daily_capacity_hours.max' => __('company.errors.daily_capacity_hours'),
|
||||
]);
|
||||
|
||||
if (! DailyCapacity::isValid($this->daily_capacity_hours)) {
|
||||
$this->addError('daily_capacity_hours', __('company.errors.daily_capacity_hours'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$store->save(new CompanyDetails($this->name, $this->business_id, $this->address, $this->phone, $this->email, $this->menu_name));
|
||||
$capacity->save($this->daily_capacity_hours);
|
||||
} catch (InvalidDailyCapacity) {
|
||||
$this->addError('daily_capacity_hours', __('company.errors.daily_capacity_hours'));
|
||||
|
||||
return;
|
||||
} catch (CompanyNameRequired) {
|
||||
$this->addError('name', __('company.errors.name'));
|
||||
|
||||
@@ -85,6 +105,7 @@ new class extends Component
|
||||
}
|
||||
|
||||
$this->business_id = (string) $store->get()?->businessId;
|
||||
$this->daily_capacity_hours = $capacity->hours() ?? '';
|
||||
$this->statusMessage = __('company.saved');
|
||||
}
|
||||
|
||||
@@ -111,6 +132,9 @@ new class extends Component
|
||||
<x-input wire:model="phone" type="tel" :label="__('company.fields.phone')" autocomplete="tel" />
|
||||
<x-input wire:model="email" type="email" :label="__('company.fields.email')" autocomplete="email" />
|
||||
|
||||
<h2 class="pt-2 text-lg font-semibold">{{ __('company.calendar_heading') }}</h2>
|
||||
<x-input wire:model="daily_capacity_hours" inputmode="decimal" :label="__('company.fields.daily_capacity_hours')" :hint="__('company.fields.daily_capacity_hours_hint')" autocomplete="off" />
|
||||
|
||||
<x-button submit :text="__('company.save')" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user