ui(plans): disable-on-submit for inline status/publish forms
This commit is contained in:
@@ -270,9 +270,9 @@
|
|||||||
<a href="{!! $renewalMissingSubscriptionUrl !!}" class="btn btn-secondary btn-sm">续费缺订阅</a>
|
<a href="{!! $renewalMissingSubscriptionUrl !!}" class="btn btn-secondary btn-sm">续费缺订阅</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="post" action="/admin/plans/{{ $plan->id }}/set-status" class="mt-6 actions gap-10">
|
<form method="post" action="/admin/plans/{{ $plan->id }}/set-status" class="mt-6 actions gap-10" data-action="disable-on-submit">
|
||||||
@csrf
|
@csrf
|
||||||
<select name="status" onchange="this.form.submit()" class="w-140">
|
<select name="status" onchange="this.form.submit()" class="w-140" data-role="plan-set-status">
|
||||||
@foreach(($filterOptions['statuses'] ?? []) as $value => $label)
|
@foreach(($filterOptions['statuses'] ?? []) as $value => $label)
|
||||||
<option value="{{ $value }}" @selected($plan->status === $value)>{{ $label }}</option>
|
<option value="{{ $value }}" @selected($plan->status === $value)>{{ $label }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
@@ -280,10 +280,10 @@
|
|||||||
<noscript><button type="submit" class="btn btn-secondary btn-sm">更新状态</button></noscript>
|
<noscript><button type="submit" class="btn btn-secondary btn-sm">更新状态</button></noscript>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form method="post" action="/admin/plans/{{ $plan->id }}/set-published" class="mt-6 actions gap-10">
|
<form method="post" action="/admin/plans/{{ $plan->id }}/set-published" class="mt-6 actions gap-10" data-action="disable-on-submit">
|
||||||
@csrf
|
@csrf
|
||||||
@php $isPublished = (bool) $plan->published_at; @endphp
|
@php $isPublished = (bool) $plan->published_at; @endphp
|
||||||
<select name="published" onchange="this.form.submit()" class="w-140">
|
<select name="published" onchange="this.form.submit()" class="w-140" data-role="plan-set-published">
|
||||||
<option value="1" @selected($isPublished)>已发布</option>
|
<option value="1" @selected($isPublished)>已发布</option>
|
||||||
<option value="0" @selected(!$isPublished)>未发布</option>
|
<option value="0" @selected(!$isPublished)>未发布</option>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Plan;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminPlanIndexSetStatusAndPublishedFormsShouldDisableOnSubmitTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function loginAsPlatformAdmin(): void
|
||||||
|
{
|
||||||
|
$this->seed();
|
||||||
|
|
||||||
|
$this->post('/admin/login', [
|
||||||
|
'email' => 'platform.admin@demo.local',
|
||||||
|
'password' => 'Platform@123456',
|
||||||
|
])->assertRedirect('/admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_plans_index_inline_forms_should_disable_on_submit(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
Plan::query()->create([
|
||||||
|
'code' => 'plan_inline_disable_submit_01',
|
||||||
|
'name' => '套餐行内表单禁用提交测试',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 9.9,
|
||||||
|
'list_price' => 9.9,
|
||||||
|
'status' => 'active',
|
||||||
|
'sort' => 1,
|
||||||
|
'published_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$res = $this->get('/admin/plans');
|
||||||
|
$res->assertOk();
|
||||||
|
|
||||||
|
$html = (string) $res->getContent();
|
||||||
|
|
||||||
|
$this->assertStringContainsString('data-role="plan-set-status"', $html);
|
||||||
|
$this->assertStringContainsString('data-role="plan-set-published"', $html);
|
||||||
|
|
||||||
|
// 两个表单都应启用 disable-on-submit 机制,避免重复提交。
|
||||||
|
$this->assertStringContainsString('action="/admin/plans/', $html);
|
||||||
|
$this->assertStringContainsString('data-action="disable-on-submit"', $html);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user