mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 08:25:43 +00:00
fix(rates): render stored rate currency, default last mile to birr
The rate matrix currency cell hardcoded USD, so a last-mile rate priced in ETB still displayed as dollars. formatCell now takes the row and reads its currency code, falling back to USD. Last-mile currency select gets defaultValue ETB (new generic FormFieldDef.defaultValue for create-time pre-selection) and lists ETB (Birr) first; USD stays selectable. Backend already persisted and validated the chosen currency.
This commit is contained in:
@@ -234,7 +234,7 @@ const RuleEngineCardGrid = ({
|
||||
{col.header}:
|
||||
</Text>
|
||||
<div style={{ textAlign: "right", flex: 1 }}>
|
||||
{formatCell(displayValue, col.format)}
|
||||
{formatCell(displayValue, col.format, record)}
|
||||
</div>
|
||||
</Group>
|
||||
);
|
||||
|
||||
@@ -127,6 +127,8 @@ const buildInitialValues = (
|
||||
} else {
|
||||
values[field.name] = raw;
|
||||
}
|
||||
} else if (field.defaultValue !== undefined) {
|
||||
values[field.name] = field.defaultValue;
|
||||
} else if (field.type === "boolean") {
|
||||
values[field.name] = false;
|
||||
} else if (field.type === "number") {
|
||||
|
||||
@@ -17,7 +17,13 @@ const extractLabel = (value: unknown): string | null => {
|
||||
);
|
||||
};
|
||||
|
||||
export const formatCell = (value: unknown, format?: ColumnFormat): ReactNode => {
|
||||
export const formatCell = (
|
||||
value: unknown,
|
||||
format?: ColumnFormat,
|
||||
// The row the cell came from — currency amounts read their code off it so a
|
||||
// last-mile rate priced in birr does not render as USD.
|
||||
row?: Record<string, unknown>,
|
||||
): ReactNode => {
|
||||
if (value === null || value === undefined || value === "") {
|
||||
return <Text size="sm" c="dimmed">—</Text>;
|
||||
}
|
||||
@@ -109,9 +115,10 @@ export const formatCell = (value: unknown, format?: ColumnFormat): ReactNode =>
|
||||
|
||||
if (format === "currency") {
|
||||
const num = Number(value);
|
||||
const code = typeof row?.currency === "string" ? row.currency : "USD";
|
||||
return (
|
||||
<Text size="sm" fw={500}>
|
||||
{Number.isNaN(num) ? String(value) : `USD ${num.toLocaleString()}`}
|
||||
{Number.isNaN(num) ? String(value) : `${code} ${num.toLocaleString()}`}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user