feat: Add document download and upload. Add NFC support and enhance attendance and permits views
- Improved error message handling in LoginScreen for invalid credentials. - Added new images: mariani-icon.png and mariani-splash.png. - Updated AddDocumentModal to handle file extensions and improve UI. - Enhanced CalendarWidget to support month change callbacks. - Introduced NfcScanModal for NFC tag scanning with animations. - Revamped QrScanModal to utilize camera for QR code scanning. - Removed mock data from data.ts and streamlined Office data. - Updated package dependencies for expo-camera and react-native-nfc-manager. - Added utility function to parse seconds to time format. - Refactored document upload logic to use FormData for server uploads.
This commit is contained in:
@ -13,12 +13,14 @@ interface AddDocumentModalProps {
|
||||
export default function AddDocumentModal({ visible, onClose, onUpload, isUploading = false }: AddDocumentModalProps) {
|
||||
const [selectedFile, setSelectedFile] = useState<DocumentPicker.DocumentPickerAsset | null>(null);
|
||||
const [customTitle, setCustomTitle] = useState('');
|
||||
const [fileExtension, setFileExtension] = useState('');
|
||||
|
||||
// Reset dello stato quando il modale si apre/chiude
|
||||
useEffect(() => {
|
||||
if (!visible) {
|
||||
setSelectedFile(null);
|
||||
setCustomTitle('');
|
||||
setFileExtension('');
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
@ -34,10 +36,16 @@ export default function AddDocumentModal({ visible, onClose, onUpload, isUploadi
|
||||
|
||||
const asset = result.assets[0];
|
||||
setSelectedFile(asset);
|
||||
|
||||
// Pre-compila il titolo con il nome del file
|
||||
setCustomTitle(asset.name);
|
||||
|
||||
|
||||
const lastDotIndex = asset.name.lastIndexOf('.');
|
||||
if (lastDotIndex !== -1) {
|
||||
setCustomTitle(asset.name.substring(0, lastDotIndex));
|
||||
setFileExtension(asset.name.substring(lastDotIndex));
|
||||
} else {
|
||||
setCustomTitle(asset.name);
|
||||
setFileExtension('');
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.error("Errore selezione file:", err);
|
||||
}
|
||||
@ -45,13 +53,16 @@ export default function AddDocumentModal({ visible, onClose, onUpload, isUploadi
|
||||
|
||||
const handleUpload = () => {
|
||||
if (!selectedFile) return;
|
||||
const fullTitle = customTitle ? `${customTitle}${fileExtension}` : selectedFile.name;
|
||||
|
||||
// Se il titolo custom è vuoto, usiamo il nome originale
|
||||
onUpload(selectedFile, customTitle || selectedFile.name);
|
||||
onUpload(selectedFile, fullTitle);
|
||||
};
|
||||
|
||||
const removeFile = () => {
|
||||
setSelectedFile(null);
|
||||
setCustomTitle('');
|
||||
setFileExtension('');
|
||||
};
|
||||
|
||||
// Formatta dimensione file
|
||||
@ -73,7 +84,7 @@ export default function AddDocumentModal({ visible, onClose, onUpload, isUploadi
|
||||
>
|
||||
<View className="flex-1 justify-center items-center bg-black/50 px-6">
|
||||
<View className="bg-white w-full rounded-[2rem] p-6 shadow-xl">
|
||||
|
||||
|
||||
{/* Header */}
|
||||
<View className="flex-row justify-between items-center mb-6">
|
||||
<Text className="text-xl font-bold text-gray-800">Carica Documento</Text>
|
||||
@ -84,10 +95,10 @@ export default function AddDocumentModal({ visible, onClose, onUpload, isUploadi
|
||||
|
||||
{/* Body */}
|
||||
<View className="gap-5">
|
||||
|
||||
|
||||
{/* Area Selezione File */}
|
||||
{!selectedFile ? (
|
||||
<TouchableOpacity
|
||||
<TouchableOpacity
|
||||
onPress={pickDocument}
|
||||
className="h-64 border-2 border-dashed border-gray-300 rounded-2xl items-center justify-center bg-gray-50 active:bg-gray-100"
|
||||
>
|
||||
@ -120,20 +131,25 @@ export default function AddDocumentModal({ visible, onClose, onUpload, isUploadi
|
||||
{/* Campo Rinomina (Visibile solo se c'è un file) */}
|
||||
{selectedFile && (
|
||||
<View>
|
||||
<Text className="text-gray-700 font-bold mb-2 ml-1 text-sm">Nome Documento (Opzionale)</Text>
|
||||
<TextInput
|
||||
value={customTitle}
|
||||
onChangeText={setCustomTitle}
|
||||
placeholder="Come vuoi chiamare questo file?"
|
||||
className="w-full p-4 bg-gray-50 rounded-xl border border-gray-200 text-gray-800 text-base"
|
||||
/>
|
||||
<Text className="text-gray-700 font-bold mb-2 ml-1 text-sm">Rinomina File</Text>
|
||||
<View className="flex-row items-center w-full bg-gray-50 rounded-xl border border-gray-200 overflow-hidden">
|
||||
<TextInput
|
||||
value={customTitle}
|
||||
onChangeText={setCustomTitle}
|
||||
placeholder="Nome del file"
|
||||
className="flex-1 p-4 text-gray-800 text-base"
|
||||
/>
|
||||
<Text className="px-4 text-gray-400 font-medium text-base flex items-center justify-center">
|
||||
{fileExtension}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Footer Buttons */}
|
||||
<View className="flex-row gap-3 mt-8">
|
||||
<TouchableOpacity
|
||||
<TouchableOpacity
|
||||
onPress={onClose}
|
||||
className="flex-1 py-4 bg-gray-100 rounded-xl items-center"
|
||||
disabled={isUploading}
|
||||
@ -141,7 +157,7 @@ export default function AddDocumentModal({ visible, onClose, onUpload, isUploadi
|
||||
<Text className="text-gray-600 font-bold text-base">Annulla</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<TouchableOpacity
|
||||
<TouchableOpacity
|
||||
onPress={handleUpload}
|
||||
disabled={!selectedFile || isUploading}
|
||||
className={`flex-1 py-4 rounded-xl items-center flex-row justify-center gap-2 ${!selectedFile ? 'bg-gray-300' : 'bg-[#099499]'}`}
|
||||
|
||||
Reference in New Issue
Block a user