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

fix: Use user locale on last konnector execution date (SCR-916) #2659

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { fetchKonnectorData } from '../helpers/konnectorBlock'
const KonnectorBlock = ({ file }) => {
const [konnector, setKonnector] = useState()
const client = useClient()
const { t } = useI18n()
const { t, lang } = useI18n()
const slug = get(file, 'cozyMetadata.createdByApp')
const sourceAccountIdentifier = get(
file,
Expand Down Expand Up @@ -84,6 +84,7 @@ const KonnectorBlock = ({ file }) => {
const label = makeLabel({
t,
konnector,
lang,
trigger,
isRunning: trigger.current_state.status === 'running'
})
Expand Down
12 changes: 10 additions & 2 deletions packages/cozy-harvest-lib/src/components/cards/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// @ts-check
import { formatLocallyDistanceToNow } from 'cozy-ui/transpiled/react/providers/I18n/format'
import {
formatLocallyDistanceToNow,
initFormat
} from 'cozy-ui/transpiled/react/providers/I18n/format'

import { isDisconnected } from '../../helpers/konnectors'
import { getLastSuccessDate } from '../../helpers/triggers'
Expand All @@ -20,9 +23,14 @@ const getDifferenceInMillisecondes = date => {
* @param {import('cozy-client/types/types').IOCozyKonnector} options.konnector - Associated Connector
* @param {object} options.trigger - Associated trigger
* @param {object} options.isRunning - If the connector is running
* @param {string} options.lang - lang identifier ('fr', 'en')
* @returns {string}
*/
export const makeLabel = ({ t, konnector, trigger, isRunning }) => {
export const makeLabel = ({ t, konnector, trigger, isRunning, lang }) => {
if (lang) {
// force current language for cozy-ui formatLocallyDistanceToNow
initFormat(lang)(new Date())
}
const lastSuccessDate = getLastSuccessDate(trigger)
if (isRunning) {
return t('card.launchTrigger.lastSync.syncing')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('makeLabel', () => {
it('should return "Sync. ago..." if lastSuccessDate is defined and > 5 minutes', () => {
const res = makeLabel({
t,
lang: 'fr',
trigger: {
current_state: { last_success: '2020-12-25T11:55:00.000Z' }
},
Expand Down
Loading