feat: add authentication check before updating filament and improve error handling
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
mobile/.env.production
|
||||||
@@ -153,26 +153,30 @@ export default function EditFilamentScreen(): React.ReactElement {
|
|||||||
}
|
}
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
// TODO: UpdateFilamentUseCase via container DI
|
const user = useAuthStore.getState().user;
|
||||||
const updated = {
|
if (!user) {
|
||||||
...filament!,
|
Alert.alert('Erro', 'Usuário não autenticado.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = await updateFilamentUseCase.execute(filament!.id, user.id, {
|
||||||
brand: data.brand,
|
brand: data.brand,
|
||||||
model: data.model ?? null,
|
model: data.model ?? null,
|
||||||
colorHex: selectedColor,
|
colorHex: selectedColor,
|
||||||
material: selectedMaterial,
|
material: selectedMaterial,
|
||||||
spoolPresetId: selectedPresetId,
|
spoolPresetId: selectedPresetId,
|
||||||
totalWeightG: Number(data.totalWeightG),
|
totalWeightG: Number(data.totalWeightG),
|
||||||
netWeightG: netWeight,
|
|
||||||
tempHotendC: data.tempHotendC ?? null,
|
tempHotendC: data.tempHotendC ?? null,
|
||||||
tempBedC: data.tempBedC ?? null,
|
tempBedC: data.tempBedC ?? null,
|
||||||
flowFactorPct: data.flowFactorPct ?? null,
|
flowFactorPct: data.flowFactorPct ?? null,
|
||||||
notes: data.notes ?? null,
|
notes: data.notes ?? null,
|
||||||
updatedAt: new Date().toISOString(),
|
});
|
||||||
};
|
|
||||||
updateFilament(updated);
|
updateFilament(updated);
|
||||||
router.back();
|
router.back();
|
||||||
} catch {
|
} catch (err) {
|
||||||
Alert.alert('Erro', 'Não foi possível salvar as alterações.');
|
console.error('update filament error', err);
|
||||||
|
Alert.alert('Erro', 'Falha ao atualizar: ' + (err as Error).message);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user