Skip to content

Commit 1a1e179

Browse files
authored
Merge pull request #843 from AppQuality/add-delete-comment-media-action
feat: added delete action to comment medias
2 parents b348b79 + f59844f commit 1a1e179

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

src/common/schema.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,15 @@ export interface paths {
306306
};
307307
};
308308
};
309+
'/media-comment/{mcid}': {
310+
/** Delete a media-comment */
311+
delete: operations['delete-media-comment-mcid'];
312+
parameters: {
313+
path: {
314+
mcid: string;
315+
};
316+
};
317+
};
309318
'/projects': {
310319
post: operations['post-projects'];
311320
};
@@ -640,7 +649,7 @@ export interface components {
640649
/**
641650
* @description -1: no bug form;
642651
* 0: only bug form;
643-
* 1: bug form with bug parade';
652+
* 1: bug form with bug parade;
644653
*/
645654
bug_form?: number;
646655
type: {
@@ -2222,7 +2231,7 @@ export interface operations {
22222231
};
22232232
};
22242233
};
2225-
/** If there's a group, post new tag into that group; otherwise, create the group and add tag into the new group. */
2234+
/** If there is a group, post new tag into that group; otherwise, create the group and add tag into the new group. */
22262235
requestBody: {
22272236
content: {
22282237
'application/json': {
@@ -2381,6 +2390,26 @@ export interface operations {
23812390
302: never;
23822391
};
23832392
};
2393+
/** Delete a media-comment */
2394+
'delete-media-comment-mcid': {
2395+
parameters: {
2396+
path: {
2397+
mcid: string;
2398+
};
2399+
};
2400+
responses: {
2401+
/** OK */
2402+
200: {
2403+
content: {
2404+
'application/json': { [key: string]: unknown };
2405+
};
2406+
};
2407+
/** Unauthorized */
2408+
401: unknown;
2409+
/** Not Found */
2410+
404: unknown;
2411+
};
2412+
};
23842413
'post-projects': {
23852414
responses: {
23862415
/** OK */

src/features/api/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,15 @@ const injectedRtkApi = api.injectEndpoints({
374374
getMediaById: build.query<GetMediaByIdApiResponse, GetMediaByIdApiArg>({
375375
query: (queryArg) => ({ url: `/media/${queryArg.id}` }),
376376
}),
377+
deleteMediaCommentByMcid: build.mutation<
378+
DeleteMediaCommentByMcidApiResponse,
379+
DeleteMediaCommentByMcidApiArg
380+
>({
381+
query: (queryArg) => ({
382+
url: `/media-comment/${queryArg.mcid}`,
383+
method: 'DELETE',
384+
}),
385+
}),
377386
postProjects: build.mutation<PostProjectsApiResponse, PostProjectsApiArg>({
378387
query: (queryArg) => ({
379388
url: `/projects`,
@@ -1149,7 +1158,7 @@ export type PostCampaignsByCidVideoTagsApiResponse =
11491158
/** status 200 OK */ VideoTag;
11501159
export type PostCampaignsByCidVideoTagsApiArg = {
11511160
cid: string;
1152-
/** If there's a group, post new tag into that group; otherwise, create the group and add tag into the new group. */
1161+
/** If there is a group, post new tag into that group; otherwise, create the group and add tag into the new group. */
11531162
body: {
11541163
group: {
11551164
name: string;
@@ -1230,6 +1239,10 @@ export type GetMediaByIdApiResponse = unknown;
12301239
export type GetMediaByIdApiArg = {
12311240
id: string;
12321241
};
1242+
export type DeleteMediaCommentByMcidApiResponse = /** status 200 OK */ object;
1243+
export type DeleteMediaCommentByMcidApiArg = {
1244+
mcid: string;
1245+
};
12331246
export type PostProjectsApiResponse = /** status 200 OK */ Project;
12341247
export type PostProjectsApiArg = {
12351248
body: {
@@ -1571,7 +1584,7 @@ export type Campaign = {
15711584
is_public: number;
15721585
/** -1: no bug form;
15731586
0: only bug form;
1574-
1: bug form with bug parade'; */
1587+
1: bug form with bug parade; */
15751588
bug_form?: number;
15761589
type: {
15771590
id: number;
@@ -2054,6 +2067,7 @@ export const {
20542067
useDeleteInsightsByIidMutation,
20552068
usePatchInsightsByIidMutation,
20562069
useGetMediaByIdQuery,
2070+
useDeleteMediaCommentByMcidMutation,
20572071
usePostProjectsMutation,
20582072
useGetProjectsByPidQuery,
20592073
usePatchProjectsByPidMutation,

src/pages/Bug/Actions.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ChatProvider, LG, Skeleton } from '@appquality/unguess-design-system';
1+
import {
2+
ChatProvider,
3+
LG,
4+
Skeleton,
5+
useToast,
6+
Notification,
7+
} from '@appquality/unguess-design-system';
28
import { useCallback, useState } from 'react';
39
import { useTranslation } from 'react-i18next';
410
import { useParams } from 'react-router-dom';
@@ -12,6 +18,7 @@ import {
1218
useGetCampaignsByCidBugsAndBidQuery,
1319
usePostCampaignsByCidBugsAndBidCommentsMutation,
1420
usePostCampaignsByCidBugsAndBidMediaMutation,
21+
useDeleteMediaCommentByMcidMutation,
1522
} from 'src/features/api';
1623
import { styled } from 'styled-components';
1724
import { Data } from '@appquality/unguess-design-system/build/stories/chat/context/chatContext';
@@ -88,6 +95,10 @@ export const Actions = () => {
8895

8996
const [uploadMedia] = usePostCampaignsByCidBugsAndBidMediaMutation();
9097

98+
const [deleteMediaComment] = useDeleteMediaCommentByMcidMutation();
99+
100+
const { addToast } = useToast();
101+
91102
interface MyFormData extends FormData {
92103
media: string | string[];
93104
}
@@ -129,6 +140,28 @@ export const Actions = () => {
129140

130141
// return data;
131142

143+
const handleDeleteMediaComment = (mcid: string) => {
144+
deleteMediaComment({ mcid })
145+
.unwrap()
146+
.then(() => {
147+
refetch();
148+
})
149+
.catch((e) => {
150+
addToast(
151+
({ close }) => (
152+
<Notification
153+
onClose={close}
154+
type="error"
155+
message={e.message ? e.message : 'Error while deleting media'}
156+
closeText="X"
157+
isPrimary
158+
/>
159+
),
160+
{ placement: 'top' }
161+
);
162+
});
163+
};
164+
132165
const createCommentHandler = useCallback(
133166
(editor, mentions) => {
134167
if (editor) {
@@ -189,6 +222,11 @@ export const Actions = () => {
189222
setMediaIds((prev) =>
190223
prev.filter((media) => media.internal_id !== internalId)
191224
);
225+
const mediaToDelete = mediaIds.find(
226+
(media) => media.internal_id === internalId
227+
);
228+
if (mediaToDelete)
229+
handleDeleteMediaComment(mediaToDelete.id.toString());
192230
}}
193231
>
194232
<Divider style={{ margin: `${appTheme.space.md} auto` }} />

0 commit comments

Comments
 (0)