Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions formulus/src/screens/SyncScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ const SyncScreen = () => {
if (syncState.isActive) return;

try {
const userInfo = await getUserInfo();
if (!userInfo) {
Alert.alert(
'Authentication Error',
'Please log in to update app bundle',
);
return;
}

if (!updateAvailable && !isAdmin) {
Alert.alert(
'Permission Denied',
'Admin privileges required to force update app bundle',
);
return;
}

startSync(false);
await syncService.updateAppBundle();
const syncTime = new Date().toISOString();
Expand All @@ -111,14 +128,24 @@ const SyncScreen = () => {
} catch (error) {
const errorMessage = (error as Error).message;
finishSync(errorMessage);
Alert.alert('Error', 'Failed to update app bundle!\n' + errorMessage);

if (errorMessage.includes('401')) {
Alert.alert(
'Authentication Error',
'Your session has expired. Please log in again.',
);
} else {
Alert.alert('Error', 'Failed to update app bundle!\n' + errorMessage);
}
}
}, [
syncState.isActive,
startSync,
finishSync,
updatePendingUploads,
updatePendingObservations,
updateAvailable,
isAdmin,
]);

const checkForUpdates = useCallback(async (force: boolean = false) => {
Expand All @@ -132,10 +159,10 @@ const SyncScreen = () => {
const manifest = await synkronusApi.getManifest();
setServerBundleVersion(manifest.version);
} catch (err) {
// Server manifest unavailable
setServerBundleVersion(currentVersion);
}
} catch (error) {
// Update check failed
console.warn('Update check failed:', error);
}
}, []);

Expand All @@ -149,7 +176,7 @@ const SyncScreen = () => {
if (pendingObservations > 0 || pendingUploads.count > 0) {
return 'Pending Sync';
}
return 'Ready';
return 'All synced';
};

const status = getDataSyncStatus();
Expand Down Expand Up @@ -253,14 +280,10 @@ const SyncScreen = () => {
{status}
</Text>
{!syncState.isActive &&
!syncState.error &&
(pendingObservations > 0 || pendingUploads.count > 0) && (
<Text style={styles.statusCardSubtext}>Tap to sync now</Text>
)}
{!syncState.isActive &&
pendingObservations === 0 &&
pendingUploads.count === 0 && (
<Text style={styles.statusCardSubtext}>All synced</Text>
)}
</TouchableOpacity>

<View style={styles.statusCard}>
Expand Down
Loading