- Fiche d'identité par organisation (technicien référent, FAI, IP publiques, prestataires liés) accessible depuis un nouveau menu. - Nouveau module Prestataires dédié (catalogue léger réutilisable entre communes, avec journal de suivi des échanges) plutôt que de détourner les organisations de type "Fournisseur". - Nouveau menu Infrastructure par organisation avec schémas réseau/fonctionnel édités via draw.io embarqué (URL configurable, cf. réglages admin). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
218 lines
9.4 KiB
PHP
218 lines
9.4 KiB
PHP
<?php
|
|
|
|
use App\Models\Provider;
|
|
use App\Models\ProviderLogEntry;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Livewire\Component;
|
|
use Livewire\WithFileUploads;
|
|
|
|
new class extends Component
|
|
{
|
|
use WithFileUploads;
|
|
|
|
public ?Provider $provider = null;
|
|
|
|
public string $name = '';
|
|
public string $phone = '';
|
|
public string $email = '';
|
|
public string $website = '';
|
|
public string $notes = '';
|
|
|
|
public $logo = null;
|
|
|
|
public string $newLogCategory = 'contact';
|
|
public string $newLogNote = '';
|
|
|
|
public function mount(?Provider $provider = null): void
|
|
{
|
|
if ($provider?->exists) {
|
|
$this->provider = $provider;
|
|
$this->name = $provider->name;
|
|
$this->phone = $provider->phone ?? '';
|
|
$this->email = $provider->email ?? '';
|
|
$this->website = $provider->website ?? '';
|
|
$this->notes = $provider->notes ?? '';
|
|
}
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$validated = $this->validate([
|
|
'name' => 'required|string|max:255',
|
|
'phone' => 'nullable|string|max:50',
|
|
'email' => 'nullable|email|max:255',
|
|
'website' => 'nullable|string|max:255',
|
|
'notes' => 'nullable|string',
|
|
'logo' => 'nullable|image|max:2048',
|
|
]);
|
|
|
|
unset($validated['logo']);
|
|
|
|
foreach (['phone', 'email', 'website', 'notes'] as $field) {
|
|
$validated[$field] = $validated[$field] !== '' ? $validated[$field] : null;
|
|
}
|
|
|
|
if ($this->provider?->exists) {
|
|
$this->provider->update($validated);
|
|
} else {
|
|
$this->provider = Provider::create($validated);
|
|
}
|
|
|
|
if ($this->logo) {
|
|
if ($this->provider->logo_path) {
|
|
Storage::disk('public')->delete($this->provider->logo_path);
|
|
}
|
|
|
|
$path = $this->logo->store("providers/{$this->provider->id}", 'public');
|
|
$this->provider->update(['logo_path' => $path]);
|
|
}
|
|
|
|
session()->flash('status', "Prestataire « {$this->provider->name} » enregistré.");
|
|
|
|
$this->redirectRoute('providers.index', navigate: true);
|
|
}
|
|
|
|
public function addLogEntry(): void
|
|
{
|
|
$this->validate([
|
|
'newLogCategory' => 'required|in:'.implode(',', array_keys(ProviderLogEntry::CATEGORIES)),
|
|
'newLogNote' => 'required|string',
|
|
]);
|
|
|
|
$this->provider->logEntries()->create([
|
|
'category' => $this->newLogCategory,
|
|
'note' => $this->newLogNote,
|
|
'created_by' => auth()->id(),
|
|
]);
|
|
|
|
$this->newLogNote = '';
|
|
}
|
|
|
|
public function deleteLogEntry(int $entryId): void
|
|
{
|
|
$this->provider->logEntries()->findOrFail($entryId)->delete();
|
|
}
|
|
|
|
public function with(): array
|
|
{
|
|
return [
|
|
'logEntries' => $this->provider?->exists ? $this->provider->logEntries()->with('creator')->limit(30)->get() : collect(),
|
|
'categories' => ProviderLogEntry::CATEGORIES,
|
|
];
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="max-w-2xl">
|
|
<h1 class="mb-6 text-2xl font-semibold text-slate-900">
|
|
{{ $provider?->exists ? 'Modifier le prestataire' : 'Nouveau prestataire' }}
|
|
</h1>
|
|
|
|
@if (session('status'))
|
|
<div class="mb-4 rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-700">
|
|
{{ session('status') }}
|
|
</div>
|
|
@endif
|
|
|
|
<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">Logo</label>
|
|
<div class="mt-1 flex items-center gap-4">
|
|
<img src="{{ $logo ? $logo->temporaryUrl() : ($provider?->logo_url ?? asset('images/default-organization-logo.svg')) }}"
|
|
class="h-16 w-16 rounded border border-slate-200 object-contain p-1" alt="Logo">
|
|
<input type="file" wire:model="logo" accept="image/*"
|
|
class="block text-sm text-slate-600 file:mr-3 file:rounded file:border-0 file:bg-slate-100 file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-slate-700 hover:file:bg-slate-200">
|
|
</div>
|
|
@error('logo') <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="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 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">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>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-slate-700">Site web</label>
|
|
<input type="text" wire:model="website" placeholder="https://..."
|
|
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">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>
|
|
|
|
<div class="flex items-center gap-3 pt-2">
|
|
<button type="submit"
|
|
class="cursor-pointer rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
|
Enregistrer
|
|
</button>
|
|
<a href="{{ route('providers.index') }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
|
|
</div>
|
|
</form>
|
|
|
|
@if ($provider?->exists)
|
|
<div class="mt-8 rounded border border-slate-200 bg-white p-6">
|
|
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Journal de suivi</h2>
|
|
|
|
<form wire:submit="addLogEntry" class="mb-4 space-y-2 rounded border border-slate-100 bg-slate-50 p-3">
|
|
<div class="flex items-start gap-2">
|
|
<select wire:model="newLogCategory" class="rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
|
@foreach ($categories as $value => $label)
|
|
<option value="{{ $value }}">{{ $label }}</option>
|
|
@endforeach
|
|
</select>
|
|
<textarea wire:model="newLogNote" rows="2" placeholder="Ex: mail envoyé le 21/08 pour demander des précisions..."
|
|
class="flex-1 rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
|
|
<button type="submit" class="cursor-pointer rounded bg-slate-900 px-3 py-1.5 text-sm text-white hover:bg-slate-700">Ajouter</button>
|
|
</div>
|
|
@error('newLogNote') <p class="text-sm text-red-600">{{ $message }}</p> @enderror
|
|
</form>
|
|
|
|
<div class="space-y-3">
|
|
@forelse ($logEntries as $entry)
|
|
<div wire:key="log-{{ $entry->id }}" class="flex items-start justify-between gap-4 border-b border-slate-100 pb-3 last:border-0 last:pb-0">
|
|
<div>
|
|
<span class="mb-1 inline-block rounded-full px-2 py-0.5 text-xs font-medium
|
|
{{ match($entry->category) {
|
|
'contact' => 'bg-blue-100 text-blue-700',
|
|
'observation' => 'bg-slate-100 text-slate-600',
|
|
'incident' => 'bg-red-100 text-red-700',
|
|
default => 'bg-slate-100 text-slate-600',
|
|
} }}">
|
|
{{ $entry->categoryLabel() }}
|
|
</span>
|
|
<p class="whitespace-pre-line text-sm text-slate-900">{{ $entry->note }}</p>
|
|
<p class="mt-1 text-xs text-slate-500">{{ $entry->creator?->name ?? 'système' }} · {{ $entry->created_at->diffForHumans() }}</p>
|
|
</div>
|
|
<button type="button" wire:click="deleteLogEntry({{ $entry->id }})"
|
|
wire:confirm="Supprimer cette entrée ?"
|
|
class="cursor-pointer shrink-0 text-xs text-red-500 hover:text-red-700">
|
|
Supprimer
|
|
</button>
|
|
</div>
|
|
@empty
|
|
<p class="text-sm text-slate-400">Aucune entrée dans le journal pour le moment.</p>
|
|
@endforelse
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|