Skip to content

Commit

Permalink
Implement reportAbuse in DiscussionApps
Browse files Browse the repository at this point in the history
Co-authored-by: Anna Beddow <[email protected]>
  • Loading branch information
ioannakok and abeddow91 committed Mar 7, 2024
1 parent bf35f2f commit 6429f71
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ export const AbuseReportForm = ({
}

reportAbuse({
categoryId,
categoryId: categoryId.toString(),
reason,
email,
commentId,
commentId: commentId.toString(),
})
.then((response) => {
if (response.kind === 'error') {
Expand Down
38 changes: 28 additions & 10 deletions dotcom-rendering/src/components/DiscussionApps.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,31 @@ const addUsername = async (username: string): Promise<Result<string, true>> => {
});
};

/***
* Currently we are using the web handler for both authenticated and unauthenticated users.
* Once we have knowlege of if the user is authenticated from bridget, we can implement an apps-specific function below, to allow us to send user data to analytics.
*/
// const reportAbuse = async (): Promise<Result<string, true>> => {
// console.log('reportAbuse');
// return { kind: 'error', error: 'ApiError' };
// };
const reportAbuse = async ({
commentId,
categoryId,
reason,
email,
}: {
commentId: string;
categoryId: string;
reason?: string;
email?: string;
}): Promise<Result<string, true>> => {
return getdiscussionClient()
.reportAbuse({ commentId, categoryId, reason, email })
.then((response) => {
if (response.__type == 'error') {
return error('NativeError');
} else {
if (response.response.errorCode) {
return error('ApiError');
}

return ok(true);
}
});
};

const mockedProfile: UserProfile = {
userId: 'userId',
Expand Down Expand Up @@ -127,17 +144,18 @@ const getUser = async (): Promise<Reader> => {
onReply,
onRecommend,
addUsername,
reportAbuse: reportAbuseWeb(undefined),
reportAbuse,
profile: userProfile,
};
} else {
// TODO: Handle the error properly
return {
kind: 'Reader',
onComment,
onReply,
onRecommend,
addUsername,
reportAbuse: reportAbuseWeb(undefined),
reportAbuse,
profile: mockedProfile,
};
}
Expand Down
16 changes: 6 additions & 10 deletions dotcom-rendering/src/lib/discussionApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,18 @@ export const reportAbuse =
email,
reason,
}: {
commentId: number;
categoryId: number;
commentId: string;
categoryId: string;
reason?: string;
email?: string;
}): Promise<Result<string, true>> => {
const url =
joinUrl(
options.baseUrl,
'comment',
commentId.toString(),
'reportAbuse',
) + objAsParams(defaultParams);
joinUrl(options.baseUrl, 'comment', commentId, 'reportAbuse') +
objAsParams(defaultParams);

const data = new URLSearchParams();
data.append('categoryId', categoryId.toString());
email && data.append('email', email.toString());
data.append('categoryId', categoryId);
email && data.append('email', email);
reason && data.append('reason', reason);

const authOptions = authStatus
Expand Down

0 comments on commit 6429f71

Please sign in to comment.