Skip to content

Commit 87b7050

Browse files
authored
Fix inconsistent validation error when deploying new app interface (#547)
* fix: use setError instead of trigger to show validation error * fix: use setError in app details too
2 parents c386e72 + 684d762 commit 87b7050

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/features/app-interfaces/components/create/app-details.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type FormInnerProps = {
4545

4646
function FormInner({ helper }: FormInnerProps) {
4747
const formCtx = useFormContext<z.infer<typeof schema>>()
48-
const { setValue, trigger } = formCtx
48+
const { setValue, setError, clearErrors } = formCtx
4949
const loadableAppInterfaces = useLoadableAppInterfacesAtom()
5050
const appInterfaceNameFieldValue = formCtx.watch('name')
5151
const [appInterfaceName] = useDebounce(appInterfaceNameFieldValue, 500)
@@ -56,9 +56,17 @@ function FormInner({ helper }: FormInnerProps) {
5656
(appInterface) => appInterface.name.toLowerCase() === appInterfaceName.toLowerCase()
5757
)
5858
setValue('appInterfaceExists', appInterfaceExists)
59-
trigger('name')
59+
60+
if (appInterfaceExists) {
61+
setError('name', {
62+
type: 'manual',
63+
message: 'App interface with this name already exists',
64+
})
65+
} else {
66+
clearErrors('name')
67+
}
6068
}
61-
}, [appInterfaceName, loadableAppInterfaces, setValue, trigger])
69+
}, [appInterfaceName, loadableAppInterfaces, setValue, setError, clearErrors])
6270

6371
return (
6472
<>

src/features/app-interfaces/components/create/deployment-details.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function FormInner({
6161
helper,
6262
}: FormInnerProps) {
6363
const formCtx = useFormContext<z.infer<BaseForm>>()
64-
const { setValue, trigger } = formCtx
64+
const { setValue, setError, clearErrors } = formCtx
6565
const loadableAppInterfaces = useLoadableAppInterfacesAtom()
6666
const appInterfaceNameFieldValue = formCtx.watch('name')
6767
const [appInterfaceName] = useDebounce(appInterfaceNameFieldValue, 500)
@@ -72,9 +72,17 @@ function FormInner({
7272
(appInterface) => appInterface.name.toLowerCase() === appInterfaceName.toLowerCase()
7373
)
7474
setValue('appInterfaceExists', appInterfaceExists)
75-
trigger('name')
75+
76+
if (appInterfaceExists) {
77+
setError('name', {
78+
type: 'manual',
79+
message: 'App interface with this name already exists',
80+
})
81+
} else {
82+
clearErrors('name')
83+
}
7684
}
77-
}, [appInterfaceName, loadableAppInterfaces, setValue, trigger])
85+
}, [appInterfaceName, loadableAppInterfaces, setValue, setError, clearErrors])
7886

7987
return (
8088
<>

0 commit comments

Comments
 (0)