+ {open && (
+
- {yearOpen && (
-
- {years.map((year) => (
-
- ))}
-
- )}
-
-
-
- {monthOpen && (
-
-
+
+
+ {yearOpen && (
+
{years.map((year) => (
))}
- {MONTH_LABELS.map((label, index) => {
- const month = index + 1
- const isSelected =
- value.mode === "year_month" && value.year === contextYear && value.month === month
+ )}
+
- return (
-
- )
- })}
-
- )}
-
+
+
+ {monthOpen && (
+
+
+ {years.map((year) => (
+
+ ))}
+
+ {MONTH_LABELS.map((label, index) => {
+ const month = index + 1
+ const isSelected =
+ value.mode === "year_month" && value.year === contextYear && value.month === month
-
-
- {customOpen && (
-
-
-
- setCustomFrom(e.target.value)}
- className="h-8 text-xs"
- />
+ return (
+
+ )
+ })}
-
-
- setCustomTo(e.target.value)}
- className="h-8 text-xs"
- />
+ )}
+
+
+
+
+ {customOpen && (
+
-
-
- )}
+ )}
+
-
- )}
+ )}
+
)
}
diff --git a/src/components/dashboard/RevenueTrendCard.tsx b/src/components/dashboard/RevenueTrendCard.tsx
index e658681..9add94e 100644
--- a/src/components/dashboard/RevenueTrendCard.tsx
+++ b/src/components/dashboard/RevenueTrendCard.tsx
@@ -11,7 +11,7 @@ import { aggregateRevenueByMonth, formatRevenueAxisTick } from "../../lib/analyt
import type { DateRevenue } from "../../types/analytics.types"
import spinnerSrc from "../../assets/Circular-indeterminate progress indicator.svg"
-export function RevenueTrendCard() {
+export function RevenueTrendCard({ paymentMethod }: { paymentMethod?: string }) {
const currentYear = new Date().getFullYear()
const [year, setYear] = useState(currentYear)
const [totalRevenue, setTotalRevenue] = useState(0)
@@ -26,7 +26,11 @@ export function RevenueTrendCard() {
const fetchRevenueTrend = async () => {
setLoading(true)
try {
- const res = await getDashboard({ mode: "year", year })
+ const res = await getDashboard({
+ mode: "year",
+ year,
+ ...(paymentMethod ? { payment_method: paymentMethod } : {}),
+ })
if (cancelled) return
setTotalRevenue(res.data.payments.total_revenue)
setDailyRevenue(res.data.payments.revenue_last_30_days)
@@ -44,7 +48,7 @@ export function RevenueTrendCard() {
return () => {
cancelled = true
}
- }, [year])
+ }, [year, paymentMethod])
const chartData = useMemo(
() => aggregateRevenueByMonth(dailyRevenue, year),
diff --git a/src/index.css b/src/index.css
index 3d6f0e1..9149776 100644
--- a/src/index.css
+++ b/src/index.css
@@ -175,4 +175,141 @@
.scrollbar-none::-webkit-scrollbar {
display: none;
}
+
+ /* Sonner toast — polished admin notifications */
+ [data-sonner-toaster] {
+ --width: min(420px, calc(100vw - 2rem));
+ font-family: inherit;
+ }
+
+ [data-sonner-toaster][data-y-position="top"] {
+ top: 1.25rem;
+ }
+
+ .yimaru-toast[data-sonner-toast] {
+ --yimaru-toast-accent: #9e2891;
+ width: var(--width);
+ display: flex;
+ align-items: flex-start;
+ gap: 0.75rem;
+ padding: 0.875rem 1rem 0.875rem 1rem;
+ border-radius: 0.75rem;
+ border: 1px solid var(--gs-200);
+ border-left: 3px solid var(--yimaru-toast-accent);
+ background: var(--gs-50);
+ color: hsl(var(--foreground));
+ box-shadow:
+ 0 1px 2px rgba(15, 23, 42, 0.04),
+ 0 12px 32px rgba(15, 23, 42, 0.1);
+ font-size: 0.875rem;
+ line-height: 1.4;
+ letter-spacing: -0.01em;
+ }
+
+ html.dark .yimaru-toast[data-sonner-toast] {
+ box-shadow:
+ 0 1px 2px rgba(0, 0, 0, 0.25),
+ 0 16px 40px rgba(0, 0, 0, 0.45);
+ }
+
+ .yimaru-toast[data-sonner-toast] [data-icon] {
+ margin-top: 0.1rem;
+ width: 1.125rem;
+ height: 1.125rem;
+ flex-shrink: 0;
+ color: var(--yimaru-toast-accent);
+ }
+
+ .yimaru-toast[data-sonner-toast] [data-icon] svg {
+ width: 1.125rem;
+ height: 1.125rem;
+ }
+
+ .yimaru-toast[data-sonner-toast] [data-content] {
+ flex: 1;
+ min-width: 0;
+ gap: 0.2rem;
+ }
+
+ .yimaru-toast__title {
+ font-size: 0.875rem;
+ font-weight: 600;
+ color: hsl(var(--foreground));
+ letter-spacing: -0.015em;
+ }
+
+ .yimaru-toast__description {
+ font-size: 0.8125rem;
+ font-weight: 400;
+ color: var(--gs-500);
+ line-height: 1.45;
+ }
+
+ .yimaru-toast__close {
+ position: absolute !important;
+ top: 0.55rem !important;
+ right: 0.55rem !important;
+ left: auto !important;
+ transform: none !important;
+ width: 1.5rem !important;
+ height: 1.5rem !important;
+ border-radius: 0.375rem !important;
+ border: 1px solid transparent !important;
+ background: transparent !important;
+ color: var(--gs-400) !important;
+ opacity: 0.85;
+ transition:
+ background-color 0.15s ease,
+ color 0.15s ease,
+ border-color 0.15s ease;
+ }
+
+ .yimaru-toast__close:hover {
+ background: var(--gs-100) !important;
+ border-color: var(--gs-200) !important;
+ color: var(--gs-600) !important;
+ opacity: 1;
+ }
+
+ .yimaru-toast__action {
+ margin-top: 0.35rem;
+ height: 1.75rem;
+ padding: 0 0.75rem;
+ border-radius: 0.375rem;
+ background: #9e2891;
+ color: #fff;
+ font-size: 0.75rem;
+ font-weight: 600;
+ }
+
+ .yimaru-toast__cancel {
+ margin-top: 0.35rem;
+ height: 1.75rem;
+ padding: 0 0.75rem;
+ border-radius: 0.375rem;
+ background: var(--gs-100);
+ color: var(--gs-600);
+ font-size: 0.75rem;
+ font-weight: 500;
+ }
+
+ .yimaru-toast--success {
+ --yimaru-toast-accent: #059669;
+ }
+
+ .yimaru-toast--error {
+ --yimaru-toast-accent: #dc2626;
+ }
+
+ .yimaru-toast--warning {
+ --yimaru-toast-accent: #d97706;
+ }
+
+ .yimaru-toast--info {
+ --yimaru-toast-accent: #9e2891;
+ }
+
+ .yimaru-toast[data-sonner-toast][data-styled="true"] {
+ padding-right: 2.25rem;
+ }
}
diff --git a/src/lib/activityLogActor.ts b/src/lib/activityLogActor.ts
index 1bfc873..2b58613 100644
--- a/src/lib/activityLogActor.ts
+++ b/src/lib/activityLogActor.ts
@@ -1,5 +1,6 @@
import { getTeamMemberById } from "../api/team.api"
import { getUserById } from "../api/users.api"
+import { formatAppDate } from "./datetime"
import { TEAM_ROLE_OPTIONS, formatTeamRoleLabel } from "./teamRoles"
import type { TeamMember, TeamMemberDetail } from "../types/team.types"
import type { UserProfileData } from "../types/user.types"
@@ -149,11 +150,5 @@ export async function fetchActorProfile(
}
export function formatActorDate(iso: string): string {
- const d = new Date(iso)
- if (Number.isNaN(d.getTime())) return iso
- return d.toLocaleDateString(undefined, {
- year: "numeric",
- month: "short",
- day: "numeric",
- })
+ return formatAppDate(iso, iso)
}
diff --git a/src/lib/activityLogDisplay.ts b/src/lib/activityLogDisplay.ts
index 652ff74..efec81a 100644
--- a/src/lib/activityLogDisplay.ts
+++ b/src/lib/activityLogDisplay.ts
@@ -1,4 +1,10 @@
import type { ActivityLog, ActivityLogActorKind } from "../types/activity-log.types"
+import {
+ formatAppDate,
+ formatAppTime,
+ toAppDayEndISO,
+ toAppDayStartISO,
+} from "./datetime"
export type ActorDisplay = {
name: string
@@ -355,19 +361,11 @@ export function activityLogResourcePath(
}
export function formatActivityDate(dateStr: string): string {
- return new Date(dateStr).toLocaleDateString(undefined, {
- year: "numeric",
- month: "short",
- day: "numeric",
- })
+ return formatAppDate(dateStr, "—")
}
export function formatActivityTime(dateStr: string): string {
- return new Date(dateStr).toLocaleTimeString(undefined, {
- hour: "2-digit",
- minute: "2-digit",
- second: "2-digit",
- })
+ return formatAppTime(dateStr, "—")
}
export function getRelativeActivityTime(dateStr: string): string {
@@ -386,9 +384,9 @@ export function getRelativeActivityTime(dateStr: string): string {
}
export function toRfc3339StartOfDay(dateValue: string): string {
- return new Date(`${dateValue}T00:00:00`).toISOString()
+ return toAppDayStartISO(dateValue)
}
export function toRfc3339EndOfDay(dateValue: string): string {
- return new Date(`${dateValue}T23:59:59.999`).toISOString()
+ return toAppDayEndISO(dateValue)
}
diff --git a/src/lib/analytics.ts b/src/lib/analytics.ts
index 2e01e92..074132c 100644
--- a/src/lib/analytics.ts
+++ b/src/lib/analytics.ts
@@ -121,9 +121,56 @@ const MONTH_SHORT = [
"Dec",
] as const
+/** Calendar Y-M-D from an analytics series date (API encodes civil days as UTC midnight). */
+export function analyticsSeriesYmd(dateStr: string): string | null {
+ const match = /^(\d{4}-\d{2}-\d{2})/.exec(String(dateStr ?? "").trim())
+ return match ? match[1] : null
+}
+
+/**
+ * Format a daily analytics series date for charts.
+ * Uses the civil YYYY-MM-DD from the API — never the browser local timezone —
+ * so EAT buckets stay aligned with payments/Chapa.
+ */
+export function formatAnalyticsSeriesDate(dateStr: string): string {
+ const ymd = analyticsSeriesYmd(dateStr)
+ if (ymd) {
+ const [year, month, day] = ymd.split("-").map(Number)
+ const d = new Date(Date.UTC(year, month - 1, day))
+ return d.toLocaleDateString("en-US", {
+ month: "short",
+ day: "numeric",
+ timeZone: "UTC",
+ })
+ }
+ const d = new Date(dateStr)
+ if (Number.isNaN(d.getTime())) return String(dateStr)
+ return d.toLocaleDateString("en-US", {
+ month: "short",
+ day: "numeric",
+ timeZone: "UTC",
+ })
+}
+
function formatShortDate(iso: string) {
+ const ymd = analyticsSeriesYmd(iso)
+ if (ymd) {
+ const [year, month, day] = ymd.split("-").map(Number)
+ const d = new Date(Date.UTC(year, month - 1, day))
+ return d.toLocaleDateString("en-US", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ timeZone: "UTC",
+ })
+ }
const d = new Date(iso)
- return d.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" })
+ return d.toLocaleDateString("en-US", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ timeZone: "UTC",
+ })
}
function formatBreakdownLabel(label: string) {
@@ -154,8 +201,14 @@ export function aggregateRevenueByMonth(daily: DateRevenue[], year: number): Mon
}))
for (const { date, revenue } of daily) {
- const parsed = new Date(date)
- if (parsed.getUTCFullYear() !== year) continue
+ const ymd = analyticsSeriesYmd(date)
+ const parsed = ymd
+ ? (() => {
+ const [year, month, day] = ymd.split("-").map(Number)
+ return new Date(Date.UTC(year, month - 1, day))
+ })()
+ : new Date(date)
+ if (Number.isNaN(parsed.getTime()) || parsed.getUTCFullYear() !== year) continue
monthly[parsed.getUTCMonth()].revenue += revenue
}
diff --git a/src/lib/appVersions.ts b/src/lib/appVersions.ts
index eb57308..c12f4a2 100644
--- a/src/lib/appVersions.ts
+++ b/src/lib/appVersions.ts
@@ -4,6 +4,7 @@ import type {
AppVersion,
AppVersionStatus,
} from "../types/app-version.types"
+import { formatAppDateTime } from "./datetime"
export const APP_PLATFORMS: { value: AppPlatform; label: string }[] = [
{ value: "ANDROID", label: "Android" },
@@ -65,13 +66,7 @@ export function formatAppVersionCreatedAt(raw: string): string {
const datePart = raw.split(" ")[0]
return datePart || raw
}
- return d.toLocaleString(undefined, {
- year: "numeric",
- month: "short",
- day: "numeric",
- hour: "2-digit",
- minute: "2-digit",
- })
+ return formatAppDateTime(normalized)
}
export function versionLabel(version: Pick
): string {
diff --git a/src/lib/csvExportFilters.ts b/src/lib/csvExportFilters.ts
index b944d18..da01903 100644
--- a/src/lib/csvExportFilters.ts
+++ b/src/lib/csvExportFilters.ts
@@ -1,6 +1,7 @@
import type { GetUsersParams } from "../api/users.api"
import { buildUsersListQuery } from "../api/users.api"
import { paymentsFilterParams } from "../api/payments.api"
+import { nextCalendarDay } from "./payments"
import type { ActivityLogFilters } from "../types/activity-log.types"
import type { QueryParams } from "./csv-export"
@@ -10,13 +11,21 @@ export function paymentListFiltersToExportQuery(filters: {
planCategory?: string
currency?: string
reference?: string
+ /** Inclusive YYYY-MM-DD; mapped to created_from. */
+ dateFrom?: string
+ /** Inclusive YYYY-MM-DD; mapped to exclusive created_to. */
+ dateTo?: string
}): QueryParams {
+ const dateFrom = filters.dateFrom?.trim()
+ const dateTo = filters.dateTo?.trim()
return paymentsFilterParams({
...(filters.status ? { status: filters.status } : {}),
...(filters.provider ? { provider: filters.provider } : {}),
...(filters.planCategory ? { plan_category: filters.planCategory } : {}),
...(filters.currency ? { currency: filters.currency } : {}),
...(filters.reference ? { reference: filters.reference } : {}),
+ ...(dateFrom ? { created_from: dateFrom } : {}),
+ ...(dateTo ? { created_to: nextCalendarDay(dateTo) } : {}),
})
}
diff --git a/src/lib/datetime.ts b/src/lib/datetime.ts
new file mode 100644
index 0000000..0a860f6
--- /dev/null
+++ b/src/lib/datetime.ts
@@ -0,0 +1,96 @@
+/** Default business timezone for Yimaru (East Africa Time, UTC+3, no DST). */
+export const APP_TIMEZONE = "Africa/Addis_Ababa"
+export const APP_TIMEZONE_LABEL = "EAT"
+/** Fixed offset used when building RFC3339 bounds from calendar days. */
+export const APP_TIMEZONE_OFFSET = "+03:00"
+
+export function isValidDateInput(value: string | null | undefined): value is string {
+ return Boolean(value && /^\d{4}-\d{2}-\d{2}/.test(value.trim()))
+}
+
+/** Calendar YYYY-MM-DD of an instant in the app timezone. */
+export function toAppCalendarDate(iso: string | Date): string | null {
+ const d = typeof iso === "string" ? new Date(iso) : iso
+ if (Number.isNaN(d.getTime())) return null
+ return new Intl.DateTimeFormat("en-CA", {
+ timeZone: APP_TIMEZONE,
+ year: "numeric",
+ month: "2-digit",
+ day: "2-digit",
+ }).format(d)
+}
+
+export function formatAppDate(
+ iso: string | null | undefined,
+ emptyLabel = "—",
+): string {
+ if (!iso) return emptyLabel
+ const d = new Date(iso)
+ if (Number.isNaN(d.getTime())) return emptyLabel
+ return d.toLocaleDateString("en-GB", {
+ timeZone: APP_TIMEZONE,
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ })
+}
+
+export function formatAppDateTime(
+ iso: string | null | undefined,
+ emptyLabel = "—",
+): string {
+ if (!iso) return emptyLabel
+ const d = new Date(iso)
+ if (Number.isNaN(d.getTime())) return emptyLabel
+ return d.toLocaleString("en-GB", {
+ timeZone: APP_TIMEZONE,
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ hour: "2-digit",
+ minute: "2-digit",
+ hour12: false,
+ })
+}
+
+export function formatAppTime(
+ iso: string | null | undefined,
+ emptyLabel = "—",
+): string {
+ if (!iso) return emptyLabel
+ const d = new Date(iso)
+ if (Number.isNaN(d.getTime())) return emptyLabel
+ return d.toLocaleTimeString("en-GB", {
+ timeZone: APP_TIMEZONE,
+ hour: "2-digit",
+ minute: "2-digit",
+ second: "2-digit",
+ hour12: false,
+ })
+}
+
+/** Midnight EAT for a YYYY-MM-DD calendar day, as RFC3339. */
+export function toAppDayStartISO(ymd: string): string {
+ const day = ymd.trim().slice(0, 10)
+ return `${day}T00:00:00${APP_TIMEZONE_OFFSET}`
+}
+
+/** End of EAT calendar day (inclusive-style), as RFC3339. */
+export function toAppDayEndISO(ymd: string): string {
+ const day = ymd.trim().slice(0, 10)
+ return `${day}T23:59:59.999${APP_TIMEZONE_OFFSET}`
+}
+
+/** Next calendar day (UTC date arithmetic on Y-M-D components). */
+export function nextAppCalendarDay(ymd: string): string {
+ const [year, month, day] = ymd.trim().slice(0, 10).split("-").map(Number)
+ if (!year || !month || !day) return ymd
+ const dt = new Date(Date.UTC(year, month - 1, day))
+ dt.setUTCDate(dt.getUTCDate() + 1)
+ return dt.toISOString().slice(0, 10)
+}
+
+/** Exclusive upper bound: next EAT midnight after ymd. */
+export function toAppNextDayStartISO(ymd: string): string {
+ return toAppDayStartISO(nextAppCalendarDay(ymd))
+}
diff --git a/src/lib/emailTemplatePreview.ts b/src/lib/emailTemplatePreview.ts
index a605c1d..92ae75e 100644
--- a/src/lib/emailTemplatePreview.ts
+++ b/src/lib/emailTemplatePreview.ts
@@ -1,3 +1,5 @@
+import { formatAppDateTime } from "./datetime"
+
const SAMPLE_VALUES: Record = {
OTP: "123456",
FirstName: "Alex",
@@ -42,10 +44,7 @@ export function formatEmailTemplateDate(raw: string | null | undefined) {
if (Number.isNaN(parsed.getTime())) {
return text.split(" +")[0]?.trim() || text
}
- return parsed.toLocaleString(undefined, {
- dateStyle: "medium",
- timeStyle: "short",
- })
+ return formatAppDateTime(text)
}
export function emailTemplateStatusBadgeVariant(status: string) {
diff --git a/src/lib/faqDisplay.ts b/src/lib/faqDisplay.ts
index b3c213e..a99a831 100644
--- a/src/lib/faqDisplay.ts
+++ b/src/lib/faqDisplay.ts
@@ -1,4 +1,5 @@
import type { FAQ, FAQStatus } from "../types/faq.types"
+import { formatAppDateTime } from "./datetime"
export function faqStatusBadgeVariant(status: string): "success" | "secondary" {
const normalized = status.toUpperCase()
@@ -22,10 +23,7 @@ export function formatFaqDate(raw: string | null | undefined): string {
if (Number.isNaN(parsed.getTime())) {
return text.split(" +")[0]?.trim() || text
}
- return parsed.toLocaleString(undefined, {
- dateStyle: "medium",
- timeStyle: "short",
- })
+ return formatAppDateTime(text)
}
export function deriveFaqCategories(faqs: FAQ[]): string[] {
diff --git a/src/lib/notificationBulk.ts b/src/lib/notificationBulk.ts
index 131cf6e..5a9d9a2 100644
--- a/src/lib/notificationBulk.ts
+++ b/src/lib/notificationBulk.ts
@@ -8,6 +8,7 @@ import type {
} from "../types/notification.types"
import { getUsers } from "../api/users.api"
import { getTeamMembers } from "../api/team.api"
+import { formatAppDateTime } from "./datetime"
import { TEAM_ROLE_OPTIONS } from "./teamRoles"
export const PLATFORM_ROLES: { value: PlatformRole; label: string }[] = [
@@ -122,13 +123,7 @@ export function formatScheduledAtLabel(value: string): string {
if (!value) return "Set date & time"
const parsed = new Date(value)
if (Number.isNaN(parsed.getTime())) return value
- return parsed.toLocaleString("en-US", {
- month: "short",
- day: "numeric",
- year: "numeric",
- hour: "2-digit",
- minute: "2-digit",
- })
+ return formatAppDateTime(value)
}
export function scheduledStatusBadgeVariant(
diff --git a/src/lib/notificationDisplay.ts b/src/lib/notificationDisplay.ts
index 7fedba7..d61fb75 100644
--- a/src/lib/notificationDisplay.ts
+++ b/src/lib/notificationDisplay.ts
@@ -10,6 +10,7 @@ import {
Video,
ShieldAlert,
} from "lucide-react"
+import { formatAppDate, formatAppDateTime } from "./datetime"
export const NOTIFICATION_TYPE_CONFIG: Record<
string,
@@ -67,11 +68,7 @@ export function formatNotificationTimestamp(ts: string) {
if (diffHr < 24) return `${diffHr}h ago`
if (diffDay < 7) return `${diffDay}d ago`
- return date.toLocaleDateString("en-US", {
- month: "short",
- day: "numeric",
- year: date.getFullYear() !== now.getFullYear() ? "numeric" : undefined,
- })
+ return formatAppDate(ts)
}
export function formatNotificationTypeLabel(type: string) {
@@ -82,15 +79,7 @@ export function formatNotificationTypeLabel(type: string) {
}
export function formatNotificationDateTime(ts: string) {
- const date = new Date(ts)
- if (Number.isNaN(date.getTime())) return "unassigned"
- return date.toLocaleString(undefined, {
- year: "numeric",
- month: "short",
- day: "numeric",
- hour: "2-digit",
- minute: "2-digit",
- })
+ return formatAppDateTime(ts, "unassigned")
}
export function isMeaningfulExpiry(expires: string) {
diff --git a/src/lib/payments.ts b/src/lib/payments.ts
index 0013a2d..e38a9cf 100644
--- a/src/lib/payments.ts
+++ b/src/lib/payments.ts
@@ -1,4 +1,10 @@
import { formatPlanCategory } from "./subscriptionPlans"
+import {
+ APP_TIMEZONE,
+ formatAppDateTime,
+ nextAppCalendarDay,
+ toAppCalendarDate,
+} from "./datetime"
import type { Payment } from "../types/payment.types"
export function formatPaymentAmount(payment: Pick): string {
@@ -9,17 +15,39 @@ export function formatPaymentAmount(payment: Pick): string | null {
+ const raw = payment.paid_at || payment.created_at
+ if (!raw) return null
+ return toAppCalendarDate(raw)
+}
+
+/** Inclusive YYYY-MM-DD range against the payment event date in EAT. */
+export function paymentMatchesDateRange(
+ payment: Pick,
+ from?: string,
+ to?: string,
+): boolean {
+ const fromDay = from?.trim()
+ const toDay = to?.trim()
+ if (!fromDay && !toDay) return true
+ const day = paymentEventDateEAT(payment)
+ if (!day) return false
+ if (fromDay && day < fromDay) return false
+ if (toDay && day > toDay) return false
+ return true
+}
+
+/** Next calendar day as YYYY-MM-DD (for exclusive API upper bounds). */
+export function nextCalendarDay(ymd: string): string {
+ return nextAppCalendarDay(ymd)
}
export function formatPaymentStatus(status: string): string {
diff --git a/src/lib/personaDisplay.ts b/src/lib/personaDisplay.ts
index a5a8b4a..107e6a4 100644
--- a/src/lib/personaDisplay.ts
+++ b/src/lib/personaDisplay.ts
@@ -2,6 +2,7 @@ import type {
GetPersonasResponse,
PersonaListItem,
} from "../types/persona.types"
+import { formatAppDate } from "./datetime"
import amanuelAvatar from "../assets/personas/amanuel.png"
import aseffaAvatar from "../assets/personas/aseffa.png"
import bethelAvatar from "../assets/personas/bethel.png"
@@ -91,13 +92,7 @@ export function mapPersonaToCard(persona: PersonaListItem): PersonaCardModel {
export function formatPersonaDate(dateStr: string | null | undefined): string {
if (!dateStr?.trim()) return "unassigned"
- const d = new Date(dateStr)
- if (Number.isNaN(d.getTime())) return dateStr
- return d.toLocaleDateString(undefined, {
- year: "numeric",
- month: "short",
- day: "numeric",
- })
+ return formatAppDate(dateStr, dateStr)
}
export function personaStatusLabel(isActive: boolean): string {
diff --git a/src/lib/ratingsDisplay.ts b/src/lib/ratingsDisplay.ts
index 16d0370..09387b2 100644
--- a/src/lib/ratingsDisplay.ts
+++ b/src/lib/ratingsDisplay.ts
@@ -1,4 +1,5 @@
import type { RatingTargetType } from "../types/ratings.types"
+import { formatAppDate, formatAppDateTime } from "./datetime"
export function formatAverageStars(value: number): string {
if (!Number.isFinite(value) || value <= 0) return "0.0"
@@ -6,25 +7,11 @@ export function formatAverageStars(value: number): string {
}
export function formatRatingDate(dateStr: string): string {
- const d = new Date(dateStr)
- if (Number.isNaN(d.getTime())) return dateStr || "unassigned"
- return d.toLocaleDateString(undefined, {
- year: "numeric",
- month: "short",
- day: "numeric",
- })
+ return formatAppDate(dateStr, dateStr || "unassigned")
}
export function formatRatingDateTime(dateStr: string): string {
- const d = new Date(dateStr)
- if (Number.isNaN(d.getTime())) return dateStr || "unassigned"
- return d.toLocaleString(undefined, {
- year: "numeric",
- month: "short",
- day: "numeric",
- hour: "2-digit",
- minute: "2-digit",
- })
+ return formatAppDateTime(dateStr, dateStr || "unassigned")
}
export function targetTypeLabel(type: RatingTargetType): string {
diff --git a/src/lib/subscriptionPlans.ts b/src/lib/subscriptionPlans.ts
index 516dcf2..20a2cc0 100644
--- a/src/lib/subscriptionPlans.ts
+++ b/src/lib/subscriptionPlans.ts
@@ -4,6 +4,7 @@ import type {
SubscriptionPlanDurationUnit,
UpdateSubscriptionPlanPayload,
} from "../types/subscription.types"
+import { formatAppDate } from "./datetime"
export const SUBSCRIPTION_PLAN_CATEGORIES: {
value: SubscriptionPlanCategory
@@ -78,13 +79,7 @@ export function formatPlanCategory(category: string): string {
}
export function formatPlanCreatedAt(iso: string): string {
- const d = new Date(iso)
- if (Number.isNaN(d.getTime())) return iso
- return d.toLocaleDateString(undefined, {
- year: "numeric",
- month: "short",
- day: "numeric",
- })
+ return formatAppDate(iso, iso)
}
export function planToUpdatePayload(
diff --git a/src/lib/teamInvitation.ts b/src/lib/teamInvitation.ts
index d272e9f..44dd6f3 100644
--- a/src/lib/teamInvitation.ts
+++ b/src/lib/teamInvitation.ts
@@ -1,4 +1,5 @@
import type { VerifyInvitationData } from "../types/teamInvitation.types"
+import { formatAppDateTime } from "./datetime"
export function formatTeamRoleLabel(role: string | undefined): string {
if (!role) return "unassigned"
@@ -9,7 +10,7 @@ export function formatInvitationExpiry(raw: string | undefined): string | null {
if (!raw) return null
const d = new Date(raw)
if (Number.isNaN(d.getTime())) return raw
- return d.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" })
+ return formatAppDateTime(raw)
}
/** User-facing title when verify returns valid: false. */
diff --git a/src/pages/DashboardPage.tsx b/src/pages/DashboardPage.tsx
index b0ec911..f2b175a 100644
--- a/src/pages/DashboardPage.tsx
+++ b/src/pages/DashboardPage.tsx
@@ -48,6 +48,7 @@ import { useEffect, useState, type ReactNode } from "react"
import { Link } from "react-router-dom"
import { AnalyticsTimeRangeFilter, getDashboardFilterLabel } from "../components/analytics/AnalyticsTimeRangeFilter"
import {
+ formatAnalyticsSeriesDate,
getPrimaryQuestionTypeSummary,
getSeriesPeriodLabel,
getSubscriptionMetrics,
@@ -76,8 +77,7 @@ function DashboardSectionTitle({ children }: { children: ReactNode }) {
}
function formatDate(dateStr: string) {
- const d = new Date(dateStr)
- return d.toLocaleDateString("en-US", { month: "short", day: "numeric" })
+ return formatAnalyticsSeriesDate(dateStr)
}
const DEFAULT_FILTERS: DashboardFilters = { mode: "all_time" }
@@ -465,7 +465,7 @@ export function DashboardPage() {
Revenue & subscriptions
-
+
("")
const [planCategoryFilter, setPlanCategoryFilter] = useState("")
const [currencyFilter, setCurrencyFilter] = useState("")
+ const [dateFrom, setDateFrom] = useState("")
+ const [dateTo, setDateTo] = useState("")
const [selected, setSelected] = useState(null)
const listFilters: PaymentListFilters = {
@@ -150,10 +155,20 @@ export function PaymentsPage() {
provider: providerFilter,
planCategory: planCategoryFilter,
currency: currencyFilter,
+ dateFrom,
+ dateTo,
}
const exportParams = useMemo(
- () => paymentListFiltersToExportQuery(listFilters),
+ () =>
+ paymentListFiltersToExportQuery({
+ status: listFilters.status || undefined,
+ provider: listFilters.provider || undefined,
+ planCategory: listFilters.planCategory || undefined,
+ currency: listFilters.currency || undefined,
+ dateFrom: listFilters.dateFrom || undefined,
+ dateTo: listFilters.dateTo || undefined,
+ }),
[listFilters],
)
@@ -162,6 +177,8 @@ export function PaymentsPage() {
{ value: providerFilter },
{ value: planCategoryFilter },
{ value: currencyFilter },
+ { value: dateFrom },
+ { value: dateTo },
])
const hasActiveFilters = activeFilterCount > 0 || Boolean(searchQuery.trim())
@@ -188,7 +205,16 @@ export function PaymentsPage() {
useEffect(() => {
setPage(1)
- }, [searchQuery, statusFilter, providerFilter, planCategoryFilter, currencyFilter, pageSize])
+ }, [
+ searchQuery,
+ statusFilter,
+ providerFilter,
+ planCategoryFilter,
+ currencyFilter,
+ dateFrom,
+ dateTo,
+ pageSize,
+ ])
const filteredPayments = useMemo(() => {
return payments.filter((payment) => {
@@ -206,6 +232,7 @@ export function PaymentsPage() {
) {
return false
}
+ if (!paymentMatchesDateRange(payment, dateFrom, dateTo)) return false
return paymentMatchesSearch(payment, searchQuery)
})
}, [
@@ -214,6 +241,8 @@ export function PaymentsPage() {
providerFilter,
planCategoryFilter,
currencyFilter,
+ dateFrom,
+ dateTo,
searchQuery,
])
@@ -250,6 +279,8 @@ export function PaymentsPage() {
setProviderFilter("")
setPlanCategoryFilter("")
setCurrencyFilter("")
+ setDateFrom("")
+ setDateTo("")
setSearchQuery("")
setPage(1)
}
@@ -438,6 +469,45 @@ export function PaymentsPage() {
))}
+
+
+
+ setDateFrom(e.target.value)}
+ disabled={loading}
+ className="h-9 rounded-[6px] text-sm"
+ />
+
+
+
+ setDateTo(e.target.value)}
+ disabled={loading}
+ className="h-9 rounded-[6px] text-sm"
+ />
+
+
+ Dates use EAT (Africa/Addis_Ababa)
+
+
{loading ? (
diff --git a/src/types/analytics.types.ts b/src/types/analytics.types.ts
index f754a78..72f51d9 100644
--- a/src/types/analytics.types.ts
+++ b/src/types/analytics.types.ts
@@ -180,6 +180,7 @@ export type DashboardDateFilterMode = "all_time" | "year" | "year_month" | "cust
export interface DashboardDateFilter {
mode: DashboardDateFilterMode
+ timezone?: string
year?: number
month?: number
from?: string
@@ -189,6 +190,7 @@ export interface DashboardDateFilter {
series_start?: string
series_end?: string
ref_date?: string
+ payment_method?: string
}
export type DashboardFilterMode = DashboardDateFilterMode
@@ -199,6 +201,8 @@ export interface DashboardFilters {
month?: number
from?: string
to?: string
+ /** Optional payment/revenue filter (e.g. CHAPA, ARIFPAY, ADMIN_GRANT). */
+ payment_method?: string
}
export interface DashboardData {
diff --git a/src/types/payment.types.ts b/src/types/payment.types.ts
index ccf0737..e585311 100644
--- a/src/types/payment.types.ts
+++ b/src/types/payment.types.ts
@@ -63,6 +63,14 @@ export interface GetPaymentsParams {
currency?: string
/** Partial match on session_id, nonce, or transaction_id. */
reference?: string
+ /** Inclusive lower bound on created_at (RFC3339 or YYYY-MM-DD). */
+ created_from?: string
+ /** Exclusive upper bound on created_at (RFC3339 or YYYY-MM-DD). */
+ created_to?: string
+ /** Inclusive lower bound on paid_at (RFC3339 or YYYY-MM-DD). */
+ paid_from?: string
+ /** Exclusive upper bound on paid_at (RFC3339 or YYYY-MM-DD). */
+ paid_to?: string
limit?: number
offset?: number
}