@@ -25,24 +25,40 @@ import { transformErrors } from '@/pages/Entities/components/CaseCreation/compon
25
25
import { useTranslateUiDefinitionQuery } from '@/domains/ui-definition/hooks/queries/useTranslateUiDefinitionQuery/useTranslateUiDefinitionQuery' ;
26
26
import { useDeleteUbosByIdsMutation } from '@/domains/workflows/hooks/mutations/useDeleteUbosByIdsMutation/useDeleteUbosByIdsMutation' ;
27
27
import { useCreateUboMutation } from '@/domains/workflows/hooks/mutations/useCreateUboMutation/useCreateUboMutation' ;
28
+ import { useLocale } from '@/common/hooks/useLocale/useLocale' ;
28
29
29
- export const useManageUbosBlock = ( ) => {
30
+ export const useManageUbosBlock = ( {
31
+ create,
32
+ } : {
33
+ create : {
34
+ enabled : boolean ;
35
+ } ;
36
+ } ) => {
30
37
const { data : workflow } = useCurrentCaseQuery ( ) ;
31
38
const { data : workflowDefinition } = useWorkflowDefinitionByIdQuery ( {
32
39
workflowDefinitionId : workflow ?. workflowDefinition ?. id ?? '' ,
33
40
} ) ;
34
41
const uiDefinition = workflowDefinition ?. uiDefinitions ?. find (
35
42
uiDefinition => uiDefinition . uiContext === 'collection_flow' ,
36
43
) ;
44
+ const locale = useLocale ( ) ;
37
45
const { data : translatedUbos } = useTranslateUiDefinitionQuery ( {
38
46
id : uiDefinition ?. id ?? '' ,
39
47
partialUiDefinition : ubosFormJsonDefinition ,
48
+ locale,
40
49
} ) ;
41
50
const { formSchema, uiSchema } = createFormSchemaFromUIElements ( translatedUbos ?? { } ) ;
42
51
const [ isAddingUbo , _toggleIsAddingUbo , toggleOnIsAddingUbo , toggleOffIsAddingUbo ] = useToggle ( ) ;
52
+ const [ isManageUbosOpen , toggleIsManageUbosOpen ] = useToggle ( ) ;
43
53
const { mutate : mutateCreateUbo } = useCreateUboMutation ( {
44
54
workflowId : workflow ?. id ,
45
- onSuccess : toggleOffIsAddingUbo ,
55
+ onSuccess : ( ) => {
56
+ if ( ! isAddingUbo ) {
57
+ return ;
58
+ }
59
+
60
+ toggleOffIsAddingUbo ( ) ;
61
+ } ,
46
62
} ) ;
47
63
const { mutate : mutateDeleteUbosByIds } = useDeleteUbosByIdsMutation ( {
48
64
workflowId : workflow ?. id ,
@@ -107,6 +123,7 @@ export const useManageUbosBlock = () => {
107
123
< Dialog
108
124
trigger = {
109
125
< Button
126
+ type = { 'button' }
110
127
variant = { 'ghost' }
111
128
size = { 'icon' }
112
129
className = { 'aria-disabled:pointer-events-none aria-disabled:opacity-50' }
@@ -119,7 +136,7 @@ export const useManageUbosBlock = () => {
119
136
description = {
120
137
< p className = { `text-sm` } >
121
138
Are you sure you want to remove this UBO? This action will be logged, and the
122
- UBO's data will be removed from the case and webhooks .
139
+ UBO's data will be removed from the case.
123
140
</ p >
124
141
}
125
142
content = { null }
@@ -191,8 +208,11 @@ export const useManageUbosBlock = () => {
191
208
type : 'node' ,
192
209
value : (
193
210
< Dialog
211
+ open = { isManageUbosOpen }
212
+ onOpenChange = { toggleIsManageUbosOpen }
194
213
trigger = {
195
214
< Button
215
+ type = { 'button' }
196
216
variant = "outline"
197
217
className = {
198
218
'ms-auto px-2 py-0 text-xs aria-disabled:pointer-events-none aria-disabled:opacity-50'
@@ -204,7 +224,7 @@ export const useManageUbosBlock = () => {
204
224
}
205
225
content = {
206
226
< div className = { 'flex flex-col justify-between space-y-4' } >
207
- { ! isAddingUbo && (
227
+ { ( ! create . enabled || ! isAddingUbo ) && (
208
228
< div className = { 'flex flex-col gap-4' } >
209
229
< h2 className = { 'text-lg font-semibold' } > Manage UBOs</ h2 >
210
230
< UrlDataTable
@@ -216,34 +236,51 @@ export const useManageUbosBlock = () => {
216
236
} }
217
237
props = { {
218
238
scroll : {
219
- className : 'h-[73vh]' ,
239
+ className : '[&>div]:max- h-[73vh]' ,
220
240
} ,
221
241
} }
222
242
/>
223
- < Button
224
- className = { 'ms-auto aria-disabled:pointer-events-none aria-disabled:opacity-50' }
225
- onClick = { toggleOnIsAddingUbo }
226
- aria-disabled = { ! caseState . writeEnabled }
227
- >
228
- Add
229
- </ Button >
243
+ { create . enabled && (
244
+ < Button
245
+ type = { 'button' }
246
+ className = {
247
+ 'ms-auto aria-disabled:pointer-events-none aria-disabled:opacity-50'
248
+ }
249
+ onClick = { toggleOnIsAddingUbo }
250
+ aria-disabled = { ! caseState . writeEnabled }
251
+ >
252
+ Add UBO
253
+ </ Button >
254
+ ) }
230
255
</ div >
231
256
) }
232
- { isAddingUbo && (
233
- < div className = { 'flex flex-col gap-4' } >
234
- < Button variant = { 'ghost' } onClick = { toggleOffIsAddingUbo } className = { 'me-auto' } >
235
- < ArrowLeft className = { 'text-muted-foreground' } size = { 14 } />
257
+ { create . enabled && isAddingUbo && (
258
+ < >
259
+ < Button
260
+ type = { 'button' }
261
+ variant = { 'ghost' }
262
+ onClick = { toggleOffIsAddingUbo }
263
+ className = {
264
+ 'absolute left-4 top-4 rounded-sm p-0 opacity-70 transition-opacity d-4 hover:bg-transparent hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 data-[state=open]:bg-slate-100 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900 dark:data-[state=open]:bg-slate-800'
265
+ }
266
+ >
267
+ < ArrowLeft className = { 'd-4' } />
236
268
</ Button >
237
- < ScrollArea orientation = { 'vertical' } className = { 'h-[73vh]' } >
238
- < DynamicForm
239
- schema = { formSchema }
240
- uiSchema = { uiSchema }
241
- onSubmit = { onSubmit }
242
- layouts = { layouts as typeof baseLayouts }
243
- transformErrors = { transformErrors }
244
- />
245
- </ ScrollArea >
246
- </ div >
269
+
270
+ < div className = { 'flex flex-col gap-4' } >
271
+ < h2 className = { 'text-lg font-semibold' } > Add UBO</ h2 >
272
+ < ScrollArea orientation = { 'vertical' } className = { 'h-[73vh]' } >
273
+ < DynamicForm
274
+ schema = { formSchema }
275
+ uiSchema = { uiSchema }
276
+ onSubmit = { onSubmit }
277
+ layouts = { layouts as typeof baseLayouts }
278
+ transformErrors = { transformErrors }
279
+ className = { '[&>div>fieldset>div:first-of-type]:py-0 [&>div]:py-0' }
280
+ />
281
+ </ ScrollArea >
282
+ </ div >
283
+ </ >
247
284
) }
248
285
</ div >
249
286
}
0 commit comments