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,143 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Location;
|
||||
use App\Models\Organization;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public Organization $organization;
|
||||
public ?Location $location = null;
|
||||
|
||||
public string $name = '';
|
||||
public string $address_line_1 = '';
|
||||
public string $address_line_2 = '';
|
||||
public string $city = '';
|
||||
public string $region = '';
|
||||
public string $postal_code = '';
|
||||
public string $country = '';
|
||||
public string $phone = '';
|
||||
public bool $is_primary = false;
|
||||
|
||||
public function mount(Organization $organization, ?Location $location = null): void
|
||||
{
|
||||
$this->organization = $organization;
|
||||
|
||||
if ($location?->exists) {
|
||||
$this->location = $location;
|
||||
$this->name = $location->name;
|
||||
$this->address_line_1 = $location->address_line_1 ?? '';
|
||||
$this->address_line_2 = $location->address_line_2 ?? '';
|
||||
$this->city = $location->city ?? '';
|
||||
$this->region = $location->region ?? '';
|
||||
$this->postal_code = $location->postal_code ?? '';
|
||||
$this->country = $location->country ?? '';
|
||||
$this->phone = $location->phone ?? '';
|
||||
$this->is_primary = $location->is_primary;
|
||||
}
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$validated = $this->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'address_line_1' => 'nullable|string|max:255',
|
||||
'address_line_2' => 'nullable|string|max:255',
|
||||
'city' => 'nullable|string|max:255',
|
||||
'region' => 'nullable|string|max:255',
|
||||
'postal_code' => 'nullable|string|max:255',
|
||||
'country' => 'nullable|string|max:255',
|
||||
'phone' => 'nullable|string|max:255',
|
||||
'is_primary' => 'boolean',
|
||||
]);
|
||||
|
||||
if ($validated['is_primary']) {
|
||||
$this->organization->locations()
|
||||
->when($this->location?->exists, fn ($query) => $query->whereKeyNot($this->location->id))
|
||||
->update(['is_primary' => false]);
|
||||
}
|
||||
|
||||
if ($this->location?->exists) {
|
||||
$this->location->update($validated);
|
||||
session()->flash('status', "Site \"{$this->location->name}\" mis à jour.");
|
||||
} else {
|
||||
$this->organization->locations()->create($validated);
|
||||
session()->flash('status', "Site \"{$this->name}\" créé.");
|
||||
}
|
||||
|
||||
$this->redirectRoute('organizations.locations.index', $this->organization, navigate: true);
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<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">
|
||||
{{ $location?->exists ? 'Modifier le site' : 'Nouveau site' }}
|
||||
</h1>
|
||||
|
||||
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Nom</label>
|
||||
<input type="text" wire:model="name"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('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">Adresse ligne 1</label>
|
||||
<input type="text" wire:model="address_line_1"
|
||||
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">Adresse ligne 2</label>
|
||||
<input type="text" wire:model="address_line_2"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Ville</label>
|
||||
<input type="text" wire:model="city"
|
||||
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">Région</label>
|
||||
<input type="text" wire:model="region"
|
||||
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">Code postal</label>
|
||||
<input type="text" wire:model="postal_code"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Pays</label>
|
||||
<input type="text" wire:model="country"
|
||||
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">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="flex items-center gap-2 text-sm text-slate-700">
|
||||
<input type="checkbox" wire:model="is_primary" class="rounded border-slate-300">
|
||||
Site principal
|
||||
</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.locations.index', $organization) }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user