mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 22:25:42 +00:00
fix(backoffice): stop sharing the position cookie with Smart Office
Both apps wrote a cookie named `current-position-id` but stored different ids in it — freight the `employeePositionId`, Smart Office the `position.id`. On a shared domain each login overwrote the other's desk selection, and the loser silently fell back to the first position. Freight now uses `freight-current-position-id` through a small helper that reads the old name once, so a session live across the deploy keeps its desk, and clears it on every write. Also mounts the position switcher in the freight dashboard header. It only existed under /performance-management, so on every other page a two-desk user had no way to switch and was stuck on whatever `useAuthUser` defaulted to. It now hides below two positions rather than showing a one-option dropdown to the single-desk majority. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,10 @@ import {
|
||||
TooltipTrigger,
|
||||
} from "@/shared/common/ui/tooltip";
|
||||
import { PositionName } from "../dto/delegation/delegationDto";
|
||||
import {
|
||||
getPositionCookie,
|
||||
setPositionCookie,
|
||||
} from "@/shared/utils/positionCookie";
|
||||
interface BasePosition {
|
||||
id: string;
|
||||
employeePositionId: string;
|
||||
@@ -55,7 +59,7 @@ export const PositionSelect = () => {
|
||||
? unFilteredUserDetails.employee.flatMap((emp) => emp?.positions ?? [])
|
||||
: [];
|
||||
const selectablePositions = allPositions ?? [];
|
||||
const currentPositionCookie = Cookies.get("current-position-id");
|
||||
const currentPositionCookie = getPositionCookie();
|
||||
const delegatedPositionCookie = Cookies.get("delegatedPositionId");
|
||||
const activePositionId =
|
||||
selectedPositionId || currentPositionCookie || delegatedPositionCookie;
|
||||
@@ -85,15 +89,18 @@ export const PositionSelect = () => {
|
||||
// (useAuthUser already self-heals this cookie for the same reason.)
|
||||
if (
|
||||
currentPosition.employeePositionId &&
|
||||
Cookies.get("current-position-id") !== currentPosition.employeePositionId
|
||||
getPositionCookie() !== currentPosition.employeePositionId
|
||||
) {
|
||||
Cookies.set("current-position-id", currentPosition.employeePositionId);
|
||||
setPositionCookie(currentPosition.employeePositionId);
|
||||
}
|
||||
|
||||
applyDelegationCookie(currentPosition);
|
||||
}, [currentPosition, isLoading, selectedPositionId, setSelectedPositionId]);
|
||||
|
||||
if (isLoading || selectablePositions.length === 0) return null;
|
||||
// Below two desks there is nothing to switch between. This now sits in the
|
||||
// main freight header, so a one-option dropdown would show for every
|
||||
// single-desk staff member.
|
||||
if (isLoading || selectablePositions.length < 2) return null;
|
||||
|
||||
const handleChange = (value: string) => {
|
||||
const selected = selectablePositions.find((pos) => pos.id === value);
|
||||
@@ -102,7 +109,7 @@ export const PositionSelect = () => {
|
||||
// dropdown's own value is position.id, which the API does not match on.
|
||||
setSelectedPositionId(selected?.employeePositionId ?? value);
|
||||
if (selected?.employeePositionId) {
|
||||
Cookies.set("current-position-id", selected.employeePositionId);
|
||||
setPositionCookie(selected.employeePositionId);
|
||||
}
|
||||
applyDelegationCookie(selected);
|
||||
|
||||
|
||||
@@ -12,9 +12,11 @@ import {
|
||||
} from "@/record-management/dto/userRecords/teetersAndSignatureDto";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
import { getPositionCookie } from "@/shared/utils/positionCookie";
|
||||
|
||||
export const withHeaders = (passPosId: boolean = false) => {
|
||||
const unitId = Cookies.get("unit-id");
|
||||
const positionId = Cookies.get("current-position-id");
|
||||
const positionId = getPositionCookie();
|
||||
const projectId = Cookies.get("current-project-id");
|
||||
const delegatedPositionId = Cookies.get("delegatedPositionId");
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
import { getPositionCookie } from "@/shared/utils/positionCookie";
|
||||
|
||||
export const withHeaders = () => {
|
||||
const tenantKey = Cookies.get("tenant-key");
|
||||
const unitId = Cookies.get("unit-id");
|
||||
const positionId = Cookies.get("current-position-id");
|
||||
const positionId = getPositionCookie();
|
||||
const projectId = Cookies.get("current-project-id");
|
||||
const delegatedPositionId = Cookies.get("delegatedPositionId");
|
||||
const headers: Record<string, string> = {};
|
||||
|
||||
Reference in New Issue
Block a user