diff --git a/.env.example b/.env.example index f3afcc4..a263397 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1 @@ -REACT_APP_API_URL=http://stackspin_proxy:8081/api/v1 REACT_APP_HYDRA_PUBLIC_URL=https://sso.init.stackspin.net \ No newline at end of file diff --git a/src/components/UserModal/UserModal.tsx b/src/components/UserModal/UserModal.tsx deleted file mode 100644 index 404db4b..0000000 --- a/src/components/UserModal/UserModal.tsx +++ /dev/null @@ -1,277 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import _ from 'lodash'; -import { TrashIcon } from '@heroicons/react/outline'; -import { useFieldArray, useForm, useWatch } from 'react-hook-form'; -import { Banner, Modal, ConfirmationModal } from 'src/components'; -import { Input, Select } from 'src/components/Form'; -import { User, UserRole, useUsers } from 'src/services/users'; -import { useAuth } from 'src/services/auth'; -import { appAccessList, initialUserForm } from './consts'; -import { UserModalProps } from './types'; - -export const UserModal = ({ open, onClose, userId, setUserId }: UserModalProps) => { - const [deleteModal, setDeleteModal] = useState(false); - const [isAdminRoleSelected, setAdminRoleSelected] = useState(true); - const [isPersonalModal, setPersonalModal] = useState(false); - const { - user, - loadUser, - loadPersonalInfo, - editUserById, - editPersonalInfo, - createNewUser, - userModalLoading, - deleteUserById, - clearSelectedUser, - } = useUsers(); - const { currentUser, isAdmin } = useAuth(); - - const { control, reset, handleSubmit } = useForm({ - defaultValues: initialUserForm, - }); - - const { fields, update } = useFieldArray({ - control, - name: 'app_roles', - }); - - useEffect(() => { - if (userId) { - const currentUserId = currentUser?.id; - if (currentUserId === userId) { - setPersonalModal(true); - loadPersonalInfo(); - } else { - loadUser(userId); - } - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [userId, open]); - - useEffect(() => { - if (!_.isEmpty(user)) { - reset(user); - } - - return () => { - reset(initialUserForm); - }; - }, [user, reset, open]); - - const dashboardRole = useWatch({ - control, - name: 'app_roles.0.role', - }); - - useEffect(() => { - const isAdminDashboardRoleSelected = dashboardRole === UserRole.Admin; - setAdminRoleSelected(isAdminDashboardRoleSelected); - if (isAdminDashboardRoleSelected) { - fields.forEach((field, index) => update(index, { name: field.name, role: UserRole.Admin })); - } else { - fields.forEach((field, index) => update(index, { name: field.name, role: UserRole.User })); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [dashboardRole]); - - const handleSave = async () => { - try { - if (isPersonalModal) { - await handleSubmit((data) => editPersonalInfo(data))(); - } else if (userId) { - await handleSubmit((data) => editUserById(data))(); - } else { - await handleSubmit((data) => createNewUser(data))(); - } - } catch (e: any) { - // Continue - } - - onClose(); - clearSelectedUser(); - setUserId(null); - }; - - const handleKeyPress = (e: any) => { - if (e.key === 'Enter' || e.key === 'NumpadEnter') { - handleSave(); - } - }; - - const handleClose = () => { - onClose(); - clearSelectedUser(); - setUserId(null); - }; - - const deleteModalOpen = () => setDeleteModal(true); - const deleteModalClose = () => setDeleteModal(false); - - const handleDelete = () => { - if (userId) { - deleteUserById(userId); - } - - clearSelectedUser(); - setUserId(null); - handleClose(); - deleteModalClose(); - }; - - return ( - <> - -