diff --git a/web/src/app/rotations/util.test.ts b/web/src/app/rotations/util.test.ts index daed35693f..2d7a5fbf67 100644 --- a/web/src/app/rotations/util.test.ts +++ b/web/src/app/rotations/util.test.ts @@ -1,6 +1,10 @@ -import { calcNewActiveIndex, handoffSummary, reorderList } from './util' +import { + calcNewActiveIndex, + handoffSummary, + HandoffSummaryInput, + reorderList, +} from './util' import { Settings, Zone } from 'luxon' -import { CreateRotationInput } from '../../schema' let oldZone: Zone beforeAll(() => { @@ -45,7 +49,7 @@ describe('calcNewActiveIndex', () => { }) describe('handoffSummary', () => { - const check = (rotation: Partial, exp: string): void => { + const check = (rotation: HandoffSummaryInput, exp: string): void => { expect(handoffSummary(rotation)).toBe(exp) } diff --git a/web/src/app/rotations/util.js b/web/src/app/rotations/util.tsx similarity index 81% rename from web/src/app/rotations/util.js rename to web/src/app/rotations/util.tsx index e90460c271..ffd914dc05 100644 --- a/web/src/app/rotations/util.js +++ b/web/src/app/rotations/util.tsx @@ -1,8 +1,13 @@ import { DateTime } from 'luxon' +import { CreateRotationInput, RotationType } from '../../schema' // calcNewActiveIndex returns the newActiveIndex for a swap operation // -1 will be returned if there was no change -export function calcNewActiveIndex(oldActiveIndex, oldIndex, newIndex) { +export function calcNewActiveIndex( + oldActiveIndex: number, + oldIndex: number, + newIndex: number, +): number { if (oldIndex === newIndex) { return -1 } @@ -21,7 +26,7 @@ export function calcNewActiveIndex(oldActiveIndex, oldIndex, newIndex) { } // formatTime returns the formatted time with the timezone (if different than local timezone) -export function formatTime(time, tz) { +export function formatTime(time: string, tz: string): string { const schedTime = DateTime.fromISO(time, { zone: tz }).toLocaleString( DateTime.TIME_SIMPLE, ) @@ -36,7 +41,7 @@ export function formatTime(time, tz) { } // formatDay returns the day given a time and timezone -export function formatDay(time, tz) { +export function formatDay(time: string, tz: string): string { const day = DateTime.fromISO(time, { zone: tz }).weekdayLong const localDay = DateTime.fromISO(time).weekdayLong @@ -49,7 +54,11 @@ export function formatDay(time, tz) { // formatWeeklySummary returns the summary for a weekly rotation // taking into consideration extra formatting needed if timezone does not match with local timezone -export function formatWeeklySummary(shiftLength, start, tz) { +export function formatWeeklySummary( + shiftLength: number, + start: string, + tz: string, +): string { let details = '' const day = DateTime.fromISO(start, { zone: tz }).weekdayLong const schedTime = DateTime.fromISO(start, { zone: tz }).toLocaleString( @@ -71,8 +80,14 @@ export function formatWeeklySummary(shiftLength, start, tz) { return details } +export interface HandoffSummaryInput extends Partial { + start: string + shiftLength: number + type: RotationType +} + // handoffSummary returns the summary description for the rotation -export function handoffSummary(rotation) { +export function handoffSummary(rotation: HandoffSummaryInput): string { const tz = rotation.timeZone if (!tz) return 'Loading handoff information...' @@ -106,7 +121,11 @@ export function handoffSummary(rotation) { // reorderList will move an item from the oldIndex to the newIndex, preserving order // returning the result as a new array. -export function reorderList(_items, oldIndex, newIndex) { +export function reorderList( + _items: unknown[], + oldIndex: number, + newIndex: number, +): unknown[] { const items = _items.slice() items.splice(oldIndex, 1) // remove 1 element from oldIndex position items.splice(newIndex, 0, _items[oldIndex]) // add dest to newIndex position