@@ -2,6 +2,7 @@ import { Row as TRow } from "@tanstack/react-table";
22import Table from "components/Table/Table" ;
33import React from "react" ;
44import { assignmentColumns as getBaseAssignmentColumns } from "../Assignments/AssignmentColumns" ;
5+ import { capitalizeFirstWord , formatDate } from "utils/dataFormatter" ;
56
67interface ActionHandler {
78 icon : string ;
@@ -99,22 +100,18 @@ const CourseAssignments: React.FC<CourseAssignmentsProps> = ({ courseId, courseN
99100 } ,
100101 ] ;
101102
103+ // TODO: update it with actual api calls to get assignment list
102104 const generateFakeAssignments = ( ) => {
103105 const numAssignments = 3 + Math . floor ( Math . random ( ) * 3 ) ;
104106 return Array . from ( { length : numAssignments } , ( _ , idx ) => ( {
105107 id : parseInt ( `${ courseId } ${ idx } ` ) ,
106- name : `Assignment ${ idx + 1 } for ${ courseName } ` ,
107- courseName : courseName ,
108+ name : `Assignment ${ idx + 1 } ` ,
108109 description : "This is a fake assignment" ,
109110 created_at : new Date ( Date . now ( ) - Math . random ( ) * 10000000000 ) . toISOString ( ) ,
110111 updated_at : new Date ( ) . toISOString ( ) ,
111112 } ) ) ;
112113 } ;
113114
114- const capitalizeSentence = ( str : string ) => {
115- return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) . toLowerCase ( ) ;
116- } ;
117-
118115 const getAssignmentColumns = ( actions : ActionHandler [ ] ) => {
119116 const baseColumns = getBaseAssignmentColumns (
120117 ( ) => { } ,
@@ -144,35 +141,22 @@ const CourseAssignments: React.FC<CourseAssignmentsProps> = ({ courseId, courseN
144141 return [ ...baseColumns , actionsColumn ] ;
145142 } ;
146143
147- // Helper function to format the dates
148- const formatDate = ( dateString : string ) : string => {
149- const date = new Date ( dateString ) ;
150- const options : Intl . DateTimeFormatOptions = {
151- month : 'short' ,
152- day : 'numeric' ,
153- year : 'numeric' ,
154- hour : 'numeric' ,
155- minute : 'numeric' ,
156- hour12 : true
157- } ;
158- return date . toLocaleString ( 'en-US' , options ) ;
159- } ;
160-
161-
162144 const assignments = generateFakeAssignments ( ) ;
163145 const columns = getAssignmentColumns ( actionHandlers ) ;
164146
165- // Remove the 'Course Name' column from column definitions to hide it.
166- const filteredColumns = columns . filter ( ( col ) => col . header !== "Course Name" ) ;
167- // Remove 'courseName' field from assignment data to hide it and Format date fields.
168- const filteredAssignments = assignments . map (
169- ( { name, courseName, created_at, updated_at, ...rest } ) => ( {
170- ...rest ,
171- name : capitalizeSentence ( name ) ,
172- created_at : formatDate ( created_at ) , // Format 'created_at' date
173- updated_at : formatDate ( updated_at ) , // Format 'updated_at' date
174- } )
175- ) ;
147+ // Format all heading data fields.
148+ const filteredColumns = columns . map ( ( { header, ...rest } ) => ( {
149+ ...rest ,
150+ header : capitalizeFirstWord ( header as string ) ,
151+ } ) ) ;
152+
153+ // Format some assignment data fields.
154+ const filteredAssignments = assignments . map ( ( { name, created_at, updated_at, ...rest } ) => ( {
155+ ...rest ,
156+ name : capitalizeFirstWord ( name ) ,
157+ created_at : formatDate ( created_at ) , // Format 'created_at' date
158+ updated_at : formatDate ( updated_at ) , // Format 'updated_at' date
159+ } ) ) ;
176160
177161 return (
178162 < div className = "px-4 py-2 bg-light" >
0 commit comments