@@ -31,6 +31,7 @@ type User = {
3131 email : string
3232 image ?: string
3333 capabilities ?: string [ ]
34+ adsDisabled ?: boolean
3435}
3536
3637export const Route = createFileRoute ( {
@@ -42,6 +43,9 @@ function UsersPage() {
4243 const [ editingCapabilities , setEditingCapabilities ] = useState < string [ ] > ( [ ] )
4344 const [ cursors , setCursors ] = useState < string [ ] > ( [ '' ] ) // Track cursor history for navigation
4445 const [ currentPageIndex , setCurrentPageIndex ] = useState ( 0 )
46+ const [ updatingAdsUserId , setUpdatingAdsUserId ] = useState < string | null > (
47+ null
48+ )
4549
4650 const user = useConvexQuery ( api . auth . getCurrentUser )
4751 const usersQuery = useQuery ( {
@@ -57,6 +61,7 @@ function UsersPage() {
5761 const updateUserCapabilities = useConvexMutation (
5862 api . users . updateUserCapabilities
5963 )
64+ const adminSetAdsDisabled = useConvexMutation ( api . users . adminSetAdsDisabled )
6065
6166 const availableCapabilities = useMemo (
6267 ( ) => [ 'admin' , 'disableAds' , 'builder' ] ,
@@ -104,6 +109,16 @@ function UsersPage() {
104109 [ editingCapabilities ]
105110 )
106111
112+ const handleToggleAdsDisabled = useCallback (
113+ async ( userId : string , nextValue : boolean ) => {
114+ adminSetAdsDisabled ( {
115+ userId : userId as Id < 'users' > ,
116+ adsDisabled : nextValue ,
117+ } )
118+ } ,
119+ [ adminSetAdsDisabled ]
120+ )
121+
107122 // Define columns using the column helper
108123 const columns = useMemo < ColumnDef < User , any > [ ] > (
109124 ( ) => [
@@ -177,6 +192,25 @@ function UsersPage() {
177192 )
178193 } ,
179194 } ,
195+ {
196+ id : 'adsDisabled' ,
197+ header : 'Ads Disabled' ,
198+ cell : ( { row } ) => {
199+ const user = row . original
200+ const checked = Boolean ( user . adsDisabled )
201+ return (
202+ < input
203+ type = "checkbox"
204+ checked = { checked }
205+ onChange = { ( e ) =>
206+ handleToggleAdsDisabled ( user . _id , e . target . checked )
207+ }
208+ disabled = { updatingAdsUserId === user . _id }
209+ className = "h-4 w-4 accent-blue-600"
210+ />
211+ )
212+ } ,
213+ } ,
180214 {
181215 id : 'actions' ,
182216 header : 'Actions' ,
0 commit comments