Skip to content

Commit

Permalink
implemented delete modal button functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nalinikantheti committed Nov 9, 2023
1 parent 54646ba commit 86fddd6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/api/protectedApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export interface ProtectedApiClient {
) => Promise<void>;
readonly addSites: (request: AddSitesRequest) => Promise<void>;
readonly sendEmail: (request: SendEmailRequest) => Promise<void>;
readonly deleteImage: (
imageId: number,
) => Promise<void>;
readonly filterSites: (
params: FilterSitesParams,
) => Promise<FilterSitesResponse>;
Expand Down Expand Up @@ -197,6 +200,8 @@ export const ParameterizedApiRoutes = {
UPDATE_SITE: (siteId: number): string => `${baseSiteRoute}${siteId}/update`,
NAME_SITE_ENTRY: (siteId: number): string =>
`${baseSiteRoute}${siteId}/name_entry`,
DELETE_IMAGE: (imageId: number): string =>
`${baseSiteRoute}site_image/${imageId}`,
};

export const ParameterizedAdminApiRoutes = {
Expand Down Expand Up @@ -556,6 +561,12 @@ const sendEmail = (request: SendEmailRequest): Promise<void> => {
);
};

const deleteImage = (imageId: number): Promise<void> => {
return AppAxiosInstance.delete(
ParameterizedApiRoutes.DELETE_IMAGE(imageId),
).then((res) => res.data);
};

const filterSites = (
params: FilterSitesParams,
): Promise<FilterSitesResponse> => {
Expand Down Expand Up @@ -611,6 +622,7 @@ const Client: ProtectedApiClient = Object.freeze({
nameSiteEntry,
addSites,
sendEmail,
deleteImage,
filterSites,
});

Expand Down
33 changes: 19 additions & 14 deletions src/components/treePage/siteImageCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export const DeleteSiteImageButton = styled(LinkButton)`
}
`;

function onClickDeleteImage() {
protectedApiClient.delete
}


export const SiteImageCarousel: React.FC = () => {
const { t } = useTranslation(n(site, 'treePage'), { nsMode: 'fallback' });
Expand All @@ -87,6 +85,12 @@ export const SiteImageCarousel: React.FC = () => {

const onAfterChange = (currentSlide: number) =>
setCurrSlideIndex(currentSlide);
function onClickDeleteImage(imageId: number) {
protectedApiClient.deleteImage(imageId).then((ok) => {
message.success('success');
setShowDeleteForm(false);
});
}

return (
<>
Expand Down Expand Up @@ -129,19 +133,20 @@ export const SiteImageCarousel: React.FC = () => {
</div>
</Space>
</FooterContainer>
<Modal
title="Delete Site Image"
visible={showDeleteForm}
onOk={() => setShowDeleteForm(false)}
onCancel={() => setShowDeleteForm(false)}
footer={null}
// closeIcon={<StyledClose />}
>
<p>Are you sure you want to delete this image?</p>
<ConfirmDelete
onClick={() => onClickDeleteImage(latestEntrySiteImages[currSlideIndex].imageId)}>Delete</ConfirmDelete>
</Modal>
</CarouselContainer>
)}
<Modal
title="Delete Site Image"
visible={showDeleteForm}
onOk={() => setShowDeleteForm(false)}
onCancel={() => setShowDeleteForm(false)}
footer={null}
// closeIcon={<StyledClose />}
>
<p>Are you sure you want to delete this image?</p>
<ConfirmDelete onClick={onClickDeleteImage}>Delete</ConfirmDelete>
</Modal>
</>
);
};

0 comments on commit 86fddd6

Please sign in to comment.