mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-21 08:40:32 +02:00
added ability to delete reports
This commit is contained in:
parent
553f93828f
commit
37b7f39eb5
@ -350,6 +350,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"report": {
|
"report": {
|
||||||
|
"mutations": {
|
||||||
|
"success": {
|
||||||
|
"reportDeleted": "Report has been deleted!"
|
||||||
|
}
|
||||||
|
},
|
||||||
"emailMeta": {
|
"emailMeta": {
|
||||||
"flow": "{{from}} -> {{to}}",
|
"flow": "{{from}} -> {{to}}",
|
||||||
"emptySubject": "<No Subject>"
|
"emptySubject": "<No Subject>"
|
||||||
|
10
src/apis/delete-report.ts
Normal file
10
src/apis/delete-report.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import {SimpleDetailResponse} from "~/server-types"
|
||||||
|
import {client} from "~/constants/axios-client"
|
||||||
|
|
||||||
|
export default async function deleteReport(id: string): Promise<SimpleDetailResponse> {
|
||||||
|
const {data} = await client.delete(`${import.meta.env.VITE_SERVER_BASE_URL}/report/${id}`, {
|
||||||
|
withCredentials: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
@ -34,3 +34,5 @@ export * from "./get-alias"
|
|||||||
export {default as getAlias} from "./get-alias"
|
export {default as getAlias} from "./get-alias"
|
||||||
export * from "./update-alias"
|
export * from "./update-alias"
|
||||||
export {default as updateAlias} from "./update-alias"
|
export {default as updateAlias} from "./update-alias"
|
||||||
|
export * from "./delete-report"
|
||||||
|
export {default as deleteReport} from "./delete-report"
|
||||||
|
@ -1,17 +1,23 @@
|
|||||||
import {ReactElement, useState} from "react"
|
import {ReactElement, useState} from "react"
|
||||||
|
import {useNavigate} from "react-router-dom"
|
||||||
|
import {useTranslation} from "react-i18next"
|
||||||
|
import {MdDelete} from "react-icons/md"
|
||||||
|
import {TiCancel} from "react-icons/ti"
|
||||||
|
import {AxiosError} from "axios"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Alert,
|
|
||||||
Button,
|
Button,
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogContentText,
|
DialogContentText,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
Typography,
|
|
||||||
} from "@mui/material"
|
} from "@mui/material"
|
||||||
import {useTranslation} from "react-i18next"
|
import {useMutation} from "@tanstack/react-query"
|
||||||
import {MdDelete} from "react-icons/md"
|
|
||||||
import {TiCancel} from "react-icons/ti"
|
import {deleteReport} from "~/apis"
|
||||||
|
import {useErrorSuccessSnacks} from "~/hooks"
|
||||||
|
import {SimpleDetailResponse} from "~/server-types"
|
||||||
|
|
||||||
export interface DeleteButtonProps {
|
export interface DeleteButtonProps {
|
||||||
id: string
|
id: string
|
||||||
@ -19,6 +25,16 @@ export interface DeleteButtonProps {
|
|||||||
|
|
||||||
export default function ReportDetailRoute({id}: DeleteButtonProps): ReactElement {
|
export default function ReportDetailRoute({id}: DeleteButtonProps): ReactElement {
|
||||||
const {t} = useTranslation()
|
const {t} = useTranslation()
|
||||||
|
const {showError, showSuccess} = useErrorSuccessSnacks()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const {mutate} = useMutation<SimpleDetailResponse, AxiosError, void>(() => deleteReport(id), {
|
||||||
|
onError: showError,
|
||||||
|
onSuccess: () => {
|
||||||
|
showSuccess(t("relations.report.mutations.success.reportDeleted"))
|
||||||
|
navigate("/reports")
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const [showDeleteDialog, setShowDeleteDialog] = useState<boolean>(false)
|
const [showDeleteDialog, setShowDeleteDialog] = useState<boolean>(false)
|
||||||
|
|
||||||
@ -47,7 +63,12 @@ export default function ReportDetailRoute({id}: DeleteButtonProps): ReactElement
|
|||||||
<Button startIcon={<TiCancel />} onClick={() => setShowDeleteDialog(false)}>
|
<Button startIcon={<TiCancel />} onClick={() => setShowDeleteDialog(false)}>
|
||||||
{t("general.cancelLabel")}
|
{t("general.cancelLabel")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button startIcon={<MdDelete />} color="error">
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
startIcon={<MdDelete />}
|
||||||
|
color="error"
|
||||||
|
onClick={() => mutate()}
|
||||||
|
>
|
||||||
{t("routes.ReportDetailRoute.actions.delete.continueAction")}
|
{t("routes.ReportDetailRoute.actions.delete.continueAction")}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
|
@ -4,14 +4,12 @@ import {useTranslation} from "react-i18next"
|
|||||||
import React, {ReactElement} from "react"
|
import React, {ReactElement} from "react"
|
||||||
|
|
||||||
import {useQuery} from "@tanstack/react-query"
|
import {useQuery} from "@tanstack/react-query"
|
||||||
import {Button, List} from "@mui/material"
|
import {List} from "@mui/material"
|
||||||
|
|
||||||
import {DecryptedReportContent, Report} from "~/server-types"
|
import {DecryptedReportContent, Report} from "~/server-types"
|
||||||
import {getReport} from "~/apis"
|
import {getReport} from "~/apis"
|
||||||
import {DecryptReport, SimpleOverlayInformation, SimplePageBuilder} from "~/components"
|
import {DecryptReport, SimpleOverlayInformation, SimplePageBuilder} from "~/components"
|
||||||
import {WithEncryptionRequired} from "~/hocs"
|
import {WithEncryptionRequired} from "~/hocs"
|
||||||
import {BsTrash} from "react-icons/bs"
|
|
||||||
import {MdDelete} from "react-icons/md"
|
|
||||||
import DeleteButton from "~/route-widgets/ReportDetailRoute/DeleteButton"
|
import DeleteButton from "~/route-widgets/ReportDetailRoute/DeleteButton"
|
||||||
import ProxiedImagesListItem from "~/route-widgets/ReportDetailRoute/ProxiedImagesListItem"
|
import ProxiedImagesListItem from "~/route-widgets/ReportDetailRoute/ProxiedImagesListItem"
|
||||||
import QueryResult from "~/components/QueryResult"
|
import QueryResult from "~/components/QueryResult"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user