fix(backoffice): make position type optional for unit departments

Creating a department under a unit required picking a position type,
which is not always known at that point. Sub-department creation is
unchanged and still requires one.

PositionPayload.positionTypeId becomes optional and the field is omitted
from the request body when unset rather than sent as an empty string.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Nathnael
2026-07-23 13:41:39 +00:00
parent 48f1d08faf
commit 063a8799f5
2 changed files with 6 additions and 12 deletions

View File

@@ -21,7 +21,7 @@ export interface PositionPayload {
organizationId: string;
parentPositionId?: string;
projectId?: string;
positionTypeId: string;
positionTypeId?: string;
}
export interface PositionQueryParams {
orderBy?: string;

View File

@@ -48,8 +48,6 @@ export function AddDepartmentForm({
if (!nameAm.trim())
newErrors.nameAm = t("organization.amharicNameRequired");
if (!key.trim()) newErrors.key = t("contentManagement.keyRequired");
if (!positionTypeId)
newErrors.positionTypeId = t("contentManagement.selectPosType");
setErrors(newErrors);
return Object.keys(newErrors).length === 0;
@@ -71,7 +69,7 @@ export function AddDepartmentForm({
key: key.trim().toLowerCase().replace(/\s+/g, "-"),
unitId,
organizationId,
positionTypeId,
...(positionTypeId ? { positionTypeId } : {}),
};
createPosition({
@@ -90,12 +88,11 @@ export function AddDepartmentForm({
return (
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="positionType">{t("organization.positionTypes")}</Label>
<Label htmlFor="positionType">
{t("organization.positionTypes")} ({t("common.optional")})
</Label>
<Select
onValueChange={(value) => {
setPositionTypeId(value);
setErrors((prev) => ({ ...prev, positionTypeId: "" }));
}}
onValueChange={setPositionTypeId}
value={positionTypeId}
disabled={isLoadingTypes}
>
@@ -110,9 +107,6 @@ export function AddDepartmentForm({
))}
</SelectContent>
</Select>
{errors.positionTypeId && (
<p className="text-red-500 text-sm">{errors.positionTypeId}</p>
)}
</div>
<div className="space-y-2">