diff --git a/resources/scripts/components/server/users/EditSubuserModal.tsx b/resources/scripts/components/server/users/EditSubuserModal.tsx index 281e52a58..a046528db 100644 --- a/resources/scripts/components/server/users/EditSubuserModal.tsx +++ b/resources/scripts/components/server/users/EditSubuserModal.tsx @@ -1,4 +1,4 @@ -import React, { forwardRef, MutableRefObject, useRef } from 'react'; +import React, { forwardRef, useRef } from 'react'; import { Subuser } from '@/state/server/subusers'; import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; import { array, object, string } from 'yup'; @@ -39,8 +39,9 @@ const EditSubuserModal = forwardRef(({ subuser, ...pr return ( -

{subuser ? 'Edit subuser' : 'Create new subuser'}

+

{subuser ? `Modify permissions for ${subuser.email}` : 'Create new subuser'}

+ {!subuser &&
(({ subuser, ...pr description={'Enter the email address of the user you wish to invite as a subuser for this server.'} />
+ }
{Object.keys(permissions).filter(key => key !== 'websocket').map((key, index) => ( { - const appendSubuser = ServerContext.useStoreActions(actions => actions.subusers.appendSubuser); + const [ visible, setVisible ] = useState(false); return (
+ {visible && + setVisible(false)} + /> + }
@@ -26,7 +32,7 @@ export default ({ subuser }: Props) => { type={'button'} aria-label={'Edit subuser'} className={'block text-sm p-2 text-neutral-500 hover:text-neutral-100 transition-colors duration-150 mr-4'} - onClick={() => null} + onClick={() => setVisible(true)} > diff --git a/resources/scripts/state/server/subusers.ts b/resources/scripts/state/server/subusers.ts index 46e69f470..c859ecead 100644 --- a/resources/scripts/state/server/subusers.ts +++ b/resources/scripts/state/server/subusers.ts @@ -38,7 +38,20 @@ const subusers: ServerSubuserStore = { }), appendSubuser: action((state, payload) => { - state.data = [ ...state.data.filter(user => user.uuid !== payload.uuid), payload ]; + let matched = false; + state.data = [ + ...state.data + .map(user => { + if (user.uuid === payload.uuid) { + matched = true; + + return payload; + } + + return user; + }) + .concat(matched ? [] : [ payload ]), + ]; }), removeSubuser: action((state, payload) => {