|
|
|
@ -35,6 +35,7 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
@@ -35,6 +35,7 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
|
|
|
|
|
setSearchVal, |
|
|
|
|
loadMore, |
|
|
|
|
loadParams, |
|
|
|
|
totalUsersCount, |
|
|
|
|
} = useFetchChatUsers(); |
|
|
|
|
|
|
|
|
|
const toggleSelectAll = () => { |
|
|
|
@ -59,8 +60,15 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
@@ -59,8 +60,15 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
|
|
|
|
|
}, [allSelected, items]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (selectedUsers.length === loadParams?.count) setAllSelected(true); |
|
|
|
|
}, [loadParams?.count, selectedUsers]); |
|
|
|
|
if (totalUsersCount > 0 && selectedUsers.length === totalUsersCount) |
|
|
|
|
setAllSelected(true); |
|
|
|
|
}, [selectedUsers, totalUsersCount]); |
|
|
|
|
|
|
|
|
|
const handleUnselectUser = (userId: number) => { |
|
|
|
|
unselectUser(userId); |
|
|
|
|
|
|
|
|
|
if (allSelected) setAllSelected(false); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Modal show={isOpen} toggle={() => onClose()} title="Нове пуш-сповіщення"> |
|
|
|
@ -108,11 +116,15 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
@@ -108,11 +116,15 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
|
|
|
|
|
name="users" |
|
|
|
|
control={form.control} |
|
|
|
|
rules={{ |
|
|
|
|
required: "Потрібно вибрати принаймні 1 користувача", |
|
|
|
|
minLength: { |
|
|
|
|
message: "Потрібно вибрати принаймні 1 користувача", |
|
|
|
|
value: 1, |
|
|
|
|
}, |
|
|
|
|
required: allSelected |
|
|
|
|
? null |
|
|
|
|
: "Потрібно вибрати принаймні 1 користувача", |
|
|
|
|
minLength: allSelected |
|
|
|
|
? null |
|
|
|
|
: { |
|
|
|
|
message: "Потрібно вибрати принаймні 1 користувача", |
|
|
|
|
value: 1, |
|
|
|
|
}, |
|
|
|
|
}} |
|
|
|
|
render={({ field: { value }, fieldState }) => ( |
|
|
|
|
<> |
|
|
|
@ -120,7 +132,7 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
@@ -120,7 +132,7 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
|
|
|
|
|
items={items} |
|
|
|
|
selectedUsers={value} |
|
|
|
|
selectOne={selectUser} |
|
|
|
|
unSelectOne={unselectUser} |
|
|
|
|
unSelectOne={handleUnselectUser} |
|
|
|
|
excludeIds={[]} |
|
|
|
|
loadMore={loadMore} |
|
|
|
|
count={loadParams.count} |
|
|
|
|