forked from bitwarden/clients
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use expiration date messages from cozy-client
- Loading branch information
Showing
4 changed files
with
28 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
apps/browser/src/vault/popup/components/vault/view-expiration-date.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
· | ||
<span *ngIf="field.expirationData.isExpired" class="text-danger"> | ||
{{ "expired" | i18n }} | ||
{{ message }} | ||
</span> | ||
<span *ngIf="field.expirationData.isExpiringSoon" class="text-warning"> | ||
{{ "expiredIn" | i18n }} {{ getExpirationDistance() }} | ||
{{ message }} | ||
</span> |
35 changes: 26 additions & 9 deletions
35
apps/browser/src/vault/popup/components/vault/view-expiration-date.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,42 @@ | ||
/* eslint-disable import/no-duplicates */ | ||
import { Component, Input } from "@angular/core"; | ||
import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict"; | ||
import fr from "date-fns/locale/fr"; | ||
import { Component, Input, OnInit } from "@angular/core"; | ||
import { models } from "cozy-client"; | ||
|
||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; | ||
import { FieldView } from "@bitwarden/common/vault/models/view/field.view"; | ||
|
||
const { makeExpiredMessage, makeExpiresInMessage } = models.paper; | ||
|
||
@Component({ | ||
selector: "app-vault-view-expiration-date", | ||
templateUrl: "./view-expiration-date.component.html", | ||
}) | ||
export class ViewExpirationDateComponent { | ||
export class ViewExpirationDateComponent implements OnInit { | ||
@Input() field: FieldView; | ||
message: string; | ||
|
||
constructor(private i18nService: I18nService) {} | ||
|
||
getExpirationDistance(): string { | ||
return formatDistanceToNowStrict( | ||
new Date(this.field.expirationData.expirationDate), | ||
ngOnInit() { | ||
if (this.field.expirationData.isExpired) { | ||
this.message = this.getExpiredMessage(); | ||
} else if (this.field.expirationData.isExpiringSoon) { | ||
this.message = this.getExpiresInMessage(); | ||
} | ||
} | ||
|
||
getExpiredMessage(): string { | ||
return makeExpiredMessage( | ||
this.field.expirationData.expirationDate, | ||
// @ts-expect-error I did not succeed in getting i18nService.translationLocale so I fallback to a private property | ||
{ lang: this.i18nService.systemLanguage } | ||
); | ||
} | ||
|
||
getExpiresInMessage(): string { | ||
return makeExpiresInMessage( | ||
this.field.expirationData.expirationDate, | ||
// @ts-expect-error I did not succeed in getting i18nService.translationLocale so I fallback to a private property | ||
{ locale: this.i18nService.systemLanguage === "fr" ? fr : undefined } | ||
{ lang: this.i18nService.systemLanguage } | ||
); | ||
} | ||
} |