Initial commit: SuiviCPT personal finance tracker
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>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Livewire\Household;
|
||||
|
||||
use App\Models\Household;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
|
||||
#[Layout('layouts.guest')]
|
||||
class Create extends Component
|
||||
{
|
||||
public string $name = '';
|
||||
|
||||
public function create(): void
|
||||
{
|
||||
$this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$user = auth()->user();
|
||||
|
||||
$household = Household::create([
|
||||
'name' => $this->name,
|
||||
'owner_id' => $user->id,
|
||||
]);
|
||||
|
||||
$user->households()->attach($household->id, ['role' => 'owner']);
|
||||
$user->forceFill(['current_household_id' => $household->id])->save();
|
||||
|
||||
$this->redirect(route('dashboard', absolute: false), navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.household.create');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user