feat: add 'can_be_assigned' field to users with updates to user creation, retrieval, and assignment queries
This commit is contained in:
@@ -97,6 +97,30 @@ export default function UserManagementPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleAssignable = async (userId, canBeAssigned) => {
|
||||
try {
|
||||
const response = await fetch(`/api/admin/users/${userId}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ can_be_assigned: !canBeAssigned }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to update user");
|
||||
}
|
||||
|
||||
setUsers(users.map(user =>
|
||||
user.id === userId
|
||||
? { ...user, can_be_assigned: !canBeAssigned }
|
||||
: user
|
||||
));
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
}
|
||||
};
|
||||
|
||||
const getRoleColor = (role) => {
|
||||
switch (role) {
|
||||
case "admin":
|
||||
@@ -207,6 +231,9 @@ export default function UserManagementPage() {
|
||||
<Badge color={user.is_active ? "green" : "red"}>
|
||||
{user.is_active ? "Active" : "Inactive"}
|
||||
</Badge>
|
||||
<Badge color={user.can_be_assigned ? "blue" : "gray"}>
|
||||
{user.can_be_assigned ? "Assignable" : "Not Assignable"}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
@@ -237,6 +264,20 @@ export default function UserManagementPage() {
|
||||
)}
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center space-x-4">
|
||||
<div className="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id={`assignable-${user.id}`}
|
||||
checked={user.can_be_assigned || false}
|
||||
onChange={() => handleToggleAssignable(user.id, user.can_be_assigned)}
|
||||
className="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"
|
||||
/>
|
||||
<label htmlFor={`assignable-${user.id}`} className="text-sm text-gray-700">
|
||||
Can be assigned to projects/tasks
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex space-x-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
@@ -290,7 +331,8 @@ function CreateUserModal({ onClose, onUserCreated }) {
|
||||
username: "",
|
||||
password: "",
|
||||
role: "user",
|
||||
is_active: true
|
||||
is_active: true,
|
||||
can_be_assigned: true
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
@@ -408,6 +450,19 @@ function CreateUserModal({ onClose, onUserCreated }) {
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="can_be_assigned"
|
||||
checked={formData.can_be_assigned}
|
||||
onChange={(e) => setFormData({ ...formData, can_be_assigned: e.target.checked })}
|
||||
className="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"
|
||||
/>
|
||||
<label htmlFor="can_be_assigned" className="ml-2 block text-sm text-gray-900">
|
||||
Can be assigned to projects/tasks
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="flex space-x-3 pt-4">
|
||||
<Button type="submit" disabled={loading} className="flex-1">
|
||||
{loading ? "Creating..." : "Create User"}
|
||||
|
||||
Reference in New Issue
Block a user