Overview
Sampling point actions provide CRUD operations for sampling points and analytics endpoints for dashboard metrics. All functions are located in src/app/actions/sampling-points.ts.
Sampling Point Operations
getSamplingPointsService
Retrieves a paginated list of sampling points with optional filtering.
Query parameters for filtering and pagination Items per page (default: 10)
Search term for filtering sampling points
Array of sampling point objects
Pagination metadata Total number of sampling points
Whether there is a next page
Whether there is a previous page
Server Component
With Search
Error Handling
import { getSamplingPointsService } from "@/app/actions" ;
export default async function SamplingPointsPage ({ searchParams }) {
const params = await searchParams ;
const page = parseInt ( String ( params ?. page ?? 1 ), 10 );
const limit = parseInt ( String ( params ?. limit ?? 10 ), 10 );
const search = typeof params ?. search === "string" ? params . search : "" ;
const { data : samplingPoints , meta } = await getSamplingPointsService ({
page ,
limit ,
search
});
return < SamplingPointTable data ={ samplingPoints } meta ={ meta } />;
}
On permission errors (403), this function returns an empty data array with zero total instead of throwing an error.
getSamplingPointService
Retrieves a single sampling point by ID.
Unique sampling point identifier
Complete sampling point object with parent asset and assignee details
Basic Usage
With Error Handling
import { getSamplingPointService } from "@/app/actions" ;
const samplingPoint = await getSamplingPointService ( "sp-123" );
console . log ( samplingPoint . name );
console . log ( samplingPoint . parent_asset . name );
console . log ( samplingPoint . status );
console . log ( samplingPoint . assignee ?. first_name );
addSamplingPointService
Creates a new sampling point.
payload
AddSamplingPointPayload
required
Sampling point creation data Sampling point tag/identifier
Standard API response object Whether the operation succeeded
Created sampling point data
Client Component
With Attachments
"use client" ;
import { addSamplingPointService } from "@/app/actions" ;
import { AddSamplingPointPayload } from "@/schema" ;
import { toast } from "sonner" ;
export function AddSamplingPointForm () {
const handleSubmit = async ( data : AddSamplingPointPayload ) => {
const response = await addSamplingPointService ( data );
if ( response . success ) {
toast . success ( "Sampling point added successfully" );
router . push ( "/sampling-points" );
} else {
toast . error ( response . message || "Failed to add sampling point" );
}
};
return < form onSubmit ={ handleSubmit }> ...</ form > ;
}
editSamplingPointService
Updates an existing sampling point.
Sampling point ID to update
payload
AddSamplingPointPayload
required
Updated sampling point data (same structure as addSamplingPointService)
Standard API response object
import { editSamplingPointService } from "@/app/actions" ;
import { toast } from "sonner" ;
const handleUpdate = async (
samplingPointId : string ,
data : AddSamplingPointPayload
) => {
const response = await editSamplingPointService ( samplingPointId , data );
if ( response . success ) {
toast . success ( "Sampling point updated successfully" );
} else {
toast . error ( response . message );
}
};
deleteSamplingPointService
Deletes a sampling point.
Sampling point ID to delete
Standard API response object
import { deleteSamplingPointService } from "@/app/actions" ;
import { toast } from "sonner" ;
const handleDelete = async ( samplingPointId : string ) => {
const response = await deleteSamplingPointService ( samplingPointId );
if ( response . success ) {
toast . success ( "Sampling point deleted successfully" );
} else {
toast . error ( response . message );
}
};
Analytics Operations
getSamplingPointsAnalyticsService
Retrieves sampling point analytics for dashboard metrics.
data
SamplingPointAnalytics | null
Sampling point analytics data or null on error Total number of sampling points
Number of sampling points due
Number of sampling points overdue
import { getSamplingPointsAnalyticsService } from "@/app/actions" ;
export default async function Dashboard () {
const analytics = await getSamplingPointsAnalyticsService ();
if ( ! analytics ) {
return < div > Analytics unavailable </ div > ;
}
return (
< div >
< MetricCard
title = "Total Sampling Points"
value = {analytics. total_sampling_points }
trend = {analytics. total_trend_percentage }
/>
< MetricCard
title = "Due"
value = {analytics. sampling_points_due }
trend = {analytics. due_trend_percentage }
/>
< MetricCard
title = "Overdue"
value = {analytics. sampling_points_overdue }
trend = {analytics. overdue_trend_percentage }
/>
</ div >
);
}
Returns null on permission errors (403) or network issues instead of throwing.
Type Definitions
SamplingPoint
The complete sampling point object includes extensive details about the sampling point, parent asset, assignee, and sampling route. Key fields:
interface SamplingPoint {
id : string ;
name : string ;
tag : string ;
parent_asset : {
id : string ;
name : string ;
tag : string ;
type : string ;
// ... additional asset fields
};
circuit_type : string ;
component_type : string ;
sample_frequency : string ;
system_capacity : string ;
current_oil_grade : string ;
status : string ;
severity : string ;
sampling_port_type : string ;
sampling_port_location : string ;
lab_destination : string ;
sampling_volume : string ;
special_instructions : string ;
last_sample_date : number ;
effective_date : number ;
next_due_date : number ;
assignee ?: {
id : string ;
first_name : string ;
last_name : string ;
email : string ;
} | null ;
sampling_route ?: {
id : string ;
name : string ;
description ?: string ;
} | null ;
attachments ?: Array <{
name : string ;
url : string ;
}>;
created_at : number ;
created_at_datetime : string ;
updated_at : number ;
updated_at_datetime : string ;
}
SamplingPointAnalytics
interface SamplingPointAnalytics {
total_sampling_points : number ;
sampling_points_due : number ;
sampling_points_overdue : number ;
total_trend_percentage : number ;
due_trend_percentage : number ;
overdue_trend_percentage : number ;
}
Import from the appropriate locations:
import {
getSamplingPointsService ,
addSamplingPointService ,
editSamplingPointService ,
deleteSamplingPointService ,
getSamplingPointService ,
getSamplingPointsAnalyticsService ,
} from "@/app/actions" ;
import { SamplingPoint , SamplingPointAnalytics } from "@/types" ;
import { AddSamplingPointPayload , ADD_SAMPLING_POINT_SCHEMA } from "@/schema" ;
import { ApiResponse } from "@/app/actions" ;