diff --git a/app/Livewire/ConfirmCancelPackage.php b/app/Livewire/ConfirmCancelPackage.php index d79f27f..57a0fee 100644 --- a/app/Livewire/ConfirmCancelPackage.php +++ b/app/Livewire/ConfirmCancelPackage.php @@ -19,11 +19,11 @@ class ConfirmCancelPackage extends ModalComponent public function cancelPackage() { $customer = $this->customer(); - $instance = $customer?->instances()->latest('id')->first(); + // Target the ACTIVE package explicitly — a newer failed/deprovisioned + // record must not shadow an older active instance (v1: one active/customer). + $instance = $customer?->instances()->where('status', 'active')->latest('id')->first(); - // Only an active package can be cancelled — never resurrect an already - // cancelled/deprovisioned/scheduled instance. - if ($instance === null || $instance->status !== 'active') { + if ($instance === null) { return $this->redirectRoute('settings', navigate: true); } @@ -74,7 +74,7 @@ class ConfirmCancelPackage extends ModalComponent public function render() { - $instance = $this->customer()?->instances()->latest('id')->first(); + $instance = $this->customer()?->instances()->where('status', 'active')->latest('id')->first(); return view('livewire.confirm-cancel-package', [ 'subdomain' => $instance?->subdomain ?? '', diff --git a/app/Livewire/Settings.php b/app/Livewire/Settings.php index b5df2e3..824dcad 100644 --- a/app/Livewire/Settings.php +++ b/app/Livewire/Settings.php @@ -150,15 +150,19 @@ class Settings extends Component public function render() { $c = $this->customer(); - $instance = $c?->instances()->latest('id')->first(); + // Prefer the active/cancelling instance for the package section so the + // controls line up with what cancellation actually targets. + $active = $c?->instances()->where('status', 'active')->latest('id')->first(); + $scheduled = $c?->instances()->where('status', 'cancellation_scheduled')->latest('id')->first(); + $instance = $active ?? $scheduled ?? $c?->instances()->latest('id')->first(); return view('livewire.settings', [ 'customer' => $c, 'instance' => $instance, 'branding' => $c?->brandingResolved(), 'logoUrl' => $this->brandLogoPath ? Storage::disk('public')->url($this->brandLogoPath) : null, - 'hasActivePackage' => $instance !== null && ! in_array($instance->status, ['cancelled', 'deprovisioned'], true), - 'cancellationScheduled' => $instance !== null && $instance->status === 'cancellation_scheduled', + 'hasActivePackage' => $active !== null, + 'cancellationScheduled' => $active === null && $scheduled !== null, ]); } }