feat(MED-105): log opening analysis results from orders view

This commit is contained in:
2025-08-28 12:35:30 +03:00
parent b4985afdf0
commit 2ffad84100
5 changed files with 43 additions and 8 deletions

View File

@@ -0,0 +1,18 @@
'use server';
import { createPageViewLog, PageViewAction } from "~/lib/services/audit/pageView.service";
import { loadCurrentUserAccount } from "../../_lib/server/load-user-account";
export async function logAnalysisResultsNavigateAction(analysisOrderId: string) {
const account = await loadCurrentUserAccount();
if (!account) {
throw new Error('Account not found');
}
await createPageViewLog({
accountId: account.id,
action: PageViewAction.VIEW_ANALYSIS_RESULTS_FROM_ORDER,
extraData: {
analysisOrderId,
},
});
}

View File

@@ -1,3 +1,5 @@
'use client';
import { Trans } from '@kit/ui/trans'; import { Trans } from '@kit/ui/trans';
import { import {
Table, Table,
@@ -10,18 +12,26 @@ import {
import { StoreOrderLineItem } from "@medusajs/types"; import { StoreOrderLineItem } from "@medusajs/types";
import { AnalysisOrder } from '~/lib/services/order.service'; import { AnalysisOrder } from '~/lib/services/order.service';
import { formatDate } from 'date-fns'; import { formatDate } from 'date-fns';
import Link from 'next/link';
import { Eye } from 'lucide-react'; import { Eye } from 'lucide-react';
import { useRouter } from 'next/navigation';
import { logAnalysisResultsNavigateAction } from './actions';
export default function OrderItemsTable({ items, title, analysisOrder }: { export default function OrderItemsTable({ items, title, analysisOrder }: {
items: StoreOrderLineItem[]; items: StoreOrderLineItem[];
title: string; title: string;
analysisOrder: AnalysisOrder; analysisOrder: AnalysisOrder;
}) { }) {
const router = useRouter();
if (!items || items.length === 0) { if (!items || items.length === 0) {
return null; return null;
} }
const openAnalysisResults = async () => {
await logAnalysisResultsNavigateAction(analysisOrder.medusa_order_id);
router.push(`/home/analysis-results`);
}
return ( return (
<Table className="rounded-lg border border-separate"> <Table className="rounded-lg border border-separate">
<TableHeader className="text-ui-fg-subtle txt-medium-plus"> <TableHeader className="text-ui-fg-subtle txt-medium-plus">
@@ -60,13 +70,12 @@ export default function OrderItemsTable({ items, title, analysisOrder }: {
<TableCell className="text-right px-6"> <TableCell className="text-right px-6">
<span className="flex gap-x-1 justify-end w-[30px]"> <span className="flex gap-x-1 justify-end w-[30px]">
<Link href={`/home/analysis-results`} className="flex items-center justify-between text-small-regular"> <button
<button className="flex gap-x-1 text-ui-fg-subtle hover:text-ui-fg-base cursor-pointer "
className="flex gap-x-1 text-ui-fg-subtle hover:text-ui-fg-base cursor-pointer" onClick={openAnalysisResults}
> >
<Eye /> <Eye />
</button> </button>
</Link>
</span> </span>
</TableCell> </TableCell>
</TableRow> </TableRow>

View File

@@ -2,6 +2,7 @@ import { getSupabaseServerClient } from '@kit/supabase/server-client';
export enum PageViewAction { export enum PageViewAction {
VIEW_ANALYSIS_RESULTS = 'VIEW_ANALYSIS_RESULTS', VIEW_ANALYSIS_RESULTS = 'VIEW_ANALYSIS_RESULTS',
VIEW_ANALYSIS_RESULTS_FROM_ORDER = 'VIEW_ANALYSIS_RESULTS_FROM_ORDER',
REGISTRATION_SUCCESS = 'REGISTRATION_SUCCESS', REGISTRATION_SUCCESS = 'REGISTRATION_SUCCESS',
VIEW_ORDER_ANALYSIS = 'VIEW_ORDER_ANALYSIS', VIEW_ORDER_ANALYSIS = 'VIEW_ORDER_ANALYSIS',
VIEW_TEAM_ACCOUNT_DASHBOARD = 'VIEW_TEAM_ACCOUNT_DASHBOARD', VIEW_TEAM_ACCOUNT_DASHBOARD = 'VIEW_TEAM_ACCOUNT_DASHBOARD',
@@ -10,9 +11,11 @@ export enum PageViewAction {
export const createPageViewLog = async ({ export const createPageViewLog = async ({
accountId, accountId,
action, action,
extraData,
}: { }: {
accountId: string; accountId: string;
action: PageViewAction; action: PageViewAction;
extraData?: Record<string, any>;
}) => { }) => {
try { try {
const supabase = getSupabaseServerClient(); const supabase = getSupabaseServerClient();
@@ -34,6 +37,7 @@ export const createPageViewLog = async ({
account_id: accountId, account_id: accountId,
action, action,
changed_by: user.id, changed_by: user.id,
extra_data: extraData,
}) })
.throwOnError(); .throwOnError();
} catch (error) { } catch (error) {

View File

@@ -115,6 +115,7 @@ export type Database = {
changed_by: string changed_by: string
created_at: string created_at: string
id: number id: number
extra_data?: Json | null
} }
Insert: { Insert: {
account_id: string account_id: string
@@ -122,6 +123,7 @@ export type Database = {
changed_by: string changed_by: string
created_at?: string created_at?: string
id?: number id?: number
extra_data?: Json | null
} }
Update: { Update: {
account_id?: string account_id?: string
@@ -129,6 +131,7 @@ export type Database = {
changed_by?: string changed_by?: string
created_at?: string created_at?: string
id?: number id?: number
extra_data?: Json | null
} }
Relationships: [] Relationships: []
} }

View File

@@ -0,0 +1 @@
ALTER TABLE audit.page_views ADD COLUMN extra_data JSONB;