diff --git a/ui/components/admin.js b/ui/components/admin.js index 7b3622c21f..92471c854b 100644 --- a/ui/components/admin.js +++ b/ui/components/admin.js @@ -2,8 +2,6 @@ import { useState } from 'react' import useSWR, { useSWRConfig } from 'swr' import { PlusIcon } from '@heroicons/react/outline' -import { validateEmail } from '../lib/email' - import InputDropdown from './input' import DeleteModal from './modals/delete' import ErrorMessage from './error-message' @@ -60,7 +58,7 @@ export default function () { const { data: auth } = useSWR('/api/users/self') const { mutate } = useSWRConfig() - const [adminEmail, setAdminEmail] = useState('') + const [name, setName] = useState('') const [error, setError] = useState('') const userGrants = grants?.filter(g => g.user) @@ -73,43 +71,35 @@ export default function () { }) .then(() => { mutate('/api/grants?resource=infra&privilege=admin') - setAdminEmail('') + setName('') }).catch((e) => setError(e.message || 'something went wrong, please try again later.')) } const handleInputChange = (value) => { - setAdminEmail(value) + setName(value) setError('') } const handleKeyDownEvent = (key) => { - if (key === 'Enter' && adminEmail.length > 0) { + if (key === 'Enter' && name.length > 0) { handleAddAdmin() } } const handleAddAdmin = () => { - if (validateEmail(adminEmail)) { - setError('') - - fetch(`/api/users?name=${adminEmail}`) - .then((response) => response.json()) - .then(({ items = [] }) => { - if (items.length === 0) { - fetch('/api/users', { - method: 'POST', - body: JSON.stringify({ name: adminEmail }) - }) - .then((response) => response.json()) - .then((user) => grantAdminAccess(user.id)) - .catch((error) => console.error(error)) - } else { - grantAdminAccess(items[0].id) - } - }) - } else { - setError('Invalid email') - } + setError('') + + fetch(`/api/users?name=${name}`) + .then((response) => response.json()) + .then(({ items = [] }) => { + if (items.length === 0) { + setError('User does not exist') + } else { + grantAdminAccess(items[0].id) + } + }).catch(e => { + setError(e) + }) } return ( @@ -118,9 +108,9 @@ export default function () {
handleInputChange(e.target.value)} handleKeyDown={(e) => handleKeyDownEvent(e.key)} @@ -129,7 +119,7 @@ export default function () {
{error &&

{error}

} diff --git a/ui/pages/users/index.js b/ui/pages/users/index.js index ed61bf98f4..a8b9060640 100644 --- a/ui/pages/users/index.js +++ b/ui/pages/users/index.js @@ -16,7 +16,7 @@ import DeleteModal from '../../components/modals/delete' import ResourcesGrant from '../../components/resources-grant' const columns = [{ - Header: 'Email', + Header: 'Name', accessor: u => u, Cell: ({ value: user }) => (