Files
FarmaFinder/apps/frontend-mobile/components/MedicineCard.tsx
T
Antoni Nuñez Romeu ee958d4525
Run Tests on Branches / Detect Changes (push) Successful in 13s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Successful in 1m40s
Run Tests on Branches / Frontend Mobile Tests (push) Successful in 1m37s
Run Tests on Branches / Parapharmacy API Tests (push) Has been skipped
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
feat(i18n-mobile): add bilingual support (Català / Castellano) for React Native app
Add lightweight i18n system matching the web app architecture.
Language persisted in AsyncStorage('ff-lang').

New files:
- src/i18n/locales/ca.js (~190 translation keys)
- src/i18n/locales/es.js (~190 translation keys)
- src/i18n/LanguageContext.jsx (Provider + AsyncStorage)
- src/i18n/useTranslation.js (hook)
- src/i18n/index.js (barrel export)

Modified 16 files:
- app/_layout.tsx: wrap with LanguageProvider, translate stack titles
- app/(tabs)/_layout.tsx: translate tab bar labels
- app/(tabs)/index.tsx: translate home screen
- app/(tabs)/search.tsx: translate search screen
- app/(tabs)/alerts.tsx: translate alerts screen
- app/(tabs)/profile.tsx: translate profile + add language selector (CA/ES)
- app/(tabs)/scan.tsx: translate scanner screen
- app/auth/login.tsx: translate login/register
- app/medicine/[id].tsx: translate medicine detail
- app/pharmacy/[id].tsx: translate pharmacy detail
- app/product/[source]/[id].tsx: translate product detail
- 5 components: MedicineCard, StockBadge, SearchBar, LoadingSpinner, BarcodeScanner

Language selector in Profile screen (globe icon + CA/ES toggle).
No routes changed. No API calls affected.
2026-07-17 10:22:41 +02:00

134 lines
3.6 KiB
TypeScript

import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity, useWindowDimensions } from 'react-native';
import { useRouter } from 'expo-router';
import { Ionicons } from '@expo/vector-icons';
import { useThemeContext } from './ThemeProvider';
import { spacing, borderRadius } from '../constants/theme';
import { StockBadge } from './StockBadge';
import { Medicine } from '../types';
import { useTranslation } from '../src/i18n';
const TABLET_MIN_WIDTH = 768;
interface MedicineCardProps {
medicine: Medicine;
}
export function MedicineCard({ medicine }: MedicineCardProps) {
const router = useRouter();
const { width } = useWindowDimensions();
const isTablet = width >= TABLET_MIN_WIDTH;
const { colors } = useThemeContext();
const { t } = useTranslation();
const handlePress = () => {
router.push(`/medicine/${medicine.nregistro}`);
};
return (
<TouchableOpacity
style={[styles.card, isTablet && styles.cardTablet, { backgroundColor: colors.card }]}
onPress={handlePress}
activeOpacity={0.7}
>
<View style={styles.header}>
<Text style={[styles.name, isTablet && styles.nameTablet, { color: colors.text }]} numberOfLines={2}>
{medicine.name}
</Text>
{medicine.stock != null && <StockBadge stock={medicine.stock} />}
</View>
<Text style={[styles.principioActivo, { color: colors.textSecondary }]} numberOfLines={1}>
{medicine.active_ingredient}{medicine.dosage ? ` - ${medicine.dosage}` : ''}
</Text>
<View style={styles.footer}>
<View style={styles.priceContainer}>
<Ionicons name="pricetag" size={14} color={colors.textSecondary} />
<Text style={[styles.price, isTablet && styles.priceTablet, { color: colors.primary }]}>
{medicine.precio != null ? `${medicine.precio.toFixed(2)} €` : t('medicineCard.noPrice')}
</Text>
</View>
<View style={styles.labContainer}>
<Ionicons name="business" size={14} color={colors.textSecondary} />
<Text style={[styles.laboratorio, isTablet && styles.laboratorioTablet, { color: colors.textSecondary }]} numberOfLines={1}>
{medicine.laboratory}
</Text>
</View>
</View>
</TouchableOpacity>
);
}
const styles = StyleSheet.create({
card: {
borderRadius: borderRadius.lg,
padding: spacing.md,
marginHorizontal: spacing.lg,
marginVertical: spacing.xs,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.06,
shadowRadius: 8,
elevation: 2,
},
cardTablet: {
padding: spacing.lg,
maxWidth: 700,
alignSelf: 'center',
width: '100%',
},
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-start',
marginBottom: spacing.xs,
},
name: {
flex: 1,
fontSize: 16,
fontWeight: '600',
marginRight: spacing.sm,
},
nameTablet: {
fontSize: 18,
},
principioActivo: {
fontSize: 14,
marginBottom: spacing.sm,
},
footer: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
priceContainer: {
flexDirection: 'row',
alignItems: 'center',
},
price: {
fontSize: 14,
fontWeight: '600',
marginLeft: spacing.xs,
},
priceTablet: {
fontSize: 16,
},
labContainer: {
flexDirection: 'row',
alignItems: 'center',
flex: 1,
justifyContent: 'flex-end',
},
laboratorio: {
fontSize: 12,
marginLeft: spacing.xs,
maxWidth: 120,
},
laboratorioTablet: {
fontSize: 14,
maxWidth: 200,
},
});