Skip to main content

Pause Windows

This package contains functions for retrieving, creating, and deleting pause windows from the public api. There are two types of pause windows - account and person. When an account pause window is active, all of the user/account's cadence actions with due dates that fall within the pause window will be modified so that their due date is outside of the pause window. Additional information about account pause windows can be found here.

Person pause windows affect only the actions related to an individual person that is currently out of office.

Pause Statuses

Every pause window will have a 'current_state'. Only windows that are currently 'paused' or 'pausing' are considered active pause windows.

type PAUSE_STATUS =
| 'paused'
| 'pausing'
| 'scheduled'
| 'resuming'
| 'completed'
| 'failed'
| 'canceled'

Get Account Pause Cadence Window

Calling getAccountPauseCadenceWindow with no arguments will return an array with all account pause windows.

There will only ever be one account pause window at a time.

import { getAccountPauseCadenceWindow } from '@shared/pause-window'

async function workWithPauseWindow() {
const { data } = await getAccountPauseCadenceWindow()

console.log(data[0])
}

Create Account Pause Cadence Window

In order to create an account pause cadence window, a start_at and resume_at date will need to be provided.

A successful response will return the newly created pause window.

If the pause window starts immediately - the process of pausing will begin and the status of the pause window will be 'pausing' until all action due dates have been successfully updated.

import { createAccountPauseCadenceWindow } from '@shared/pause-window'

async function workWithPauseWindow() {
const pauseDate = DateTime.local().plus({ days: 12 }).toISODate()
const resumeDate = DateTime.local().plus({ days: 15 }).toISODate()
const { data, error, errors } = await createAccountPauseCadenceWindow({
start_at: pauseDate,
resume_at: resumeDate,
})

console.log(data)
}

Use Account Pause Cadence Window

No arguments are needed for the useAccountPauseWindow hook. If the pause window is already cached - a request will not be made to the api.

import { useAccountPauseWindow } from '@shared/pause-window'

async function workWithPauseWindow() {
const { data } = useAccountPauseWindow()

const pauseWindow = data?.data?.length ? data.data[0] : null

console.log(pauseWindow)
}

Invalidate Account Pause Cadence Window

No arguments are needed for the invalidateAccountPauseWindow function. Invalidating the account pause window removes the current cached data. The next time the useAccountPauseWindow hook is utilized, a network request will be made to fetch the pause window and cache it.

import { invalidateAccountPauseWindow } from '@shared/pause-window'

invalidateAccountPauseWindow()

Get Person Pause Cadence Window

A person id is required to fetch pause windows for that person.

There can only be one pause window per person.

import { getPersonPauseWindow } from '@shared/pause-window'

async function workWithPauseWindow() {
const personID = 1
const { data } = await getPersonPauseWindow(personID)

console.log(data[0])
}

Create Person Pause Cadence Window

In order to create an person pause window, a person_id and resume_at date will need to be provided.

A successful response will return the newly created pause window.

The pause window will start immediately.

import { createPersonPauseWindow } from '@shared/pause-window'

async function workWithPauseWindow() {
const personID = 1
const resumeDate = DateTime.local().plus({ days: 15 }).toISODate()
const { data, error, errors } = await createPersonPauseWindow({
person_id: personID,
resume_at: resumeDate,
})

console.log(data)
}

Use Person Pause Cadence Window

A person id is required for the usePersonPauseWindow hook. If the pause window is already cached - a request will not be made to the api.

import { usePersonPauseWindow } from '@shared/pause-window'

async function workWithPauseWindow() {
const personID = 1
const { data } = usePersonPauseWindow(personID)

const pauseWindow = data?.data?.length ? data.data[0] : null

console.log(pauseWindow)
}

Invalidate Person Pause Cadence Window

A person id is required for the invalidatePersonPauseWindow function. Invalidating the person pause window removes the current cached data. The next time the usePersonPauseWindow hook is utilized, a network request will be made to fetch the pause window and cache it.

import { invalidatePersonPauseWindow } from '@shared/pause-window'

const personID = 1
invalidatePersonPauseWindow(personID)

Delete Pause Cadence Window

A pause window id is a required argument for the deleteAccountPauseWindow and the deletePersonPauseWindow functions.

import {
deleteAccountPauseWindow,
deletePersonPauseWindow,
} from '@shared/pause-window'

// Potential response types:

const successResponse = {
ok: true,
bodyUsed: false,
redirected: false,
status: 204,
statusText: 'No Content',
type: 'cors',
url: 'https://api.devsalesloft.com/v2/cadence_pause_windows/1',
}

// In order to delete a pause window successfully, it must be present.
const errorResponse = {
data: { error: 'Not found' },
ok: false,
bodyUsed: false,
redirected: false,
status: 404,
statusText: 'Not Found',
type: 'cors',
url: 'https://api.devsalesloft.com/v2/cadence_pause_windows/1',
}

// In order to delete a pause window successfully, it cannot have a current_state of 'pausing'
const errorsResponse = {
data: {
errors: { id: ["can't be destroyed when pausing"] },
},
ok: false,
bodyUsed: false,
redirected: false,
status: 422,
statusText: 'Unprocessable Entity',
type: 'cors',
url: 'https://api.devsalesloft.com/v2/cadence_pause_windows/1',
}

async function workWithAccountPauseWindow() {
const response = await deleteAccountPauseWindow(1)

console.log(response)
}

async function workWithPersonPauseWindow() {
const response = await deletePersonPauseWindow(1)

console.log(response)
}