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()
.label(intl.get('project_task.schema.label.rate'))
.required(),
cost_estimate: Yup.number().required(),
estimate_minutes: Yup.string().label(
intl.get('project_task.schema.label.task_house'),
),
estimate_hours: Yup.string()
.label(intl.get('project_task.schema.label.estimate_hours'))
.nullable(),
});
export const CreateProjectTaskFormSchema = Schema;

View File

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

View File

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

View File

@@ -9,7 +9,7 @@ export function EstimateAmount({ baseCurrency }) {
const { values } = useFormikContext();
// Calculate estimate amount.
const estimatedAmount = _.multiply(values.rate, values.estimate_minutes);
const estimatedAmount = _.multiply(values.rate, values.estimate_hours);
return (
<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`
display: flex;
justify-content: flex-end;