feat(mobile): add complete consent flow (banner, health modal, privacy, i18n)
This commit is contained in:
@@ -3,12 +3,16 @@ import { View, StyleSheet } from 'react-native';
|
||||
import { useRouter } from 'expo-router';
|
||||
import { BarcodeScanner } from '../components/BarcodeScanner';
|
||||
import { searchMedicines } from '../services/medicines';
|
||||
import { hasConsent } from '../services/consent';
|
||||
import HealthConsentModal from '../components/HealthConsentModal';
|
||||
|
||||
export default function ScannerScreen() {
|
||||
const router = useRouter();
|
||||
const [isSearching, setIsSearching] = useState(false);
|
||||
const [showHealthConsent, setShowHealthConsent] = useState(false);
|
||||
const [pendingBarcode, setPendingBarcode] = useState<string | null>(null);
|
||||
|
||||
const handleBarcodeScanned = async (barcode: string) => {
|
||||
const processBarcode = async (barcode: string) => {
|
||||
setIsSearching(true);
|
||||
try {
|
||||
const results = await searchMedicines(barcode);
|
||||
@@ -25,6 +29,16 @@ export default function ScannerScreen() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleBarcodeScanned = async (barcode: string) => {
|
||||
const healthConsent = await hasConsent('health_data');
|
||||
if (!healthConsent) {
|
||||
setPendingBarcode(barcode);
|
||||
setShowHealthConsent(true);
|
||||
return;
|
||||
}
|
||||
await processBarcode(barcode);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
router.back();
|
||||
};
|
||||
@@ -35,6 +49,24 @@ export default function ScannerScreen() {
|
||||
onBarcodeScanned={handleBarcodeScanned}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
{showHealthConsent && (
|
||||
<HealthConsentModal
|
||||
onAccept={async () => {
|
||||
setShowHealthConsent(false);
|
||||
if (pendingBarcode) {
|
||||
const { saveConsents, getLocalConsents } = await import('../services/consent');
|
||||
const current = await getLocalConsents();
|
||||
await saveConsents({ ...current, health_data: true });
|
||||
await processBarcode(pendingBarcode);
|
||||
setPendingBarcode(null);
|
||||
}
|
||||
}}
|
||||
onCancel={() => {
|
||||
setShowHealthConsent(false);
|
||||
setPendingBarcode(null);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user