Skip to content

Commit c362886

Browse files
committed
Add validation for contract dates
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
1 parent f728a29 commit c362886

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

apps/console/src/pages/organizations/people/NewPeopleView.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ function NewPeopleViewContent() {
151151
description: error.message || "Failed to create person",
152152
variant: "destructive",
153153
});
154+
155+
const defaultErrorValues = {
156+
title: "Error",
157+
description: error.message || "Failed to save changes",
158+
variant: "destructive" as const
159+
};
160+
161+
if (error.message?.includes("contract end date must be after or equal to start date")) {
162+
toast({
163+
...defaultErrorValues,
164+
description:
165+
"Contract end date must be after or equal to start date.",
166+
});
167+
}
168+
else {
169+
toast(defaultErrorValues);
170+
}
154171
},
155172
});
156173
};

apps/console/src/pages/organizations/people/PeopleView.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,29 @@ function PeopleViewContent({
143143
setEditedFields(new Set());
144144
},
145145
onError: (error) => {
146+
const defaultErrorValues = {
147+
title: "Error",
148+
description: error.message || "Failed to save changes",
149+
variant: "destructive" as const
150+
};
151+
146152
if (error.message?.includes("concurrent modification")) {
147153
toast({
148-
title: "Error",
149-
description:
150-
"Someone else modified this person. Reloading latest data.",
151-
variant: "destructive",
154+
...defaultErrorValues,
155+
description: "Someone else modified this person. Reloading latest data.",
152156
});
153157
loadQuery({ peopleId: data.node.id! });
154-
} else {
158+
}
159+
else if (error.message?.includes("contract end date must be after or equal to start date")) {
155160
toast({
156-
title: "Error",
157-
description: error.message || "Failed to save changes",
158-
variant: "destructive",
161+
...defaultErrorValues,
162+
description:
163+
"Contract end date must be after or equal to start date.",
159164
});
160165
}
166+
else {
167+
toast(defaultErrorValues);
168+
}
161169
},
162170
});
163171
}, [commit, data.node.id, formData, loadQuery, toast]);

pkg/probo/people_service.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ func (s PeopleService) Update(
161161
people.ContractEndDate = *req.ContractEndDate
162162
}
163163

164+
if people.ContractStartDate != nil && people.ContractEndDate != nil {
165+
if people.ContractEndDate.Before(*people.ContractStartDate) {
166+
return fmt.Errorf("contract end date must be after or equal to start date")
167+
}
168+
}
169+
164170
people.UpdatedAt = time.Now()
165171

166172
return people.Update(ctx, conn, s.svc.scope)
@@ -176,6 +182,12 @@ func (s PeopleService) Create(
176182
ctx context.Context,
177183
req CreatePeopleRequest,
178184
) (*coredata.People, error) {
185+
if req.ContractStartDate != nil && req.ContractEndDate != nil {
186+
if req.ContractEndDate.Before(*req.ContractStartDate) {
187+
return nil, fmt.Errorf("contract end date must be after or equal to start date")
188+
}
189+
}
190+
179191
now := time.Now()
180192
peopleID := gid.New(s.svc.scope.GetTenantID(), coredata.PeopleEntityType)
181193

0 commit comments

Comments
 (0)