feat: Enhance note creation and project cancellation with user information and translations
This commit is contained in:
@@ -73,6 +73,20 @@ async function createNoteHandler(req) {
|
||||
)
|
||||
.run(project_id || null, task_id || null, note, req.user?.id || null);
|
||||
|
||||
// Get the created note with user info
|
||||
const createdNote = db
|
||||
.prepare(
|
||||
`
|
||||
SELECT n.*,
|
||||
u.name as created_by_name,
|
||||
u.username as created_by_username
|
||||
FROM notes n
|
||||
LEFT JOIN users u ON n.created_by = u.id
|
||||
WHERE n.note_id = ?
|
||||
`
|
||||
)
|
||||
.get(result.lastInsertRowid);
|
||||
|
||||
// Log note creation
|
||||
await logApiActionSafe(
|
||||
req,
|
||||
@@ -85,7 +99,7 @@ async function createNoteHandler(req) {
|
||||
}
|
||||
);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
return NextResponse.json(createdNote);
|
||||
} catch (error) {
|
||||
console.error("Error creating note:", error);
|
||||
return NextResponse.json(
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
AUDIT_ACTIONS,
|
||||
RESOURCE_TYPES,
|
||||
} from "@/lib/auditLogSafe.js";
|
||||
import { getUserLanguage, serverT } from "@/lib/serverTranslations";
|
||||
|
||||
// Make sure the DB is initialized before queries run
|
||||
initializeDatabase();
|
||||
@@ -86,7 +87,8 @@ async function updateProjectHandler(req, { params }) {
|
||||
minute: '2-digit'
|
||||
});
|
||||
|
||||
const cancellationNote = `Projekt został wycofany w dniu ${cancellationDate}`;
|
||||
const language = getUserLanguage();
|
||||
const cancellationNote = `${serverT("Project cancelled on", language)} ${cancellationDate}`;
|
||||
|
||||
try {
|
||||
addNoteToProject(parseInt(id), cancellationNote, userId, true); // true for is_system
|
||||
|
||||
@@ -24,6 +24,11 @@ export default function ProjectViewPage() {
|
||||
const [notes, setNotes] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// Helper function to add a new note to the list
|
||||
const addNote = (newNote) => {
|
||||
setNotes(prevNotes => [newNote, ...prevNotes]);
|
||||
};
|
||||
|
||||
// Helper function to check if user can delete a note
|
||||
const canDeleteNote = (note) => {
|
||||
if (!session?.user) return false;
|
||||
@@ -597,7 +602,7 @@ export default function ProjectViewPage() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="mb-6">
|
||||
<NoteForm projectId={params.id} />
|
||||
<NoteForm projectId={params.id} onNoteAdded={addNote} />
|
||||
</div>
|
||||
{notes.length === 0 ? (
|
||||
<div className="text-center py-12">
|
||||
|
||||
Reference in New Issue
Block a user