Skip to content

Commit

Permalink
fix: Use user locale on last konnector execution date
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleface committed Jan 15, 2025
1 parent a00baa1 commit 18e8083
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/cozy-harvest-lib/src/components/KonnectorBlock.jsx
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

0 comments on commit 18e8083

Please sign in to comment.