22
33import { estimatePasswordStrength } from '@douglasneuroinformatics/libpasswd' ;
44import { Form , Heading } from '@douglasneuroinformatics/libui/components' ;
5- import type { FormProps } from '@douglasneuroinformatics/libui/components' ;
6- import { useTranslation } from '@douglasneuroinformatics/libui/hooks' ;
5+ import { useNotificationsStore , useTranslation } from '@douglasneuroinformatics/libui/hooks' ;
76import { $BasePermissionLevel , $CreateUserData } from '@opendatacapture/schemas/user' ;
87import type { CreateUserData } from '@opendatacapture/schemas/user' ;
98import { createFileRoute , useNavigate } from '@tanstack/react-router' ;
@@ -19,20 +18,22 @@ const RouteComponent = () => {
1918 const navigate = useNavigate ( ) ;
2019 const groupsQuery = useGroupsQuery ( ) ;
2120 const createUserMutation = useCreateUserMutation ( ) ;
21+ const notification = useNotificationsStore ( ) ;
2222
23- const handleSubmit : FormProps < any > [ 'onSubmit' ] = async ( data : CreateUserData ) => {
23+ const handleSubmit = async ( data : CreateUserData ) => {
2424 // check if username exists
25-
2625 const existingUsername = await axios . get ( `/v1/users/check-username/${ encodeURIComponent ( data . username ) } ` ) ;
2726
28- if ( existingUsername ) {
29- return { success : false , errorMessage : t ( 'common.usernameExists' ) } ;
30- }
31-
32- createUserMutation . mutate ( { data } ) ;
27+ if ( existingUsername . data !== false ) {
28+ notification . addNotification ( {
29+ type : 'error' ,
30+ message : t ( 'common.usernameExists' )
31+ } ) ;
32+ } else {
33+ createUserMutation . mutate ( { data } ) ;
3334
34- void navigate ( { to : '..' } ) ;
35- return { success : true } ;
35+ void navigate ( { to : '..' } ) ;
36+ }
3637 } ;
3738
3839 return (
0 commit comments