56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
/* eslint-disable canonical/sort-keys */
|
|
import * as CRMTypes from '@/graphql/crm.types';
|
|
import { useStore } from '@/stores/hooks';
|
|
import { useApolloClient } from '@apollo/client';
|
|
import { useEffect } from 'react';
|
|
|
|
/**
|
|
* @param {import('@apollo/client').ApolloClient} apolloClient
|
|
* @param {*} onCompleted
|
|
*/
|
|
function getInsuranceData({ query }, onCompleted) {
|
|
query({
|
|
query: CRMTypes.GetInsuranceCompaniesDocument,
|
|
}).then(({ data }) => {
|
|
const insurance = {
|
|
osago: {
|
|
insuranceCompany: data.accounts.filter((x) =>
|
|
x?.evo_type_ins_policy?.includes(100_000_001)
|
|
),
|
|
},
|
|
kasko: {
|
|
insuranceCompany: data.accounts.filter((x) =>
|
|
x?.evo_type_ins_policy?.includes(100_000_000)
|
|
),
|
|
},
|
|
fingap: {
|
|
insuranceCompany: data.accounts.filter((x) =>
|
|
x?.evo_type_ins_policy?.includes(100_000_002)
|
|
),
|
|
},
|
|
};
|
|
|
|
onCompleted(insurance);
|
|
});
|
|
}
|
|
|
|
export function useInsuranceData() {
|
|
const { $tables } = useStore();
|
|
const apolloClient = useApolloClient();
|
|
|
|
function handleOnCompleted(options) {
|
|
Object.keys(options).forEach((key) => {
|
|
const rowOptions = options[key];
|
|
if (rowOptions !== undefined) {
|
|
Object.keys(rowOptions).forEach((valueName) => {
|
|
$tables.insurance.row(key).setOptions(valueName, rowOptions[valueName]);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
useEffect(() => {
|
|
getInsuranceData(apolloClient, handleOnCompleted);
|
|
}, []);
|
|
}
|