actual/packages/desktop-client/src/components/util/DisplayId.js

39 lines
969 B
JavaScript
Raw Normal View History

import React from 'react';
2022-04-29 02:44:38 +00:00
import { CachedAccounts } from 'loot-core/src/client/data-hooks/accounts';
import { CachedPayees } from 'loot-core/src/client/data-hooks/payees';
2022-04-29 02:44:38 +00:00
import { Text } from 'loot-design/src/components/common';
import { colors } from 'loot-design/src/style';
2022-04-29 02:44:38 +00:00
export default function DisplayId({ type, id, noneColor = colors.n8 }) {
let DataComponent;
switch (type) {
case 'payees':
DataComponent = CachedPayees;
break;
case 'accounts':
DataComponent = CachedAccounts;
break;
default:
throw new Error('DisplayId: unknown object type: ' + type);
}
return (
<DataComponent idKey={true}>
{data => {
let item = data[id];
return (
<Text
style={item == null ? { color: noneColor } : null}
title={item ? item.name : 'None'}
>
{item ? item.name : 'None'}
</Text>
);
}}
</DataComponent>
);
}