-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeedbackFilters.ts
More file actions
62 lines (50 loc) · 1.61 KB
/
Copy pathfeedbackFilters.ts
File metadata and controls
62 lines (50 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { FeedbackSubmission } from "@/types/feedback";
import { resolvedBelievability, resolvedRecommendationIntent, resolvedStripeIntent } from "@/types/feedback";
export const STRIPE_CONNECT_EARLY_ACCESS_REPORT_ID = "stripe_connect_early_access";
export type FeedbackFilterParams = {
believability?: string;
recommendation_intent?: string;
stripe_connection_intent?: string;
report_id?: string;
};
export function isStripeConnectEarlyAccess(item: FeedbackSubmission): boolean {
return item.report_id === STRIPE_CONNECT_EARLY_ACCESS_REPORT_ID;
}
export function formatFeedbackReportId(item: FeedbackSubmission): string {
if (isStripeConnectEarlyAccess(item)) {
return "Stripe Connect early access";
}
return item.report_id;
}
export function applyFilters(
feedback: FeedbackSubmission[],
searchParams: FeedbackFilterParams,
): FeedbackSubmission[] {
return feedback.filter((item) => {
if (searchParams.report_id && item.report_id !== searchParams.report_id) {
return false;
}
if (searchParams.believability && resolvedBelievability(item) !== searchParams.believability) {
return false;
}
if (
searchParams.recommendation_intent &&
resolvedRecommendationIntent(item) !== searchParams.recommendation_intent
) {
return false;
}
if (
searchParams.stripe_connection_intent &&
resolvedStripeIntent(item) !== searchParams.stripe_connection_intent
) {
return false;
}
return true;
});
}
export function formatRate(value: number | null): string {
if (value === null) {
return "—";
}
return `${value}%`;
}