diff --git a/Components/Calculation/addons/currency-addon.tsx b/Components/Calculation/addons/currency-addon.tsx index 09abcfc..b2499b7 100644 --- a/Components/Calculation/addons/currency-addon.tsx +++ b/Components/Calculation/addons/currency-addon.tsx @@ -1,7 +1,6 @@ -import { gql, useApolloClient } from '@apollo/client'; +import { gql, useQuery } from '@apollo/client'; import type * as CRMTypes from 'graphql/crm.types'; import { observer } from 'mobx-react-lite'; -import { useState } from 'react'; import { useStore } from 'stores/hooks'; const QUERY_GET_CURRENCY_SYMBOL = gql` @@ -17,26 +16,17 @@ const CurrencyAddon = observer(() => { const currencyid = $calculation.$values.getValue('supplierCurrency'); - const [currencySymbol, setCurrencySymbol] = useState(null); - - const { query } = useApolloClient(); - - if (!currencyid) return null; - - query({ - query: QUERY_GET_CURRENCY_SYMBOL, + const { data } = useQuery< + CRMTypes.GetCurrencySymbolQuery, + CRMTypes.GetCurrencySymbolQueryVariables + >(QUERY_GET_CURRENCY_SYMBOL, { variables: { currencyid, }, - }) - .then(({ data }) => { - setCurrencySymbol(data?.transactioncurrency?.currencysymbol); - }) - .catch(() => { - setCurrencySymbol(null); - }); + skip: !currencyid, + }); - return {currencySymbol}; + return {data?.transactioncurrency?.currencysymbol}; }); export default ;