mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
fix
This commit is contained in:
@@ -25,6 +25,22 @@ interface BasePosition {
|
|||||||
isDelegate: boolean;
|
isDelegate: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `x-delegated-position-id` names the DELEGATOR's position and the API matches
|
||||||
|
* it against `position.id`. This used to be set for every selection, carrying
|
||||||
|
* `employeePositionId` — so it matched nothing, and because the API resolves
|
||||||
|
* the delegation header *before* the current-position one, it swallowed the
|
||||||
|
* whole selection: every request ran as the employee's first position no
|
||||||
|
* matter what the picker said. Only a genuine delegate carries it.
|
||||||
|
*/
|
||||||
|
const applyDelegationCookie = (position?: BasePosition | null) => {
|
||||||
|
if (position?.isDelegate && position.id) {
|
||||||
|
Cookies.set("delegatedPositionId", position.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Cookies.remove("delegatedPositionId");
|
||||||
|
};
|
||||||
|
|
||||||
export const PositionSelect = () => {
|
export const PositionSelect = () => {
|
||||||
const {
|
const {
|
||||||
unFilteredUserDetails,
|
unFilteredUserDetails,
|
||||||
@@ -63,26 +79,32 @@ export const PositionSelect = () => {
|
|||||||
setSelectedPositionId(currentPosition.employeePositionId);
|
setSelectedPositionId(currentPosition.employeePositionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cookies.get("current-position-id") !== currentPosition.id) {
|
// The API matches x-current-position-id against employeePositionId, NOT
|
||||||
Cookies.set("current-position-id", currentPosition.id);
|
// position.id — writing the latter never matches, so the guard silently
|
||||||
}
|
// falls back to the employee's first position and the picker does nothing.
|
||||||
|
// (useAuthUser already self-heals this cookie for the same reason.)
|
||||||
if (
|
if (
|
||||||
currentPosition.employeePositionId &&
|
currentPosition.employeePositionId &&
|
||||||
Cookies.get("delegatedPositionId") !== currentPosition.employeePositionId
|
Cookies.get("current-position-id") !== currentPosition.employeePositionId
|
||||||
) {
|
) {
|
||||||
Cookies.set("delegatedPositionId", currentPosition.employeePositionId);
|
Cookies.set("current-position-id", currentPosition.employeePositionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyDelegationCookie(currentPosition);
|
||||||
}, [currentPosition, isLoading, selectedPositionId, setSelectedPositionId]);
|
}, [currentPosition, isLoading, selectedPositionId, setSelectedPositionId]);
|
||||||
|
|
||||||
if (isLoading || selectablePositions.length === 0) return null;
|
if (isLoading || selectablePositions.length === 0) return null;
|
||||||
|
|
||||||
const handleChange = (value: string) => {
|
const handleChange = (value: string) => {
|
||||||
setSelectedPositionId(value);
|
|
||||||
const selected = selectablePositions.find((pos) => pos.id === value);
|
const selected = selectablePositions.find((pos) => pos.id === value);
|
||||||
|
|
||||||
Cookies.set("current-position-id", value);
|
// Both the picker state and the cookie key off employeePositionId — the
|
||||||
Cookies.set("delegatedPositionId", selected?.employeePositionId || "");
|
// 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);
|
||||||
|
}
|
||||||
|
applyDelegationCookie(selected);
|
||||||
|
|
||||||
// Invalidate relevant queries
|
// Invalidate relevant queries
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user