Skip to content

Commit

Permalink
feat(backup): Display last backup status
Browse files Browse the repository at this point in the history
  • Loading branch information
zatteo committed Aug 24, 2023
1 parent 45400fb commit f554261
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/photos/ducks/backup/components/LastBackupStatus.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react'

import { useI18n } from 'cozy-ui/transpiled/react'

import Typography from 'cozy-ui/transpiled/react/Typography'
import { useBackupData } from '../hooks/useBackupData'

const LastBackupStatus = () => {
const { t } = useI18n()

const { backupInfo } = useBackupData()

if (!backupInfo || !backupInfo.lastBackup) return null

const {
lastBackup: {
status,
errorMessage,
backedUpMediaCount,
totalMediasToBackupCount
}
} = backupInfo

let lastBackupDescription

if (status === 'success' && totalMediasToBackupCount > 0) {
if (backedUpMediaCount === totalMediasToBackupCount) {
lastBackupDescription = t('Backup.LastBackupStatus.success', {
smart_count: totalMediasToBackupCount
})
} else {
lastBackupDescription = t('Backup.LastBackupStatus.partialSuccess', {
smart_count: totalMediasToBackupCount,
backedUpMediaCount
})
}
} else if (status === 'error') {
lastBackupDescription = errorMessage
} else {
return null
}

return (
<Typography className="u-mt-1-half" align="center">
{t('Backup.LastBackupStatus.lastBackup')} {lastBackupDescription}
</Typography>
)
}

export default LastBackupStatus
2 changes: 2 additions & 0 deletions src/photos/ducks/backup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BackupInfo from './components/BackupInfo'
import BackupActions from './components/BackupActions'
import BackupDescription from './components/BackupDescription'
import InstallAppAlert from './components/InstallAppAlert'
import LastBackupStatus from './components/LastBackupStatus'
import AllowPermissionsModal from './components/AllowPermissionsModal'
import { BackupError } from './components/BackupError'

Expand All @@ -33,6 +34,7 @@ const BackupPage = () => {
<BackupInfo />
{!isFlagshipApp() ? <InstallAppAlert /> : null}
<BackupActions />
{isFlagshipApp() ? <LastBackupStatus /> : null}
{isFlagshipApp() ? <BackupDescription /> : null}
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/photos/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@
"description": "Backup automatically all your photos and videos from your mobile devices",
"install": "Install our app"
},
"LastBackupStatus": {
"lastBackup": "Last backup:",
"success": "%{smart_count} element backed up |||| %{smart_count} elements backed up",
"partialSuccess": "%{backedUpMediaCount}/%{smart_count} element backed up |||| %{backedUpMediaCount}/%{smart_count} elements backed up"
},
"AllowPermissionsModal": {
"title": "Allow access to your photos and videos",
"description": "Cozy needs access to the photos and videos stored on your device in order to synchronize them.",
Expand Down

0 comments on commit f554261

Please sign in to comment.