Add risk assessment tab

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Jonathan
2025-06-03 18:35:21 +02:00
committed by Sacha Al Himdani
parent 7d2d26aab5
commit b660c0ce7f
27 changed files with 2020 additions and 311 deletions

View File

@@ -48,6 +48,23 @@ export function TranslatorProvider({
);
}
const MINUTES = 60_000;
const HOURS = MINUTES * 60;
const DAYS = HOURS * 24;
const WEEKS = DAYS * 7;
const MONTHS = DAYS * 30;
const YEARS = DAYS * 365;
const relativeFormat = [
{ limit: YEARS, unit: "years" },
{ limit: MONTHS, unit: "months" },
{ limit: WEEKS, unit: "weeks" },
{ limit: DAYS, unit: "days" },
{ limit: HOURS, unit: "hours" },
{ limit: MINUTES, unit: "minutes" },
{ limit: 0, unit: "seconds" },
] as const;
export function useTranslate() {
const { translate, lang } = useContext(TranslatorContext);
const dateFormat = (
@@ -67,12 +84,33 @@ export function useTranslate() {
}
return new Intl.DateTimeFormat(lang, options).format(date);
};
const relativeDateFormat = (
data: Date | string | null | undefined,
options: Intl.RelativeTimeFormatOptions = {
style: "long",
}
) => {
if (!data) {
return "";
}
const distanceInSeconds =
(data instanceof Date ? data.getTime() : parseDate(data).getTime()) -
Date.now();
const formatter = new Intl.RelativeTimeFormat(lang, options);
for (const { limit, unit } of relativeFormat) {
if (Math.abs(distanceInSeconds) > limit) {
return formatter.format(Math.round(distanceInSeconds / limit), unit);
}
}
return "";
};
return {
lang,
__: translate,
dateFormat: dateFormat,
relativeDateFormat,
dateTimeFormat: (
date: Date | string | null | undefined,
options: Intl.DateTimeFormatOptions = {

View File

@@ -1,19 +1,16 @@
{
"name": "@probo/i18n",
"version": "1.0.0",
"description": "",
"main": "./TranslatorProvider.tsx",
"scripts": {},
"peerDependencies": {
"react": "^18.0"
},
"keywords": [],
"author": "",
"license": "ISC",
"main": "./TranslatorProvider.tsx",
"devDependencies": {
"@types/react": "^19.1.2"
},
"dependencies": {
"date-fns": "^4.1.0"
}
"peerDependencies": {
"react": "^18.0"
},
"description": "",
"keywords": [],
"license": "ISC",
"scripts": {}
}