/**
* =========================================================================
* PLATEFORME ECO-PANNEAU.FR - VERSION 1.0.0
* Vue Saisie Déléguée (Partage sécurisé sans authentification globale)
* =========================================================================
*/
window.pano_DelegateView = ({ token, showToast }) => {
const { useState, useEffect } = React;
const [panneau, setPanneau] = useState(null);
const [loading, setLoading] = useState(true);
const [isSaving, setIsSaving] = useState(false);
const [error, setError] = useState(null);
const [editingEntity, setEditingEntity] = useState(null);
const [confirmDialog, setConfirmDialog] = useState(null);
const { LoaderIcon, AlertTriangleIcon, ShieldIcon, CheckCircleIcon } = window.pano_getIcons();
const ConfirmModal = window.pano_ConfirmModal || (() => null);
const Button = window.pano_Button || (() => null);
const PanneauEditor = window.pano_PanneauEditorForm || (() => null);
const EntityEditor = window.pano_EntityEditorModal || (() => null);
useEffect(() => {
fetch(window.pano_ECO_CONFIG.apiBaseUrl + 'panneaux/delegated_access&token=' + encodeURIComponent(token) + '&_t=' + Date.now())
.then(r => r.json())
.then(d => {
if (d.status === 'success') {
setPanneau(d.data);
} else {
setError(d.message);
}
setLoading(false);
})
.catch(() => {
setError("Erreur réseau");
setLoading(false);
});
}, [token]);
const handleSave = async () => {
const d = await window.pano_apiFetch('panneaux/delegated_update', {
body: { token, ...panneau },
setLoading: setIsSaving,
successMessage: "Informations enregistrées avec succès."
});
};
if (loading) {
return (
{LoaderIcon &&
}
Vérification de l'accès...
);
}
if (error) {
return (
{AlertTriangleIcon &&
}
Accès refusé
{error}
);
}
return (
Vous avez été invité à compléter les informations légales de ce panneau (intervenants, sous-traitants, PDF de l'arrêté). Vos modifications seront directement répercutées sur l'affichage public.
{PanneauEditor && (
window.location.href = '?'}
onPublish={handleSave}
onEditEntity={(loc, data) => setEditingEntity({location: loc, data})}
deleteEntity={(loc) => {
setConfirmDialog({
title: "Supprimer l'élément",
message: "Êtes-vous sûr de vouloir supprimer cet élément de l'équipe ?",
confirmText: "Supprimer",
type: "error",
isDestructive: true,
onConfirm: () => {
let newInter = [...(panneau.intervenants || [])];
let newLots = JSON.parse(JSON.stringify(panneau.lots || []));
if (loc.type === 'intervenant') {
newInter.splice(loc.index, 1);
} else if (loc.type === 'lot') {
newLots.splice(loc.index, 1);
} else {
newLots[loc.lotIndex].entreprises.splice(loc.index, 1);
}
setPanneau({ ...panneau, intervenants: newInter, lots: newLots });
setConfirmDialog(null);
},
onCancel: () => setConfirmDialog(null)
});
}}
isSaving={isSaving}
uiMode="delege"
lockedFields={panneau.lockedFields || []}
showToast={showToast}
/>
)}
{editingEntity && EntityEditor && (
{
let newInter = [...(panneau.intervenants || [])];
let newLots = JSON.parse(JSON.stringify(panneau.lots || []));
const loc = editingEntity.location;
if (loc.type === 'intervenant') {
if (loc.index !== undefined) {
newInter[loc.index] = editingEntity.data;
} else {
newInter.push({...editingEntity.data, id: crypto.randomUUID()});
}
} else if (loc.type === 'lot') {
if (loc.index !== undefined) {
newLots[loc.index] = {...newLots[loc.index], ...editingEntity.data};
} else {
newLots.push({...editingEntity.data, id: crypto.randomUUID(), entreprises: []});
}
} else if (loc.type === 'entreprise') {
if (loc.index !== undefined) {
newLots[loc.lotIndex].entreprises[loc.index] = editingEntity.data;
} else {
newLots[loc.lotIndex].entreprises.push({...editingEntity.data, id: crypto.randomUUID()});
}
}
setPanneau({ ...panneau, intervenants: newInter, lots: newLots });
setEditingEntity(null);
}}
showToast={showToast}
/>
)}
{confirmDialog && ConfirmModal && (
)}
);
};
/* EOF ========== [_react/_delegate_view.jsx] */