1
1
import { Grid , Icon , TextField } from "@mui/material" ;
2
2
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" ;
4
4
import { ErrorMessages , InputBox } from "@churchapps/apphelper" ;
5
5
import { ContentPicker } from "./ContentPicker" ;
6
6
@@ -35,6 +35,20 @@ export const NewTask = (props: Props) => {
35
35
return result . length === 0 ;
36
36
}
37
37
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
+
38
52
const handleSave = async ( ) => {
39
53
if ( validate ( ) ) {
40
54
const tasks = await ApiHelper . post ( "/tasks" , [ task ] , "DoingApi" ) ;
@@ -50,6 +64,7 @@ export const NewTask = (props: Props) => {
50
64
//message.contentId = tasks[0].id;
51
65
await ApiHelper . post ( "/messages" , [ message ] , "MessagingApi" ) ;
52
66
}
67
+ await sendNotification ( tasks [ 0 ] ) ;
53
68
props . onSave ( ) ;
54
69
}
55
70
}
0 commit comments