@@ -21,6 +21,7 @@ import DateField from "src/core/components/fields/DateField"
2121import { InformationCircleIcon } from "@heroicons/react/24/outline"
2222import { Tooltip } from "react-tooltip"
2323import LabeledTextAreaField from "src/core/components/fields/LabeledTextAreaField"
24+ import { useForm } from "react-final-form"
2425
2526export type Tag = {
2627 id : string
@@ -129,6 +130,48 @@ export function TaskForm<S extends z.ZodType<any, any>>(props: TaskFormProps<S>)
129130 setTags ( [ ] )
130131 }
131132
133+ const contributorIds = contributorOptions . map ( ( c ) => c . id )
134+ const teamIds = teamOptions . map ( ( t ) => t . id )
135+
136+ const ContributorsBulkButtons : React . FC < {
137+ contributorCount : number
138+ contributorIds : number [ ]
139+ teamIds : number [ ]
140+ } > = ( { contributorCount, contributorIds, teamIds } ) => {
141+ const formApi = useForm ( )
142+ const selectAllContributors = ( ) => formApi . change ( "projectMembersId" , contributorIds )
143+ const clearAllContributors = ( ) => formApi . change ( "projectMembersId" , [ ] )
144+ return (
145+ < div className = "flex justify-center items-center gap-3 mb-3" >
146+ < button type = "button" className = "btn btn-primary" onClick = { selectAllContributors } >
147+ Select all contributors ({ contributorCount } )
148+ </ button >
149+ < button type = "button" className = "btn btn-secondary" onClick = { clearAllContributors } >
150+ Clear
151+ </ button >
152+ </ div >
153+ )
154+ }
155+
156+ const TeamsBulkButtons : React . FC < { teamCount : number ; teamIds : number [ ] } > = ( {
157+ teamCount,
158+ teamIds,
159+ } ) => {
160+ const formApi = useForm ( )
161+ const selectAllTeams = ( ) => formApi . change ( "teamsId" , teamIds )
162+ const clearAllTeams = ( ) => formApi . change ( "teamsId" , [ ] )
163+ return (
164+ < div className = "flex justify-center items-center gap-3 mb-3" >
165+ < button type = "button" className = "btn btn-primary" onClick = { selectAllTeams } >
166+ Select all teams ({ teamCount } )
167+ </ button >
168+ < button type = "button" className = "btn btn-secondary" onClick = { clearAllTeams } >
169+ Clear
170+ </ button >
171+ </ div >
172+ )
173+ }
174+
132175 return (
133176 < Form < S >
134177 { ...formProps }
@@ -190,7 +233,14 @@ export function TaskForm<S extends z.ZodType<any, any>>(props: TaskFormProps<S>)
190233 buttonClassName = "w-1/2 mb-4 mt-2"
191234 saveButton = { true }
192235 >
193- < CheckboxFieldTable name = "projectMembersId" options = { contributorOptions } />
236+ < div className = "col-span-full w-full grid grid-cols-1 gap-4" >
237+ < ContributorsBulkButtons
238+ contributorCount = { contributorOptions . length }
239+ contributorIds = { contributorIds }
240+ teamIds = { teamIds }
241+ />
242+ < CheckboxFieldTable name = "projectMembersId" options = { contributorOptions } />
243+ </ div >
194244 </ ToggleModal >
195245 { /* Teams */ }
196246 < ToggleModal
@@ -199,7 +249,10 @@ export function TaskForm<S extends z.ZodType<any, any>>(props: TaskFormProps<S>)
199249 buttonClassName = "w-1/2"
200250 saveButton = { true }
201251 >
202- < CheckboxFieldTable name = "teamsId" options = { teamOptions } />
252+ < div className = "col-span-full w-full grid grid-cols-1 gap-4" >
253+ < TeamsBulkButtons teamCount = { teamOptions . length } teamIds = { teamIds } />
254+ < CheckboxFieldTable name = "teamsId" options = { teamOptions } />
255+ </ div >
203256 </ ToggleModal >
204257 </ CollapseCard >
205258
0 commit comments