import React, { useEffect } from 'react'; import Admin from 'shared/components/Admin'; import Select from 'shared/components/Select'; import GlobalTopNavbar from 'App/TopNavbar'; import { useUsersQuery, useDeleteUserAccountMutation, useCreateUserAccountMutation, UsersDocument, UsersQuery, } from 'shared/generated/graphql'; import Input from 'shared/components/Input'; import styled from 'styled-components'; import Button from 'shared/components/Button'; import { useForm, Controller } from 'react-hook-form'; import { usePopup, Popup } from 'shared/components/PopupMenu'; import produce from 'immer'; import updateApolloCache from 'shared/utils/cache'; import { useCurrentUser } from 'App/context'; import { Redirect } from 'react-router'; import NOOP from 'shared/utils/noop'; const DeleteUserWrapper = styled.div` display: flex; flex-direction: column; `; const DeleteUserDescription = styled.p` font-size: 14px; `; const DeleteUserButton = styled(Button)` margin-top: 6px; padding: 6px 12px; width: 100%; `; type DeleteUserPopupProps = { onDeleteUser: () => void; }; const DeleteUserPopup: React.FC = ({ onDeleteUser }) => { return ( Deleting this user will remove all user related data. onDeleteUser()} color="danger"> Delete user ); }; type RoleCodeOption = { label: string; value: string; }; type CreateUserData = { email: string; username: string; fullName: string; initials: string; password: string; roleCode: RoleCodeOption; }; const CreateUserForm = styled.form` display: flex; flex-direction: column; margin: 0 12px; `; const CreateUserButton = styled(Button)` margin-top: 8px; padding: 6px 12px; width: 100%; `; const AddUserInput = styled(Input)` margin-bottom: 8px; `; const InputError = styled.span` color: rgba(${props => props.theme.colors.danger}); font-size: 12px; `; type AddUserPopupProps = { onAddUser: (user: CreateUserData) => void; }; const AddUserPopup: React.FC = ({ onAddUser }) => { const { register, handleSubmit, errors, control } = useForm(); const createUser = (data: CreateUserData) => { onAddUser(data); }; return ( {errors.fullName && {errors.fullName.message}} (