Prompt: when user logs in for the first time, they should see a modal asking to create an organization (only name input for organization). Keep the design similar to homepage/login/register in terms of color scheme. User should not be able to delete ALL organization they have, to have at least one is mendatory

Session:
Total cost:            $5.44 (costs may be inaccurate due to usage of unknown models)
Total duration (API):  50m 49s
Total duration (wall): 1h 10m 53s
Total code changes:    2972 lines added, 29 lines removed

Usage by model:
qwen/qwen3.6-35b-a3b:  287.3k input, 69.6k output, 11.5m cache read, 0 cache write ($5.37)
claude-haiku-4-5:  9.4k input, 13.3k output, 8.3k cache read, 0 cache write ($0.0767)

Runtime: llamacpp
Model: Qwen 3.6 35B A3B Q4 K M
Coding Agent: ClaudeCode
This commit is contained in:
Darius Rapalis
2026-04-29 11:15:16 +03:00
parent 8e65638401
commit b4b2fd8c1e
11 changed files with 2476 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Http\Controllers;
use App\Models\Organization;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class OrganizationController extends Controller
{
public function show(Organization $organization)
{
abort_unless($organization->user_id === auth()->id(), 403);
return view('organizations.show', compact('organization'));
}
public function store(Request $request): JsonResponse|RedirectResponse
{
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
]);
$user = Auth::user();
$user->organizations()->create(['name' => $validated['name']]);
$user->update(['has_organization' => true]);
return response()->json([
'redirect' => route('dashboard'),
'message' => 'Organization created successfully.',
]);
}
public function switch(Organization $organization)
{
abort_unless($organization->user_id === auth()->id(), 403);
auth()->user()->update(['current_organization_id' => $organization->id]);
return redirect()->route('organizations.show', $organization);
}
public function destroy(Organization $organization): JsonResponse|RedirectResponse
{
$user = Auth::user();
if ($organization->user_id !== $user->id) {
return response()->json(['error' => 'Unauthorized'], 403);
}
if ($user->organizations()->count() <= 1) {
return response()->json([
'error' => 'You must have at least one organization.',
]);
}
$organization->delete();
return response()->json([
'message' => 'Organization deleted.',
]);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Organization extends Model
{
use HasFactory;
protected $fillable = ['user_id', 'name'];
protected function casts(): array
{
return [
'id' => 'integer',
'user_id' => 'integer',
];
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

View File

@@ -3,20 +3,27 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Models\Organization;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
#[Fillable(['name', 'email', 'password'])]
#[Fillable(['name', 'email', 'password', 'has_organization', 'current_organization_id'])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable;
public function organizations(): HasMany
{
return $this->hasMany(Organization::class);
}
/**
* Get the attributes that should be cast.
*

View File

@@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('organizations', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('organizations');
}
};

View File

@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->boolean('has_organization')->default(false)->after('password');
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('has_organization');
});
}
};

View File

@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->foreignId('current_organization_id')->nullable()->constrained('organizations')->nullOnDelete();
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['current_organization_id']);
$table->dropColumn('current_organization_id');
});
}
};

View File

@@ -387,5 +387,171 @@
</div>
</div>
</div>
{{-- Organization creation modal --}}
<div id="org-modal" class="org-modal" style="display: {{ auth()->check() && !auth()->user()->has_organization ? 'flex' : 'none' }};">
<div class="org-modal-backdrop" data-close-modal></div>
<div class="org-modal-card">
<div class="org-modal__header">
<h2>Create your first organization</h2>
<p>Organizations help you group your projects and team members together.</p>
</div>
<div class="org-modal__body">
<div class="form-control">
<label for="org-name">Organization name</label>
<input type="text" id="org-name" name="name" placeholder="e.g. My Company" maxlength="255">
</div>
<p id="org-error" class="org-error" style="display:none;"></p>
</div>
<div class="org-modal__footer">
<button type="button" class="btn-cancel" data-close-modal>Cancel</button>
<button type="button" class="btn-primary" id="org-create-btn" onclick="createOrganization()">Create</button>
</div>
</div>
</div>
<script>
function createOrganization() {
const name = document.getElementById('org-name').value.trim();
const errorEl = document.getElementById('org-error');
const btn = document.getElementById('org-create-btn');
if (!name) {
errorEl.textContent = 'Please enter an organization name.';
errorEl.style.display = 'block';
return;
}
btn.textContent = 'Creating...';
btn.disabled = true;
errorEl.style.display = 'none';
fetch('{{ route("organizations.store") }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json'
},
body: JSON.stringify({ name: name })
})
.then(res => res.json())
.then(data => {
if (data.redirect) {
window.location.href = data.redirect;
} else if (data.errors) {
const messages = Object.values(data.errors).flat().join('\n');
errorEl.textContent = messages;
errorEl.style.display = 'block';
}
})
.catch(err => {
errorEl.textContent = 'Something went wrong. Please try again.';
errorEl.style.display = 'block';
})
.finally(() => {
btn.textContent = 'Create';
btn.disabled = false;
});
}
document.querySelectorAll('[data-close-modal]').forEach(el => {
el.addEventListener('click', () => {
document.getElementById('org-modal').style.display = 'none';
});
});
document.getElementById('org-name').addEventListener('input', function () {
document.getElementById('org-error').style.display = 'none';
});
document.getElementById('org-name').addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
e.preventDefault();
createOrganization();
}
});
</script>
<style>
.org-modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 200;
align-items: center;
justify-content: center;
}
.org-modal-backdrop {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
cursor: pointer;
}
.org-modal-card {
position: relative;
background: var(--bg-white);
border-radius: 8px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
width: 100%;
max-width: 400px;
padding: 32px;
z-index: 1;
}
.org-modal__header {
margin-bottom: 24px;
}
.org-modal__header h2 {
font-size: 20px;
font-weight: 700;
color: var(--text-dark);
margin-bottom: 6px;
}
.org-modal__header p {
font-size: 14px;
color: var(--text-medium);
line-height: 1.5;
}
.org-modal__body {
margin-bottom: 24px;
}
.org-modal__footer {
display: flex;
justify-content: flex-end;
gap: 12px;
}
.btn-cancel {
padding: 10px 20px;
font-size: 14px;
font-weight: 600;
font-family: inherit;
color: var(--text-medium);
background: var(--bg-light);
border: 1px solid var(--border-color);
border-radius: 8px;
cursor: pointer;
transition: background-color 0.15s;
}
.btn-cancel:hover {
background: #e9e9ed;
}
.org-error {
color: var(--error-color);
font-size: 13px;
margin-top: 8px;
line-height: 1.4;
}
@media (max-width: 480px) {
.org-modal-card {
margin: 16px;
padding: 24px;
}
}
</style>
</body>
</html>

View File

@@ -357,5 +357,171 @@
</p>
</div>
</div>
{{-- Organization creation modal --}}
<div id="org-modal" class="org-modal" style="display: flex;">
<div class="org-modal-backdrop" data-close-modal></div>
<div class="org-modal-card">
<div class="org-modal__header">
<h2>Create your first organization</h2>
<p>Organizations help you group your projects and team members together.</p>
</div>
<div class="org-modal__body">
<div class="form-control">
<label for="org-name">Organization name</label>
<input type="text" id="org-name" name="name" placeholder="e.g. My Company" maxlength="255">
</div>
<p id="org-error" class="org-error" style="display:none;"></p>
</div>
<div class="org-modal__footer">
<button type="button" class="btn-cancel" data-close-modal>Cancel</button>
<button type="button" class="btn-primary" id="org-create-btn" onclick="createOrganization()">Create</button>
</div>
</div>
</div>
<script>
function createOrganization() {
const name = document.getElementById('org-name').value.trim();
const errorEl = document.getElementById('org-error');
const btn = document.getElementById('org-create-btn');
if (!name) {
errorEl.textContent = 'Please enter an organization name.';
errorEl.style.display = 'block';
return;
}
btn.textContent = 'Creating...';
btn.disabled = true;
errorEl.style.display = 'none';
fetch('{{ route("organizations.store") }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json'
},
body: JSON.stringify({ name: name })
})
.then(res => res.json())
.then(data => {
if (data.redirect) {
window.location.href = data.redirect;
} else if (data.errors) {
const messages = Object.values(data.errors).flat().join('\n');
errorEl.textContent = messages;
errorEl.style.display = 'block';
}
})
.catch(err => {
errorEl.textContent = 'Something went wrong. Please try again.';
errorEl.style.display = 'block';
})
.finally(() => {
btn.textContent = 'Create';
btn.disabled = false;
});
}
document.querySelectorAll('[data-close-modal]').forEach(el => {
el.addEventListener('click', () => {
document.getElementById('org-modal').style.display = 'none';
});
});
document.getElementById('org-name').addEventListener('input', function () {
document.getElementById('org-error').style.display = 'none';
});
document.getElementById('org-name').addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
e.preventDefault();
createOrganization();
}
});
</script>
<style>
.org-modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 200;
align-items: center;
justify-content: center;
}
.org-modal-backdrop {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
cursor: pointer;
}
.org-modal-card {
position: relative;
background: var(--bg-white);
border-radius: 8px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
width: 100%;
max-width: 400px;
padding: 32px;
z-index: 1;
}
.org-modal__header {
margin-bottom: 24px;
}
.org-modal__header h2 {
font-size: 20px;
font-weight: 700;
color: var(--text-dark);
margin-bottom: 6px;
}
.org-modal__header p {
font-size: 14px;
color: var(--text-medium);
line-height: 1.5;
}
.org-modal__body {
margin-bottom: 24px;
}
.org-modal__footer {
display: flex;
justify-content: flex-end;
gap: 12px;
}
.btn-cancel {
padding: 10px 20px;
font-size: 14px;
font-weight: 600;
font-family: inherit;
color: var(--text-medium);
background: var(--bg-light);
border: 1px solid var(--border-color);
border-radius: 8px;
cursor: pointer;
transition: background-color 0.15s;
}
.btn-cancel:hover {
background: #e9e9ed;
}
.org-error {
color: var(--error-color);
font-size: 13px;
margin-top: 8px;
line-height: 1.4;
}
@media (max-width: 480px) {
.org-modal-card {
margin: 16px;
padding: 24px;
}
}
</style>
</body>
</html>

View File

@@ -0,0 +1,363 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ $organization->name }} - TimeLog</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap" rel="stylesheet">
<style>
:root {
--primary: #03a9f4;
--primary-dark: #0287c5;
--text-dark: #333;
--text-medium: #546e7a;
--text-muted: #9ba8b0;
--bg-light: #f2f6f8;
--bg-white: #fff;
--border-color: #e9e9ed;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
color: var(--text-dark);
background: var(--bg-light);
min-height: 100vh;
}
.topbar {
background: var(--bg-white);
border-bottom: 1px solid var(--border-color);
padding: 12px 24px;
display: flex;
align-items: center;
justify-content: space-between;
}
.topbar .org-name {
font-size: 18px;
font-weight: 700;
color: var(--text-dark);
}
.topbar .logout {
font-size: 14px;
color: var(--primary);
text-decoration: none;
}
.topbar .logout:hover {
text-decoration: underline;
}
.dashboard {
max-width: 800px;
margin: 60px auto;
padding: 0 24px;
text-align: center;
}
.dashboard h1 {
font-size: 28px;
font-weight: 800;
margin-bottom: 8px;
}
.dashboard p {
font-size: 16px;
color: var(--text-medium);
margin-bottom: 32px;
}
.org-cards {
display: flex;
gap: 16px;
flex-wrap: wrap;
justify-content: center;
margin-bottom: 40px;
}
.org-card {
background: var(--bg-white);
border: 2px solid var(--primary);
border-radius: 8px;
padding: 20px 32px;
text-align: center;
}
.org-card h3 {
font-size: 16px;
font-weight: 600;
color: var(--text-dark);
}
.org-card .badge {
display: inline-block;
background: var(--primary);
color: white;
font-size: 11px;
font-weight: 600;
padding: 2px 8px;
border-radius: 4px;
margin-top: 6px;
}
.add-org-btn {
background: var(--bg-white);
border: 2px dashed var(--border-color);
border-radius: 8px;
padding: 20px 32px;
cursor: pointer;
transition: border-color 0.15s;
font-family: inherit;
font-size: 16px;
color: var(--text-medium);
}
.add-org-btn:hover {
border-color: var(--primary);
color: var(--primary);
}
.section-title {
font-size: 18px;
font-weight: 700;
color: var(--text-dark);
margin-bottom: 16px;
}
.org-list {
display: flex;
flex-direction: column;
gap: 8px;
max-width: 500px;
margin: 0 auto;
}
.org-list-item {
background: var(--bg-white);
border: 1px solid var(--border-color);
border-radius: 8px;
padding: 12px 16px;
display: flex;
align-items: center;
justify-content: space-between;
}
.org-list-item .name {
font-size: 14px;
font-weight: 600;
}
.org-list-item .actions {
display: flex;
align-items: center;
gap: 12px;
}
.org-list-item .switch-btn {
font-size: 13px;
color: var(--primary);
background: none;
border: none;
cursor: pointer;
font-family: inherit;
}
.org-list-item .switch-btn:hover {
text-decoration: underline;
}
.org-list-item .del-btn {
font-size: 13px;
color: var(--error-color, #bf2600);
background: none;
border: none;
cursor: pointer;
font-family: inherit;
}
.org-list-item .del-btn:hover {
text-decoration: underline;
}
@media (max-width: 768px) {
.dashboard { margin-top: 30px; }
}
</style>
</head>
<body>
<div class="topbar">
<span class="org-name">{{ $organization->name }}</span>
<a href="{{ url('/') }}" class="logout">Log out</a>
</div>
<div class="dashboard">
<h1>Welcome to TimeLog</h1>
<p>Start tracking time in your organization.</p>
<div class="org-cards">
<div class="org-card">
<h3>{{ $organization->name }}</h3>
<span class="badge">Current</span>
</div>
<button class="add-org-btn" onclick="document.getElementById('org-modal').style.display='flex'">+ Add organization</button>
</div>
<h3 class="section-title">Your organizations</h3>
<div class="org-list">
@foreach(auth()->user()->organizations as $org)
<div class="org-list-item">
<span class="name">{{ $org->name }}{{ $org->id === $organization->id ? ' (current)' : '' }}</span>
<span class="actions">
@if($org->id !== $organization->id)
<form method="POST" action="{{ route('organizations.show', $org) }}" style="display:inline;">
@method('PUT')
@csrf
<button type="submit" class="switch-btn">Switch</button>
</form>
@endif
@if(auth()->user()->organizations->count() > 1 && $org->id !== $organization->id)
<form method="POST" action="{{ route('organizations.destroy', $org) }}" onsubmit="return confirm('Delete this organization?');">
@csrf
@method('DELETE')
<button type="submit" class="del-btn">Delete</button>
</form>
@endif
</span>
</div>
@endforeach
</div>
</div>
<div id="org-modal" class="org-modal" style="display:none;">
<div class="org-modal-backdrop" data-close-modal></div>
<div class="org-modal-card">
<div class="org-modal__header">
<h2>Add an organization</h2>
</div>
<div class="org-modal__body">
<div class="form-control">
<label for="org-name">Organization name</label>
<input type="text" id="org-name" name="name" placeholder="e.g. My Company" maxlength="255">
</div>
<p id="org-error" class="org-error" style="display:none;"></p>
</div>
<div class="org-modal__footer">
<button type="button" class="btn-cancel" data-close-modal>Cancel</button>
<button type="button" class="btn-primary" id="org-create-btn" onclick="createOrganization()">Create</button>
</div>
</div>
</div>
<script>
function createOrganization() {
const name = document.getElementById('org-name').value.trim();
const errorEl = document.getElementById('org-error');
const btn = document.getElementById('org-create-btn');
if (!name) {
errorEl.textContent = 'Please enter an organization name.';
errorEl.style.display = 'block';
return;
}
btn.textContent = 'Creating...';
btn.disabled = true;
errorEl.style.display = 'none';
fetch('{{ route("organizations.store") }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json'
},
body: JSON.stringify({ name: name })
})
.then(res => res.json())
.then(data => {
if (data.redirect) {
window.location.href = data.redirect;
} else if (data.errors) {
const messages = Object.values(data.errors).flat().join('\n');
errorEl.textContent = messages;
errorEl.style.display = 'block';
}
})
.catch(err => {
errorEl.textContent = 'Something went wrong. Please try again.';
errorEl.style.display = 'block';
})
.finally(() => {
btn.textContent = 'Create';
btn.disabled = false;
});
}
document.querySelectorAll('[data-close-modal]').forEach(el => {
el.addEventListener('click', () => {
document.getElementById('org-modal').style.display = 'none';
});
});
document.getElementById('org-name').addEventListener('input', function () {
document.getElementById('org-error').style.display = 'none';
});
document.getElementById('org-name').addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
e.preventDefault();
createOrganization();
}
});
</script>
<style>
.org-modal {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
z-index: 200;
align-items: center;
justify-content: center;
}
.org-modal-backdrop {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0, 0, 0, 0.5);
cursor: pointer;
}
.org-modal-card {
position: relative;
background: var(--bg-white);
border-radius: 8px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
width: 100%;
max-width: 400px;
padding: 32px;
z-index: 1;
}
.org-modal__header { margin-bottom: 24px; }
.org-modal__header h2 { font-size: 20px; font-weight: 700; color: var(--text-dark); margin-bottom: 6px; }
.org-modal__body { margin-bottom: 24px; }
.org-modal__footer { display: flex; justify-content: flex-end; gap: 12px; }
.org-modal__footer .btn-primary {
padding: 10px 20px;
background: var(--primary);
color: white;
border: none;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
font-family: inherit;
}
.org-modal__footer .btn-cancel {
padding: 10px 20px;
font-size: 14px;
font-weight: 600;
font-family: inherit;
color: var(--text-medium);
background: var(--bg-light);
border: 1px solid var(--border-color);
border-radius: 8px;
cursor: pointer;
}
.form-control { margin-bottom: 16px; }
.form-control label { display: block; font-size: 12px; font-weight: 500; color: var(--text-medium); margin-bottom: 4px; }
.form-control input {
width: 100%;
height: 40px;
padding: 8px 12px;
font-size: 14px;
font-family: inherit;
border: 1px solid var(--border-color);
border-radius: 4px;
background: var(--bg-light);
outline: none;
}
.org-error { color: #bf2600; font-size: 13px; margin-top: 8px; line-height: 1.4; }
@media (max-width: 480px) {
.org-modal-card { margin: 16px; padding: 24px; }
}
</style>
</body>
</html>

View File

@@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\OrganizationController;
use Illuminate\Support\Facades\Route;
// Homepage
@@ -26,6 +27,31 @@ Route::post('/register', function () {
return redirect()->route('register');
})->name('register.post');
// Organization CRUD
Route::middleware('auth')->group(function () {
Route::post('/organizations', [OrganizationController::class, 'store'])->name('organizations.store');
Route::delete('/organizations/{organization}', [OrganizationController::class, 'destroy'])->name('organizations.destroy');
Route::put('/organizations/{organization}/switch', [OrganizationController::class, 'switch'])->name('organizations.switch');
});
// Dashboard (redirects to organizations if user has any, else login)
Route::get('/dashboard', function () {
if (!auth()->check()) {
return redirect()->route('login');
}
$user = auth()->user();
if ($user->has_organization && $user->organizations()->exists()) {
$org = $user->organizations()->first();
return redirect()->route('organizations.show', $org);
}
return view('home');
})->name('dashboard');
// Organization management
Route::middleware('auth')->group(function () {
Route::get('/organizations/{organization}', [OrganizationController::class, 'show'])->name('organizations.show');
});
// Feature pages
Route::get('/features/{feature}', function ($feature) {
return view('features.show', ['feature' => $feature]);