From 9459834b0e55985210a4b10cbff9555d43685e2b Mon Sep 17 00:00:00 2001 From: frakarr Date: Sun, 7 Dec 2025 12:54:51 +0100 Subject: [PATCH] fix: Improve condo ID handling and add error message Prevents client-side generation of condo IDs, delegating this to the backend/service for consistency. Introduces an alert for save condo errors and ensures the active condo is correctly updated or set. Adds logic to auto-select the first condo if none is active. --- .dockerignore | Bin 81 -> 105 bytes .toignore | 1 - Dockerfile | 15 -------- nginx.conf | 23 +----------- pages/Settings.tsx | 89 ++++++++++++++++++++++++++++----------------- server/Dockerfile | 8 ---- 6 files changed, 56 insertions(+), 80 deletions(-) delete mode 100644 .toignore diff --git a/.dockerignore b/.dockerignore index 10c5075f1f010ae3f81113205ea3014be510d60b..b3e90c29e43ec3e8cab67b74444927db2400e19e 100644 GIT binary patch literal 105 zcmaFAfA9PKd*gsOOBP6k196$QZXS>-;ZOpS>_7}e3=m2?147F|C { const handleCondoSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { + // FIX: Do not generate ID for new condo, let backend/service handle it (POST vs PUT check) const payload: Condo = { - id: editingCondo ? editingCondo.id : crypto.randomUUID(), + id: editingCondo ? editingCondo.id : '', name: condoForm.name, address: condoForm.address, defaultMonthlyQuota: condoForm.defaultMonthlyQuota }; - await CondoService.saveCondo(payload); + const savedCondo = await CondoService.saveCondo(payload); const list = await CondoService.getCondos(); setCondos(list); - if (activeCondo?.id === payload.id) setActiveCondo(payload); + + if (activeCondo?.id === savedCondo.id) { + setActiveCondo(savedCondo); + } + + // Auto-select if it's the first one or none selected + if (!activeCondo && list.length === 1) { + CondoService.setActiveCondo(savedCondo.id); + } + setShowCondoModal(false); window.dispatchEvent(new Event('condo-updated')); - } catch (e) { console.error(e); } + } catch (e) { console.error(e); alert("Errore nel salvataggio del condominio"); } }; const handleDeleteCondo = async (id: string) => { @@ -300,7 +310,10 @@ export const SettingsPage: React.FC = () => { setFamilies([...families, newFamily]); } setShowFamilyModal(false); - } catch (e) { console.error(e); } + } catch (e: any) { + console.error(e); + alert(`Errore: ${e.message || "Impossibile salvare la famiglia"}`); + } }; // --- User Handlers --- @@ -359,7 +372,7 @@ export const SettingsPage: React.FC = () => { ...noticeForm, date: editingNotice ? editingNotice.date : new Date().toISOString() }; - const saved = await CondoService.saveNotice(payload); + await CondoService.saveNotice(payload); setNotices(await CondoService.getNotices()); setShowNoticeModal(false); } catch (e) { console.error(e); } @@ -383,7 +396,7 @@ export const SettingsPage: React.FC = () => { setShowReadDetailsModal(true); }; - // --- Alert Handlers (Placeholder for brevity, logic same as before) --- + // --- Alert Handlers --- const openAddAlertModal = () => { setEditingAlert(null); setAlertForm({ subject: '', body: '', daysOffset: 1, offsetType: 'before_next_month', sendHour: 9, active: true }); setShowAlertModal(true); }; const openEditAlertModal = (alert: AlertDefinition) => { setEditingAlert(alert); setAlertForm(alert); setShowAlertModal(true); }; const handleAlertSubmit = async (e: React.FormEvent) => { @@ -463,7 +476,7 @@ export const SettingsPage: React.FC = () => { {isAdmin && activeTab === 'general' && (
{!activeCondo ? ( -
Nessun condominio selezionato.
+
Nessun condominio selezionato. Crea un condominio nella sezione "Lista Condomini".
) : (

Dati Condominio Corrente

@@ -514,32 +527,40 @@ export const SettingsPage: React.FC = () => { {/* Families Tab */} {isAdmin && activeTab === 'families' && (
-
-
Famiglie in: {activeCondo?.name}
- -
-
- - - - {families.map(family => ( - - - - - - - - ))} - -
NomeInternoEmailQuotaAzioni
{family.name}{family.unitNumber}{family.contactEmail} - {family.customMonthlyQuota ? ( - € {family.customMonthlyQuota} - ) : ( - Default (€ {activeCondo?.defaultMonthlyQuota}) - )} -
-
+ {!activeCondo ? ( +
+

Seleziona o crea un condominio per gestire le famiglie.

+
+ ) : ( + <> +
+
Famiglie in: {activeCondo.name}
+ +
+
+ + + + {families.map(family => ( + + + + + + + + ))} + +
NomeInternoEmailQuotaAzioni
{family.name}{family.unitNumber}{family.contactEmail} + {family.customMonthlyQuota ? ( + € {family.customMonthlyQuota} + ) : ( + Default (€ {activeCondo.defaultMonthlyQuota}) + )} +
+
+ + )}
)} diff --git a/server/Dockerfile b/server/Dockerfile index 56965f6..e69de29 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,8 +0,0 @@ -FROM node:20-alpine -WORKDIR /app -COPY package*.json ./ -RUN npm install -COPY . . -EXPOSE 3001 -CMD ["npm", "start"] -