update
This commit is contained in:
@@ -9,9 +9,12 @@ import { z } from 'zod';
|
||||
import { Ionicons } from '@expo/vector-icons';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import { usePresetStore } from '@store/presetStore';
|
||||
import { useAuthStore } from '@store/authStore';
|
||||
import { Input } from '@presentation/components/ui/Input';
|
||||
import { Button } from '@presentation/components/ui/Button';
|
||||
import { colors, typography, spacing, radius } from '@shared/theme';
|
||||
import type { UpdateSpoolPresetInput } from '@domain/SpoolPreset';
|
||||
import { updatePresetUseCase, deletePresetUseCase } from '@infrastructure/container';
|
||||
|
||||
const schema = z.object({
|
||||
name: z.string().min(1, 'Nome obrigatório'),
|
||||
@@ -64,9 +67,20 @@ export default function EditPresetScreen(): React.ReactElement {
|
||||
{
|
||||
text: 'Excluir',
|
||||
style: 'destructive',
|
||||
onPress: () => {
|
||||
removePreset(preset!.id);
|
||||
router.replace('/(app)/(tabs)/config' as never);
|
||||
onPress: async () => {
|
||||
try {
|
||||
const user = useAuthStore.getState().user;
|
||||
if (!user) {
|
||||
Alert.alert('Erro', 'Usuário não autenticado');
|
||||
return;
|
||||
}
|
||||
|
||||
await deletePresetUseCase.execute(preset!.id, user.id);
|
||||
removePreset(preset!.id);
|
||||
router.replace('/(app)/(tabs)/config' as never);
|
||||
} catch (error) {
|
||||
Alert.alert('Erro', `Falha ao deletar: ${(error as Error).message}`);
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -76,15 +90,22 @@ export default function EditPresetScreen(): React.ReactElement {
|
||||
async function onSubmit(data: FormData): Promise<void> {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
// TODO: UpdatePresetUseCase via DI container
|
||||
updatePreset({
|
||||
...preset!,
|
||||
const user = useAuthStore.getState().user;
|
||||
if (!user) {
|
||||
Alert.alert('Erro', 'Usuário não autenticado');
|
||||
return;
|
||||
}
|
||||
|
||||
const input: UpdateSpoolPresetInput = {
|
||||
name: data.name,
|
||||
spoolWeightG: Number(data.spoolWeightG),
|
||||
});
|
||||
};
|
||||
|
||||
const updated = await updatePresetUseCase.execute(preset!.id, user.id, input);
|
||||
updatePreset(updated);
|
||||
router.back();
|
||||
} catch {
|
||||
Alert.alert('Erro', 'Não foi possível salvar as alterações.');
|
||||
} catch (error) {
|
||||
Alert.alert('Erro', `Não foi possível salvar as alterações: ${(error as Error).message}`);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user