Add Moodle + Pohoda connectors
- Moodle: courses->goals, assignments->tasks, completion, grades, webhook - Pohoda: XML-RPC adapter, invoice sync, webhook - All 3 connectors (Odoo, Moodle, Pohoda) returning 200 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,284 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState, useCallback } from "react";
|
||||
import { useRouter, useParams } from "next/navigation";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import {
|
||||
getTask,
|
||||
getGroups,
|
||||
updateTask,
|
||||
deleteTask,
|
||||
Task,
|
||||
Group,
|
||||
} from "@/lib/api";
|
||||
import TaskForm from "@/components/TaskForm";
|
||||
import StatusBadge from "@/components/StatusBadge";
|
||||
|
||||
function isDone(status: string): boolean {
|
||||
return status === "done" || status === "completed";
|
||||
}
|
||||
|
||||
export default function TaskDetailPage() {
|
||||
const { token } = useAuth();
|
||||
const router = useRouter();
|
||||
const params = useParams();
|
||||
const id = params.id as string;
|
||||
const [task, setTask] = useState<Task | null>(null);
|
||||
const [groups, setGroups] = useState<Group[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
const loadTask = useCallback(async () => {
|
||||
if (!token || !id) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
const [taskData, groupsData] = await Promise.all([
|
||||
getTask(token, id),
|
||||
getGroups(token),
|
||||
]);
|
||||
setTask(taskData);
|
||||
setGroups(groupsData.data || []);
|
||||
} catch (err) {
|
||||
setError(
|
||||
err instanceof Error ? err.message : "Chyba p\u0159i na\u010d\u00edt\u00e1n\u00ed \u00fakolu"
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [token, id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) {
|
||||
router.replace("/login");
|
||||
return;
|
||||
}
|
||||
loadTask();
|
||||
}, [token, router, loadTask]);
|
||||
|
||||
async function handleUpdate(data: Partial<Task>) {
|
||||
if (!token || !id) return;
|
||||
await updateTask(token, id, data);
|
||||
setEditing(false);
|
||||
loadTask();
|
||||
}
|
||||
|
||||
async function handleDelete() {
|
||||
if (!token || !id) return;
|
||||
if (!confirm("Opravdu smazat tento \u00fakol?")) return;
|
||||
setDeleting(true);
|
||||
try {
|
||||
await deleteTask(token, id);
|
||||
router.push("/tasks");
|
||||
} catch (err) {
|
||||
setError(
|
||||
err instanceof Error ? err.message : "Chyba p\u0159i maz\u00e1n\u00ed"
|
||||
);
|
||||
setDeleting(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleQuickStatus(newStatus: Task["status"]) {
|
||||
if (!token || !id) return;
|
||||
try {
|
||||
await updateTask(token, id, { status: newStatus });
|
||||
loadTask();
|
||||
} catch (err) {
|
||||
setError(
|
||||
err instanceof Error ? err.message : "Chyba p\u0159i zm\u011bn\u011b stavu"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!token) return null;
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex justify-center py-12">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error || !task) {
|
||||
return (
|
||||
<div className="text-center py-12">
|
||||
<p className="text-red-500">{error || "\u00dakol nenalezen"}</p>
|
||||
<button
|
||||
onClick={() => router.push("/tasks")}
|
||||
className="mt-4 text-blue-600 hover:underline"
|
||||
>
|
||||
Zp\u011bt na \u00fakoly
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (editing) {
|
||||
return (
|
||||
<div className="max-w-lg mx-auto">
|
||||
<h1 className="text-xl font-bold mb-4">Upravit \u00fakol</h1>
|
||||
<TaskForm
|
||||
groups={groups}
|
||||
initial={task}
|
||||
onSubmit={handleUpdate}
|
||||
onCancel={() => setEditing(false)}
|
||||
submitLabel="Ulo\u017eit zm\u011bny"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const PRIORITY_LABELS: Record<string, { label: string; dot: string }> = {
|
||||
low: { label: "N\u00edzk\u00e1", dot: "\ud83d\udfe2" },
|
||||
medium: { label: "St\u0159edn\u00ed", dot: "\ud83d\udfe1" },
|
||||
high: { label: "Vysok\u00e1", dot: "\ud83d\udfe0" },
|
||||
urgent: { label: "Urgentn\u00ed", dot: "\ud83d\udd34" },
|
||||
};
|
||||
|
||||
const pri = PRIORITY_LABELS[task.priority] || PRIORITY_LABELS.medium;
|
||||
const taskDone = isDone(task.status);
|
||||
|
||||
return (
|
||||
<div className="max-w-lg mx-auto space-y-6">
|
||||
{/* Back button */}
|
||||
<button
|
||||
onClick={() => router.push("/tasks")}
|
||||
className="text-sm text-muted hover:text-foreground flex items-center gap-1"
|
||||
>
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M15 19l-7-7 7-7"
|
||||
/>
|
||||
</svg>
|
||||
Zp\u011bt
|
||||
</button>
|
||||
|
||||
{/* Task detail card */}
|
||||
<div className="bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-2xl p-6">
|
||||
<div className="flex items-start justify-between gap-4 mb-4">
|
||||
<div className="flex items-start gap-3">
|
||||
{task.group_icon && (
|
||||
<span className="text-2xl">{task.group_icon}</span>
|
||||
)}
|
||||
<h1
|
||||
className={`text-xl font-bold ${
|
||||
taskDone ? "line-through text-muted" : ""
|
||||
}`}
|
||||
>
|
||||
{task.title}
|
||||
</h1>
|
||||
</div>
|
||||
<StatusBadge status={task.status} size="md" />
|
||||
</div>
|
||||
|
||||
{task.description && (
|
||||
<p className="text-muted mb-4 whitespace-pre-wrap leading-relaxed">
|
||||
{task.description}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-2 gap-3 text-sm">
|
||||
<div>
|
||||
<span className="text-muted">Priorita:</span>
|
||||
<span className="ml-2 font-medium">
|
||||
{pri.dot} {pri.label}
|
||||
</span>
|
||||
</div>
|
||||
{task.group_name && (
|
||||
<div>
|
||||
<span className="text-muted">Skupina:</span>
|
||||
<span
|
||||
className="ml-2 inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium text-white"
|
||||
style={{
|
||||
backgroundColor: task.group_color || "#6b7280",
|
||||
}}
|
||||
>
|
||||
{task.group_icon && (
|
||||
<span className="mr-1">{task.group_icon}</span>
|
||||
)}
|
||||
{task.group_name}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{task.due_at && (
|
||||
<div>
|
||||
<span className="text-muted">Term\u00edn:</span>
|
||||
<span className="ml-2">
|
||||
{new Date(task.due_at).toLocaleString("cs-CZ")}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<span className="text-muted">Vytvo\u0159eno:</span>
|
||||
<span className="ml-2">
|
||||
{new Date(task.created_at).toLocaleString("cs-CZ")}
|
||||
</span>
|
||||
</div>
|
||||
{task.completed_at && (
|
||||
<div>
|
||||
<span className="text-muted">Dokon\u010deno:</span>
|
||||
<span className="ml-2">
|
||||
{new Date(task.completed_at).toLocaleString("cs-CZ")}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Quick status buttons */}
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
{!taskDone && (
|
||||
<button
|
||||
onClick={() => handleQuickStatus("done")}
|
||||
className="px-4 py-2 bg-green-600 hover:bg-green-700 text-white rounded-lg text-sm font-medium transition-colors"
|
||||
>
|
||||
Ozna\u010dit jako hotov\u00e9
|
||||
</button>
|
||||
)}
|
||||
{task.status === "pending" && (
|
||||
<button
|
||||
onClick={() => handleQuickStatus("in_progress")}
|
||||
className="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-sm font-medium transition-colors"
|
||||
>
|
||||
Zah\u00e1jit
|
||||
</button>
|
||||
)}
|
||||
{taskDone && (
|
||||
<button
|
||||
onClick={() => handleQuickStatus("pending")}
|
||||
className="px-4 py-2 bg-yellow-600 hover:bg-yellow-700 text-white rounded-lg text-sm font-medium transition-colors"
|
||||
>
|
||||
Znovu otev\u0159\u00edt
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Action buttons */}
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={() => setEditing(true)}
|
||||
className="flex-1 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors font-medium"
|
||||
>
|
||||
Upravit
|
||||
</button>
|
||||
<button
|
||||
onClick={handleDelete}
|
||||
disabled={deleting}
|
||||
className="px-6 py-2.5 border border-red-300 dark:border-red-800 text-red-600 dark:text-red-400 rounded-lg hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors font-medium disabled:opacity-50"
|
||||
>
|
||||
{deleting ? "Ma\u017eu..." : "Smazat"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ interface StatusBadgeProps {
|
||||
|
||||
const STATUS_MAP: Record<string, { label: string; bg: string; text: string; dot: string }> = {
|
||||
pending: {
|
||||
label: "\u010Cek\u00e1",
|
||||
label: "Čeká",
|
||||
bg: "bg-yellow-100 dark:bg-yellow-900/30",
|
||||
text: "text-yellow-800 dark:text-yellow-300",
|
||||
dot: "bg-yellow-500",
|
||||
},
|
||||
in_progress: {
|
||||
label: "Prob\u00edh\u00e1",
|
||||
label: "Probíhá",
|
||||
bg: "bg-blue-100 dark:bg-blue-900/30",
|
||||
text: "text-blue-800 dark:text-blue-300",
|
||||
dot: "bg-blue-500",
|
||||
@@ -31,7 +31,7 @@ const STATUS_MAP: Record<string, { label: string; bg: string; text: string; dot:
|
||||
dot: "bg-green-500",
|
||||
},
|
||||
cancelled: {
|
||||
label: "Zru\u0161eno",
|
||||
label: "Zrušeno",
|
||||
bg: "bg-gray-100 dark:bg-gray-800/30",
|
||||
text: "text-gray-600 dark:text-gray-400",
|
||||
dot: "bg-gray-400",
|
||||
|
||||
@@ -12,17 +12,17 @@ interface TaskFormProps {
|
||||
}
|
||||
|
||||
const STATUSES = [
|
||||
{ value: "pending", label: "\u010Cek\u00e1" },
|
||||
{ value: "in_progress", label: "Prob\u00edh\u00e1" },
|
||||
{ value: "pending", label: "Čeká" },
|
||||
{ value: "in_progress", label: "Probíhá" },
|
||||
{ value: "done", label: "Hotovo" },
|
||||
{ value: "cancelled", label: "Zru\u0161eno" },
|
||||
{ value: "cancelled", label: "Zrušeno" },
|
||||
];
|
||||
|
||||
const PRIORITIES = [
|
||||
{ value: "low", label: "N\u00edzk\u00e1" },
|
||||
{ value: "medium", label: "St\u0159edn\u00ed" },
|
||||
{ value: "high", label: "Vysok\u00e1" },
|
||||
{ value: "urgent", label: "Urgentn\u00ed" },
|
||||
{ value: "low", label: "Nízká" },
|
||||
{ value: "medium", label: "Střední" },
|
||||
{ value: "high", label: "Vysoká" },
|
||||
{ value: "urgent", label: "Urgentní" },
|
||||
];
|
||||
|
||||
export default function TaskForm({
|
||||
@@ -30,7 +30,7 @@ export default function TaskForm({
|
||||
initial,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
submitLabel = "Ulo\u017eit",
|
||||
submitLabel = "Uložit",
|
||||
}: TaskFormProps) {
|
||||
const [title, setTitle] = useState(initial?.title || "");
|
||||
const [description, setDescription] = useState(initial?.description || "");
|
||||
@@ -46,7 +46,7 @@ export default function TaskForm({
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!title.trim()) {
|
||||
setError("N\u00e1zev je povinn\u00fd");
|
||||
setError("Název je povinný");
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
@@ -62,7 +62,7 @@ export default function TaskForm({
|
||||
});
|
||||
} catch (err) {
|
||||
setError(
|
||||
err instanceof Error ? err.message : "Chyba p\u0159i ukl\u00e1d\u00e1n\u00ed"
|
||||
err instanceof Error ? err.message : "Chyba při ukládání"
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -78,13 +78,13 @@ export default function TaskForm({
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">N\u00e1zev *</label>
|
||||
<label className="block text-sm font-medium mb-1">Název *</label>
|
||||
<input
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
className="w-full px-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none transition-shadow"
|
||||
placeholder="Co je t\u0159eba ud\u011blat..."
|
||||
placeholder="Co je třeba udělat..."
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
@@ -158,7 +158,7 @@ export default function TaskForm({
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Term\u00edn</label>
|
||||
<label className="block text-sm font-medium mb-1">Termín</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={dueAt}
|
||||
@@ -174,14 +174,14 @@ export default function TaskForm({
|
||||
disabled={loading}
|
||||
className="flex-1 bg-blue-600 hover:bg-blue-700 text-white font-medium py-2.5 px-4 rounded-lg transition-colors disabled:opacity-50 min-h-[44px]"
|
||||
>
|
||||
{loading ? "Ukl\u00e1d\u00e1m..." : submitLabel}
|
||||
{loading ? "Ukládám..." : submitLabel}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onCancel}
|
||||
className="px-4 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors min-h-[44px]"
|
||||
>
|
||||
Zru\u0161it
|
||||
Zrušit
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -41,7 +41,7 @@ export default function TaskModal({ groups, onSubmit, onClose }: TaskModalProps)
|
||||
className="fixed inset-0 z-50 flex items-end sm:items-center justify-center"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label="Nov\u00fd \u00fakol"
|
||||
aria-label="Nový úkol"
|
||||
>
|
||||
{/* Backdrop */}
|
||||
<div
|
||||
@@ -65,11 +65,11 @@ export default function TaskModal({ groups, onSubmit, onClose }: TaskModalProps)
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between mb-5">
|
||||
<h2 className="text-lg font-semibold">Nov\u00fd \u00fakol</h2>
|
||||
<h2 className="text-lg font-semibold">Nový úkol</h2>
|
||||
<button
|
||||
onClick={handleClose}
|
||||
className="p-2 rounded-lg text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors min-w-[44px] min-h-[44px] flex items-center justify-center"
|
||||
aria-label="Zav\u0159\u00edt"
|
||||
aria-label="Zavřít"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@@ -90,7 +90,7 @@ export default function TaskModal({ groups, onSubmit, onClose }: TaskModalProps)
|
||||
groups={groups}
|
||||
onSubmit={onSubmit}
|
||||
onCancel={handleClose}
|
||||
submitLabel="Vytvo\u0159it"
|
||||
submitLabel="Vytvořit"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user