feat(mobile): add complete consent flow (banner, health modal, privacy, i18n)

This commit is contained in:
Antoni Nuñez Romeu
2026-08-26 15:24:09 +02:00
parent 1f918be99d
commit 80c473e439
9 changed files with 350 additions and 2 deletions
+59
View File
@@ -0,0 +1,59 @@
import * as SecureStore from 'expo-secure-store';
import { api } from './api';
const CONSENT_KEY = 'consents';
export interface Consents {
essential: boolean;
analytics: boolean;
preferences: boolean;
health_data: boolean;
}
const DEFAULT_CONSENTS: Consents = {
essential: true,
analytics: false,
preferences: false,
health_data: false,
};
export async function getLocalConsents(): Promise<Consents> {
try {
const stored = await SecureStore.getItemAsync(CONSENT_KEY);
if (stored) return { ...DEFAULT_CONSENTS, ...JSON.parse(stored), essential: true };
} catch {}
return { ...DEFAULT_CONSENTS };
}
export async function setLocalConsents(consents: Consents): Promise<void> {
try { await SecureStore.setItemAsync(CONSENT_KEY, JSON.stringify(consents)); } catch {}
}
export async function hasConsentChoice(): Promise<boolean> {
try { return (await SecureStore.getItemAsync(CONSENT_KEY)) !== null; } catch { return false; }
}
export async function fetchServerConsents(): Promise<Consents | null> {
try {
const res = await api.get('/consents');
await setLocalConsents(res.data);
return res.data;
} catch { return null; }
}
export async function saveConsents(consents: Consents): Promise<Consents> {
const toSave = { ...consents, essential: true };
await setLocalConsents(toSave);
try {
const res = await api.put('/consents', {
categories: { analytics: toSave.analytics, preferences: toSave.preferences, health_data: toSave.health_data },
});
await setLocalConsents(res.data);
return res.data;
} catch { return toSave; }
}
export async function hasConsent(category: keyof Consents): Promise<boolean> {
const consents = await getLocalConsents();
return consents[category] === true;
}