Skip to content

Fix current user bug #3321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/presentation/AppHeader/AppHeaderMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CircleIcon } from 'src/components/CircleIcon';
import classes from 'src/components/presentation/AppHeader/AppHeaderMenu.module.css';
import { Lang } from 'src/features/language/Lang';
import { useLanguage } from 'src/features/language/useLanguage';
import { useCurrentParty, useInstanceOwnerParty } from 'src/features/party/PartiesProvider';
import { useInstanceOwnerParty, useSelectedParty } from 'src/features/party/PartiesProvider';
import { useProfile } from 'src/features/profile/ProfileProvider';
import { useIsMobile } from 'src/hooks/useDeviceWidths';
import { logoutUrlAltinn } from 'src/utils/urls/urlHelper';
Expand Down Expand Up @@ -85,7 +85,7 @@ export function AppHeaderMenu({ logoColor }: AppHeaderMenuProps) {
*/
function useGetOnBehalfOf() {
const instanceOwnerParty = useInstanceOwnerParty();
const selectedParty = useCurrentParty();
const selectedParty = useSelectedParty();
const userParty = useProfile()?.party;

const onBehalfOfParty = instanceOwnerParty ?? selectedParty;
Expand Down
4 changes: 2 additions & 2 deletions src/components/presentation/BackNavigationButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useAppQueries } from 'src/core/contexts/AppQueriesProvider';
import { useIsProcessing } from 'src/core/contexts/processingContext';
import { Lang } from 'src/features/language/Lang';
import { useLanguage } from 'src/features/language/useLanguage';
import { useCurrentParty } from 'src/features/party/PartiesProvider';
import { useSelectedParty } from 'src/features/party/PartiesProvider';
import { useIsSubformPage, useNavigationParam } from 'src/features/routing/AppRoutingContext';
import { useIsMobile } from 'src/hooks/useDeviceWidths';
import { useNavigatePage } from 'src/hooks/useNavigatePage';
Expand All @@ -20,7 +20,7 @@ import { getMessageBoxUrl } from 'src/utils/urls/urlHelper';
export function BackNavigationButton(props: Parameters<typeof Button>[0]) {
const { langAsString } = useLanguage();
const isMobile = useIsMobile();
const party = useCurrentParty();
const party = useSelectedParty();
const mainPageKey = useNavigationParam('mainPageKey');
const isSubform = useIsSubformPage();
const { returnUrl, isFetchingReturnUrl } = useReturnUrl();
Expand Down
8 changes: 4 additions & 4 deletions src/features/entrypoint/Entrypoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { FormProvider } from 'src/features/form/FormContext';
import { InstantiateContainer } from 'src/features/instantiate/containers/InstantiateContainer';
import { NoValidPartiesError } from 'src/features/instantiate/containers/NoValidPartiesError';
import {
useCurrentParty,
useCurrentPartyIsValid,
useHasSelectedParty,
useSelectedParty,
useSelectedPartyIsValid,
useValidParties,
} from 'src/features/party/PartiesProvider';
import { useProfile } from 'src/features/profile/ProfileProvider';
Expand Down Expand Up @@ -45,10 +45,10 @@ export const Entrypoint = () => {
} = useApplicationMetadata();
const profile = useProfile();
const validParties = useValidParties();
const partyIsValid = useCurrentPartyIsValid();
const partyIsValid = useSelectedPartyIsValid();
const userHasSelectedParty = useHasSelectedParty();
const allowAnonymous = useAllowAnonymousIs(true);
const party = useCurrentParty();
const party = useSelectedParty();

if (isStateless && allowAnonymous && !party) {
// Anonymous stateless app. No need to log in and select party, but cannot create a new instance.
Expand Down
8 changes: 4 additions & 4 deletions src/features/formData/FormDataWrite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ALTINN_ROW_ID } from 'src/features/formData/types';
import { getFormDataQueryKey } from 'src/features/formData/useFormDataQuery';
import { useLaxChangeInstance, useLaxInstanceId } from 'src/features/instance/InstanceContext';
import { useCurrentLanguage } from 'src/features/language/LanguageProvider';
import { useCurrentParty } from 'src/features/party/PartiesProvider';
import { useSelectedParty } from 'src/features/party/PartiesProvider';
import { type BackendValidationIssueGroups, IgnoredValidators } from 'src/features/validation';
import { useIsUpdatingInitialValidations } from 'src/features/validation/backendValidation/backendValidationQuery';
import { useAsRef } from 'src/hooks/useAsRef';
Expand Down Expand Up @@ -96,7 +96,7 @@ function useFormDataSaveMutation() {
const cancelSave = useSelector((s) => s.cancelSave);
const isStateless = useApplicationMetadata().isStatelessApp;
const debounce = useSelector((s) => s.debounce);
const currentPartyId = useCurrentParty()?.partyId;
const selectedPartyId = useSelectedParty()?.partyId;
const waitFor = useWaitForState<
{ prev: { [dataType: string]: object }; next: { [dataType: string]: object } },
FormDataContext
Expand Down Expand Up @@ -203,9 +203,9 @@ function useFormDataSaveMutation() {

if (isStateless) {
const options: AxiosRequestConfig = {};
if (currentPartyId !== undefined) {
if (selectedPartyId !== undefined) {
options.headers = {
party: `partyid:${currentPartyId}`,
party: `partyid:${selectedPartyId}`,
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/features/formData/useFormDataQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { AxiosRequestConfig } from 'axios';
import { useAppQueries } from 'src/core/contexts/AppQueriesProvider';
import { type QueryDefinition } from 'src/core/queries/usePrefetchQuery';
import { useApplicationMetadata } from 'src/features/applicationMetadata/ApplicationMetadataProvider';
import { useCurrentParty } from 'src/features/party/PartiesProvider';
import { useSelectedParty } from 'src/features/party/PartiesProvider';
import { useMemoDeepEqual } from 'src/hooks/useStateDeepEqual';
import { isAxiosError } from 'src/utils/isAxiosError';
import { maybeAuthenticationRedirect } from 'src/utils/maybeAuthenticationRedirect';
Expand Down Expand Up @@ -55,12 +55,12 @@ export async function invalidateFormDataQueries(queryClient: QueryClient) {
}

export function useFormDataQueryOptions() {
const currentPartyId = useCurrentParty()?.partyId;
const selectedPartyId = useSelectedParty()?.partyId;
const isStateless = useApplicationMetadata().isStatelessApp;
const options: AxiosRequestConfig = {};
if (isStateless && currentPartyId !== undefined) {
if (isStateless && selectedPartyId !== undefined) {
options.headers = {
party: `partyid:${currentPartyId}`,
party: `partyid:${selectedPartyId}`,
};
}
return options;
Expand Down
4 changes: 2 additions & 2 deletions src/features/instantiate/containers/InstantiateContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { InstantiateValidationError } from 'src/features/instantiate/containers/
import { MissingRolesError } from 'src/features/instantiate/containers/MissingRolesError';
import { UnknownError } from 'src/features/instantiate/containers/UnknownError';
import { useInstantiation } from 'src/features/instantiate/InstantiationContext';
import { useCurrentParty } from 'src/features/party/PartiesProvider';
import { useSelectedParty } from 'src/features/party/PartiesProvider';
import { useAsRef } from 'src/hooks/useAsRef';
import { AltinnPalette } from 'src/theme/altinnAppTheme';
import { changeBodyBackground } from 'src/utils/bodyStyling';
Expand All @@ -14,7 +14,7 @@ import { HttpStatusCodes } from 'src/utils/network/networking';

export const InstantiateContainer = () => {
changeBodyBackground(AltinnPalette.greyLight);
const party = useCurrentParty();
const party = useSelectedParty();
const instantiation = useInstantiation();
const clearRef = useAsRef(instantiation.clear);

Expand Down
4 changes: 2 additions & 2 deletions src/features/instantiate/containers/MissingRolesError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Link } from 'react-router-dom';
import { InstantiationErrorPage } from 'src/features/instantiate/containers/InstantiationErrorPage';
import { Lang } from 'src/features/language/Lang';
import { useLanguage } from 'src/features/language/useLanguage';
import { useCurrentParty } from 'src/features/party/PartiesProvider';
import { useSelectedParty } from 'src/features/party/PartiesProvider';
import { getHostname } from 'src/utils/urls/appUrlHelper';

export function MissingRolesError() {
const { langAsString } = useLanguage();
const selectedParty = useCurrentParty();
const selectedParty = useSelectedParty();

return (
<InstantiationErrorPage
Expand Down
14 changes: 7 additions & 7 deletions src/features/instantiate/containers/PartySelection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { userEvent } from '@testing-library/user-event';

import { getPartyMock, getPartyWithSubunitMock, getServiceOwnerPartyMock } from 'src/__mocks__/getPartyMock';
import { PartySelection } from 'src/features/instantiate/containers/PartySelection';
import { useCurrentParty, useCurrentPartyIsValid } from 'src/features/party/PartiesProvider';
import { useSelectedParty, useSelectedPartyIsValid } from 'src/features/party/PartiesProvider';
import { renderWithDefaultProviders } from 'src/test/renderWithProviders';

const deletedParty = getPartyMock({
Expand All @@ -32,13 +32,13 @@ const parties = [
];

function TestWrapper(props: PropsWithChildren) {
const currentParty = useCurrentParty();
const partyIsValid = useCurrentPartyIsValid();
const selectedParty = useSelectedParty();
const partyIsValid = useSelectedPartyIsValid();
return (
<>
{props.children}
<div data-testid='valid-party'>{JSON.stringify(partyIsValid)}</div>
<div data-testid='current-party'>{JSON.stringify(currentParty?.partyId ?? false)}</div>
<div data-testid='current-party'>{JSON.stringify(selectedParty?.partyId ?? false)}</div>
</>
);
}
Expand Down Expand Up @@ -150,9 +150,9 @@ describe('PartySelection', () => {
}

await user.click(screen.getByRole('button', { name: partyName }));
await waitFor(() => expect(mutations.doSetCurrentParty.mock).toHaveBeenCalled());
expect(mutations.doSetCurrentParty.mock).toHaveBeenCalledWith(expectedPartyId);
mutations.doSetCurrentParty.resolve('Party successfully updated');
await waitFor(() => expect(mutations.doSetSelectedParty.mock).toHaveBeenCalled());
expect(mutations.doSetSelectedParty.mock).toHaveBeenCalledWith(expectedPartyId);
mutations.doSetSelectedParty.resolve('Party successfully updated');
await waitFor(() => expect(screen.getByTestId('current-party')).toHaveTextContent(`${expectedPartyId}`));
await waitFor(() => expect(screen.getByTestId('valid-party')).toHaveTextContent('true'));
},
Expand Down
8 changes: 4 additions & 4 deletions src/features/instantiate/containers/PartySelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import classes from 'src/features/instantiate/containers/PartySelection.module.c
import { Lang } from 'src/features/language/Lang';
import { useLanguage } from 'src/features/language/useLanguage';
import {
useCurrentParty,
usePartiesAllowedToInstantiate,
useSetCurrentParty,
useSelectedParty,
useSetHasSelectedParty,
useSetSelectedParty,
} from 'src/features/party/PartiesProvider';
import { useNavigate } from 'src/features/routing/AppRoutingContext';
import { AltinnPalette } from 'src/theme/altinnAppTheme';
Expand All @@ -36,8 +36,8 @@ export const PartySelection = () => {
const match = useMatch(`/party-selection/:errorCode`);
const errorCode = match?.params.errorCode;

const selectParty = useSetCurrentParty();
const selectedParty = useCurrentParty();
const selectParty = useSetSelectedParty();
const selectedParty = useSelectedParty();
const setUserHasSelectedParty = useSetHasSelectedParty();

const partiesAllowedToInstantiate = usePartiesAllowedToInstantiate() ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { useAppQueries } from 'src/core/contexts/AppQueriesProvider';
import { delayedContext } from 'src/core/contexts/delayedContext';
import { createQueryContext } from 'src/core/contexts/queryContext';
import { InstantiateContainer } from 'src/features/instantiate/containers/InstantiateContainer';
import { useCurrentParty } from 'src/features/party/PartiesProvider';
import { useSelectedParty } from 'src/features/party/PartiesProvider';

const useActiveInstancesQuery = () => {
const { fetchActiveInstances } = useAppQueries();
const currentParty = useCurrentParty();
const selectedParty = useSelectedParty();

const utils = useQuery({
queryKey: ['getActiveInstances', currentParty?.partyId],
queryKey: ['getActiveInstances', selectedParty?.partyId],
queryFn: async () => {
const simpleInstances = await fetchActiveInstances(currentParty?.partyId ?? -1);
const simpleInstances = await fetchActiveInstances(selectedParty?.partyId ?? -1);

// Sort array by last changed date
simpleInstances.sort((a, b) => new Date(a.lastChanged).getTime() - new Date(b.lastChanged).getTime());
Expand Down
8 changes: 4 additions & 4 deletions src/features/instantiate/selection/InstanceSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import classes from 'src/features/instantiate/selection/InstanceSelection.module.css';
import { Lang } from 'src/features/language/Lang';
import { useLanguage } from 'src/features/language/useLanguage';
import { useCurrentParty } from 'src/features/party/PartiesProvider';
import { useSelectedParty } from 'src/features/party/PartiesProvider';
import { useSetNavigationEffect } from 'src/features/routing/AppRoutingContext';
import { useIsMobileOrTablet } from 'src/hooks/useDeviceWidths';
import { focusMainContent } from 'src/hooks/useNavigatePage';
Expand Down Expand Up @@ -65,7 +65,7 @@ function InstanceSelection() {
const mobileView = useIsMobileOrTablet();
const rowsPerPageOptions = instanceSelectionOptions?.rowsPerPageOptions ?? [10, 25, 50];
const instantiate = useInstantiation().instantiate;
const currentParty = useCurrentParty();
const selectedParty = useSelectedParty();
const storeCallback = useSetNavigationEffect();
const { performProcess, isAnyProcessing, isThisProcessing: isLoading } = useIsProcessing();

Expand Down Expand Up @@ -275,9 +275,9 @@ function InstanceSelection() {
size='md'
onClick={() =>
performProcess(async () => {
if (currentParty) {
if (selectedParty) {
storeCallback(focusMainContent);
await instantiate(currentParty.partyId);
await instantiate(selectedParty.partyId);
}
})
}
Expand Down
Loading