Skip to content

Commit 5084bc8

Browse files
improve: send task assigning notification (#292)
1 parent 8a3174e commit 5084bc8

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/tasks/components/NewTask.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Grid, Icon, TextField } from "@mui/material";
22
import React from "react";
3-
import { ApiHelper, ConversationInterface, Locale, MessageInterface, TaskInterface, UserHelper } from "@churchapps/apphelper";
3+
import { ApiHelper, ArrayHelper, ConversationInterface, Locale, MessageInterface, TaskInterface, UserHelper } from "@churchapps/apphelper";
44
import { ErrorMessages, InputBox } from "@churchapps/apphelper";
55
import { ContentPicker } from "./ContentPicker";
66

@@ -35,6 +35,20 @@ export const NewTask = (props: Props) => {
3535
return result.length === 0;
3636
}
3737

38+
const sendNotification = async (task: TaskInterface) => {
39+
const type = task.assignedToType;
40+
const id = task.assignedToId;
41+
let data: any = { peopleIds: [id], contentType: "task", contentId: task.id, message: `New Task Assignment: ${task.title}` };
42+
43+
if (type === "group") {
44+
const groupMembers = await ApiHelper.get("/groupmembers?groupId=" + task.assignedToId.toString(), "MembershipApi");
45+
const ids = ArrayHelper.getIds(groupMembers, "personId");
46+
data.peopleIds = ids;
47+
}
48+
49+
await ApiHelper.post("/notifications/create", data, "MessagingApi");
50+
}
51+
3852
const handleSave = async () => {
3953
if (validate()) {
4054
const tasks = await ApiHelper.post("/tasks", [task], "DoingApi");
@@ -50,6 +64,7 @@ export const NewTask = (props: Props) => {
5064
//message.contentId = tasks[0].id;
5165
await ApiHelper.post("/messages", [message], "MessagingApi");
5266
}
67+
await sendNotification(tasks[0]);
5368
props.onSave();
5469
}
5570
}

0 commit comments

Comments
 (0)