update personal code util

This commit is contained in:
2025-09-09 00:09:15 +03:00
parent 5b91ece1ec
commit 3bdc1cfefc
2 changed files with 14 additions and 15 deletions

View File

@@ -59,7 +59,7 @@ const cards = ({
}) => [ }) => [
{ {
title: 'dashboard:gender', title: 'dashboard:gender',
description: gender ?? 'dashboard:male', description: gender ?? '-',
icon: <User />, icon: <User />,
iconBg: 'bg-success', iconBg: 'bg-success',
}, },
@@ -153,7 +153,7 @@ export default function Dashboard({
<> <>
<div className="xs:grid-cols-2 grid auto-rows-fr gap-3 sm:grid-cols-4 lg:grid-cols-5"> <div className="xs:grid-cols-2 grid auto-rows-fr gap-3 sm:grid-cols-4 lg:grid-cols-5">
{cards({ {cards({
gender, gender: gender.label,
age, age,
height, height,
weight, weight,

View File

@@ -90,17 +90,6 @@ export function getBmiBackgroundColor(bmiStatus: BmiCategory | null): string {
} }
} }
export function getGenderStringFromPersonalCode(personalCode: string) {
switch (PersonalCode.parsePersonalCode(personalCode).gender) {
case 'F':
return 'common:female';
case 'M':
return 'common:male';
default:
return 'common:unknown';
}
}
type AgeRange = '18-29' | '30-39' | '40-49' | '50-59' | '60'; type AgeRange = '18-29' | '30-39' | '40-49' | '50-59' | '60';
export default class PersonalCode { export default class PersonalCode {
static getPersonalCode(personalCode: string | null) { static getPersonalCode(personalCode: string | null) {
@@ -115,7 +104,7 @@ export default class PersonalCode {
static parsePersonalCode(personalCode: string): { static parsePersonalCode(personalCode: string): {
ageRange: AgeRange; ageRange: AgeRange;
gender: 'M' | 'F'; gender: { label: string; value: string };
dob: Date; dob: Date;
age: number; age: number;
} { } {
@@ -139,7 +128,17 @@ export default class PersonalCode {
} }
throw new Error('Age range not supported'); throw new Error('Age range not supported');
})(); })();
const gender = parsed.getGender() === Gender.MALE ? 'M' : 'F'; const gender = (() => {
const gender = parsed.getGender();
switch (gender) {
case Gender.FEMALE:
return { label: 'common:female', value: 'F' };
case Gender.MALE:
return { label: 'common:male', value: 'M' };
default:
throw new Error('Gender not supported');
}
})();
return { return {
ageRange, ageRange,