Skip to content

Commit 35a7a88

Browse files
Merge pull request #126 from VipinDevelops/remove-reminder
[FEAT]: Add remove and open button in reminder's modal
2 parents 7a7cca0 + 3bbc554 commit 35a7a88

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

github/enum/Modals.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,8 @@ export enum ModalsEnum {
215215
MAIN_MODAL_ASSIGN_ISSUES_DESCRIPTION = "Assign issues to your team members",
216216
NEW_REMINDER_VIEW = "new-reminder-view",
217217
UNSUBSCRIBE_REMINDER_ACTION = "unsubscribe-reminder-action",
218-
REMINDER_LIST_MODAL_VIEW= "reminder-list-view"
218+
REMINDER_LIST_MODAL_VIEW= "reminder-list-view",
219+
REMINDER_LIST_MODAL="reminder-list-modal",
220+
REMINDER_OPEN_REPO_ACTION="open-repo-action",
221+
REMINDER_REMOVE_REPO_ACTION="remove-repo-reminder-action"
219222
}

github/handlers/ExecuteBlockActionHandler.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ import { addIssueCommentsModal } from "../modals/addIssueCommentModal";
5353
import { GitHubIssuesStarterModal } from "../modals/getIssuesStarterModal";
5454
import { githubSearchModal } from "../modals/githubSearchModal";
5555
import { NewIssueStarterModal } from "../modals/newIssueStarterModal";
56-
import { unsubscribedPR } from "../persistance/remind";
56+
import { removeRepoReminder, unsubscribedPR } from "../persistance/remind";
57+
import { reminderModal } from "../modals/remindersModal";
5758

5859
export class ExecuteBlockActionHandler {
5960

@@ -1162,6 +1163,15 @@ export class ExecuteBlockActionHandler {
11621163
await sendNotification(this.read, this.modify, user, room as IRoom, message);
11631164

11641165
}
1166+
1167+
case ModalsEnum.REMINDER_REMOVE_REPO_ACTION : {
1168+
const {value, user} = context.getInteractionData();
1169+
await removeRepoReminder(this.read, this.persistence, value as string, user);
1170+
1171+
const updatedReminderModal = await reminderModal({modify: this.modify, read:this.read, persistence: this.persistence, http: this.http, uikitcontext: context});
1172+
1173+
return context.getInteractionResponder().updateModalViewResponse( updatedReminderModal);
1174+
}
11651175
}
11661176
} catch (error) {
11671177
console.log(error);

github/modals/remindersModal.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IHttp, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors';
2-
import { ITextObject, TextObjectType } from '@rocket.chat/apps-engine/definition/uikit/blocks';
2+
import { ButtonStyle, ITextObject, TextObjectType } from '@rocket.chat/apps-engine/definition/uikit/blocks';
33
import { IUIKitModalViewParam } from '@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder';
44
import { ModalsEnum } from '../enum/Modals';
55
import { SlashCommandContext } from '@rocket.chat/apps-engine/definition/slashcommands';
@@ -24,16 +24,27 @@ export async function reminderModal({ modify, read, persistence, http, slashcomm
2424
for (let repository of reminders.repos) {
2525
block.addSectionBlock({
2626
text: { text: `${repository}`, type: TextObjectType.PLAINTEXT },
27-
accessory: block.newButtonElement({
28-
actionId: ModalsEnum.OPEN_REPO_ACTION,
29-
text: {
30-
text: ModalsEnum.OPEN_REPO_LABEL,
31-
type: TextObjectType.PLAINTEXT
32-
},
33-
url: `https://github.com/${repository}`
34-
})
3527
});
3628

29+
block.addActionsBlock({
30+
blockId:ModalsEnum.REMINDER_LIST_MODAL,
31+
32+
elements:[
33+
block.newButtonElement({
34+
actionId: ModalsEnum.OPEN_REPO_ACTION,
35+
text: block.newPlainTextObject("Open"),
36+
url:`https://github.com/${repository}`,
37+
style: ButtonStyle.PRIMARY,
38+
39+
}),
40+
block.newButtonElement({
41+
actionId: ModalsEnum.REMINDER_REMOVE_REPO_ACTION,
42+
text: block.newPlainTextObject("Remove"),
43+
value: `${repository}`,
44+
style: ButtonStyle.DANGER,
45+
})]
46+
})
47+
3748
block.addDividerBlock();
3849
}
3950
} else {

github/persistance/remind.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export async function unsubscribedPR(read: IRead, persistence: IPersistence, rep
8282
prnum: [PullRequestNumber]
8383
})
8484
}
85-
85+
8686
await persistence.updateByAssociation(assoc, reminders)
8787
}
8888

@@ -117,3 +117,23 @@ export async function getUserReminder(read:IRead,User:IUser):Promise<IReminder>{
117117
const index = reminders.findIndex((reminder)=>reminder.userid === User.id);
118118
return reminders[index];
119119
}
120+
121+
export async function removeRepoReminder(read:IRead,persistence:IPersistence,repository:string,User:IUser){
122+
const reminders = await getAllReminders(read);
123+
const idx = reminders.findIndex((u: IReminder) => u.userid === User.id);
124+
125+
if (idx === -1) {
126+
return;
127+
}
128+
129+
const repoindex = reminders[idx].repos.findIndex((repo)=>repo == repository);
130+
131+
if (repoindex === -1) {
132+
return;
133+
}
134+
135+
reminders[idx].repos.splice(repoindex,1);
136+
await persistence.updateByAssociation(assoc, reminders);
137+
}
138+
139+

0 commit comments

Comments
 (0)