feat: Update task assignment logic to exclude admin users and enhance project page layout

This commit is contained in:
2025-09-29 19:25:15 +02:00
parent 5aac63dfde
commit e68b185aeb
4 changed files with 24 additions and 23 deletions

View File

@@ -47,10 +47,19 @@ async function createProjectTaskHandler(req) {
const taskData = { const taskData = {
...data, ...data,
created_by: req.user?.id || null, created_by: req.user?.id || null,
// If no assigned_to is specified, default to the creator
assigned_to: data.assigned_to || req.user?.id || null,
}; };
// Set assigned_to: if specified, use it; otherwise default to creator only if they're not admin
if (data.assigned_to) {
taskData.assigned_to = data.assigned_to;
} else if (req.user?.id) {
// Check if the creator is an admin - if so, don't assign to them
const userRole = db.prepare('SELECT role FROM users WHERE id = ?').get(req.user.id);
taskData.assigned_to = userRole?.role === 'admin' ? null : req.user.id;
} else {
taskData.assigned_to = null;
}
const result = createProjectTask(taskData); const result = createProjectTask(taskData);
return NextResponse.json({ success: true, id: result.lastInsertRowid }); return NextResponse.json({ success: true, id: result.lastInsertRowid });
} catch (error) { } catch (error) {

View File

@@ -449,15 +449,15 @@ export default function ProjectListPage() {
<th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-[200px] md:w-[250px]"> <th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-[200px] md:w-[250px]">
{t('projects.projectName')} {t('projects.projectName')}
</th> </th>
<th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-20 md:w-24 hidden lg:table-cell">
{t('projects.address')}
</th>
<th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-16 md:w-20 hidden sm:table-cell"> <th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-16 md:w-20 hidden sm:table-cell">
WP WP
</th> </th>
<th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-14 md:w-16 hidden md:table-cell"> <th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-14 md:w-16 hidden md:table-cell">
{t('projects.city')} {t('projects.city')}
</th> </th>
<th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-20 md:w-24 hidden lg:table-cell">
{t('projects.address')}
</th>
<th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-14 md:w-16 hidden sm:table-cell"> <th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-14 md:w-16 hidden sm:table-cell">
{t('projects.plot')} {t('projects.plot')}
</th> </th>
@@ -471,7 +471,7 @@ export default function ProjectListPage() {
{t('common.status') || 'Status'} {t('common.status') || 'Status'}
</th> </th>
<th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-14 md:w-16"> <th className="text-left px-2 py-3 font-semibold text-xs text-gray-700 dark:text-gray-300 w-14 md:w-16">
{t('common.actions') || 'Akcje'} Placeholder
</th> </th>
</tr> </tr>
</thead> </thead>
@@ -504,6 +504,12 @@ export default function ProjectListPage() {
</span> </span>
</Link> </Link>
</td> </td>
<td
className="px-2 py-3 text-xs text-gray-600 dark:text-gray-400 truncate hidden lg:table-cell"
title={project.address}
>
{project.address || "N/A"}
</td>
<td <td
className="px-2 py-3 text-xs text-gray-600 dark:text-gray-400 truncate hidden sm:table-cell" className="px-2 py-3 text-xs text-gray-600 dark:text-gray-400 truncate hidden sm:table-cell"
title={project.wp} title={project.wp}
@@ -516,12 +522,6 @@ export default function ProjectListPage() {
> >
{project.city || "N/A"} {project.city || "N/A"}
</td> </td>
<td
className="px-2 py-3 text-xs text-gray-600 dark:text-gray-400 truncate hidden lg:table-cell"
title={project.address}
>
{project.address || "N/A"}
</td>
<td <td
className="px-2 py-3 text-xs text-gray-600 dark:text-gray-400 truncate hidden sm:table-cell" className="px-2 py-3 text-xs text-gray-600 dark:text-gray-400 truncate hidden sm:table-cell"
title={project.plot} title={project.plot}
@@ -563,15 +563,7 @@ export default function ProjectListPage() {
</div> </div>
</td> </td>
<td className="px-2 py-3"> <td className="px-2 py-3">
<Link href={`/projects/${project.project_id}`}> <span className="text-xs text-gray-500">Placeholder</span>
<Button
variant="outline"
size="sm"
className="text-xs px-2 py-1 w-full sm:w-auto"
>
{t('common.view') || 'Wyświetl'}
</Button>
</Link>
</td> </td>
</tr> </tr>
))} ))}

View File

@@ -146,7 +146,7 @@ export function getAllUsersForAssignment() {
` `
SELECT id, name, username, role SELECT id, name, username, role
FROM users FROM users
WHERE is_active = 1 WHERE is_active = 1 AND role != 'admin'
ORDER BY name ORDER BY name
` `
) )

View File

@@ -296,7 +296,7 @@ export function getAllUsersForTaskAssignment() {
` `
SELECT id, name, username, role SELECT id, name, username, role
FROM users FROM users
WHERE is_active = 1 WHERE is_active = 1 AND role != 'admin'
ORDER BY name ASC ORDER BY name ASC
` `
) )