Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/common/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ export interface paths {
};
};
};
'/media-comment/{mcid}': {
/** Delete a media-comment */
delete: operations['delete-media-comment-mcid'];
parameters: {
path: {
mcid: string;
};
};
};
'/projects': {
post: operations['post-projects'];
};
Expand Down Expand Up @@ -640,7 +649,7 @@ export interface components {
/**
* @description -1: no bug form;
* 0: only bug form;
* 1: bug form with bug parade';
* 1: bug form with bug parade;
*/
bug_form?: number;
type: {
Expand Down Expand Up @@ -2222,7 +2231,7 @@ export interface operations {
};
};
};
/** If there's a group, post new tag into that group; otherwise, create the group and add tag into the new group. */
/** If there is a group, post new tag into that group; otherwise, create the group and add tag into the new group. */
requestBody: {
content: {
'application/json': {
Expand Down Expand Up @@ -2381,6 +2390,26 @@ export interface operations {
302: never;
};
};
/** Delete a media-comment */
'delete-media-comment-mcid': {
parameters: {
path: {
mcid: string;
};
};
responses: {
/** OK */
200: {
content: {
'application/json': { [key: string]: unknown };
};
};
/** Unauthorized */
401: unknown;
/** Not Found */
404: unknown;
};
};
'post-projects': {
responses: {
/** OK */
Expand Down
18 changes: 16 additions & 2 deletions src/features/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@ const injectedRtkApi = api.injectEndpoints({
getMediaById: build.query<GetMediaByIdApiResponse, GetMediaByIdApiArg>({
query: (queryArg) => ({ url: `/media/${queryArg.id}` }),
}),
deleteMediaCommentByMcid: build.mutation<
DeleteMediaCommentByMcidApiResponse,
DeleteMediaCommentByMcidApiArg
>({
query: (queryArg) => ({
url: `/media-comment/${queryArg.mcid}`,
method: 'DELETE',
}),
}),
postProjects: build.mutation<PostProjectsApiResponse, PostProjectsApiArg>({
query: (queryArg) => ({
url: `/projects`,
Expand Down Expand Up @@ -1149,7 +1158,7 @@ export type PostCampaignsByCidVideoTagsApiResponse =
/** status 200 OK */ VideoTag;
export type PostCampaignsByCidVideoTagsApiArg = {
cid: string;
/** If there's a group, post new tag into that group; otherwise, create the group and add tag into the new group. */
/** If there is a group, post new tag into that group; otherwise, create the group and add tag into the new group. */
body: {
group: {
name: string;
Expand Down Expand Up @@ -1230,6 +1239,10 @@ export type GetMediaByIdApiResponse = unknown;
export type GetMediaByIdApiArg = {
id: string;
};
export type DeleteMediaCommentByMcidApiResponse = /** status 200 OK */ object;
export type DeleteMediaCommentByMcidApiArg = {
mcid: string;
};
export type PostProjectsApiResponse = /** status 200 OK */ Project;
export type PostProjectsApiArg = {
body: {
Expand Down Expand Up @@ -1571,7 +1584,7 @@ export type Campaign = {
is_public: number;
/** -1: no bug form;
0: only bug form;
1: bug form with bug parade'; */
1: bug form with bug parade; */
bug_form?: number;
type: {
id: number;
Expand Down Expand Up @@ -2054,6 +2067,7 @@ export const {
useDeleteInsightsByIidMutation,
usePatchInsightsByIidMutation,
useGetMediaByIdQuery,
useDeleteMediaCommentByMcidMutation,
usePostProjectsMutation,
useGetProjectsByPidQuery,
usePatchProjectsByPidMutation,
Expand Down
40 changes: 39 additions & 1 deletion src/pages/Bug/Actions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ChatProvider, LG, Skeleton } from '@appquality/unguess-design-system';
import {
ChatProvider,
LG,
Skeleton,
useToast,
Notification,
} from '@appquality/unguess-design-system';
import { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
Expand All @@ -12,6 +18,7 @@ import {
useGetCampaignsByCidBugsAndBidQuery,
usePostCampaignsByCidBugsAndBidCommentsMutation,
usePostCampaignsByCidBugsAndBidMediaMutation,
useDeleteMediaCommentByMcidMutation,
} from 'src/features/api';
import { styled } from 'styled-components';
import { Data } from '@appquality/unguess-design-system/build/stories/chat/context/chatContext';
Expand Down Expand Up @@ -88,6 +95,10 @@ export const Actions = () => {

const [uploadMedia] = usePostCampaignsByCidBugsAndBidMediaMutation();

const [deleteMediaComment] = useDeleteMediaCommentByMcidMutation();

const { addToast } = useToast();

interface MyFormData extends FormData {
media: string | string[];
}
Expand Down Expand Up @@ -129,6 +140,28 @@ export const Actions = () => {

// return data;

const handleDeleteMediaComment = (mcid: string) => {
deleteMediaComment({ mcid })
.unwrap()
.then(() => {
refetch();
})
.catch((e) => {
addToast(
({ close }) => (
<Notification
onClose={close}
type="error"
message={e.message ? e.message : 'Error while deleting media'}
closeText="X"
isPrimary
/>
),
{ placement: 'top' }
);
});
};

const createCommentHandler = useCallback(
(editor, mentions) => {
if (editor) {
Expand Down Expand Up @@ -189,6 +222,11 @@ export const Actions = () => {
setMediaIds((prev) =>
prev.filter((media) => media.internal_id !== internalId)
);
const mediaToDelete = mediaIds.find(
(media) => media.internal_id === internalId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non capisco bene il tipo di questo internalId per capire se quel triplo uguale può funzionare, mi da any.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internalId è di tipo string

);
if (mediaToDelete)
handleDeleteMediaComment(mediaToDelete.id.toString());
}}
>
<Divider style={{ margin: `${appTheme.space.md} auto` }} />
Expand Down