Initial commit: CABM-IT (ItGlue-style MSP documentation platform)
Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Contact;
|
||||
use App\Models\Organization;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public Organization $organization;
|
||||
public ?Contact $contact = null;
|
||||
|
||||
public string $first_name = '';
|
||||
public string $last_name = '';
|
||||
public string $title = '';
|
||||
public string $email = '';
|
||||
public string $phone = '';
|
||||
public string $mobile = '';
|
||||
public ?int $location_id = null;
|
||||
public bool $is_important = false;
|
||||
public string $notes = '';
|
||||
|
||||
public function mount(Organization $organization, ?Contact $contact = null): void
|
||||
{
|
||||
$this->organization = $organization;
|
||||
|
||||
if ($contact?->exists) {
|
||||
$this->contact = $contact;
|
||||
$this->first_name = $contact->first_name;
|
||||
$this->last_name = $contact->last_name;
|
||||
$this->title = $contact->title ?? '';
|
||||
$this->email = $contact->email ?? '';
|
||||
$this->phone = $contact->phone ?? '';
|
||||
$this->mobile = $contact->mobile ?? '';
|
||||
$this->location_id = $contact->location_id;
|
||||
$this->is_important = $contact->is_important;
|
||||
$this->notes = $contact->notes ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$validated = $this->validate([
|
||||
'first_name' => 'required|string|max:255',
|
||||
'last_name' => 'required|string|max:255',
|
||||
'title' => 'nullable|string|max:255',
|
||||
'email' => 'nullable|email|max:255',
|
||||
'phone' => 'nullable|string|max:255',
|
||||
'mobile' => 'nullable|string|max:255',
|
||||
'location_id' => 'nullable|exists:locations,id',
|
||||
'is_important' => 'boolean',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
if ($this->contact?->exists) {
|
||||
$this->contact->update($validated);
|
||||
session()->flash('status', "Contact \"{$this->contact->full_name}\" mis à jour.");
|
||||
} else {
|
||||
$this->organization->contacts()->create($validated);
|
||||
session()->flash('status', "Contact \"{$this->first_name} {$this->last_name}\" créé.");
|
||||
}
|
||||
|
||||
$this->redirectRoute('organizations.contacts.index', $this->organization, navigate: true);
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [
|
||||
'locations' => $this->organization->locations()->orderBy('name')->get(),
|
||||
];
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="max-w-2xl">
|
||||
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||
<h1 class="mb-6 text-2xl font-semibold text-slate-900">
|
||||
{{ $contact?->exists ? 'Modifier le contact' : 'Nouveau contact' }}
|
||||
</h1>
|
||||
|
||||
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Prénom</label>
|
||||
<input type="text" wire:model="first_name"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('first_name') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Nom</label>
|
||||
<input type="text" wire:model="last_name"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('last_name') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Titre</label>
|
||||
<input type="text" wire:model="title"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Site</label>
|
||||
<select wire:model="location_id"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
<option value="">—</option>
|
||||
@foreach ($locations as $location)
|
||||
<option value="{{ $location->id }}">{{ $location->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Email</label>
|
||||
<input type="email" wire:model="email"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('email') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Téléphone</label>
|
||||
<input type="text" wire:model="phone"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Mobile</label>
|
||||
<input type="text" wire:model="mobile"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Notes</label>
|
||||
<textarea wire:model="notes" rows="3"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
|
||||
</div>
|
||||
|
||||
<label class="flex items-center gap-2 text-sm text-slate-700">
|
||||
<input type="checkbox" wire:model="is_important" class="rounded border-slate-300">
|
||||
Contact important
|
||||
</label>
|
||||
|
||||
<div class="flex items-center gap-3 pt-2">
|
||||
<button type="submit"
|
||||
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||
Enregistrer
|
||||
</button>
|
||||
<a href="{{ route('organizations.contacts.index', $organization) }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Organization;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public Organization $organization;
|
||||
|
||||
#[Url]
|
||||
public string $search = '';
|
||||
|
||||
public function delete(int $contactId): void
|
||||
{
|
||||
$contact = $this->organization->contacts()->findOrFail($contactId);
|
||||
$contact->delete();
|
||||
|
||||
session()->flash('status', "Contact \"{$contact->full_name}\" supprimé.");
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [
|
||||
'contacts' => $this->organization->contacts()
|
||||
->with('location')
|
||||
->when($this->search, fn ($query) => $query->where(function ($q) {
|
||||
$q->where('first_name', 'like', "%{$this->search}%")
|
||||
->orWhere('last_name', 'like', "%{$this->search}%")
|
||||
->orWhere('email', 'like', "%{$this->search}%");
|
||||
}))
|
||||
->orderByDesc('is_important')
|
||||
->orderBy('last_name')
|
||||
->paginate(15),
|
||||
];
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div>
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||
<h1 class="text-2xl font-semibold text-slate-900">Contacts</h1>
|
||||
</div>
|
||||
<a href="{{ route('organizations.contacts.create', $organization) }}"
|
||||
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||
+ Nouveau contact
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<input type="text" wire:model.live.debounce.300ms="search" placeholder="Filtrer par nom ou email..."
|
||||
class="mb-4 w-full max-w-sm rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
|
||||
<div class="overflow-x-auto rounded border border-slate-200 bg-white">
|
||||
<table class="min-w-full divide-y divide-slate-200 text-sm">
|
||||
<thead class="bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500">
|
||||
<tr>
|
||||
<th class="px-4 py-3">Nom</th>
|
||||
<th class="px-4 py-3">Titre</th>
|
||||
<th class="px-4 py-3">Email</th>
|
||||
<th class="px-4 py-3">Téléphone</th>
|
||||
<th class="px-4 py-3">Site</th>
|
||||
<th class="px-4 py-3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100">
|
||||
@forelse ($contacts as $contact)
|
||||
<tr wire:key="contact-{{ $contact->id }}">
|
||||
<td class="px-4 py-3">
|
||||
<a href="{{ route('organizations.contacts.edit', [$organization, $contact]) }}"
|
||||
class="font-medium text-slate-900 hover:underline">
|
||||
{{ $contact->full_name }}
|
||||
</a>
|
||||
@if ($contact->is_important)
|
||||
<span class="ml-2 rounded-full bg-amber-100 px-2 py-0.5 text-xs font-medium text-amber-700">Important</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $contact->title ?? '—' }}</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $contact->email ?? '—' }}</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $contact->phone ?? '—' }}</td>
|
||||
<td class="px-4 py-3 text-slate-600">{{ $contact->location?->name ?? '—' }}</td>
|
||||
<td class="px-4 py-3 text-right whitespace-nowrap">
|
||||
<a href="{{ route('organizations.contacts.edit', [$organization, $contact]) }}" class="text-slate-500 hover:text-slate-900">Modifier</a>
|
||||
<button type="button"
|
||||
wire:click="delete({{ $contact->id }})"
|
||||
wire:confirm="Supprimer ce contact ? Cette action est irréversible."
|
||||
class="ml-3 text-red-500 hover:text-red-700">
|
||||
Supprimer
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="6" class="px-4 py-6 text-center text-slate-400">Aucun contact pour le moment.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
{{ $contacts->links() }}
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user