"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { Card, CardHeader, CardContent } from "@/components/ui/Card"; import Button from "@/components/ui/Button"; import Badge from "@/components/ui/Badge"; import PageContainer from "@/components/ui/PageContainer"; import PageHeader from "@/components/ui/PageHeader"; import { useTranslation } from "@/lib/i18n"; export default function TaskTemplatesPage() { const { t } = useTranslation(); const [templates, setTemplates] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchTemplates = async () => { try { const response = await fetch('/api/tasks/templates'); if (response.ok) { const data = await response.json(); setTemplates(data); } else { console.error('Failed to fetch templates'); } } catch (error) { console.error('Error fetching templates:', error); } finally { setLoading(false); } }; fetchTemplates(); }, []); const getTaskCategoryBadge = (taskCategory) => { const colors = { design: "bg-blue-100 text-blue-800", construction: "bg-green-100 text-green-800" }; return ( {taskCategory === "design" ? "Projektowe" : taskCategory === "construction" ? "Budowlane" : taskCategory} ); }; if (loading) { return ( {t('taskTemplates.newTemplate')} , Zestawy zadań ]} /> {t('common.loading')} ); } return ( {t('taskTemplates.newTemplate')} , Zestawy zadań ]} /> {templates.length === 0 ? ( {t('taskTemplates.noTemplates')} {t('taskTemplates.noTemplatesMessage')} {t('taskTemplates.newTemplate')} ) : ( {templates.map((template) => ( {template.name} {template.max_wait_days} {t('common.days')} {getTaskCategoryBadge(template.task_category)} {template.description && ( {template.description} )}{" "} {t('taskTemplates.editTemplate')} ))}{" "} )} ); }
{t('taskTemplates.noTemplatesMessage')}
{template.description}