fix(mobile): onError på 15 mutationer – inga tysta miss (MIKRO 52)
CI / Typecheck, test & build (push) Successful in 1m37s
CI / Typecheck, test & build (push) Successful in 1m37s
This commit is contained in:
@@ -51,19 +51,27 @@ export default function MemoryScreen() {
|
|||||||
mutationFn: (id: string) =>
|
mutationFn: (id: string) =>
|
||||||
api(`/v1/me/memory/${id}`, { method: "PATCH", body: { verified: true } }),
|
api(`/v1/me/memory/${id}`, { method: "PATCH", body: { verified: true } }),
|
||||||
onSuccess: invalidate,
|
onSuccess: invalidate,
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
const pause = useMutation({
|
const pause = useMutation({
|
||||||
mutationFn: ({ id, paused }: { id: string; paused: boolean }) =>
|
mutationFn: ({ id, paused }: { id: string; paused: boolean }) =>
|
||||||
api(`/v1/me/memory/${id}`, { method: "PATCH", body: { paused } }),
|
api(`/v1/me/memory/${id}`, { method: "PATCH", body: { paused } }),
|
||||||
onSuccess: invalidate,
|
onSuccess: invalidate,
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
const remove = useMutation({
|
const remove = useMutation({
|
||||||
mutationFn: (id: string) => api(`/v1/me/memory/${id}`, { method: "DELETE" }),
|
mutationFn: (id: string) => api(`/v1/me/memory/${id}`, { method: "DELETE" }),
|
||||||
onSuccess: invalidate,
|
onSuccess: invalidate,
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
const removeAll = useMutation({
|
const removeAll = useMutation({
|
||||||
mutationFn: () => api("/v1/me/memory", { method: "DELETE" }),
|
mutationFn: () => api("/v1/me/memory", { method: "DELETE" }),
|
||||||
onSuccess: invalidate,
|
onSuccess: invalidate,
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (query.isLoading) return <LoadingView />;
|
if (query.isLoading) return <LoadingView />;
|
||||||
|
|||||||
@@ -73,15 +73,21 @@ export default function ProfileScreen() {
|
|||||||
const togglePrecision = useMutation({
|
const togglePrecision = useMutation({
|
||||||
mutationFn: (mode: string) => api("/v1/me", { method: "PATCH", body: { precisionMode: mode } }),
|
mutationFn: (mode: string) => api("/v1/me", { method: "PATCH", body: { precisionMode: mode } }),
|
||||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["me"] }),
|
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["me"] }),
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
const deleteAccount = useMutation({
|
const deleteAccount = useMutation({
|
||||||
mutationFn: () => api("/v1/me", { method: "DELETE" }),
|
mutationFn: () => api("/v1/me", { method: "DELETE" }),
|
||||||
onSuccess: () => void logout().then(() => router.replace("/(auth)/login")),
|
onSuccess: () => void logout().then(() => router.replace("/(auth)/login")),
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
const resend = useMutation({
|
const resend = useMutation({
|
||||||
mutationFn: () => api("/v1/auth/resend-verification", { method: "POST" }),
|
mutationFn: () => api("/v1/auth/resend-verification", { method: "POST" }),
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Språkval (i18n M4): sparas i backend-preferenserna + lokalt, byter direkt.
|
// Språkval (i18n M4): sparas i backend-preferenserna + lokalt, byter direkt.
|
||||||
@@ -96,6 +102,8 @@ export default function ProfileScreen() {
|
|||||||
await persistLanguageTag(languageTag);
|
await persistLanguageTag(languageTag);
|
||||||
await queryClient.invalidateQueries();
|
await queryClient.invalidateQueries();
|
||||||
},
|
},
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (me.isLoading) return <LoadingView />;
|
if (me.isLoading) return <LoadingView />;
|
||||||
|
|||||||
@@ -83,12 +83,16 @@ export default function RecipeScreen() {
|
|||||||
mutationFn: (isFavorite: boolean) =>
|
mutationFn: (isFavorite: boolean) =>
|
||||||
api(`/v1/recipes/${id}/favorite`, { method: isFavorite ? "DELETE" : "POST" }),
|
api(`/v1/recipes/${id}/favorite`, { method: isFavorite ? "DELETE" : "POST" }),
|
||||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["recipe", id] }),
|
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["recipe", id] }),
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
const rate = useMutation({
|
const rate = useMutation({
|
||||||
mutationFn: (stars: number) =>
|
mutationFn: (stars: number) =>
|
||||||
api(`/v1/recipes/${id}/rate`, { method: "POST", body: { stars, feedbackTags: [] } }),
|
api(`/v1/recipes/${id}/rate`, { method: "POST", body: { stars, feedbackTags: [] } }),
|
||||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["recipe", id] }),
|
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["recipe", id] }),
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (query.isLoading) return <LoadingView />;
|
if (query.isLoading) return <LoadingView />;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { ActivityIndicator, View } from "react-native";
|
import { ActivityIndicator, Alert, View } from "react-native";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import { api } from "@/lib/api";
|
import { api } from "@/lib/api";
|
||||||
@@ -69,6 +69,8 @@ export default function ReconciliationScreen() {
|
|||||||
router.back();
|
router.back();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (query.isLoading) return <LoadingView />;
|
if (query.isLoading) return <LoadingView />;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { View } from "react-native";
|
import { Alert, View } from "react-native";
|
||||||
import { router, useLocalSearchParams } from "expo-router";
|
import { router, useLocalSearchParams } from "expo-router";
|
||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import { api } from "@/lib/api";
|
import { api } from "@/lib/api";
|
||||||
@@ -52,6 +52,8 @@ export default function ScanDiffReviewScreen() {
|
|||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
router.back();
|
router.back();
|
||||||
},
|
},
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
const rows = useMemo(() => query.data?.rows ?? [], [query.data]);
|
const rows = useMemo(() => query.data?.rows ?? [], [query.data]);
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ export default function ShoppingScreen() {
|
|||||||
setNewItem("");
|
setNewItem("");
|
||||||
invalidate();
|
invalidate();
|
||||||
},
|
},
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggle = useMutation({
|
const toggle = useMutation({
|
||||||
@@ -105,6 +107,8 @@ export default function ShoppingScreen() {
|
|||||||
body: { checked: !item.checked },
|
body: { checked: !item.checked },
|
||||||
}),
|
}),
|
||||||
onSuccess: invalidate,
|
onSuccess: invalidate,
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
const complete = useMutation({
|
const complete = useMutation({
|
||||||
@@ -119,6 +123,8 @@ export default function ShoppingScreen() {
|
|||||||
invalidate();
|
invalidate();
|
||||||
Alert.alert(t("shopping.completedTitle"), t("shopping.completedBody", { count: added }));
|
Alert.alert(t("shopping.completedTitle"), t("shopping.completedBody", { count: added }));
|
||||||
},
|
},
|
||||||
|
onError: (err) =>
|
||||||
|
Alert.alert(t("common.oops"), err instanceof Error ? err.message : t("common.error")),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (lists.isLoading || list.isLoading) return <LoadingView />;
|
if (lists.isLoading || list.isLoading) return <LoadingView />;
|
||||||
|
|||||||
Reference in New Issue
Block a user