pages/index: fetch transaction currencies

This commit is contained in:
Chika 2022-07-08 21:22:56 +03:00
parent 6f87b81400
commit bb741b7cb2
4 changed files with 42 additions and 3 deletions

View File

@ -11,7 +11,7 @@ const defaultValues: CalculationValues = {
VATInLeaseObjectPrice: 0,
leaseObjectPriceWthtVAT: 0,
engineHours: 0,
supplierCurrency: 'RUB',
supplierCurrency: null,
supplierDiscountRub: 0,
supplierDiscountPerc: 0,
leasingPeriod: 13,

View File

@ -0,0 +1,22 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: GetTransactionCurrencies
// ====================================================
export interface GetTransactionCurrencies_transactioncurrencies {
__typename: "transactioncurrency";
label: string | null;
currencysymbol: string | null;
value: any | null;
}
export interface GetTransactionCurrencies {
/**
* Валюта. statecode по умолчанию 0
*/
transactioncurrencies: (GetTransactionCurrencies_transactioncurrencies | null)[] | null;
}

View File

@ -44,13 +44,14 @@ function Home({ graphQLData }) {
/**
* set owner data to store
*/
const { ownerData } = graphQLData;
const { ownerData, transactioncurrencies } = graphQLData;
const { $calculation } = store;
$calculation.$options.setOptions({
selectLead: ownerData?.leads || [],
selectOpportunity: ownerData.opportunities || [],
selectSupplierCurrency: transactioncurrencies || [],
});
return (
@ -78,6 +79,16 @@ const QUERY_GET_OWNER_DATA = gql`
}
`;
const QUERY_GET_TRANSACTION_CURRENCIES = gql`
query GetTransactionCurrencies {
transactioncurrencies {
label: currencyname
currencysymbol
value: transactioncurrencyid
}
}
`;
export const getServerSideProps = async (ctx) => {
const user = await fetchUser({
headers: ctx?.req?.headers?.cookie
@ -96,10 +107,16 @@ export const getServerSideProps = async (ctx) => {
},
});
// prettier-ignore
const { data: { transactioncurrencies }, } = await apolloClient.query({
query: QUERY_GET_TRANSACTION_CURRENCIES,
});
return {
props: {
graphQLData: {
ownerData,
transactioncurrencies,
},
initialApolloState: apolloClient.cache.extract(),
},

View File

@ -53,7 +53,7 @@ export default class OptionsStore {
* Проверяем, что значение есть в новом списке, иначе сбрасываем значение
*/
const value = this.root.$calculation.$values.getElementValue(elementName);
if (options.length === 0 || options.some((x) => x.value === value)) {
if (!options?.length || options.some((x) => x.value === value)) {
this.root.$calculation.$values.resetElementValue(elementName);
}