diff --git a/app/Livewire/CategoryEditForm.php b/app/Livewire/CategoryEditForm.php index 98e505c8df..6f5a42b9b2 100644 --- a/app/Livewire/CategoryEditForm.php +++ b/app/Livewire/CategoryEditForm.php @@ -2,6 +2,7 @@ namespace App\Livewire; +use Livewire\Attributes\Computed; use Livewire\Component; class CategoryEditForm extends Component @@ -12,43 +13,25 @@ class CategoryEditForm extends Component public $eulaText; - public $originalSendCheckInEmailValue; - public bool $requireAcceptance; public bool $sendCheckInEmail; public bool $useDefaultEula; - public function mount() - { - $this->originalSendCheckInEmailValue = $this->sendCheckInEmail; - - if ($this->eulaText || $this->useDefaultEula) { - $this->sendCheckInEmail = 1; - } - } - public function render() { return view('livewire.category-edit-form'); } - public function updated($property, $value) - { - if (! in_array($property, ['eulaText', 'useDefaultEula'])) { - return; - } - - $this->sendCheckInEmail = $this->eulaText || $this->useDefaultEula ? 1 : $this->originalSendCheckInEmailValue; - } - - public function getShouldDisplayEmailMessageProperty(): bool + #[Computed] + public function emailWillBeSendDueToEula(): bool { return $this->eulaText || $this->useDefaultEula; } - public function getEmailMessageProperty(): string + #[Computed] + public function emailMessage(): string { if ($this->useDefaultEula) { return trans('admin/categories/general.email_will_be_sent_due_to_global_eula'); @@ -57,13 +40,9 @@ class CategoryEditForm extends Component return trans('admin/categories/general.email_will_be_sent_due_to_category_eula'); } - public function getEulaTextDisabledProperty() + #[Computed] + public function eulaTextDisabled() { return (bool)$this->useDefaultEula; } - - public function getSendCheckInEmailDisabledProperty() - { - return $this->eulaText || $this->useDefaultEula; - } } diff --git a/resources/lang/en-US/admin/categories/general.php b/resources/lang/en-US/admin/categories/general.php index 4d036996ac..ac90a98939 100644 --- a/resources/lang/en-US/admin/categories/general.php +++ b/resources/lang/en-US/admin/categories/general.php @@ -3,14 +3,15 @@ return array( 'asset_categories' => 'Asset Categories', 'category_name' => 'Category Name', - 'checkin_email' => 'Send email to user on checkin/checkout.', + 'email_to_user_upon_checkin' => 'Send email to user upon checkin.', + 'email_to_user_upon_checkin_and_checkout' => 'Send email to user upon checkin/checkout.', 'email_to_initiator' => 'Send email to you when user accepts or declines checkout.', 'checkin_email_notification' => 'This user will be sent an email on checkin/checkout.', 'clone' => 'Clone Category', 'create' => 'Create Category', 'edit' => 'Edit Category', - 'email_will_be_sent_due_to_global_eula' => 'An email will be sent to the user because the global EULA is being used.', - 'email_will_be_sent_due_to_category_eula' => 'An email will be sent to the user because a EULA is set for this category.', + 'email_will_be_sent_due_to_global_eula' => 'An email will be sent to the user upon checkout because the global EULA is being used.', + 'email_will_be_sent_due_to_category_eula' => 'An email will be sent to the user upon checkout because a EULA is set for this category.', 'eula_text' => 'Category EULA', 'eula_text_help' => 'This field allows you to customize your EULAs for specific types of assets. If you only have one EULA for all of your assets, you can check the box below to use the primary default.', 'name' => 'Category Name', diff --git a/resources/views/livewire/category-edit-form.blade.php b/resources/views/livewire/category-edit-form.blade.php index aee6fe63ed..105685b3d3 100644 --- a/resources/views/livewire/category-edit-form.blade.php +++ b/resources/views/livewire/category-edit-form.blade.php @@ -90,19 +90,19 @@ value="1" wire:model.live="sendCheckInEmail" aria-label="checkin_email" - @disabled($this->sendCheckInEmailDisabled) /> - {{ trans('admin/categories/general.checkin_email') }} + @if ($this->emailWillBeSendDueToEula) + {{ trans('admin/categories/general.email_to_user_upon_checkin') }} + @else + {{ trans('admin/categories/general.email_to_user_upon_checkin_and_checkout') }} + @endif - @if ($this->shouldDisplayEmailMessage) + @if ($this->emailWillBeSendDueToEula)
{{ $this->emailMessage }}
@endif - @if ($this->sendCheckInEmailDisabled) - - @endif diff --git a/tests/Feature/Livewire/CategoryEditFormTest.php b/tests/Feature/Livewire/CategoryEditFormTest.php index 4596af120a..1bc0448917 100644 --- a/tests/Feature/Livewire/CategoryEditFormTest.php +++ b/tests/Feature/Livewire/CategoryEditFormTest.php @@ -16,87 +16,6 @@ class CategoryEditFormTest extends TestCase ])->assertStatus(200); } - public function testSendEmailCheckboxIsCheckedOnLoadWhenSendEmailIsExistingSetting() - { - Livewire::test(CategoryEditForm::class, [ - 'sendCheckInEmail' => true, - 'eulaText' => '', - 'useDefaultEula' => false, - ])->assertSet('sendCheckInEmail', true); - } - - public function testSendEmailCheckboxIsCheckedOnLoadWhenCategoryEulaSet() - { - Livewire::test(CategoryEditForm::class, [ - 'sendCheckInEmail' => false, - 'eulaText' => 'Some Content', - 'useDefaultEula' => false, - ])->assertSet('sendCheckInEmail', true); - } - - public function testSendEmailCheckboxIsCheckedOnLoadWhenUsingDefaultEula() - { - Livewire::test(CategoryEditForm::class, [ - 'sendCheckInEmail' => false, - 'eulaText' => '', - 'useDefaultEula' => true, - ])->assertSet('sendCheckInEmail', true); - } - - public function testSendEmailCheckBoxIsUncheckedOnLoadWhenSendEmailIsFalseNoCategoryEulaSetAndNotUsingDefaultEula() - { - Livewire::test(CategoryEditForm::class, [ - 'sendCheckInEmail' => false, - 'eulaText' => '', - 'useDefaultEula' => false, - ])->assertSet('sendCheckInEmail', false); - } - - public function testSendEmailCheckboxIsCheckedWhenCategoryEulaEntered() - { - Livewire::test(CategoryEditForm::class, [ - 'sendCheckInEmail' => false, - 'useDefaultEula' => false, - ])->assertSet('sendCheckInEmail', false) - ->set('eulaText', 'Some Content') - ->assertSet('sendCheckInEmail', true); - } - - public function testSendEmailCheckboxCheckedAndDisabledAndEulaTextDisabledWhenUseDefaultEulaSelected() - { - Livewire::test(CategoryEditForm::class, [ - 'sendCheckInEmail' => false, - 'useDefaultEula' => false, - ])->assertSet('sendCheckInEmail', false) - ->set('useDefaultEula', true) - ->assertSet('sendCheckInEmail', true) - ->assertSet('eulaTextDisabled', true) - ->assertSet('sendCheckInEmailDisabled', true); - } - - public function testSendEmailCheckboxEnabledAndSetToOriginalValueWhenNoCategoryEulaAndNotUsingGlobalEula() - { - Livewire::test(CategoryEditForm::class, [ - 'eulaText' => 'Some Content', - 'sendCheckInEmail' => false, - 'useDefaultEula' => true, - ]) - ->set('useDefaultEula', false) - ->set('eulaText', '') - ->assertSet('sendCheckInEmail', false) - ->assertSet('sendCheckInEmailDisabled', false); - - Livewire::test(CategoryEditForm::class, [ - 'eulaText' => 'Some Content', - 'sendCheckInEmail' => true, - 'useDefaultEula' => true, - ]) - ->set('useDefaultEula', false) - ->set('eulaText', '') - ->assertSet('sendCheckInEmail', true) - ->assertSet('sendCheckInEmailDisabled', false); - } - public function testEulaFieldEnabledOnLoadWhenNotUsingDefaultEula() { Livewire::test(CategoryEditForm::class, [