From 5fe719a6c68a534302c384731a9b3aba4f50f604 Mon Sep 17 00:00:00 2001 From: Jasmine Rose <72074190+jasrose@users.noreply.github.com.> Date: Tue, 7 Oct 2025 23:50:39 -0400 Subject: [PATCH] update to firebase helper and call function --- components/api/delete-testimony.ts | 21 ++++++++++++++++++--- components/moderation/RemoveTestimony.tsx | 8 +++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/components/api/delete-testimony.ts b/components/api/delete-testimony.ts index cec26956a..8951d96e3 100644 --- a/components/api/delete-testimony.ts +++ b/components/api/delete-testimony.ts @@ -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) + } } diff --git a/components/moderation/RemoveTestimony.tsx b/components/moderation/RemoveTestimony.tsx index 70bc93bc6..e1364eca4 100644 --- a/components/moderation/RemoveTestimony.tsx +++ b/components/moderation/RemoveTestimony.tsx @@ -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 @@ -21,7 +19,7 @@ export const onSubmitReport = async ( resolution: Resolution, reason: string, authorUid: string, - testimonyId: string, + publicationId: string, refresh: () => void ) => { const r = await resolveReport({ @@ -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() }