Skip to main content

Tasks

This package contains functions and components for fetching, updating, and deleting tasks.

Get Tasks

Tasks are requested from the public api. We can fetch four types of tasks: ['email', 'call', 'general', 'integration']. We default to fetching 25 tasks per page, filtered by the current_state of 'scheduled', and sorted by due date.

The documentation for this endpoint can be found here.

import { getTasks } from '@shared/tasks'

export const useInfiniteTasks = ({ user }: { user: User }) =>
useInfiniteQuery(
'apps.workflow.tasks',
({ pageParam: page }) => getTasks({ page, user: user.id }),
{
getNextPageParam: (lastPage) => {
return lastPage?.metadata?.paging?.next_page ?? undefined
},
}
)

Update Task

The documentation for this endpoint can be found here.

The supported params are as follows:

interface TaskUpdateParams {
id: number
subject?: string
person_id?: number
task_type?: string
due_date?: string
due_at?: string | null
current_state?: string
user_id?: number
remind_at?: string | null
completed_at?: string | null
completed_by_user_id?: number | null
description?: string | null
is_logged?: boolean
}

Delete Task

The deleteTask endpoint only requires a task id.

Search and Global Search Services

The search services allow you to search for either a person or account. The query param is required for the search service. Global search detects if the query param is a phonenumber and updates the params accordingly.

The default params are as follows:

const defaultValues = {
query: '',
page: 1, // must be >= 1
per_page: 10, // must be >= 1
types: ['person', 'account'], // ['person', 'account'] || ['person'] || ['account']
search_type: '', // '' || 'fuzzy' || 'phone'
skip_response_metadata: true, // returns response metadata (pagination) data when set to false
}

The response type is as follows:

interface SearchResponse {
data?: {
search_results?: { data: object }[]
}
}

Task Modal

The task modal component requires the following properties in order to be rendered:

export interface TaskModalProps {
isOpen: boolean
close: () => void
title: string
personObj?: Person
task?: Task
editMode: boolean
onSaveSuccess?: () => void
isDashboardPage?: boolean
}

The task modal can be used either to create or edit a task.