Browse Source

Remove stage start date and stage end date validation

Use plan start date and plan end date as every stage start date and stage end date
tags/Baseline_180220205_Frontend
MSI\2Fi 8 months ago
parent
commit
b041e1e389
5 changed files with 86 additions and 28 deletions
  1. +2
    -2
      src/app/api/projects/actions.ts
  2. +40
    -17
      src/components/CreateProject/CreateProject.tsx
  3. +3
    -3
      src/components/CreateProject/Milestone.tsx
  4. +2
    -2
      src/components/CreateProject/MilestoneSection.tsx
  5. +39
    -4
      src/components/CreateProject/ProjectClientDetails.tsx

+ 2
- 2
src/app/api/projects/actions.ts View File

@@ -59,8 +59,8 @@ export interface CreateProjectInputs {
// Milestones // Milestones
milestones: { milestones: {
[taskGroupId: TaskGroup["id"]]: { [taskGroupId: TaskGroup["id"]]: {
startDate: string;
endDate: string;
startDate: string | null;
endDate: string | null;
payments: PaymentInputs[]; payments: PaymentInputs[];
}; };
}; };


+ 40
- 17
src/components/CreateProject/CreateProject.tsx View File

@@ -96,7 +96,9 @@ const hasErrorsInTab = (
errors.projectName || errors.projectName ||
errors.projectDescription || errors.projectDescription ||
errors.clientId || errors.clientId ||
errors.projectCode
errors.projectCode ||
errors.projectPlanStart ||
errors.projectPlanEnd
); );
case 2: case 2:
return ( return (
@@ -273,6 +275,17 @@ const CreateProject: React.FC<Props> = ({
// detect errors // detect errors
let hasErrors = false; let hasErrors = false;


if(
!data.projectPlanStart || !data.projectPlanEnd
){
formProps.setError("projectPlanStart", {
message: "projectPlanStart is not valid",
type: "required",
});
setTabIndex(0);
hasErrors = true;
}

// Tab - Staff Allocation and Resource // Tab - Staff Allocation and Resource
if ( if (
data.totalManhour === null || data.totalManhour === null ||
@@ -349,21 +362,29 @@ const CreateProject: React.FC<Props> = ({
.forEach((key) => { .forEach((key) => {
const { startDate, endDate, payments } = const { startDate, endDate, payments } =
data.milestones[parseFloat(key)]; data.milestones[parseFloat(key)];

if (
!Boolean(startDate) ||
startDate === "Invalid Date" ||
!Boolean(endDate) ||
endDate === "Invalid Date" ||
new Date(startDate) > new Date(endDate)
) {
formProps.setError("milestones", {
message: "milestones is not valid",
type: "invalid",
});
setTabIndex(3);
hasErrors = true;
}
if (
!Boolean(startDate) ||
startDate === "Invalid Date" ||
!Boolean(endDate) ||
endDate === "Invalid Date"
){
data.milestones[parseFloat(key)].startDate = null
data.milestones[parseFloat(key)].endDate = null
}
// if (
// !Boolean(startDate) ||
// startDate === "Invalid Date" ||
// !Boolean(endDate) ||
// endDate === "Invalid Date" ||
// new Date(startDate) > new Date(endDate)
// ) {
// formProps.setError("milestones", {
// message: "milestones is not valid",
// type: "invalid",
// });
// setTabIndex(3);
// hasErrors = true;
// }


projectTotal += payments.reduce( projectTotal += payments.reduce(
(acc, payment) => acc + payment.amount, (acc, payment) => acc + payment.amount,
@@ -471,7 +492,9 @@ const CreateProject: React.FC<Props> = ({
errors.projectName || errors.projectName ||
errors.projectDescription || errors.projectDescription ||
errors.projectCode || errors.projectCode ||
errors.clientId
errors.clientId ||
errors.projectPlanStart ||
errors.projectPlanEnd
) { ) {
setTabIndex(0); setTabIndex(0);
} else if ( } else if (


+ 3
- 3
src/components/CreateProject/Milestone.tsx View File

@@ -85,9 +85,9 @@ const Milestone: React.FC<Props> = ({ allTasks, isActive }) => {
milestonesKeys.forEach(key => { milestonesKeys.forEach(key => {
const { startDate, endDate, payments } = milestones[parseFloat(key)] const { startDate, endDate, payments } = milestones[parseFloat(key)]


if (new Date(startDate) > new Date(endDate) || !Boolean(startDate) || !Boolean(endDate)) {
hasError = true
}
// if (new Date(startDate) > new Date(endDate) || !Boolean(startDate) || !Boolean(endDate)) {
// hasError = true
// }


projectTotal += payments.reduce((acc, payment) => acc + payment.amount, 0) projectTotal += payments.reduce((acc, payment) => acc + payment.amount, 0)
}) })


+ 2
- 2
src/components/CreateProject/MilestoneSection.tsx View File

@@ -326,7 +326,7 @@ const MilestoneSection: React.FC<Props> = ({ taskGroupId }) => {
<Typography variant="overline" display="block" marginBlockEnd={1}> <Typography variant="overline" display="block" marginBlockEnd={1}>
{t("Stage Milestones")} {t("Stage Milestones")}
</Typography> </Typography>
<Grid container spacing={2} columns={{ xs: 6, sm: 12 }}>
{/* <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}>
<Grid item xs> <Grid item xs>
<FormControl fullWidth> <FormControl fullWidth>
<DatePicker <DatePicker
@@ -385,7 +385,7 @@ const MilestoneSection: React.FC<Props> = ({ taskGroupId }) => {
/> />
</FormControl> </FormControl>
</Grid> </Grid>
</Grid>
</Grid> */}
<Box <Box
sx={(theme) => ({ sx={(theme) => ({
marginBlockStart: 1, marginBlockStart: 1,


+ 39
- 4
src/components/CreateProject/ProjectClientDetails.tsx View File

@@ -86,6 +86,8 @@ const ProjectClientDetails: React.FC<Props> = ({
getValues, getValues,
reset, reset,
resetField, resetField,
setError,
clearErrors
} = useFormContext<CreateProjectInputs>(); } = useFormContext<CreateProjectInputs>();


const subsidiaryMap = useMemo<{ const subsidiaryMap = useMemo<{
@@ -242,6 +244,34 @@ const ProjectClientDetails: React.FC<Props> = ({
const planStart = getValues("projectPlanStart") const planStart = getValues("projectPlanStart")
const planEnd = getValues("projectPlanEnd") const planEnd = getValues("projectPlanEnd")


useEffect(() => {
let hasErrors = false
if(
!planStart || planStart > planEnd
){
hasErrors = true;
}
if(
!planEnd || planStart > planEnd
){
hasErrors = true;
}
if(hasErrors){
setError("projectPlanStart", {
message: "Project Plan Start date is not valid",
type: "required",
});
setError("projectPlanEnd", {
message: "Project Plan End date is not valid",
type: "required",
});
}else{
clearErrors("projectPlanStart")
clearErrors("projectPlanEnd")
}
},[planStart, planEnd])

return ( return (
<Card sx={{ display: isActive ? "block" : "none" }}> <Card sx={{ display: isActive ? "block" : "none" }}>
<CardContent component={Stack} spacing={4}> <CardContent component={Stack} spacing={4}>
@@ -311,8 +341,10 @@ const ProjectClientDetails: React.FC<Props> = ({
textField: { textField: {
// required: true, // required: true,
error: error:
Boolean(errors.projectPlanStart)
|| new Date(planStart) > new Date(planEnd)
// Boolean(errors.projectPlanStart)
// ||
new Date(planStart) > new Date(planEnd)
|| !Boolean(planStart)
, ,
}, },
}} }}
@@ -335,9 +367,12 @@ const ProjectClientDetails: React.FC<Props> = ({
}} }}
slotProps={{ slotProps={{
textField: { textField: {
// required: true,
error: error:
Boolean(errors.projectPlanEnd)
|| new Date(planStart) > new Date(planEnd)
// Boolean(errors.projectPlanEnd)
// ||
new Date(planStart) > new Date(planEnd)
|| !Boolean(planEnd)
, ,
}, },
}} }}


Loading…
Cancel
Save