Skip to content
Draft
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
21 changes: 18 additions & 3 deletions components/api/delete-testimony.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import { mapleClient } from "./maple-client"
import { httpsCallable } from "firebase/functions"
import { auth, functions } from "../firebase"

/**
* Admin-only route for deleting testimony.
*
* Moves testimony from published to archived.
* Moves testimony from published to archived and updates counts.
*
* @param uid user id, author of the testimony
* @param tid testimony id
* @returns 204 response (no body) if successful, or 4XX if not.
*/

export async function deleteTestimony(uid: string, tid: string) {
return mapleClient.delete(`/api/users/${uid}/testimony/${tid}`)
const user = auth.currentUser
if (!user) throw new Error("Not logged in.")

try {
const callable = httpsCallable(functions, "deleteTestimony")
const res = await callable({ uid, publicationId: tid })
return res.data
} catch (err: any) {
const msg =
err?.message ||
err?.code ||
"Delete failed"
throw new Error(msg)
}
}
8 changes: 3 additions & 5 deletions components/moderation/RemoveTestimony.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { Card, CardContent, CardHeader, Stack } from "@mui/material"
import { deleteTestimony } from "components/api/delete-testimony"
import { resolveReport } from "components/db"
import { getAuth } from "firebase/auth"
import { doc, getDoc } from "firebase/firestore"
import { Timestamp } from "functions/src/firebase"
import { FormEventHandler, useState } from "react"
import { useRedirect, useNotify, useRefresh } from "react-admin"
import { Report, Resolution } from "."
import { firestore } from "components/firebase"
import { refreshToken } from "firebase-admin/app"


export type ReportResponseValues = {
reportId: string
Expand All @@ -21,7 +19,7 @@ export const onSubmitReport = async (
resolution: Resolution,
reason: string,
authorUid: string,
testimonyId: string,
publicationId: string,
refresh: () => void
) => {
const r = await resolveReport({
Expand All @@ -36,7 +34,7 @@ export const onSubmitReport = async (

if (resolution === "remove-testimony") {
// If removing testimony, call deleteTestimony to move testimony from 'published' to 'archived'
const res = await deleteTestimony(authorUid, testimonyId)
await deleteTestimony(authorUid, publicationId)
}
refresh()
}
Expand Down
Loading