Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backup): Display last backup status #2970

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
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
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
Loading