Merge pull request #18128 from marcusmoore/fixes/17738-category-edit-form-fix
Fixed #17738 - accurately represent checkbox on category edit screen
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
</label>
|
||||
@if ($this->shouldDisplayEmailMessage)
|
||||
@if ($this->emailWillBeSendDueToEula)
|
||||
<div class="callout callout-info">
|
||||
<i class="far fa-envelope"></i>
|
||||
<span>{{ $this->emailMessage }}</span>
|
||||
</div>
|
||||
@endif
|
||||
@if ($this->sendCheckInEmailDisabled)
|
||||
<input type="hidden" name="checkin_email" wire:model.live="sendCheckInEmail" />
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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, [
|
||||
|
||||
Reference in New Issue
Block a user