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