Files
dashboards/apps/business/src/services/rollCallService.ts
T
Alireza HassaniandCursor c4e846564e Add roll-call Start/Stop UX to business and customer dashboards.
Owners/admins can run timed work days, manage tasks in a modal, and stop from the FAB or row control.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-07 13:21:07 +03:30

103 lines
2.3 KiB
TypeScript

import { apiRequest } from '../lib/api'
import { getActiveBusinessId } from '../lib/businessContext'
export interface RollCallTask {
id: string
title: string
sortOrder: number
}
export interface RollCall {
id: string
businessId: string
userId: string
workDate: string
startTime: string
endTime: string
workingMinutes: number
taskCount: number
tasks: RollCallTask[]
createdAt: string
updatedAt: string
}
export interface RollCallSummary {
totalDays: number
totalWorkingMinutes: number
totalTasks: number
}
export interface RollCallsListResponse {
items: RollCall[]
total: number
page: number
pageSize: number
summary: RollCallSummary
}
export interface ListRollCallsParams {
dateFrom?: string
dateTo?: string
page?: number
pageSize?: number
}
export interface RollCallInput {
workDate: string
startTime: string
endTime: string
tasks?: { title: string }[]
}
export type RollCallPatch = Partial<RollCallInput>
function businessPath(suffix = '') {
const businessId = getActiveBusinessId()
if (!businessId) {
throw new Error('No active business selected. Please sign in again.')
}
return `/businesses/${businessId}/roll-calls${suffix}`
}
export async function listRollCalls(
params: ListRollCallsParams = {},
signal?: AbortSignal,
) {
const q = new URLSearchParams()
if (params.dateFrom) q.set('dateFrom', params.dateFrom)
if (params.dateTo) q.set('dateTo', params.dateTo)
if (params.page !== undefined) q.set('page', String(params.page))
if (params.pageSize !== undefined) q.set('pageSize', String(params.pageSize))
const query = q.toString()
return apiRequest<RollCallsListResponse>(
`${businessPath()}${query ? `?${query}` : ''}`,
{ auth: true, signal },
)
}
export async function createRollCall(input: RollCallInput) {
return apiRequest<{ rollCall: RollCall; message: string }>(businessPath(), {
method: 'POST',
auth: true,
body: input,
})
}
export async function updateRollCall(rollCallId: string, input: RollCallPatch) {
return apiRequest<{ rollCall: RollCall; message: string }>(
businessPath(`/${rollCallId}`),
{
method: 'PATCH',
auth: true,
body: input,
},
)
}
export async function removeRollCall(rollCallId: string) {
return apiRequest<{ message: string }>(businessPath(`/${rollCallId}`), {
method: 'DELETE',
auth: true,
})
}