WIP RO Closer.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
import axios from 'axios';
|
||||
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
|
||||
bodyshop: selectBodyshop,
|
||||
jobRO: selectJobReadOnly,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(JobCloseRoGuardProfit);
|
||||
|
||||
export function JobCloseRoGuardProfit({ job, jobRO, bodyshop, form }) {
|
||||
const [costingData, setCostingData] = useState(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
async function getData() {
|
||||
try {
|
||||
if (job.id) {
|
||||
setLoading(true);
|
||||
const { data } = await axios.post('/job/costing', { jobid: job.id });
|
||||
setCostingData(data);
|
||||
}
|
||||
} catch (error) {}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
getData();
|
||||
}, [job.id]);
|
||||
|
||||
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>{' '}
|
||||
{enforceProfitPassword && (
|
||||
<Form.Item
|
||||
name="profitbypasspassword"
|
||||
label={t('jobs.labels.profitbypasspassword')}
|
||||
rules={[
|
||||
{
|
||||
required: enforceProfitPassword,
|
||||
},
|
||||
({ getFieldValue }) => ({
|
||||
validator(_, value) {
|
||||
if (
|
||||
parseFloat(costingData?.summaryData.gppercent) <
|
||||
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();
|
||||
},
|
||||
}),
|
||||
]}
|
||||
>
|
||||
<Input prefix={<LockOutlined />} type="password" placeholder="Password" />
|
||||
</Form.Item>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user