|
| 1 | +import React, { useEffect, useState } from 'react'; |
| 2 | +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; |
| 3 | +import { faUserPlus } from '@fortawesome/free-solid-svg-icons/faUserPlus'; |
| 4 | +import { ServerContext } from '@/state/server'; |
| 5 | +import Spinner from '@/components/elements/Spinner'; |
| 6 | + |
| 7 | +export default () => { |
| 8 | + const [ loading, setLoading ] = useState(true); |
| 9 | + const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); |
| 10 | + const subusers = ServerContext.useStoreState(state => state.subusers.data); |
| 11 | + const getSubusers = ServerContext.useStoreActions(actions => actions.subusers.getSubusers); |
| 12 | + |
| 13 | + useEffect(() => { |
| 14 | + getSubusers(uuid) |
| 15 | + .then(() => setLoading(false)) |
| 16 | + .catch(error => { |
| 17 | + console.error(error); |
| 18 | + }); |
| 19 | + }, [ uuid, getSubusers ]); |
| 20 | + |
| 21 | + useEffect(() => { |
| 22 | + if (subusers.length > 0) { |
| 23 | + setLoading(false); |
| 24 | + } |
| 25 | + }, [subusers]); |
| 26 | + |
| 27 | + return ( |
| 28 | + <div className={'flex my-10'}> |
| 29 | + <div className={'w-1/2'}> |
| 30 | + <h2 className={'text-neutral-300 mb-4'}>Subusers</h2> |
| 31 | + <div className={'border-t-4 border-primary-400 grey-box mt-0'}> |
| 32 | + {loading ? |
| 33 | + <div className={'w-full'}> |
| 34 | + <Spinner centered={true}/> |
| 35 | + </div> |
| 36 | + : |
| 37 | + !subusers.length ? |
| 38 | + <p className={'text-sm'}>It looks like you don't have any subusers.</p> |
| 39 | + : |
| 40 | + subusers.map(subuser => ( |
| 41 | + <div key={subuser.uuid} className={'flex items-center w-full'}> |
| 42 | + <img |
| 43 | + className={'w-10 h-10 rounded-full bg-white border-2 border-inset border-neutral-800'} |
| 44 | + src={`${subuser.image}?s=400`} |
| 45 | + /> |
| 46 | + <div className={'ml-4 flex-1'}> |
| 47 | + <p className={'text-sm'}>{subuser.email}</p> |
| 48 | + </div> |
| 49 | + <div className={'ml-4'}> |
| 50 | + <button className={'btn btn-xs btn-primary'}> |
| 51 | + Edit |
| 52 | + </button> |
| 53 | + <button className={'ml-2 btn btn-xs btn-red btn-secondary'}> |
| 54 | + Remove |
| 55 | + </button> |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + )) |
| 59 | + } |
| 60 | + </div> |
| 61 | + <div className={'flex justify-end mt-4'}> |
| 62 | + <button className={'btn btn-primary btn-sm'}> |
| 63 | + <FontAwesomeIcon icon={faUserPlus} className={'mr-1'}/> New User |
| 64 | + </button> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + ); |
| 69 | +}; |
0 commit comments