@@ -19,6 +19,7 @@ import {
1919 Text ,
2020 Th ,
2121 Thead ,
22+ Tooltip ,
2223 Tr ,
2324 useDisclosure ,
2425 useToast ,
@@ -87,6 +88,7 @@ export const ManageAccounts = () => {
8788 } = useDisclosure ( ) ;
8889 const [ editDrawerOpened , setEditDrawerOpened ] = useState ( false ) ;
8990 const [ selectedRowIds , setSelectedRowIds ] = useState < number [ ] > ( [ ] ) ;
91+ const [ checkboxMode , setCheckboxMode ] = useState < 'hidden' | 'visible-unchecked' | 'visible-checked' > ( 'hidden' ) ;
9092 const toast = useToast ( ) ;
9193
9294 const buttonStyle = {
@@ -112,10 +114,20 @@ export const ManageAccounts = () => {
112114 }
113115 } ;
114116
117+
115118 const handleSelectAllCheckboxClick = ( ) => {
116- if ( selectedRowIds . length === 0 ) {
117- setSelectedRowIds ( persons . map ( ( person ) => person . id ) ) ;
119+ if ( checkboxMode === 'hidden' ) {
120+ // State 1 -> State 2: Show checkboxes and select all
121+ setCheckboxMode ( 'visible-checked' ) ;
122+ const allIds = persons . map ( ( person ) => person . id ) ;
123+ setSelectedRowIds ( allIds ) ;
124+ } else if ( checkboxMode === 'visible-checked' ) {
125+ // State 2 -> State 3: Keep checkboxes visible but uncheck all
126+ setCheckboxMode ( 'visible-unchecked' ) ;
127+ setSelectedRowIds ( [ ] ) ;
118128 } else {
129+ // State 3 -> State 1: Hide checkboxes
130+ setCheckboxMode ( 'hidden' ) ;
119131 setSelectedRowIds ( [ ] ) ;
120132 }
121133 } ;
@@ -173,12 +185,12 @@ export const ManageAccounts = () => {
173185 ( ) => [
174186 {
175187 id : "rowNumber" ,
176- header : ( { table } ) => {
188+ header : ( ) => {
177189 return (
178190 < Box textAlign = "center" >
179191 < Checkbox
180- isChecked = { selectedRowIds . length > 0 }
181- isIndeterminate = { table . getIsSomeRowsSelected ( ) }
192+ isChecked = { checkboxMode === 'visible-checked' }
193+ isIndeterminate = { checkboxMode === 'visible-unchecked' }
182194 onChange = { handleSelectAllCheckboxClick }
183195 />
184196 </ Box >
@@ -208,8 +220,44 @@ export const ManageAccounts = () => {
208220 accessorKey : "location" ,
209221 header : "Site" ,
210222 } ,
223+ {
224+ accessorKey : "notes" ,
225+ header : "Notes" ,
226+ cell : ( { getValue } ) => {
227+ const notes = getValue ( ) as string ;
228+ const maxLength = 20 ; // Maximum characters to show before truncation
229+
230+ if ( ! notes || notes . length === 0 ) {
231+ return < Text color = "gray.400" fontStyle = "italic" > No notes</ Text > ;
232+ }
233+
234+ const truncatedNotes = notes . length > maxLength
235+ ? `${ notes . substring ( 0 , maxLength ) } ...`
236+ : notes ;
237+
238+ return (
239+ < Tooltip
240+ label = { notes }
241+ placement = "top"
242+ hasArrow
243+ maxW = "400px"
244+ whiteSpace = "pre-wrap"
245+ >
246+ < Text
247+ maxW = "200px"
248+ overflow = "hidden"
249+ textOverflow = "ellipsis"
250+ whiteSpace = "nowrap"
251+ _hover = { { color : "blue.500" } }
252+ >
253+ { truncatedNotes }
254+ </ Text >
255+ </ Tooltip >
256+ ) ;
257+ } ,
258+ } ,
211259 ] ,
212- [ ]
260+ [ selectedRowIds , persons , handleSelectAllCheckboxClick , checkboxMode ]
213261 ) ;
214262
215263 const table = useReactTable ( {
@@ -274,6 +322,8 @@ export const ManageAccounts = () => {
274322 onClick = { ( ) => {
275323 setView ( "admin" ) ;
276324 setEditDrawerOpened ( false ) ;
325+ setSelectedRowIds ( [ ] ) ;
326+ setCheckboxMode ( 'hidden' ) ;
277327 } }
278328 >
279329 Admins
@@ -282,6 +332,8 @@ export const ManageAccounts = () => {
282332 onClick = { ( ) => {
283333 setView ( "cms" ) ;
284334 setEditDrawerOpened ( false ) ;
335+ setSelectedRowIds ( [ ] ) ;
336+ setCheckboxMode ( 'hidden' ) ;
285337 } }
286338 >
287339 Case Managers
@@ -290,6 +342,8 @@ export const ManageAccounts = () => {
290342 onClick = { ( ) => {
291343 setView ( "clients" ) ;
292344 setEditDrawerOpened ( false ) ;
345+ setSelectedRowIds ( [ ] ) ;
346+ setCheckboxMode ( 'hidden' ) ;
293347 } }
294348 >
295349 Clients
@@ -300,7 +354,14 @@ export const ManageAccounts = () => {
300354 < Spacer />
301355 { view !== "clients" && (
302356 < >
303- < Button onClick = { deleteOnOpen } > Delete</ Button >
357+ < Button
358+ onClick = { deleteOnOpen }
359+ disabled = { selectedRowIds . length === 0 }
360+ colorScheme = { selectedRowIds . length === 0 ? "gray" : "red" }
361+ opacity = { selectedRowIds . length === 0 ? 0.5 : 1 }
362+ >
363+ Delete ({ selectedRowIds . length } )
364+ </ Button >
304365 < Button
305366 colorScheme = "blue"
306367 onClick = { onOpen }
@@ -402,14 +463,15 @@ export const ManageAccounts = () => {
402463 } }
403464 >
404465 { cell . column . id === "rowNumber" ? (
405- < HoverCheckbox
406- id = { row . original . id }
407- isSelected = { selectedRowIds . includes (
408- row . original . id
409- ) }
410- onSelectionChange = { handleRowSelect }
411- index = { index }
412- />
466+ < HoverCheckbox
467+ id = { row . original . id }
468+ isSelected = { selectedRowIds . includes (
469+ row . original . id
470+ ) }
471+ onSelectionChange = { handleRowSelect }
472+ index = { index }
473+ alwaysVisible = { checkboxMode !== 'hidden' }
474+ />
413475 ) : (
414476 flexRender (
415477 cell . column . columnDef . cell ,
0 commit comments