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>
78 lines
2.0 KiB
PHP
78 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Livewire\Household;
|
|
|
|
use App\Mail\HouseholdInviteMail;
|
|
use App\Models\HouseholdInvite;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Str;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.app')]
|
|
class Settings extends Component
|
|
{
|
|
public string $inviteEmail = '';
|
|
|
|
public string $inviteRole = 'member';
|
|
|
|
public function invite(): void
|
|
{
|
|
$household = auth()->user()->currentHousehold;
|
|
|
|
$this->authorize('manageMembers', $household);
|
|
|
|
$this->validate([
|
|
'inviteEmail' => ['required', 'email', 'max:255'],
|
|
'inviteRole' => ['required', 'in:owner,member'],
|
|
]);
|
|
|
|
$invite = HouseholdInvite::create([
|
|
'household_id' => $household->id,
|
|
'invited_by' => auth()->id(),
|
|
'email' => $this->inviteEmail,
|
|
'token' => Str::random(48),
|
|
'role' => $this->inviteRole,
|
|
'expires_at' => now()->addDays(7),
|
|
]);
|
|
|
|
Mail::to($this->inviteEmail)->send(new HouseholdInviteMail($invite));
|
|
|
|
$this->reset('inviteEmail');
|
|
$this->dispatch('invite-sent');
|
|
}
|
|
|
|
public function revokeInvite(int $inviteId): void
|
|
{
|
|
$household = auth()->user()->currentHousehold;
|
|
|
|
$this->authorize('manageMembers', $household);
|
|
|
|
$household->invites()->whereKey($inviteId)->whereNull('accepted_at')->delete();
|
|
}
|
|
|
|
public function removeMember(int $userId): void
|
|
{
|
|
$household = auth()->user()->currentHousehold;
|
|
|
|
$this->authorize('manageMembers', $household);
|
|
|
|
if ($userId === $household->owner_id) {
|
|
return;
|
|
}
|
|
|
|
$household->members()->detach($userId);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$household = auth()->user()->currentHousehold()->with(['members', 'invites' => fn ($q) => $q->whereNull('accepted_at')])->first();
|
|
|
|
return view('livewire.household.settings', [
|
|
'household' => $household,
|
|
]);
|
|
}
|
|
}
|