Browse Source

FIX | Send notifications

pull/9/head
Vitalik 9 months ago
parent
commit
96b78888e4
  1. 12
      src/containers/Layout/topbar/NotificationItem.tsx
  2. 4
      src/containers/User/components/user-search-with-btn.component.tsx
  3. 7
      src/shared/enums/push-notification.enum.ts
  4. 2
      src/widgets/send-notifications/hooks/use-send-notifications.hook.ts
  5. 27
      src/widgets/send-notifications/send-notifications.widget.tsx
  6. 4
      src/widgets/send-notifications/style.scss

12
src/containers/Layout/topbar/NotificationItem.tsx

@ -9,6 +9,7 @@ const iconByGroup: Record<NotificationsGroup, string> = { @@ -9,6 +9,7 @@ const iconByGroup: Record<NotificationsGroup, string> = {
[NotificationsGroup.Chats]: ChatIcon,
[NotificationsGroup.Tasks]: TaskIcon,
[NotificationsGroup.Other]: BirthdayIcon,
[NotificationsGroup.Custom]: TaskIcon,
};
interface IProps {
@ -23,6 +24,8 @@ export const NotificationItem = ({ item, onPressItem }: IProps) => { @@ -23,6 +24,8 @@ export const NotificationItem = ({ item, onPressItem }: IProps) => {
? moment(item.createDate).format("HH:mm")
: moment(item.createDate).format("DD-MM-YYYY");
const showTitle = item.group === NotificationsGroup.Custom;
return (
<div key={item.id} className="notification_content_item_wrapper">
<div style={{ display: "flex" }}>
@ -39,6 +42,7 @@ export const NotificationItem = ({ item, onPressItem }: IProps) => { @@ -39,6 +42,7 @@ export const NotificationItem = ({ item, onPressItem }: IProps) => {
</div>
<div className="notification_text">
{showTitle ? <p style={{ fontWeight: 500 }}>{item.title}</p> : null}
<p>{item.content}</p>
</div>
</div>
@ -48,9 +52,11 @@ export const NotificationItem = ({ item, onPressItem }: IProps) => { @@ -48,9 +52,11 @@ export const NotificationItem = ({ item, onPressItem }: IProps) => {
</div>
<div className="details_btn-block">
<button className="details_btn" onClick={() => onPressItem(item)}>
<p style={{ color: "#9E2743" }}>Детальніше</p>
</button>
{item?.data?.type ? (
<button className="details_btn" onClick={() => onPressItem(item)}>
<p style={{ color: "#9E2743" }}>Детальніше</p>
</button>
) : null}
</div>
<div />
</div>

4
src/containers/User/components/user-search-with-btn.component.tsx

@ -10,9 +10,11 @@ interface IProps { @@ -10,9 +10,11 @@ interface IProps {
searchStr: string;
onChangeContact: (text) => void;
selectAll: (users: IShortUser[]) => void;
allBtnLabel?: string;
}
export const UserSearchWithBtn: FC<IProps> = ({
allBtnLabel = "Додати всіх",
items,
disableIds,
searchStr,
@ -37,7 +39,7 @@ export const UserSearchWithBtn: FC<IProps> = ({ @@ -37,7 +39,7 @@ export const UserSearchWithBtn: FC<IProps> = ({
color="primary"
onClick={handleSelectAll}
>
Додати всіх
{allBtnLabel}
</Button>
</div>
);

7
src/shared/enums/push-notification.enum.ts

@ -6,7 +6,10 @@ export enum NotificationsGroup { @@ -6,7 +6,10 @@ export enum NotificationsGroup {
Chats = "c",
/** Сповіщення, що не відносяться до жодної з груп */
Other = "oth"
Other = "oth",
/** Кастомні сповіщення створенні вручну */
Custom = "cus",
}
export enum NotificationKeys {
@ -15,5 +18,5 @@ export enum NotificationKeys { @@ -15,5 +18,5 @@ export enum NotificationKeys {
NEW_CHAT_MEMBER = "newChatMembers",
TODAY_BIRTHDAY = "todayBirthday",
NEW_TASK_COMMENT = "newTaskComment",
NEW_TASK_FILE = "newTaskFile"
NEW_TASK_FILE = "newTaskFile",
}

2
src/widgets/send-notifications/hooks/use-send-notifications.hook.ts

@ -53,7 +53,7 @@ export const useSendNotifications = (onSuccess?: () => void) => { @@ -53,7 +53,7 @@ export const useSendNotifications = (onSuccess?: () => void) => {
form.reset();
notification.showSuccess("Успішно", "Сповіщення були створенні");
} catch (e) {
notification.showError("Помилка");
notification.showError("Помилка", "Не вдалось відправити сповіщення");
} finally {
setLoading(false);
}

27
src/widgets/send-notifications/send-notifications.widget.tsx

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
import React, { FC } from "react";
import React, { FC, useEffect } from "react";
import Modal from "../../components/Modal";
import { Controller } from "react-hook-form";
import { InputCheckbox, InputField, TextField } from "@/shared";
import { InputField, TextField } from "@/shared";
import { useSendNotifications } from "./hooks/use-send-notifications.hook";
import "./style.scss";
import { useFetchChatUsers } from "@/containers/User/hooks";
@ -10,9 +10,6 @@ import { @@ -10,9 +10,6 @@ import {
UsersSelectList,
} from "@/containers/User/components";
import { ButtonToolbar, Button } from "reactstrap";
import { Checkbox } from "@material-ui/core";
import { divide } from "lodash";
import { CheckField } from "@/components/Fields";
import { FormCheckbox } from "@/components/Forms/FormCheckbox";
interface Props {
@ -38,6 +35,21 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => { @@ -38,6 +35,21 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
loadParams,
} = useFetchChatUsers();
const isSelectedAll = Boolean(selectedUsers?.length === items?.length);
const toggleSelectAll = () => {
if (isSelectedAll) selectUsers([]);
else selectUsers(items);
};
const reset = () => {
setSearchVal("");
form.reset({ title: "", haveToSendEmail: false, content: "", users: [] });
};
useEffect(() => {
if (!isOpen) reset();
}, [isOpen]);
return (
<Modal show={isOpen} toggle={() => onClose()} title="Нове сповіщення">
<div className="form send-notifi-form">
@ -76,10 +88,10 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => { @@ -76,10 +88,10 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
items={items}
searchStr={searchString}
onChangeContact={setSearchVal}
selectAll={() => selectUsers(items)}
selectAll={toggleSelectAll}
allBtnLabel={isSelectedAll ? "Очистити" : "Додати всіх"}
/>
</div>
<Controller
name="users"
control={form.control}
@ -105,7 +117,6 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => { @@ -105,7 +117,6 @@ export const SendNotificationsWidget: FC<Props> = ({ isOpen, onClose }) => {
</>
)}
/>
<ButtonToolbar className="form__add-chat">
<Button
style={{ width: "220px", height: "46px" }}

4
src/widgets/send-notifications/style.scss

@ -10,6 +10,9 @@ @@ -10,6 +10,9 @@
.input-mask-field {
margin-bottom: 10px;
}
.input-mask-field .input-container{
padding: 0;
}
.text-field textarea{
height: 100px;
@ -32,6 +35,7 @@ @@ -32,6 +35,7 @@
}
.user-list-container {
width: 100%;
padding-right: 5px;
}
.ant-checkbox-input {

Loading…
Cancel
Save