fix: project task dialog.

This commit is contained in:
elforjani13
2022-09-25 22:29:51 +02:00
parent 8ac881cfd7
commit 3c3f8c6731
4 changed files with 11 additions and 36 deletions

View File

@@ -12,10 +12,9 @@ const Schema = Yup.object().shape({
rate: Yup.number() rate: Yup.number()
.label(intl.get('project_task.schema.label.rate')) .label(intl.get('project_task.schema.label.rate'))
.required(), .required(),
cost_estimate: Yup.number().required(), estimate_hours: Yup.string()
estimate_minutes: Yup.string().label( .label(intl.get('project_task.schema.label.estimate_hours'))
intl.get('project_task.schema.label.task_house'), .nullable(),
),
}); });
export const CreateProjectTaskFormSchema = Schema; export const CreateProjectTaskFormSchema = Schema;

View File

@@ -6,16 +6,14 @@ import { Intent } from '@blueprintjs/core';
import { AppToaster } from '@/components'; import { AppToaster } from '@/components';
import { CreateProjectTaskFormSchema } from './ProjectTaskForm.schema'; import { CreateProjectTaskFormSchema } from './ProjectTaskForm.schema';
import { useProjectTaskFormContext } from './ProjectTaskFormProvider'; import { useProjectTaskFormContext } from './ProjectTaskFormProvider';
import { transformToValue } from './utils';
import { compose, transformToForm } from '@/utils'; import { compose, transformToForm } from '@/utils';
import ProjectTaskFormContent from './ProjectTaskFormContent'; import ProjectTaskFormContent from './ProjectTaskFormContent';
import withDialogActions from '@/containers/Dialog/withDialogActions'; import withDialogActions from '@/containers/Dialog/withDialogActions';
const defaultInitialValues = { const defaultInitialValues = {
name: '', name: '',
charge_type: 'fixed', charge_type: 'TIME',
estimate_minutes: '', estimate_hours: '',
cost_estimate: 0,
rate: '0.00', rate: '0.00',
}; };
@@ -46,7 +44,7 @@ function ProjectTaskForm({
// Handles the form submit. // Handles the form submit.
const handleFormSubmit = (values, { setSubmitting, setErrors }) => { const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
const form = transformToValue(values); const form = {...values};
// Handle request response success. // Handle request response success.
const onSuccess = (response) => { const onSuccess = (response) => {

View File

@@ -11,7 +11,7 @@ import {
} from '@/components'; } from '@/components';
import { EstimateAmount } from './utils'; import { EstimateAmount } from './utils';
import { taskChargeOptions } from '../common/modalChargeOptions'; import { taskChargeOptions } from '../common/modalChargeOptions';
import { ChangeTypesSelect } from '../../components'; import { ProjectTaskChargeTypeSelect } from '../../components';
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization'; import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
import { compose } from '@/utils'; import { compose } from '@/utils';
@@ -40,9 +40,9 @@ function ProjectTaskFormFields({
<Col xs={4}> <Col xs={4}>
<FFormGroup <FFormGroup
label={<T id={'project_task.dialog.estimated_hours'} />} label={<T id={'project_task.dialog.estimated_hours'} />}
name={'estimate_minutes'} name={'estimate_hours'}
> >
<FInputGroup name="estimate_minutes" /> <FInputGroup name="estimate_hours" />
</FFormGroup> </FFormGroup>
</Col> </Col>
{/*------------ Charge -----------*/} {/*------------ Charge -----------*/}
@@ -53,7 +53,7 @@ function ProjectTaskFormFields({
label={<T id={'project_task.dialog.charge'} />} label={<T id={'project_task.dialog.charge'} />}
> >
<ControlGroup> <ControlGroup>
<ChangeTypesSelect <ProjectTaskChargeTypeSelect
name="charge_type" name="charge_type"
items={taskChargeOptions} items={taskChargeOptions}
popoverProps={{ minimal: true }} popoverProps={{ minimal: true }}

View File

@@ -9,7 +9,7 @@ export function EstimateAmount({ baseCurrency }) {
const { values } = useFormikContext(); const { values } = useFormikContext();
// Calculate estimate amount. // Calculate estimate amount.
const estimatedAmount = _.multiply(values.rate, values.estimate_minutes); const estimatedAmount = _.multiply(values.rate, values.estimate_hours);
return ( return (
<EstimatedAmountBase> <EstimatedAmountBase>
@@ -39,28 +39,6 @@ export function EstimateAmount({ baseCurrency }) {
); );
} }
export function transformToValue(values) {
switch (values.charge_type) {
case 'hourly_rate': {
return {
...values,
cost_estimate: values.estimate_minutes * values.rate,
};
}
case 'fixed_price': {
return {
...values,
cost_estimate: values.rate,
};
}
default: {
return {
...values,
};
}
}
}
const EstimatedAmountBase = styled.div` const EstimatedAmountBase = styled.div`
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;