@@ -2,7 +2,6 @@ import React, { useRef } from 'react'
22import {
33 Button ,
44 FormLabel ,
5- Input ,
65 Modal ,
76 ModalBody ,
87 ModalCloseButton ,
@@ -13,22 +12,16 @@ import {
1312 Stack ,
1413 useToast ,
1514 Select ,
16- FormControl ,
17- FormErrorMessage ,
1815 Text ,
19- InputGroup ,
20- InputLeftElement ,
2116} from '@chakra-ui/react'
2217import { t , Trans } from '@lingui/macro'
23- import { Field , Formik } from 'formik'
18+ import { Formik } from 'formik'
2419import { useMutation } from '@apollo/client'
25- import { useLingui } from '@lingui/react'
26- import { EmailIcon } from '@chakra-ui/icons'
2720import { bool , func , string } from 'prop-types'
28- import { object as yupObject , string as yupString } from 'yup'
2921
22+ import { EmailField } from '../components/EmailField'
3023import { UPDATE_USER_ROLE , INVITE_USER_TO_ORG } from '../graphql/mutations'
31- import { fieldRequirements } from '../utilities/fieldRequirements'
24+ import { createValidationSchema } from '../utilities/fieldRequirements'
3225
3326export function UserListModal ( {
3427 isOpen,
@@ -42,7 +35,6 @@ export function UserListModal({
4235} ) {
4336 const toast = useToast ( )
4437 const initialFocusRef = useRef ( )
45- const { i18n } = useLingui ( )
4638
4739 const [ addUser , { loading : _addUserLoading } ] = useMutation (
4840 INVITE_USER_TO_ORG ,
@@ -156,29 +148,25 @@ export function UserListModal({
156148 validateOnBlur = { false }
157149 initialValues = { {
158150 role : editingUserRole ,
159- userName : editingUserName ,
151+ email : editingUserName ,
160152 } }
161- validationSchema = { yupObject ( ) . shape ( {
162- userName : yupString ( )
163- . required ( i18n . _ ( fieldRequirements . email . required . message ) )
164- . email ( i18n . _ ( fieldRequirements . email . email . message ) ) ,
165- } ) }
153+ validationSchema = { createValidationSchema ( [ 'email' ] ) }
166154 onSubmit = { async ( values ) => {
167155 // Submit update role mutation
168156 if ( mutation === 'update' ) {
169157 await updateUserRole ( {
170158 variables : {
171159 orgId : orgId ,
172160 role : values . role ,
173- userName : values . userName ,
161+ userName : values . email ,
174162 } ,
175163 } )
176164 } else if ( mutation === 'create' ) {
177165 await addUser ( {
178166 variables : {
179167 orgId : orgId ,
180168 requestedRole : values . role ,
181- userName : values . userName ,
169+ userName : values . email ,
182170 preferredLang : 'ENGLISH' ,
183171 } ,
184172 } )
@@ -204,36 +192,7 @@ export function UserListModal({
204192 < Text > { editingUserName } </ Text >
205193 </ Stack >
206194 ) : (
207- < Field id = "userName" name = "userName" >
208- { ( { field, form } ) => (
209- < FormControl
210- isInvalid = {
211- form . errors . userName && form . touched . userName
212- }
213- >
214- < Stack isInline align = "center" >
215- < FormLabel htmlFor = "userName" fontWeight = "bold" >
216- < Trans > User:</ Trans >
217- </ FormLabel >
218- < InputGroup >
219- < InputLeftElement aria-hidden = "true" >
220- < EmailIcon color = "gray.300" />
221- </ InputLeftElement >
222- < Input
223- mb = "2"
224- { ...field }
225- id = "userName"
226- placeholder = { i18n . _ ( t `user email` ) }
227- ref = { initialFocusRef }
228- />
229- </ InputGroup >
230- </ Stack >
231- < FormErrorMessage >
232- { form . errors . userName }
233- </ FormErrorMessage >
234- </ FormControl >
235- ) }
236- </ Field >
195+ < EmailField />
237196 ) }
238197 < Stack isInline align = "center" >
239198 < FormLabel htmlFor = "role" fontWeight = "bold" mt = "2" >
0 commit comments