download kp button

This commit is contained in:
Chika 2020-12-28 12:40:55 +03:00
parent 5f615fd12f
commit bb1ac67112
16 changed files with 109 additions and 11 deletions

View File

@ -2,6 +2,7 @@
"name": "evocalculator.client", "name": "evocalculator.client",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@ant-design/icons": "^4.3.0",
"@apollo/client": "^3.3.4", "@apollo/client": "^3.3.4",
"@babel/code-frame": "^7.10.4", "@babel/code-frame": "^7.10.4",
"@babel/helper-split-export-declaration": "^7.11.0", "@babel/helper-split-export-declaration": "^7.11.0",

View File

@ -357,6 +357,9 @@ const sections: ISection[] = [
{ {
elements: ['btnCreateKP'], elements: ['btnCreateKP'],
}, },
{
elements: ['linkDownloadKp'],
},
], ],
}, },
], ],

View File

@ -1,6 +1,7 @@
import { import {
withButton, withButton,
withComputedValue, withComputedValue,
withLink,
withTable, withTable,
withValue, withValue,
} from 'client/hocs/Calculation'; } from 'client/hocs/Calculation';
@ -13,6 +14,7 @@ import elementsProps from './elements/elementsProps';
import elementsTypes from './elements/types'; import elementsTypes from './elements/types';
import elementsValues from './elements/values'; import elementsValues from './elements/values';
import tables from './elements/tables'; import tables from './elements/tables';
import elementsUrls from './elements/urls';
export function buildElement(elementName) { export function buildElement(elementName) {
const elementType = elementsTypes[elementName]; const elementType = elementsTypes[elementName];
@ -40,6 +42,13 @@ export function buildElement(elementName) {
...elementProps, ...elementProps,
}); });
} }
case ElementType.Link: {
return withLink(Component)({
name: elementName,
urlName: elementsUrls[elementName],
...elementProps,
});
}
default: { default: {
return withValue(Component)({ return withValue(Component)({
name: elementName, name: elementName,

View File

@ -9,6 +9,7 @@ import Select from 'client/Elements/Select';
import Switch from 'client/Elements/Switch'; import Switch from 'client/Elements/Switch';
import Table from 'client/Elements/Table'; import Table from 'client/Elements/Table';
import TextArea from 'client/Elements/TextArea'; import TextArea from 'client/Elements/TextArea';
import Download from 'client/Elements/Download';
import { Component } from 'core/types/Calculation/components'; import { Component } from 'core/types/Calculation/components';
import { TElements } from 'core/types/Calculation/Store/elements'; import { TElements } from 'core/types/Calculation/Store/elements';
@ -155,6 +156,7 @@ const elementsComponents: TElements<Component> = {
labelResultBonusMPL: Label, labelResultBonusMPL: Label,
labelResultDopMPLLeasing: Label, labelResultDopMPLLeasing: Label,
labelResultBonusDopProd: Label, labelResultBonusDopProd: Label,
linkDownloadKp: Download,
}; };
const tablesComponents: StoreTables<Component> = { const tablesComponents: StoreTables<Component> = {

View File

@ -12,6 +12,8 @@ import {
validatePhone, validatePhone,
} from 'client/tools/validate'; } from 'client/tools/validate';
import { DownloadOutlined } from '@ant-design/icons';
const elementsProps: TElements<ElementProps> = { const elementsProps: TElements<ElementProps> = {
selectChannel: { selectChannel: {
showSearch: true, showSearch: true,
@ -70,7 +72,6 @@ const elementsProps: TElements<ElementProps> = {
}, },
btnCreateLead: { btnCreateLead: {
type: 'primary', type: 'primary',
size: 'large',
text: 'Создать интерес', text: 'Создать интерес',
}, },
tbxLeaseObjectPrice: { tbxLeaseObjectPrice: {
@ -277,7 +278,6 @@ const elementsProps: TElements<ElementProps> = {
}, },
btnCreateKP: { btnCreateKP: {
type: 'primary', type: 'primary',
size: 'large',
text: 'Создать КП', text: 'Создать КП',
}, },
tbxCreditRate: { tbxCreditRate: {
@ -318,6 +318,11 @@ const elementsProps: TElements<ElementProps> = {
max: '500.0000', max: '500.0000',
step: '0.0001', step: '0.0001',
}, },
linkDownloadKp: {
type: 'primary',
text: 'Скачать КП',
icon: DownloadOutlined,
},
}; };
const resultElementsProps: TElements<ElementProps> = [ const resultElementsProps: TElements<ElementProps> = [

View File

@ -10,6 +10,7 @@ const elementsTypes: TElements<ElementType> = {
btnCreateKP: ElementType.Action, btnCreateKP: ElementType.Action,
btnCalculate: ElementType.Action, btnCalculate: ElementType.Action,
labelIrrInfo: ElementType.Computed, labelIrrInfo: ElementType.Computed,
linkDownloadKp: ElementType.Link,
}; };
const tablesTypes: StoreTables<ElementType> = { const tablesTypes: StoreTables<ElementType> = {

View File

@ -0,0 +1,8 @@
import { LinksNames } from 'core/types/Calculation/Store/links';
import { TElements } from 'core/types/Calculation/Store/elements';
const elementsUrls: TElements<LinksNames> = {
linkDownloadKp: 'kpUrl',
};
export default elementsUrls;

View File

@ -0,0 +1,20 @@
import { Button as AntButton } from 'antd';
import { ElementStatus } from 'core/types/statuses';
import React from 'react';
const Download = ({ status, url, text, icon: Icon, ...props }) => {
return (
<AntButton
{...props}
target="_blank"
href={url}
disabled={status === ElementStatus.Disabled || !url}
loading={status === ElementStatus.Loading}
icon={<Icon />}
>
{text}
</AntButton>
);
};
export default Download;

View File

@ -1,7 +1,15 @@
import withButton from './withButton'; import withButton from './withButton';
import withLink from './withLink';
import withComputedValue from './withComputedValue'; import withComputedValue from './withComputedValue';
import withModal from './withModal'; import withModal from './withModal';
import withTable from './withTable'; import withTable from './withTable';
import withValue from './withValue'; import withValue from './withValue';
export { withButton, withValue, withComputedValue, withModal, withTable }; export {
withButton,
withLink,
withValue,
withComputedValue,
withModal,
withTable,
};

View File

@ -0,0 +1,12 @@
import { useStatus } from 'client/hooks/Calculation/useStatus';
import { useUrl } from 'client/hooks/Calculation/useUrl';
import { observer } from 'mobx-react-lite';
import React from 'react';
export default Button => ({ name, urlName, ...props }) =>
observer(() => {
const { status } = useStatus(name);
const { url } = useUrl({ urlName });
return <Button status={status} {...props} url={url} />;
});

View File

@ -0,0 +1,6 @@
import { calculationUrls } from 'client/stores/CalculationStore';
export const useUrl = ({ urlName }) => {
const url = calculationUrls.urls[urlName];
return { url };
};

View File

@ -2,7 +2,7 @@ import { gql } from '@apollo/client';
import { message } from 'antd'; import { message } from 'antd';
import CrmService from 'client/services/CrmService'; import CrmService from 'client/services/CrmService';
import { getUser } from 'client/tools/user'; import { getUser } from 'client/tools/user';
import CalculationStore from '../..'; import CalculationStore, { calculationUrls } from '../..';
import customValues from '../lib/customValues'; import customValues from '../lib/customValues';
import { openNotification } from 'client/Elements/Notification'; import { openNotification } from 'client/Elements/Notification';
@ -14,6 +14,8 @@ export default async () => {
return; return;
} }
calculationUrls.setUrl({ name: 'kpUrl', url: undefined });
const insurances = tables.tableInsurance.rows.map(insuranceRow => { const insurances = tables.tableInsurance.rows.map(insuranceRow => {
const resObj = {}; const resObj = {};
Object.keys(insuranceRow).forEach(prop => { Object.keys(insuranceRow).forEach(prop => {
@ -77,10 +79,10 @@ export default async () => {
}); });
if (quote?.offerprintform) { if (quote?.offerprintform) {
Object.assign(document.createElement('a'), { calculationUrls.setUrl({
target: '_blank', name: 'kpUrl',
href: quote.offerprintform, url: quote.offerprintform,
}).click(); });
} }
} }
}); });

View File

@ -1,3 +1,4 @@
import { LinksNames } from './../../../core/types/Calculation/Store/links';
import { ICalculationStore } from 'core/types/Calculation/Store'; import { ICalculationStore } from 'core/types/Calculation/Store';
import { Process } from 'core/types/Calculation/Store/process'; import { Process } from 'core/types/Calculation/Store/process';
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
@ -20,6 +21,13 @@ export const calculationProcess = makeAutoObservable({
}, },
}); });
export const calculationUrls = makeAutoObservable({
urls: {},
setUrl({ name, url }: { name: LinksNames; url: string }) {
this.urls[name] = url;
},
});
const CalculationStore: ICalculationStore = makeAutoObservable( const CalculationStore: ICalculationStore = makeAutoObservable(
Object.assign( Object.assign(
{}, {},

View File

@ -133,6 +133,8 @@ export type ElementsNames =
| 'selectTracker' | 'selectTracker'
| 'labelIrrInfo'; | 'labelIrrInfo';
export type LinkElementsNames = 'linkDownloadKp';
export type ResultElementsNames = export type ResultElementsNames =
| 'labelResultTotalGraphwithNDS' | 'labelResultTotalGraphwithNDS'
| 'labelResultPlPrice' | 'labelResultPlPrice'
@ -156,8 +158,9 @@ export enum ElementType {
Computed, Computed,
Table, Table,
Action, Action,
Link,
} }
export type TElements<T> = { export type TElements<T> = {
[elementName in ElementsNames | ResultElementsNames]?: T; [elementName in ElementsNames | ResultElementsNames | LinkElementsNames]?: T;
}; };

View File

@ -0,0 +1 @@
export type LinksNames = 'kpUrl';

View File

@ -1,4 +1,8 @@
import { ElementsNames, ResultElementsNames } from './Store/elements'; import {
ElementsNames,
ResultElementsNames,
LinkElementsNames,
} from './Store/elements';
import { TableNames, TableValuesNames } from './Store/tables'; import { TableNames, TableValuesNames } from './Store/tables';
export type ElementProps = { [key: string]: any }; export type ElementProps = { [key: string]: any };
@ -23,7 +27,12 @@ export interface ITableElement {
interface IBlock { interface IBlock {
title?: string; title?: string;
elements: (ElementsNames | ResultElementsNames | TableNames)[]; elements: (
| ElementsNames
| ResultElementsNames
| TableNames
| LinkElementsNames
)[];
layout?: { [key: string]: any }; layout?: { [key: string]: any };
[key: string]: any; [key: string]: any;
} }