Laravel 11 + Livewire 3/Volt + Alpine.js + Tailwind app for household budget planning, transaction tracking, and financial dashboards. - Multi-tenant households with member invites - Plan: monthly/yearly budget per category with overrides - Suivi: transaction log with running balance (desktop + mobile quick-entry) - Dashboard: budget vs tracked breakdown + Chart.js donuts - Flux: Sankey diagram of income allocation - WCAG 2.1 AA color tokens, dark mode, accessible tables/forms - 50 Pest tests Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Livewire\Household;
|
|
|
|
use App\Models\HouseholdInvite;
|
|
use App\Models\User;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.guest')]
|
|
class AcceptInvite extends Component
|
|
{
|
|
public string $token;
|
|
|
|
public ?HouseholdInvite $invite = null;
|
|
|
|
public bool $invalid = false;
|
|
|
|
public function mount(string $token): void
|
|
{
|
|
$this->token = $token;
|
|
|
|
$invite = HouseholdInvite::with('household')->where('token', $token)->first();
|
|
|
|
if (! $invite || $invite->isExpired() || $invite->isAccepted()) {
|
|
$this->invalid = true;
|
|
|
|
return;
|
|
}
|
|
|
|
$this->invite = $invite;
|
|
|
|
$existingUser = User::where('email', $invite->email)->first();
|
|
|
|
if ($existingUser && auth()->check() && auth()->id() === $existingUser->id) {
|
|
$this->accept();
|
|
}
|
|
}
|
|
|
|
public function accept(): void
|
|
{
|
|
if (! $this->invite || ! auth()->check()) {
|
|
return;
|
|
}
|
|
|
|
$user = auth()->user();
|
|
|
|
if ($user->email !== $this->invite->email) {
|
|
$this->invalid = true;
|
|
|
|
return;
|
|
}
|
|
|
|
$user->households()->syncWithoutDetaching([
|
|
$this->invite->household_id => ['role' => $this->invite->role],
|
|
]);
|
|
|
|
$this->invite->update(['accepted_at' => now()]);
|
|
$user->forceFill(['current_household_id' => $this->invite->household_id])->save();
|
|
|
|
$this->redirect(route('dashboard', absolute: false), navigate: true);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.household.accept-invite');
|
|
}
|
|
}
|