@@ -16,6 +16,7 @@ import { withSupabase } from "../../../../../utils/supabase/withSupabase";
1616import { createOrRetrievePageSettings } from "../../../../../utils/useDatabase" ;
1717import { getPage } from "../../../../../utils/useSSR" ;
1818import { useUserData } from "../../../../../utils/useUser" ;
19+ import { createAuditLog } from "../../../../../utils/auditLog" ;
1920
2021export const getServerSideProps = withSupabase ( async ( ctx , { supabase } ) => {
2122 const { page_id } = ctx . params ;
@@ -235,6 +236,27 @@ export default function BoardSettings({
235236 throw error ;
236237 }
237238
239+ // Create audit log for board update
240+ await createAuditLog ( supabase , {
241+ page_id : page_id ,
242+ actor_id : user . id ,
243+ action : `Updated Roadmap Board: ${ boardForm . title } ` ,
244+ changes : {
245+ old : {
246+ title : board . title ,
247+ description : board . description ,
248+ slug : board . slug ,
249+ is_public : board . is_public
250+ } ,
251+ new : {
252+ title : boardForm . title ,
253+ description : boardForm . description ,
254+ slug : boardForm . slug ,
255+ is_public : boardForm . is_public
256+ }
257+ } ,
258+ } ) ;
259+
238260 // Refresh the page to show updated settings
239261 window . location . reload ( ) ;
240262 } catch ( error ) {
@@ -266,6 +288,14 @@ export default function BoardSettings({
266288 setBoardCategories ( [ ...boardCategories , data ] ) ;
267289 setNewCategory ( "" ) ;
268290 setNewCategoryColor ( "blue" ) ;
291+
292+ // Create audit log for category creation
293+ await createAuditLog ( supabase , {
294+ page_id : page_id ,
295+ actor_id : user . id ,
296+ action : `Created Roadmap Category: ${ data . name } ` ,
297+ changes : { category : data } ,
298+ } ) ;
269299 } catch ( error ) {
270300 console . error ( "Error adding category:" , error ) ;
271301 alert ( "Failed to add category" ) ;
@@ -286,20 +316,38 @@ export default function BoardSettings({
286316
287317 if ( error ) throw error ;
288318
319+ const oldCategory = boardCategories . find ( cat => cat . id === categoryId ) ;
320+ const newCategoryData = {
321+ name : categoryToEdit . trim ( ) ,
322+ color : categoryColorToEdit ,
323+ } ;
324+
289325 setBoardCategories ( ( prev ) =>
290326 prev . map ( ( cat ) =>
291327 cat . id === categoryId
292328 ? {
293329 ...cat ,
294- name : categoryToEdit . trim ( ) ,
295- color : categoryColorToEdit ,
330+ ...newCategoryData ,
296331 }
297332 : cat
298333 )
299334 ) ;
300335 setEditingCategory ( null ) ;
301336 setCategoryToEdit ( "" ) ;
302337 setCategoryColorToEdit ( "blue" ) ;
338+
339+ // Create audit log for category update
340+ if ( oldCategory ) {
341+ await createAuditLog ( supabase , {
342+ page_id : page_id ,
343+ actor_id : user . id ,
344+ action : `Updated Roadmap Category: ${ newCategoryData . name } ` ,
345+ changes : {
346+ old : oldCategory ,
347+ new : { ...oldCategory , ...newCategoryData }
348+ } ,
349+ } ) ;
350+ }
303351 } catch ( error ) {
304352 console . error ( "Error updating category:" , error ) ;
305353 alert ( "Failed to update category" ) ;
@@ -332,7 +380,18 @@ export default function BoardSettings({
332380
333381 if ( error ) throw error ;
334382
383+ const deletedCategory = boardCategories . find ( cat => cat . id === categoryId ) ;
335384 setBoardCategories ( ( prev ) => prev . filter ( ( cat ) => cat . id !== categoryId ) ) ;
385+
386+ // Create audit log for category deletion
387+ if ( deletedCategory ) {
388+ await createAuditLog ( supabase , {
389+ page_id : page_id ,
390+ actor_id : user . id ,
391+ action : `Deleted Roadmap Category: ${ deletedCategory . name } ` ,
392+ changes : { category : deletedCategory } ,
393+ } ) ;
394+ }
336395 } catch ( error ) {
337396 console . error ( "Error deleting category:" , error ) ;
338397 alert ( "Failed to delete category" ) ;
@@ -362,6 +421,14 @@ export default function BoardSettings({
362421
363422 setBoardColumns ( [ ...boardColumns , data ] ) ;
364423 setNewColumn ( "" ) ;
424+
425+ // Create audit log for column creation
426+ await createAuditLog ( supabase , {
427+ page_id : page_id ,
428+ actor_id : user . id ,
429+ action : `Created Roadmap Column: ${ data . name } ` ,
430+ changes : { column : data } ,
431+ } ) ;
365432 } catch ( error ) {
366433 console . error ( "Error adding column:" , error ) ;
367434 alert ( "Failed to add column" ) ;
@@ -379,13 +446,29 @@ export default function BoardSettings({
379446
380447 if ( error ) throw error ;
381448
449+ const oldColumn = boardColumns . find ( col => col . id === columnId ) ;
450+ const newColumnName = columnToEdit . trim ( ) ;
451+
382452 setBoardColumns ( ( prev ) =>
383453 prev . map ( ( col ) =>
384- col . id === columnId ? { ...col , name : columnToEdit . trim ( ) } : col
454+ col . id === columnId ? { ...col , name : newColumnName } : col
385455 )
386456 ) ;
387457 setEditingColumn ( null ) ;
388458 setColumnToEdit ( "" ) ;
459+
460+ // Create audit log for column update
461+ if ( oldColumn ) {
462+ await createAuditLog ( supabase , {
463+ page_id : page_id ,
464+ actor_id : user . id ,
465+ action : `Updated Roadmap Column: ${ newColumnName } ` ,
466+ changes : {
467+ old : oldColumn ,
468+ new : { ...oldColumn , name : newColumnName }
469+ } ,
470+ } ) ;
471+ }
389472 } catch ( error ) {
390473 console . error ( "Error updating column:" , error ) ;
391474 alert ( "Failed to update column" ) ;
@@ -420,7 +503,18 @@ export default function BoardSettings({
420503
421504 if ( error ) throw error ;
422505
506+ const deletedColumn = boardColumns . find ( col => col . id === columnId ) ;
423507 setBoardColumns ( ( prev ) => prev . filter ( ( col ) => col . id !== columnId ) ) ;
508+
509+ // Create audit log for column deletion
510+ if ( deletedColumn ) {
511+ await createAuditLog ( supabase , {
512+ page_id : page_id ,
513+ actor_id : user . id ,
514+ action : `Deleted Roadmap Column: ${ deletedColumn . name } ` ,
515+ changes : { column : deletedColumn } ,
516+ } ) ;
517+ }
424518 } catch ( error ) {
425519 console . error ( "Error deleting column:" , error ) ;
426520 alert ( "Failed to delete column" ) ;
@@ -471,6 +565,17 @@ export default function BoardSettings({
471565
472566 await Promise . all ( updatePromises ) ;
473567
568+ // Create audit log for column reordering
569+ await createAuditLog ( supabase , {
570+ page_id : page_id ,
571+ actor_id : user . id ,
572+ action : "Reordered Roadmap Columns" ,
573+ changes : {
574+ old_order : boardColumns . map ( col => ( { id : col . id , name : col . name , position : col . position } ) ) ,
575+ new_order : newColumns . map ( ( col , index ) => ( { id : col . id , name : col . name , position : index + 1 } ) )
576+ } ,
577+ } ) ;
578+
474579 // Update local state
475580 setBoardColumns (
476581 newColumns . map ( ( column , index ) => ( {
0 commit comments