2021-06-05 22:53:33 +00:00
|
|
|
import {CogIcon, TrashIcon, UserAddIcon, UsersIcon} from "@heroicons/react/outline";
|
|
|
|
import Dropdown from "../ui/Dropdown";
|
|
|
|
import {useState} from "react";
|
|
|
|
|
|
|
|
export default function TeamListItem(props) {
|
|
|
|
|
|
|
|
const [ team, setTeam ] = useState(props.team);
|
|
|
|
|
|
|
|
const acceptInvite = () => invitationResponse(true);
|
|
|
|
const declineInvite = () => invitationResponse(false);
|
|
|
|
|
|
|
|
const invitationResponse = (accept: boolean) => fetch('/api/user/membership', {
|
|
|
|
method: accept ? 'PATCH' : 'DELETE',
|
|
|
|
body: JSON.stringify({ teamId: props.team.id }),
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}).then( () => {
|
|
|
|
// success
|
|
|
|
setTeam(null);
|
2021-06-05 23:41:05 +00:00
|
|
|
props.onChange();
|
2021-06-05 22:53:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return (team && <li className="mb-2 mt-2 divide-y">
|
|
|
|
<div className="flex justify-between mb-2 mt-2">
|
|
|
|
<div>
|
|
|
|
<UsersIcon className="text-gray-400 group-hover:text-gray-500 flex-shrink-0 -mt-4 mr-2 h-6 w-6 inline"/>
|
|
|
|
<div className="inline-block -mt-1">
|
2021-07-30 23:05:38 +00:00
|
|
|
<span className="font-bold text-neutral-700 text-sm">{props.team.name}</span>
|
2021-06-08 16:00:06 +00:00
|
|
|
<span className="text-xs text-gray-400 -mt-1 block capitalize">{props.team.role.toLowerCase()}</span>
|
2021-06-05 22:53:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{props.team.role === 'INVITEE' && <div>
|
2021-07-30 23:05:38 +00:00
|
|
|
<button className="btn-sm bg-transparent text-green-500 border border-green-500 px-3 py-1 rounded-sm ml-2" onClick={acceptInvite}>Accept invitation</button>
|
2021-06-05 22:53:33 +00:00
|
|
|
<button className="btn-sm bg-transparent px-2 py-1 ml-1">
|
|
|
|
<TrashIcon className="h-6 w-6 inline text-gray-400 -mt-1" onClick={declineInvite} />
|
|
|
|
</button>
|
|
|
|
</div>}
|
|
|
|
{props.team.role === 'MEMBER' && <div>
|
2021-07-30 23:05:38 +00:00
|
|
|
<button onClick={declineInvite} className="btn-sm bg-transparent text-gray-400 border border-gray-400 px-3 py-1 rounded-sm ml-2">Leave</button>
|
2021-06-05 22:53:33 +00:00
|
|
|
</div>}
|
|
|
|
{props.team.role === 'OWNER' && <div>
|
|
|
|
<Dropdown className="relative inline-block text-left">
|
2021-07-30 23:05:38 +00:00
|
|
|
<button className="btn-sm bg-transparent text-gray-400 px-3 py-1 rounded-sm ml-2">
|
2021-06-05 22:53:33 +00:00
|
|
|
<CogIcon className="h-6 w-6 inline text-gray-400" />
|
|
|
|
</button>
|
2021-07-30 23:05:38 +00:00
|
|
|
<ul role="menu" className="z-10 origin-top-right absolute right-0 w-36 rounded-sm shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none">
|
2021-06-05 22:53:33 +00:00
|
|
|
<li className="text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role="menuitem">
|
|
|
|
<a className="block px-4 py-2" onClick={() => props.onActionSelect('invite')}>Invite member(s)</a>
|
|
|
|
</li>
|
|
|
|
<li className="text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role="menuitem">
|
|
|
|
<a className="block px-4 py-2" onClick={() => props.onActionSelect('edit')}>Manage team</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</Dropdown>
|
|
|
|
</div>}
|
|
|
|
</div>
|
|
|
|
{/*{props.team.userRole === 'Owner' && expanded && <div className="pt-2">
|
|
|
|
{props.team.members.length > 0 && <div>
|
|
|
|
<h2 className="text-lg font-medium text-gray-900 mb-1">Members</h2>
|
|
|
|
<table className="table-auto mb-2 w-full">
|
|
|
|
<tbody>
|
|
|
|
{props.team.members.map( (member) => <tr key={member.email}>
|
|
|
|
<td className="py-1 pl-2">Alex van Andel ({ member.email })</td>
|
|
|
|
<td>Owner</td>
|
|
|
|
<td className="text-right p-1">
|
2021-07-30 23:05:38 +00:00
|
|
|
<button className="btn-sm text-xs bg-transparent text-red-400 border border-red-400 px-3 py-1 rounded-sm ml-2"><UserRemoveIcon className="text-red-400 group-hover:text-gray-500 flex-shrink-0 -mt-1 mr-1 h-4 w-4 inline"/>Remove</button>
|
2021-06-05 22:53:33 +00:00
|
|
|
</td>
|
|
|
|
</tr>)}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>}
|
2021-07-30 23:05:38 +00:00
|
|
|
<button className="btn-sm bg-transparent text-gray-400 border border-gray-400 px-3 py-1 rounded-sm"><UserAddIcon className="text-gray-400 group-hover:text-gray-500 flex-shrink-0 -mt-1 h-6 w-6 inline"/> Invite member</button>
|
|
|
|
<button className="btn-sm bg-transparent text-red-400 border border-red-400 px-3 py-1 rounded-sm ml-2">Disband</button>
|
2021-06-05 22:53:33 +00:00
|
|
|
</div>}*/}
|
|
|
|
</li>);
|
2021-07-30 23:05:38 +00:00
|
|
|
}
|