CurrencyAddon: return null if currency is null too

This commit is contained in:
Chika 2022-07-09 09:37:15 +03:00
parent 3c5247d757
commit ce2a65bda0

View File

@ -18,27 +18,26 @@ const CurrencyAddon = observer(() => {
const currencyid = $calculation.$values.getValue('supplierCurrency');
const [currencySymbol, setCurrencySymbol] = useState('');
const [currencySymbol, setCurrencySymbol] = useState<string | null | undefined>(null);
const apolloClient = useApolloClient();
const { query } = useApolloClient();
if (currencyid) {
apolloClient
.query<GetCurrencySymbol, GetCurrencySymbolVariables>({
query: QUERY_GET_CURRENCY_SYMBOL,
variables: {
currencyid,
},
})
.then(({ data }) => {
setCurrencySymbol(data?.transactioncurrency?.currencysymbol || '');
})
.catch(() => {
setCurrencySymbol('');
});
}
if (!currencyid) return null;
return <div>{currencySymbol}</div>;
query<GetCurrencySymbol, GetCurrencySymbolVariables>({
query: QUERY_GET_CURRENCY_SYMBOL,
variables: {
currencyid,
},
})
.then(({ data }) => {
setCurrencySymbol(data?.transactioncurrency?.currencysymbol);
})
.catch(() => {
setCurrencySymbol(null);
});
return <span>{currencySymbol}</span>;
});
export default <CurrencyAddon />;