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 = {
...data,
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);
return NextResponse.json({ success: true, id: result.lastInsertRowid });
} 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]">
{t('projects.projectName')}
</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">
WP
</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">
{t('projects.city')}
</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">
{t('projects.plot')}
</th>
@@ -471,7 +471,7 @@ export default function ProjectListPage() {
{t('common.status') || 'Status'}
</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">
{t('common.actions') || 'Akcje'}
Placeholder
</th>
</tr>
</thead>
@@ -504,6 +504,12 @@ export default function ProjectListPage() {
</span>
</Link>
</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
className="px-2 py-3 text-xs text-gray-600 dark:text-gray-400 truncate hidden sm:table-cell"
title={project.wp}
@@ -516,12 +522,6 @@ export default function ProjectListPage() {
>
{project.city || "N/A"}
</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
className="px-2 py-3 text-xs text-gray-600 dark:text-gray-400 truncate hidden sm:table-cell"
title={project.plot}
@@ -563,15 +563,7 @@ export default function ProjectListPage() {
</div>
</td>
<td className="px-2 py-3">
<Link href={`/projects/${project.project_id}`}>
<Button
variant="outline"
size="sm"
className="text-xs px-2 py-1 w-full sm:w-auto"
>
{t('common.view') || 'Wyświetl'}
</Button>
</Link>
<span className="text-xs text-gray-500">Placeholder</span>
</td>
</tr>
))}