Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): mobile refund action for signal reports (#81117)

Tom Owersa6e10dddfc07
diff --git a/products/desktop/apps/mobile/src/app/inbox/[...id].tsx b/products/desktop/apps/mobile/src/app/inbox/[...id].tsx
index b688222e8223..ec4e1dfa48c9 100644
--- a/products/desktop/apps/mobile/src/app/inbox/[...id].tsx
+++ b/products/desktop/apps/mobile/src/app/inbox/[...id].tsx
@@ -1,9 +1,13 @@
import { Text } from "@components/text";
+import { computeRefundEligibility } from "@posthog/core/inbox/refundEligibility";
import {
formatSignalReportSummaryMarkdown,
inboxStatusLabel,
} from "@posthog/core/inbox/reportPresentation";
-import { DISMISSAL_REASON_OPTIONS } from "@posthog/shared";
+import {
+ DISMISSAL_REASON_OPTIONS,
+ SIGNALS_PR_REFUNDS_FLAG,
+} from "@posthog/shared";
import type {
ActionabilityJudgmentContent,
SignalFindingContent,
@@ -21,13 +25,15 @@ import {
Lightning,
Play,
Plus,
+ Receipt,
ThumbsDown,
Warning,
} from "phosphor-react-native";
-import { usePostHog } from "posthog-react-native";
+import { useFeatureFlag, usePostHog } from "posthog-react-native";
import { useCallback, useEffect, useMemo, useState } from "react";
import {
ActivityIndicator,
+ Alert,
type NativeScrollEvent,
type NativeSyntheticEvent,
Pressable,
@@ -45,6 +51,7 @@ import {
type DismissReportResult,
DismissReportSheet,
} from "@/features/inbox/components/DismissReportSheet";
+import { RefundReportSheet } from "@/features/inbox/components/RefundReportSheet";
import { ReportActivity } from "@/features/inbox/components/ReportActivity";
import { ReportFeedbackFooter } from "@/features/inbox/components/ReportFeedbackFooter";
import { SignalCard } from "@/features/inbox/components/SignalCard";
@@ -150,12 +157,14 @@ export default function ReportDetailScreen() {
const themeColors = useThemeColors();
const insets = useSafeAreaInsets();
const posthog = usePostHog();
+ const refundFlagEnabled = !!useFeatureFlag(SIGNALS_PR_REFUNDS_FLAG);
const { data: report, isLoading, error } = useInboxReport(reportId ?? null);
const { data: me } = useUserQuery();
const [reportRepo, setReportRepo] = useState<string | null>(null);
const [dismissOpen, setDismissOpen] = useState(false);
const [discussOpen, setDiscussOpen] = useState(false);
const [createPrFeedbackOpen, setCreatePrFeedbackOpen] = useState(false);
+ const [refundOpen, setRefundOpen] = useState(false);
const [signalsExpanded, setSignalsExpanded] = useState(false);
const artefactsQuery = useInboxReportArtefacts(reportId ?? null);
@@ -353,6 +362,11 @@ export default function ReportDetailScreen() {
[router, report, tracker],
);
+ const handleRefunded = useCallback(() => {
+ setRefundOpen(false);
+ if (router.canGoBack()) router.back();
+ }, [router]);
+
const handleDiscussSubmit = useCallback(
({ prompt, question }: { prompt: string; question: string }) => {
setDiscussOpen(false);
@@ -434,6 +448,9 @@ export default function ReportDetailScreen() {
? "Implement as new task"
: "Start task";
+ const { canRefund: canRefundPr, disabledReason: refundDisabledReason } =
+ computeRefundEligibility(report, refundFlagEnabled);
+
return (
<>
<ScrollView
@@ -609,6 +626,29 @@ export default function ReportDetailScreen() {
</Text>
</Pressable>
+ {canRefundPr && (
+ <Pressable
+ onPress={() => {
+ if (refundDisabledReason) {
+ Alert.alert("Can't refund this PR", refundDisabledReason);
+ return;
+ }
+ Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
+ setRefundOpen(true);
+ }}
+ accessibilityLabel="Refund PR"
+ accessibilityState={{ disabled: refundDisabledReason !== null }}
+ className={`flex-row items-center gap-2 rounded-full border border-gray-6 bg-background px-4 py-3.5 shadow-lg active:opacity-80 ${
+ refundDisabledReason ? "opacity-50" : ""
+ }`}
+ >
+ <Receipt size={16} color={themeColors.gray[11]} weight="fill" />
+ <Text className="font-semibold text-[15px] text-gray-11">
+ Refund
+ </Text>
+ </Pressable>
+ )}
+
{canStartTask && (
<View className="flex-row items-center overflow-hidden rounded-full bg-accent-9 shadow-lg">
<Pressable
@@ -661,6 +701,14 @@ export default function ReportDetailScreen() {
onClose={() => setCreatePrFeedbackOpen(false)}
onSubmit={handleStartTask}
/>
+
+ <RefundReportSheet
+ visible={refundOpen}
+ reportId={report.id}
+ reportTitle={report.title?.trim() || "Untitled report"}
+ onClose={() => setRefundOpen(false)}
+ onRefunded={handleRefunded}
+ />
</>
);
}
diff --git a/products/desktop/apps/mobile/src/features/inbox/components/RefundReportSheet.tsx b/products/desktop/apps/mobile/src/features/inbox/components/RefundReportSheet.tsx
new file mode 100644
index 000000000000..931fc32091fd
--- /dev/null
+++ b/products/desktop/apps/mobile/src/features/inbox/components/RefundReportSheet.tsx
@@ -0,0 +1,188 @@
+import { Text } from "@components/text";
+import { REFUND_REASON_OPTIONS } from "@posthog/shared";
+import type { SignalReportRefundReason } from "@posthog/shared/domain-types";
+import * as Haptics from "expo-haptics";
+import { Check } from "phosphor-react-native";
+import { useEffect, useState } from "react";
+import {
+ ActivityIndicator,
+ KeyboardAvoidingView,
+ Modal,
+ Platform,
+ Pressable,
+ ScrollView,
+ TextInput,
+ View,
+} from "react-native";
+import { useScreenInsets } from "@/hooks/useScreenInsets";
+import { useThemeColors } from "@/lib/theme";
+import { useRefundReport } from "../hooks/useInboxReports";
+
+interface RefundReportSheetProps {
+ visible: boolean;
+ reportId: string;
+ reportTitle: string;
+ onClose: () => void;
+ onRefunded: () => void;
+}
+
+export function RefundReportSheet({
+ visible,
+ reportId,
+ reportTitle,
+ onClose,
+ onRefunded,
+}: RefundReportSheetProps) {
+ const { insets, bottom, sheetContentTop } = useScreenInsets();
+ const themeColors = useThemeColors();
+ const [reason, setReason] = useState<SignalReportRefundReason | null>(null);
+ const [note, setNote] = useState("");
+ const [error, setError] = useState<string | null>(null);
+ const refund = useRefundReport(reportId);
+
+ useEffect(() => {
+ if (visible) {
+ setReason(null);
+ setNote("");
+ setError(null);
+ }
+ }, [visible]);
+
+ const handleConfirm = async () => {
+ if (!reason || refund.isPending) return;
+ setError(null);
+ const trimmedNote = note.trim();
+ try {
+ await refund.mutateAsync({
+ reason,
+ note: trimmedNote || undefined,
+ });
+ Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
+ onRefunded();
+ } catch (err) {
+ Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
+ setError(err instanceof Error ? err.message : "Couldn't refund this PR.");
+ }
+ };
+
+ const canSubmit = !!reason && !refund.isPending;
+
+ return (
+ <Modal
+ visible={visible}
+ animationType="slide"
+ presentationStyle="pageSheet"
+ onRequestClose={onClose}
+ >
+ <KeyboardAvoidingView
+ className="flex-1 bg-background"
+ behavior={Platform.OS === "ios" ? "padding" : "height"}
+ keyboardVerticalOffset={0}
+ >
+ <View
+ className="flex-1 bg-background"
+ style={{ paddingTop: sheetContentTop() }}
+ >
+ <View className="flex-row items-center justify-between border-gray-6 border-b px-4 pb-3">
+ <Text className="font-semibold text-[18px] text-gray-12">
+ Refund PR
+ </Text>
+ <Pressable
+ onPress={onClose}
+ hitSlop={12}
+ disabled={refund.isPending}
+ >
+ <Text className="text-[14px] text-accent-9">Cancel</Text>
+ </Pressable>
+ </View>
+
+ <ScrollView
+ keyboardShouldPersistTaps="handled"
+ contentContainerStyle={{
+ paddingHorizontal: 16,
+ paddingTop: 16,
+ paddingBottom: insets.bottom + 120,
+ }}
+ >
+ <Text className="text-[13px] text-gray-11 leading-snug">
+ {`You won't pay for the PR on "${reportTitle}" and it won't count toward your included PRs. The report is archived as part of the refund and can't be restored.`}
+ </Text>
+
+ <Text className="mt-5 mb-2 font-semibold text-[12px] text-gray-10 uppercase tracking-wide">
+ Reason
+ </Text>
+ <View className="overflow-hidden rounded-xl bg-gray-2">
+ {REFUND_REASON_OPTIONS.map((option, idx) => {
+ const selected = reason === option.value;
+ return (
+ <Pressable
+ key={option.value}
+ onPress={() => setReason(option.value)}
+ hitSlop={4}
+ className={`flex-row items-center justify-between px-3 py-3.5 active:bg-gray-3 ${
+ idx > 0 ? "border-gray-5 border-t" : ""
+ }`}
+ >
+ <Text className="flex-1 pr-3 text-[14px] text-gray-12">
+ {option.label}
+ </Text>
+ {selected && (
+ <Check size={16} color={themeColors.accent[9]} />
+ )}
+ </Pressable>
+ );
+ })}
+ </View>
+
+ <Text className="mt-5 mb-2 font-semibold text-[12px] text-gray-10 uppercase tracking-wide">
+ Note (optional)
+ </Text>
+ <TextInput
+ value={note}
+ onChangeText={setNote}
+ placeholder="Helps us review refunds"
+ placeholderTextColor={themeColors.gray[9]}
+ multiline
+ numberOfLines={3}
+ maxLength={4000}
+ editable={!refund.isPending}
+ className="min-h-[88px] rounded-xl bg-gray-2 px-3 py-3 text-[14px] text-gray-12"
+ style={{ textAlignVertical: "top" }}
+ />
+
+ {error && (
+ <Text className="mt-3 text-[13px] text-status-error">
+ {error}
+ </Text>
+ )}
+ </ScrollView>
+
+ <View
+ className="border-gray-6 border-t bg-background px-4 pt-3"
+ style={{ paddingBottom: bottom("compact") }}
+ >
+ <Pressable
+ onPress={handleConfirm}
+ disabled={!canSubmit}
+ className={`flex-row items-center justify-center rounded-full px-6 py-3.5 ${
+ canSubmit ? "bg-accent-9 active:opacity-80" : "bg-gray-4"
+ }`}
+ >
+ {refund.isPending ? (
+ <ActivityIndicator color={themeColors.gray[12]} />
+ ) : (
+ <Text
+ className={`font-semibold text-[15px] ${
+ canSubmit ? "text-gray-12" : "text-gray-9"
+ }`}
+ >
+ Refund PR
+ </Text>
+ )}
+ </Pressable>
+ </View>
+ </View>
+ </KeyboardAvoidingView>
+ </Modal>
+ );
+}
diff --git a/products/desktop/apps/mobile/src/features/inbox/hooks/useInboxReports.ts b/products/desktop/apps/mobile/src/features/inbox/hooks/useInboxReports.ts
index 5a9229edc989..4b891574f9a1 100644
--- a/products/desktop/apps/mobile/src/features/inbox/hooks/useInboxReports.ts
+++ b/products/desktop/apps/mobile/src/features/inbox/hooks/useInboxReports.ts
@@ -15,6 +15,7 @@ import type {
SignalProcessingStateResponse,
SignalReport,
SignalReportArtefactsResponse,
+ SignalReportRefundReason,
SignalReportSignalsResponse,
SignalReportsQueryParams,
SignalReportsResponse,
@@ -307,6 +308,23 @@ export function useDismissReport(reportId: string) {
});
}
+export function useRefundReport(reportId: string) {
+ const queryClient = useQueryClient();
+
+ return useMutation<
+ SignalReport,
+ Error,
+ { reason: SignalReportRefundReason; note?: string }
+ >({
+ mutationFn: (input) =>
+ getPostHogApiClient().refundSignalReport(reportId, input),
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: inboxKeys.detail(reportId) });
+ queryClient.invalidateQueries({ queryKey: inboxKeys.all });
+ },
+ });
+}
+
export function useRestoreReport() {
const queryClient = useQueryClient();
diff --git a/products/desktop/packages/ui/src/features/inbox/utils/refundEligibility.test.ts b/products/desktop/packages/core/src/inbox/refundEligibility.test.ts
similarity index 100%
rename from products/desktop/packages/ui/src/features/inbox/utils/refundEligibility.test.ts
rename to products/desktop/packages/core/src/inbox/refundEligibility.test.ts
diff --git a/products/desktop/packages/ui/src/features/inbox/utils/refundEligibility.ts b/products/desktop/packages/core/src/inbox/refundEligibility.ts
similarity index 100%
rename from products/desktop/packages/ui/src/features/inbox/utils/refundEligibility.ts
rename to products/desktop/packages/core/src/inbox/refundEligibility.ts
diff --git a/products/desktop/packages/shared/src/index.ts b/products/desktop/packages/shared/src/index.ts
index bdeb1115a995..d2037d4a8f74 100644
--- a/products/desktop/packages/shared/src/index.ts
+++ b/products/desktop/packages/shared/src/index.ts
@@ -281,6 +281,7 @@ export {
supports1MContext,
supportsFastMode,
} from "./reasoning-effort";
+export { REFUND_REASON_OPTIONS } from "./refund-reasons";
export {
type CloudRegion,
formatRegionBadge,
diff --git a/products/desktop/packages/shared/src/refund-reasons.ts b/products/desktop/packages/shared/src/refund-reasons.ts
new file mode 100644
index 000000000000..0005f1bbee1f
--- /dev/null
+++ b/products/desktop/packages/shared/src/refund-reasons.ts
@@ -0,0 +1,18 @@
+import type { SignalReportRefundReason } from "./domain-types";
+
+/**
+ * Canonical refund reasons shown when refunding a report's PR. Values are
+ * persisted on the refund; edit the list here only.
+ */
+export const REFUND_REASON_OPTIONS: readonly {
+ value: SignalReportRefundReason;
+ label: string;
+}[] = [
+ {
+ value: "pr_incorrect",
+ label: "The PR doesn't fix what the report describes",
+ },
+ { value: "pr_not_useful", label: "The PR works but is not useful to me" },
+ { value: "duplicate", label: "Duplicate of work already covered" },
+ { value: "other", label: "Something else…" },
+];
diff --git a/products/desktop/packages/ui/src/features/inbox/AGENTS.md b/products/desktop/packages/ui/src/features/inbox/AGENTS.md
index 2382ba62924d..f49098b41a88 100644
--- a/products/desktop/packages/ui/src/features/inbox/AGENTS.md
+++ b/products/desktop/packages/ui/src/features/inbox/AGENTS.md
@@ -110,7 +110,7 @@ The shared renderer type for the report is `SignalReport` in `packages/shared/sr
Report charts: `SignalReport.charts` carries scout-authored chart definitions (`chart_id`, `title`, `query`, `caption?`, `size?`). The desktop app renders them natively in the detail views: `packages/core/src/inbox/reportCharts.ts` classifies the stored query (runnable HogQL/trends vs saved-insight vs link-out fallback), `PostHogAPIClient.runQuery` executes runnable sources against `/api/projects/{teamId}/query/`, and `components/detail/ReportChartCard.tsx` draws the result with `@posthog/quill-charts`. Query kinds the app can't draw degrade to a card that links out to PostHog. Summary prose references charts as `[label](chart:<chart_id>)` links; `SignalReportSummaryMarkdown` turns those into in-page jumps to the chart card (plain text on list rows).
-PR refunds: `POST /api/projects/{teamId}/signals/reports/{id}/refund/` refunds a billed PR and archives the report (`PostHogAPIClient.refundSignalReport`). The action is gated behind the `signals-pr-refunds` flag (`SIGNALS_PR_REFUNDS_FLAG`) and `utils/refundEligibility.ts`'s `computeRefundEligibility`, which reads `implementation_pr_url`, `refund` (one `SignalReportRefund` per report, ever), `billing_exempt_reason`, and the backend-owned `refund_ineligibility_reason`. The server enforces the same rules, so the gate is display-only; `ReportRefundAction` shows nothing when the report is ineligible.
+PR refunds: `POST /api/projects/{teamId}/signals/reports/{id}/refund/` refunds a billed PR and archives the report (`PostHogAPIClient.refundSignalReport`). The action is gated behind the `signals-pr-refunds` flag (`SIGNALS_PR_REFUNDS_FLAG`) and `@posthog/core/inbox/refundEligibility`'s `computeRefundEligibility` (shared with the mobile host), which reads `implementation_pr_url`, `refund` (one `SignalReportRefund` per report, ever), `billing_exempt_reason`, and the backend-owned `refund_ineligibility_reason`. The server enforces the same rules, so the gate is display-only; `ReportRefundAction` shows nothing when the report is ineligible.
Card headlines are derived client-side from `summary` by `utils/reportPresentation.ts`; there is no backend headline field.
diff --git a/products/desktop/packages/ui/src/features/inbox/components/RefundReportDialog.tsx b/products/desktop/packages/ui/src/features/inbox/components/RefundReportDialog.tsx
index bcc837900ba6..88354d0acfb5 100644
--- a/products/desktop/packages/ui/src/features/inbox/components/RefundReportDialog.tsx
+++ b/products/desktop/packages/ui/src/features/inbox/components/RefundReportDialog.tsx
@@ -13,25 +13,13 @@ import {
RadioGroupItem,
Textarea,
} from "@posthog/quill";
+import { REFUND_REASON_OPTIONS } from "@posthog/shared";
import type {
SignalReport,
SignalReportRefundReason,
} from "@posthog/shared/types";
import { useId, useState } from "react";
-const REFUND_REASON_OPTIONS: {
- value: SignalReportRefundReason;
- label: string;
-}[] = [
- {
- value: "pr_incorrect",
- label: "The PR doesn't fix what the report describes",
- },
- { value: "pr_not_useful", label: "The PR works but is not useful to me" },
- { value: "duplicate", label: "Duplicate of work already covered" },
- { value: "other", label: "Something else…" },
-];
-
export interface RefundReportDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
diff --git a/products/desktop/packages/ui/src/features/inbox/hooks/useRefundReport.ts b/products/desktop/packages/ui/src/features/inbox/hooks/useRefundReport.ts
index b4f38dc523dc..2e281a9238eb 100644
--- a/products/desktop/packages/ui/src/features/inbox/hooks/useRefundReport.ts
+++ b/products/desktop/packages/ui/src/features/inbox/hooks/useRefundReport.ts
@@ -1,4 +1,5 @@
import { inboxReportKeys } from "@posthog/core/inbox/inboxQuery";
+import { computeRefundEligibility } from "@posthog/core/inbox/refundEligibility";
import { SIGNALS_PR_REFUNDS_FLAG } from "@posthog/shared";
import type {
SignalReport,
@@ -6,7 +7,6 @@ import type {
} from "@posthog/shared/types";
import { useAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
-import { computeRefundEligibility } from "@posthog/ui/features/inbox/utils/refundEligibility";
import { toast } from "@posthog/ui/primitives/toast";
import { useMutation, useQueryClient } from "@tanstack/react-query";