feat: Notifications page, Sidebar layout fixes, and Achievements enhancements
continuous-integration/drone/push Build is failing

- implemented /notifications page with overdue/upcoming alerts
- Fixed sidebar scrolling in collapsed mode
- Moved notification button to sidebar footer
- Enhanced Achievements page with streak stats and tooltips
- Improved XP history to show task titles
- Added missing translations (en/de)
- Removed top bar header
- Fixed Docker environment routing
This commit is contained in:
2025-12-17 10:06:36 +01:00
parent 7b79015ac2
commit 9819d8db0b
47 changed files with 2309 additions and 1241 deletions
File diff suppressed because it is too large Load Diff
+50
View File
@@ -20,6 +20,16 @@ import { useState } from "react";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
export default function AdminUserManagement() {
const { t } = useTranslation();
@@ -80,6 +90,18 @@ export default function AdminUserManagement() {
onError: (e: Error) => toast({ title: "Failed to create", description: e.message, variant: "destructive" }),
});
const [resetXpUser, setResetXpUser] = useState<User | null>(null);
const resetXpMutation = useMutation({
mutationFn: (userId: string) => apiRequest("POST", `/api/admin/users/${userId}/reset-xp`),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["/api/admin/users"] });
setResetXpUser(null);
toast({ title: t('userManagement.resetXpSuccess', 'User XP reset successfully') });
},
onError: (e: Error) => toast({ title: "Failed to reset XP", description: e.message, variant: "destructive" }),
});
return (
<div className="space-y-6 container mx-auto p-4 max-w-5xl">
<div className="flex justify-between items-center">
@@ -210,6 +232,14 @@ export default function AdminUserManagement() {
>
{user.isActive ? t('userManagement.table.deactivate') : t('userManagement.table.activate')}
</Button>
<Button
variant="outline"
size="sm"
onClick={() => setResetXpUser(user)}
disabled={user.role === 'admin' && user.username === 'admin'}
>
{t('userManagement.resetXp', 'Reset XP')}
</Button>
<Button
variant="ghost"
size="sm"
@@ -255,6 +285,26 @@ export default function AdminUserManagement() {
</div>
</DialogContent>
</Dialog>
<AlertDialog open={!!resetXpUser} onOpenChange={(open) => !open && setResetXpUser(null)}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t('userManagement.resetXpTitle', 'Reset User XP')}</AlertDialogTitle>
<AlertDialogDescription>
{t('userManagement.resetXpConfirm', 'Are you sure you want to reset XP and Level for user "{username}"? This action cannot be undone.', { username: resetXpUser?.username })}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel onClick={() => setResetXpUser(null)}>{t('common.cancel')}</AlertDialogCancel>
<AlertDialogAction
onClick={() => resetXpUser && resetXpMutation.mutate(resetXpUser.id)}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{resetXpMutation.isPending ? t('common.loading') : t('userManagement.resetXp', 'Reset XP')}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
);
}
+32 -5
View File
@@ -46,8 +46,8 @@ import { cn } from "@/lib/utils";
import { formatDistanceToNow } from "date-fns";
import { de } from "date-fns/locale";
import { useToast } from "@/hooks/use-toast";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
// import ReactMarkdown from "react-markdown";
// import remarkGfm from "remark-gfm";
// Types
type Conversation = {
@@ -93,7 +93,8 @@ const TypewriterMessage = ({ content, onComplete }: { content: string, onComplet
return (
<div className="prose prose-sm dark:prose-invert max-w-none break-words">
<ReactMarkdown remarkPlugins={[remarkGfm]}>{displayedContent}</ReactMarkdown>
{/* <ReactMarkdown remarkPlugins={[remarkGfm]}>{displayedContent}</ReactMarkdown> */}
{displayedContent}
</div>
);
};
@@ -168,7 +169,32 @@ export default function AiChatPage() {
},
});
// ... (Delete/Rename skipped for brevity in prompt, keeping existing) ...
// Delete Conversation
const deleteConversationMutation = useMutation({
mutationFn: async (id: string) => {
const res = await apiRequest("DELETE", `/api/ai/conversations/${id}`);
if (!res.ok) throw new Error("Failed to delete conversation");
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["/api/ai/conversations"] });
if (selectedConversationId === deleteId) {
setSelectedConversationId(null);
}
toast({ title: t('common.deleted', 'Deleted') });
},
});
// Rename Conversation
const renameConversationMutation = useMutation({
mutationFn: async ({ id, title }: { id: string, title: string }) => {
const res = await apiRequest("PATCH", `/api/ai/conversations/${id}`, { title });
if (!res.ok) throw new Error("Failed to rename conversation");
return res.json();
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["/api/ai/conversations"] });
},
});
const sendMessageMutation = useMutation({
mutationFn: async ({ conversationId, content }: { conversationId: string, content: string }) => {
@@ -592,7 +618,8 @@ export default function AiChatPage() {
<TypewriterMessage content={msg.content} onComplete={() => scrollToBottom()} />
) : (
<div className="prose prose-sm dark:prose-invert max-w-none break-words">
<ReactMarkdown remarkPlugins={[remarkGfm]}>{msg.content}</ReactMarkdown>
{/* <ReactMarkdown remarkPlugins={[remarkGfm]}>{msg.content}</ReactMarkdown> */}
{msg.content}
</div>
)
) : (
+102 -11
View File
@@ -31,9 +31,16 @@ import { BrainCircuit } from "lucide-react";
export default function AuthPage() {
const { t } = useTranslation();
const { toast } = useToast();
const [, setLocation] = useLocation();
const queryClient = useQueryClient();
const [activeTab, setActiveTab] = useState("login");
// 2FA State
const [is2FARequired, setIs2FARequired] = useState(false);
const [twoFAUserId, setTwoFAUserId] = useState<string | null>(null);
const [twoFAEmail, setTwoFAEmail] = useState<string | null>(null);
const [otpCode, setOtpCode] = useState("");
const { data: settings } = useQuery<{ registration_enabled: boolean }>({
queryKey: ["/api/settings/public"],
queryFn: async () => {
@@ -52,14 +59,26 @@ export default function AuthPage() {
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
// Handle 200 OK could be user or 2fa_required
const json = await res.json();
if (!res.ok) {
throw new Error("Invalid username or password");
throw new Error(json.message || "Invalid username or password");
}
return res.json();
return json;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["/api/user"] });
toast({ title: "Welcome back!" });
onSuccess: (data) => {
if (data.message === "2fa_required") {
setIs2FARequired(true);
setTwoFAUserId(data.userId);
setTwoFAEmail(data.email);
toast({ title: t('auth.2faCodeSent'), description: t('auth.checkEmail') });
} else {
queryClient.setQueryData(["/api/user"], data);
queryClient.invalidateQueries({ queryKey: ["/api/user"] });
toast({ title: "Welcome back!" });
setLocation('/');
}
},
onError: (error: Error) => {
toast({
@@ -70,6 +89,38 @@ export default function AuthPage() {
},
});
const verify2FAMutation = useMutation({
mutationFn: async (data: { userId: string, code: string }) => {
const res = await fetch("/api/auth/verify-2fa", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!res.ok) throw new Error(await res.text());
return res.json();
},
onSuccess: (user) => {
queryClient.setQueryData(["/api/user"], user);
queryClient.invalidateQueries({ queryKey: ["/api/user"] });
toast({ title: "Verification Successful", description: "Welcome back!" });
setLocation('/');
},
onError: (error: Error) => {
toast({
title: "Verification Failed",
description: error.message,
variant: "destructive",
});
}
});
const handleVerify2FA = (e: React.FormEvent) => {
e.preventDefault();
if (twoFAUserId && otpCode) {
verify2FAMutation.mutate({ userId: twoFAUserId, code: otpCode });
}
};
const registerMutation = useMutation({
mutationFn: async (data: InsertUser) => {
const res = await fetch("/api/register", {
@@ -83,19 +134,59 @@ export default function AuthPage() {
}
return res.json();
},
onSuccess: () => {
onSuccess: (data) => {
queryClient.invalidateQueries({ queryKey: ["/api/user"] });
queryClient.setQueryData(["/api/user"], data);
toast({ title: "Account created!" });
setLocation('/');
},
// Error handling is done in the form submission handler to set field errors
});
if (is2FARequired) {
return (
<div className="min-h-screen flex items-center justify-center p-4 bg-background">
<Card className="w-full max-w-md shadow-xl border-border/50">
<CardHeader className="text-center space-y-2">
<div className="mx-auto mb-4">
<img src="/favicon.png" alt="Logo" className="w-12 h-12 mx-auto" />
</div>
<CardTitle className="text-2xl font-bold">{t('auth.2faVerification')}</CardTitle>
<CardDescription>
{t('auth.enterCodeSentTo')} <span className="font-medium text-foreground">{twoFAUserId && twoFAEmail ? twoFAEmail : 'your email'}</span>
</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={handleVerify2FA} className="space-y-4">
<div className="space-y-2">
<Input
placeholder="123456"
className="text-center text-2xl tracking-widest"
maxLength={6}
value={otpCode}
onChange={(e) => setOtpCode(e.target.value.replace(/\D/g, ''))}
/>
<p className="text-xs text-muted-foreground text-center">{t('auth.codeExpiresIn10')}</p>
</div>
<Button className="w-full" type="submit" disabled={verify2FAMutation.isPending || otpCode.length !== 6}>
{verify2FAMutation.isPending ? t('common.verifying') : t('auth.verify')}
</Button>
<Button variant="ghost" className="w-full" type="button" onClick={() => setIs2FARequired(false)}>
{t('common.cancel')}
</Button>
</form>
</CardContent>
</Card>
</div>
);
}
return (
<div className="min-h-screen grid lg:grid-cols-2">
<div className="min-h-screen grid lg:grid-cols-2 dark">
<div className="hidden lg:flex flex-col justify-center items-center bg-zinc-900 p-12 text-white">
<div className="max-w-md space-y-4 text-center">
<div className="bg-white/10 p-4 rounded-2xl inline-block mb-4 backdrop-blur-sm">
<BrainCircuit className="w-16 h-16 text-primary-foreground" />
<div className="mb-8">
<img src="/favicon.png" alt="Logo" className="w-24 h-24" />
</div>
<h1 className="text-4xl font-bold tracking-tight">{t('auth.heroTitle')}</h1>
<p className="text-lg text-zinc-400">
@@ -107,8 +198,8 @@ export default function AuthPage() {
<div className="flex items-center justify-center p-4 bg-background">
<Card className="w-full max-w-md shadow-xl border-border/50">
<CardHeader className="text-center space-y-2">
<div className="lg:hidden mx-auto bg-primary/10 p-3 rounded-xl w-fit mb-2">
<BrainCircuit className="w-8 h-8 text-primary" />
<div className="lg:hidden mx-auto mb-4">
<img src="/favicon.png" alt="Logo" className="w-12 h-12 mx-auto" />
</div>
<CardTitle className="text-2xl font-bold">{t('auth.welcomeBack')}</CardTitle>
<CardDescription>
+2 -2
View File
@@ -12,6 +12,7 @@ import { apiRequest } from "@/lib/queryClient";
import { useToast } from "@/hooks/use-toast";
import { format } from "date-fns";
import { useState } from "react";
import { triggerConfetti } from "@/lib/confetti";
export default function FocusRoutinePage() {
const [match, params] = useRoute("/focus/routine/:type");
@@ -174,5 +175,4 @@ function getPriorityColor(priority: string) {
return 'bg-blue-500';
}
// Temporary import fix if confetti not available in module scope
import { triggerConfetti } from "@/lib/confetti";
// End of file
+134
View File
@@ -0,0 +1,134 @@
import { useTranslation } from 'react-i18next';
import { useQuery } from '@tanstack/react-query';
import { Task } from '@shared/schema';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Bell, BellOff, Calendar, AlertCircle, CheckCircle2, Clock } from 'lucide-react';
import { useNotifications } from '@/hooks/use-notifications';
import { formatDistanceToNow, isPast, isToday, addDays, isBefore } from 'date-fns';
import { de, enUS } from 'date-fns/locale';
import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";
export default function NotificationsPage() {
const { t, i18n } = useTranslation();
const { enabled, toggleEnabled, permission, requestPermission } = useNotifications({ poll: false }); // Don't double poll here
const { data: tasks = [] } = useQuery<Task[]>({
queryKey: ['/api/tasks'],
});
const now = new Date();
// Derive notifications from tasks
const notifications = tasks.flatMap(task => {
if (!task.dueDate || task.status === 'done') return [];
const dueDate = new Date(task.dueDate);
const isOverdue = isBefore(dueDate, now);
// Upcoming: due within next 24 hours
const isUpcoming = !isOverdue && isBefore(dueDate, addDays(now, 1));
if (!isOverdue && !isUpcoming) return [];
return [{
id: task.id,
type: isOverdue ? 'overdue' : 'upcoming',
task,
timestamp: dueDate
}];
}).sort((a, b) => {
// Sort: Overdue first, then by time
if (a.type !== b.type) return a.type === 'overdue' ? -1 : 1;
return a.timestamp.getTime() - b.timestamp.getTime();
});
return (
<div className="space-y-6 max-w-4xl mx-auto">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold tracking-tight">{t('notifications.title', 'Notifications')}</h1>
<p className="text-muted-foreground mt-2">
{t('notifications.description', 'Manage your alerts and view important updates.')}
</p>
</div>
</div>
{/* Settings Card */}
<Card>
<CardHeader>
<div className="flex items-center gap-2">
<Bell className="h-5 w-5 text-primary" />
<CardTitle>{t('notifications.settings.title', 'Browser Notifications')}</CardTitle>
</div>
</CardHeader>
<CardContent>
<div className="flex items-center justify-between">
<div className="space-y-0.5">
<Label htmlFor="notifications-toggle" className="text-base">
{t('notifications.enableBrowser', 'Enable Push Notifications')}
</Label>
<p className="text-sm text-muted-foreground">
{permission === 'denied'
? <span className="text-red-500">{t('notifications.settings.denied', 'Permission denied. Please enable in browser settings.')}</span>
: t('notifications.settings.description', 'Receive alerts for upcoming and overdue tasks.')}
</p>
</div>
<Switch
id="notifications-toggle"
checked={enabled}
onCheckedChange={toggleEnabled}
disabled={permission === 'denied'}
/>
</div>
{permission === 'default' && (
<div className="mt-4">
<Button variant="outline" size="sm" onClick={requestPermission}>
{t('notifications.settings.request', 'Request Permission')}
</Button>
</div>
)}
</CardContent>
</Card>
{/* Notification List */}
<div className="space-y-4">
<h2 className="text-xl font-semibold flex items-center gap-2">
<Clock className="h-5 w-5" />
{t('notifications.recent', 'Recent Alerts')}
</h2>
{notifications.length === 0 ? (
<div className="text-center py-12 border rounded-lg bg-muted/10 border-dashed">
<CheckCircle2 className="h-10 w-10 text-muted-foreground mx-auto mb-3 opacity-50" />
<p className="text-muted-foreground font-medium">{t('notifications.empty', 'All caught up! No urgent alerts.')}</p>
</div>
) : (
notifications.map((notif) => (
<Card key={notif.id} className={`border-l-4 ${notif.type === 'overdue' ? 'border-l-red-500 bg-red-50/10 dark:bg-red-900/10' : 'border-l-blue-500'}`}>
<CardContent className="p-4 flex items-start gap-4">
<div className={`p-2 rounded-full shrink-0 ${notif.type === 'overdue' ? 'bg-red-100 text-red-600 dark:bg-red-900/30 dark:text-red-400' : 'bg-blue-100 text-blue-600 dark:bg-blue-900/30 dark:text-blue-400'}`}>
{notif.type === 'overdue' ? <AlertCircle className="h-5 w-5" /> : <Calendar className="h-5 w-5" />}
</div>
<div className="flex-1">
<div className="flex items-center justify-between">
<h3 className="font-semibold">{notif.task.title}</h3>
<span className="text-xs text-muted-foreground whitespace-nowrap">
{formatDistanceToNow(notif.timestamp, { addSuffix: true, locale: i18n.language === 'de' ? de : enUS })}
</span>
</div>
<p className="text-sm text-muted-foreground mt-1">
{notif.type === 'overdue'
? t('notifications.overdueBody', 'This task is overdue!')
: t('notifications.upcomingBody', { time: formatDistanceToNow(notif.timestamp, { locale: i18n.language === 'de' ? de : enUS }) })
}
</p>
</div>
</CardContent>
</Card>
))
)}
</div>
</div>
);
}
+1
View File
@@ -31,6 +31,7 @@ export default function SetupWizard() {
},
onSuccess: (user) => {
queryClient.setQueryData(["/api/user"], user);
queryClient.invalidateQueries({ queryKey: ["/api/setup/status"] });
setLocation("/");
toast({
title: "Setup Complete",
+40 -8
View File
@@ -6,7 +6,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
import { Globe, Tag, Plus, Edit, Trash2, Layers, User as UserIcon, ShieldCheck, Share2, Server, Copy, Settings as SettingsIcon, Bell } from 'lucide-react';
import { Globe, Tag, Plus, Edit, Trash2, Layers, User as UserIcon, ShieldCheck, Share2, Server, Copy, Settings as SettingsIcon, Bell, Loader2 } from 'lucide-react';
import { Switch } from '@/components/ui/switch';
import { ShareAccessModal } from '@/components/ShareAccessModal';
import { ChangePasswordModal } from '@/components/ChangePasswordModal';
@@ -18,7 +18,7 @@ import { queryClient, apiRequest } from '@/lib/queryClient';
import { useToast } from '@/hooks/use-toast';
import { useLocation } from "wouter";
import { useNotifications } from '@/hooks/use-notifications';
import { DataExportCard } from '@/components/user/DataExportCard';
// import { DataExportCard } from '@/components/user/DataExportCard';
const NotificationSettings = () => {
const { t } = useTranslation();
@@ -62,10 +62,29 @@ export default function Settings({ onNavigateToTemplates }: SettingsProps) {
const [, setLocation] = useLocation();
// Fetch user
const { data: user } = useQuery<User>({
const { data: user, isLoading: isLoadingUser } = useQuery<User>({
queryKey: ['/api/user']
});
if (isLoadingUser) {
return (
<div className="flex items-center justify-center min-h-[50vh]">
<Loader2 className="h-8 w-8 animate-spin text-primary" />
</div>
);
}
if (!user) {
return (
<div className="flex flex-col items-center justify-center min-h-[50vh] space-y-4">
<h2 className="text-2xl font-bold">{t('common.loginRequired')}</h2>
<Button onClick={() => setLocation('/')}>
{t('auth.login')}
</Button>
</div>
);
}
const [isLabelDialogOpen, setIsLabelDialogOpen] = useState(false);
const [editingLabel, setEditingLabel] = useState<Label | null>(null);
const [labelName, setLabelName] = useState('');
@@ -79,6 +98,8 @@ export default function Settings({ onNavigateToTemplates }: SettingsProps) {
const handleLanguageChange = (value: string) => {
i18n.changeLanguage(value);
localStorage.setItem('taskflow-language', value);
// Persist to DB
privacyMutation.mutate({ language: value } as any);
console.log('Language changed to:', value);
};
@@ -98,9 +119,10 @@ export default function Settings({ onNavigateToTemplates }: SettingsProps) {
};
// Fetch labels
const { data: labels = [], isLoading: labelsLoading } = useQuery<Label[]>({
const { data: labelsData, isLoading: labelsLoading } = useQuery<Label[]>({
queryKey: ['/api/labels']
});
const labels = labelsData ?? [];
// Create label mutation
const createLabelMutation = useMutation({
@@ -296,7 +318,7 @@ export default function Settings({ onNavigateToTemplates }: SettingsProps) {
<p className="text-sm text-muted-foreground">{t('settings.social.publicLeaderboardDesc')}</p>
</div>
<Switch
checked={user?.showOnLeaderboard}
checked={!!user?.showOnLeaderboard}
onCheckedChange={(checked) => handlePrivacyUpdate({ showOnLeaderboard: checked })}
/>
</div>
@@ -306,7 +328,7 @@ export default function Settings({ onNavigateToTemplates }: SettingsProps) {
<p className="text-sm text-muted-foreground">{t('settings.social.searchableDesc')}</p>
</div>
<Switch
checked={user?.isSearchable}
checked={!!user?.isSearchable}
onCheckedChange={(checked) => handlePrivacyUpdate({ isSearchable: checked })}
/>
</div>
@@ -316,10 +338,20 @@ export default function Settings({ onNavigateToTemplates }: SettingsProps) {
<p className="text-sm text-muted-foreground">{t('settings.ai.enableUserDesc')}</p>
</div>
<Switch
checked={user?.aiEnabled}
checked={!!user?.aiEnabled}
onCheckedChange={(checked) => handlePrivacyUpdate({ aiEnabled: checked })}
/>
</div>
<div className="flex items-center justify-between">
<div className="space-y-0.5">
<p className="font-medium">{t('settings.social.2fa')}</p>
<p className="text-sm text-muted-foreground">{t('settings.social.2faDesc')}</p>
</div>
<Switch
checked={!!user?.is2faEnabled}
onCheckedChange={(checked) => handlePrivacyUpdate({ is2faEnabled: checked } as any)}
/>
</div>
<div className="pt-2">
<Button variant="outline" onClick={() => setIsShareAccessOpen(true)}>
<Share2 className="w-4 h-4 mr-2" />
@@ -554,7 +586,7 @@ export default function Settings({ onNavigateToTemplates }: SettingsProps) {
</Card>
{/* Data Export */}
<DataExportCard user={user} />
{/* <DataExportCard user={user} /> */}
{/* Admin Section */}
{