import Cookies from "js-cookie"; type CookieOptions = NonNullable[2]>; /** * Freight's own active-position cookie. * * Smart Office is a separate app on the same IAM and it also writes a cookie * named `current-position-id` — but it stores `position.id` where freight * stores `employeePositionId`. The two are not interchangeable, so on a shared * domain each app's login silently overwrote the other's desk selection and the * loser fell back to `positions[0]`. Freight keeps its own cookie name so both * can hold a selection at once. */ export const POSITION_COOKIE = "freight-current-position-id"; /** * The pre-rename, shared-with-Smart-Office name. Still read so a session that * is live across the deploy keeps its desk, and cleared on every write so the * colliding cookie does not linger. */ const LEGACY_POSITION_COOKIE = "current-position-id"; /** The active `employeePositionId`, or undefined when no desk is selected. */ export const getPositionCookie = (): string | undefined => Cookies.get(POSITION_COOKIE) ?? Cookies.get(LEGACY_POSITION_COOKIE); export const setPositionCookie = ( value: string, options?: CookieOptions, ): void => { Cookies.set(POSITION_COOKIE, value, options); Cookies.remove(LEGACY_POSITION_COOKIE); }; export const clearPositionCookie = (): void => { Cookies.remove(POSITION_COOKIE); Cookies.remove(LEGACY_POSITION_COOKIE); };