Skip to content

Commit 4c92b16

Browse files
committed
tested and working slack bot
1 parent a679b7f commit 4c92b16

3 files changed

Lines changed: 24 additions & 18 deletions

File tree

src/backend/src/services/part-review.services.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import {
1111
isAtLeastRank,
1212
RoleEnum,
1313
Review_Status,
14-
validateWBS,
15-
wbsNumComparator,
16-
wbsNamePipe
14+
validateWBS
1715
} from 'shared';
1816
import {
1917
AccessDeniedAdminOnlyException,
@@ -46,7 +44,6 @@ import { uploadFile, downloadFile } from '../utils/google-integration.utils';
4644
import ProjectsService from './projects.services';
4745
import { sendPartAssignmentPopUp, sendPartReviewRequestPopUp } from '../utils/pop-up.utils';
4846
import { sendSlackPartAssignmentNotif, sendSlackPartReviewRequestNotif } from '../utils/slack.utils';
49-
import { get } from 'http';
5047
import { getUserWithSettingsQueryArgs } from '../prisma-query-args/user.query-args';
5148

5249
export default class PartReviewService {
@@ -924,9 +921,9 @@ export default class PartReviewService {
924921
if (reviewer.userSettings?.slackId) {
925922
await sendSlackPartReviewRequestNotif(
926923
reviewer.userSettings.slackId,
927-
partLink,
924+
part.project.wbsElement.name,
928925
part.commonName,
929-
part.project.wbsElement.name
926+
partLink
930927
);
931928
}
932929
}
@@ -971,9 +968,9 @@ export default class PartReviewService {
971968
if (assignee.userSettings?.slackId) {
972969
await sendSlackPartAssignmentNotif(
973970
assignee.userSettings.slackId,
974-
partLink,
971+
part.project.wbsElement.name,
975972
part.commonName,
976-
part.project.wbsElement.name
973+
partLink
977974
);
978975
}
979976
}

src/backend/src/utils/slack.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ export const sendSlackPartReviewRequestNotif = async (
561561
) => {
562562
if (process.env.NODE_ENV !== 'production') return; // don't send msgs unless in prod
563563

564-
const msg = `Your review has been requested on part: ${partName} for project ${projectName}`;
564+
const msg = `Your review has been requested on part: ${partName} for project: ${projectName}`;
565565
const link = `https://finishlinebyner.com${partLink}`;
566566
const linkButtonText = 'View Part';
567567
await sendMessage(slackId, msg, link, linkButtonText);
@@ -575,7 +575,7 @@ export const sendSlackPartAssignmentNotif = async (
575575
) => {
576576
if (process.env.NODE_ENV !== 'production') return; // don't send msgs unless in prod
577577

578-
const msg = `You have been assigned to part: ${partName} on project ${projectName}`;
578+
const msg = `You have been assigned to part: ${partName} on project: ${projectName}`;
579579
const link = `https://finishlinebyner.com${partLink}`;
580580
const linkButtonText = 'View Part';
581581
await sendMessage(slackId, msg, link, linkButtonText);

src/frontend/src/pages/PartPage/PartPageComponents/PartOverview.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Part, Review_Status, User } from 'shared';
55
import { getReviewStatusDisplayName, getStatusColor } from '../../../utils/part.utils';
66
import { useNotifyPartAssignee, useNotifyPartReviewer } from '../../../hooks/part-review.hooks';
77
import { useState } from 'react';
8+
import { useToast } from '../../../hooks/toasts.hooks';
89

910
const PartReviewStatusPill = (status: Review_Status) => {
1011
return (
@@ -46,8 +47,9 @@ interface PartPageOverviewProps {
4647
}
4748

4849
const PartOverview: React.FC<PartPageOverviewProps> = ({ part }: PartPageOverviewProps) => {
49-
const { mutate: notifyPartAssignee } = useNotifyPartAssignee();
50-
const { mutate: notifyPartReviewer } = useNotifyPartReviewer();
50+
const { mutateAsync: notifyPartAssignee } = useNotifyPartAssignee();
51+
const { mutateAsync: notifyPartReviewer } = useNotifyPartReviewer();
52+
const toast = useToast();
5153

5254
const [notifiedUserIds, setNotifiedUserIds] = useState<Set<string>>(new Set());
5355

@@ -60,13 +62,20 @@ const PartOverview: React.FC<PartPageOverviewProps> = ({ part }: PartPageOvervie
6062
{status !== Review_Status.APPROVED && (
6163
<IconButton
6264
size="small"
63-
onClick={() => {
64-
if (isReviewer) {
65-
notifyPartReviewer({ partId, reviewerId: anyUser.userId });
66-
} else {
67-
notifyPartAssignee({ partId, assigneeId: anyUser.userId });
65+
onClick={async () => {
66+
try {
67+
if (isReviewer) {
68+
await notifyPartReviewer({ partId, reviewerId: anyUser.userId });
69+
} else {
70+
await notifyPartAssignee({ partId, assigneeId: anyUser.userId });
71+
}
72+
setNotifiedUserIds((ids) => ids.add(anyUser.userId));
73+
toast.success('' + (isReviewer ? 'Reviewer' : 'Assignee') + ' notified');
74+
} catch (error) {
75+
if (error instanceof Error) {
76+
toast.error(error.message);
77+
}
6878
}
69-
setNotifiedUserIds((ids) => ids.add(anyUser.userId));
7079
}}
7180
sx={{
7281
backgroundColor: '#444444',

0 commit comments

Comments
 (0)