Skip to content

Commit 22e07ca

Browse files
committed
fixed validation
1 parent 0624b94 commit 22e07ca

2 files changed

Lines changed: 132 additions & 2 deletions

File tree

frontend/src/Components/Positions/AddPositionForm.jsx

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ const AddPositionForm = () => {
1818
setFormData((prev) => ({ ...prev, [field]: value }));
1919
};
2020

21+
const handleRequirementChange = (field, value) => {
22+
setFormData((prev) => ({
23+
...prev,
24+
requirements: { ...prev.requirements, [field]: value },
25+
}));
26+
};
27+
2128
const handleArrayChange = (arrayName, index, value) => {
2229
setFormData((prev) => {
2330
const updatedArray = [...prev[arrayName]];
@@ -26,26 +33,59 @@ const AddPositionForm = () => {
2633
});
2734
};
2835

36+
const handleRequirementArrayChange = (arrayName, index, value) => {
37+
setFormData((prev) => ({
38+
...prev,
39+
requirements: {
40+
...prev.requirements,
41+
[arrayName]: prev.requirements[arrayName].map((item, i) =>
42+
i === index ? value : item
43+
),
44+
},
45+
}));
46+
};
47+
2948
const addToArray = (arrayName) => {
3049
setFormData((prev) => ({
3150
...prev,
3251
[arrayName]: [...prev[arrayName], ""],
3352
}));
3453
};
3554

55+
const addToRequirementArray = (arrayName) => {
56+
setFormData((prev) => ({
57+
...prev,
58+
requirements: {
59+
...prev.requirements,
60+
[arrayName]: [...prev.requirements[arrayName], ""],
61+
},
62+
}));
63+
};
64+
3665
const removeFromArray = (arrayName, index) => {
3766
setFormData((prev) => ({
3867
...prev,
3968
[arrayName]: prev[arrayName].filter((_, i) => i !== index),
4069
}));
4170
};
4271

72+
const removeFromRequirementArray = (arrayName, index) => {
73+
setFormData((prev) => ({
74+
...prev,
75+
requirements: {
76+
...prev.requirements,
77+
[arrayName]: prev.requirements[arrayName].filter((_, i) => i !== index),
78+
},
79+
}));
80+
};
81+
4382
return (
4483
<div className="w-full bg-white flex items-center justify-center p-4">
4584
<form
4685
onSubmit={handleSubmit}
4786
className="w-full px-8 bg-white/80 backdrop-blur-sm rounded-2xl"
4887
>
88+
{/* Basic Information */}
4989
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
5090
<FormInput
5191
label="Position Title"
@@ -57,6 +97,23 @@ const AddPositionForm = () => {
5797
error={errors.title}
5898
/>
5999

100+
{/* ADDED: Organizational Unit field */}
101+
<FormSelect
102+
label="Organizational Unit"
103+
required
104+
value={formData.unit_id}
105+
onChange={(e) => handleInputChange("unit_id", e.target.value)}
106+
error={errors.unit_id}
107+
options={[
108+
{ value: "", label: "Select unit" },
109+
...scopedUnits.map((unit) => ({
110+
value: unit._id,
111+
label: unit.name,
112+
})),
113+
]}
114+
disabled={isCoordinator}
115+
/>
116+
60117
<FormSelect
61118
label="Position Type"
62119
required
@@ -75,6 +132,21 @@ const AddPositionForm = () => {
75132
]}
76133
/>
77134

135+
{/* ADDED: Custom position type field (shown when "Other" is selected) */}
136+
{formData.position_type === "Other" && (
137+
<FormInput
138+
label="Custom Position Type"
139+
required
140+
type="text"
141+
value={formData.custom_position_type}
142+
onChange={(e) =>
143+
handleInputChange("custom_position_type", e.target.value)
144+
}
145+
placeholder="Specify position type"
146+
error={errors.custom_position_type}
147+
/>
148+
)}
149+
78150
<FormInput
79151
label="Number of Positions"
80152
required
@@ -88,7 +160,65 @@ const AddPositionForm = () => {
88160
/>
89161
</div>
90162

91-
<div className="pt-4 grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-6 border-t border-stone-200">
163+
{/* ADDED: Description field */}
164+
<div className="pt-4 border-t border-stone-200">
165+
<label className="block text-sm font-medium text-stone-700 mb-2">
166+
Description
167+
</label>
168+
<textarea
169+
value={formData.description}
170+
onChange={(e) => handleInputChange("description", e.target.value)}
171+
placeholder="Describe the position..."
172+
rows="4"
173+
className="w-full px-3 py-2 border border-stone-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-stone-500"
174+
/>
175+
</div>
176+
177+
{/* ADDED: Requirements section */}
178+
<div className="pt-4 border-t border-stone-200">
179+
<h3 className="text-lg font-semibold text-stone-800 mb-4">
180+
Requirements
181+
</h3>
182+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
183+
<FormInput
184+
label="Minimum CGPA"
185+
type="number"
186+
step="0.1"
187+
min="0"
188+
max="10"
189+
value={formData.requirements.min_cgpa}
190+
onChange={(e) =>
191+
handleRequirementChange("min_cgpa", Number(e.target.value))
192+
}
193+
/>
194+
195+
<FormInput
196+
label="Minimum Year"
197+
type="number"
198+
min="1"
199+
max="5"
200+
value={formData.requirements.min_year}
201+
onChange={(e) =>
202+
handleRequirementChange("min_year", Number(e.target.value))
203+
}
204+
/>
205+
</div>
206+
207+
<DynamicFieldArray
208+
label="Skills Required"
209+
array={formData.requirements.skills_required}
210+
onUpdate={(index, value) =>
211+
handleRequirementArrayChange("skills_required", index, value)
212+
}
213+
onRemove={(index) =>
214+
removeFromRequirementArray("skills_required", index)
215+
}
216+
onAdd={() => addToRequirementArray("skills_required")}
217+
/>
218+
</div>
219+
220+
{/* Responsibilities */}
221+
<div className="pt-4 grid grid-cols-1 gap-y-6 border-t border-stone-200">
92222
<DynamicFieldArray
93223
label="Responsibilities"
94224
array={formData.responsibilities}

frontend/src/Components/Positions/PositionCard.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const DynamicFieldArray = ({
119119

120120
export const PositionCard = ({ position, onViewDetails, onEdit, onDelete }) => {
121121
const desc = [
122-
{ key: "Created by", value: position.created_by || "Unknown", icon: Edit },
122+
// { key: "Created by", value: position.created_by || "Unknown", icon: Edit },
123123
{
124124
key: "Created on",
125125
value: new Date(position.created_at || Date.now()).toLocaleDateString(

0 commit comments

Comments
 (0)