WIP RO Closer.
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
import { LockOutlined } from '@ant-design/icons';
|
||||
import { Card, Form, Input } from 'antd';
|
||||
import axios from 'axios';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { connect } from 'react-redux';
|
||||
import { createStructuredSelector } from 'reselect';
|
||||
import { selectJobReadOnly } from '../../redux/application/application.selectors';
|
||||
import { selectBodyshop } from '../../redux/user/user.selectors';
|
||||
import JobCostingStatistics from '../job-costing-statistics/job-costing-statistics.component';
|
||||
import LoadingSkeleton from '../loading-skeleton/loading-skeleton.component';
|
||||
import { Card, Form, Input, Space } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { LockOutlined } from '@ant-design/icons';
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
@@ -21,7 +21,7 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
});
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(JobCloseRoGuardProfit);
|
||||
|
||||
export function JobCloseRoGuardProfit({ job, jobRO, bodyshop, form }) {
|
||||
export function JobCloseRoGuardProfit({ job, jobRO, bodyshop, form, warningCallback }) {
|
||||
const [costingData, setCostingData] = useState(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
@@ -41,14 +41,21 @@ export function JobCloseRoGuardProfit({ job, jobRO, bodyshop, form }) {
|
||||
getData();
|
||||
}, [job.id]);
|
||||
|
||||
const enforceProfitPassword =
|
||||
parseFloat(costingData?.summaryData.gppercent) < bodyshop?.md_ro_guard?.totalgppercent_minimum; //TODO Add bodyshop related values.
|
||||
|
||||
useEffect(() => {
|
||||
if (enforceProfitPassword && typeof warningCallback === 'function') {
|
||||
warningCallback(t('jobs.labels.profitbypassrequired'));
|
||||
}
|
||||
}, [enforceProfitPassword, t, warningCallback]);
|
||||
|
||||
if (loading || !costingData) return <LoadingSkeleton />;
|
||||
|
||||
const enforceProfitPassword = parseFloat(costingData?.summaryData.gppercent) < 90;
|
||||
return (
|
||||
<Card title={t('jobs.labels.profits')}>
|
||||
<Space direction="horizontal">
|
||||
<JobCostingStatistics summaryData={costingData?.summaryData} onlyGP />
|
||||
</Space>{' '}
|
||||
<Card title={t('jobs.labels.profits')} style={{ height: '100%' }}>
|
||||
<JobCostingStatistics summaryData={costingData?.summaryData} onlyGP />
|
||||
|
||||
{enforceProfitPassword && (
|
||||
<Form.Item
|
||||
name="profitbypasspassword"
|
||||
@@ -61,10 +68,9 @@ export function JobCloseRoGuardProfit({ job, jobRO, bodyshop, form }) {
|
||||
validator(_, value) {
|
||||
if (
|
||||
parseFloat(costingData?.summaryData.gppercent) <
|
||||
bodyshop.md_ro_guard.totalgppercent_minimum &&
|
||||
bodyshop?.md_ro_guard?.totalgppercent_minimum &&
|
||||
value !== bodyshop.md_ro_guard.profitbypasspassword
|
||||
) {
|
||||
console.log('We shoudl enforce it.');
|
||||
return Promise.reject(t('jobs.labels.profitbypassrequired'));
|
||||
}
|
||||
return Promise.resolve();
|
||||
|
||||
Reference in New Issue
Block a user