max number checks

This commit is contained in:
talksik
2022-05-18 05:43:46 -05:00
parent 7f2da8f43e
commit a1a7b5b280
@@ -7,6 +7,8 @@ import { Avatar, Divider, Skeleton, Spin } from 'antd';
import { User } from '@nirvana/core/models/user.model';
import CreateLineRequest from '@nirvana/core/requests/createLine.request';
const maxUserCount = 8;
export default function NewChannelForm({ handleClose }: { handleClose: () => void }) {
const [peopleSearchQuery, setPeopleSearchQuery] = useState<string>('');
@@ -58,6 +60,13 @@ export default function NewChannelForm({ handleClose }: { handleClose: () => voi
if (prevUsers.find((currUser) => currUser.email === newUser.email)) {
return prevUsers;
}
if (prevUsers.length === maxUserCount - 1) {
toast.error('you can only have 8 people per channel!');
return prevUsers;
}
return [...prevUsers, newUser];
});
@@ -91,6 +100,12 @@ export default function NewChannelForm({ handleClose }: { handleClose: () => voi
return;
}
if (selectedUsers.length === maxUserCount - 1) {
toast.error('you can only have 8 people per channel!');
return;
}
const selectedMemberIds = selectedUsers.map((selectedPerson) =>
selectedPerson._id.toString(),
);
@@ -136,6 +151,7 @@ export default function NewChannelForm({ handleClose }: { handleClose: () => voi
{/* dropdown search results */}
<div className="flex flex-col shadow-lg max-h-[500px] overflow-auto">
{(userSearchRes.loading || isSearchingUsers) && <Spin />}
{(!userSearchRes.value || userSearchRes.value?.users.length === 0) &&
selectedUsers?.length === 0 && (
<span className="p-10 text-gray-300">{`Can't find someone? Invite them and tell them the secret passcode!`}</span>