Skip to content

Commit

Permalink
Fix custom receipt not showing the correct layout (#1024)
Browse files Browse the repository at this point in the history
* Fix custom receipt

* fix receipt test
  • Loading branch information
bjosttveit authored Mar 22, 2023
1 parent 3c9da64 commit 6c08d37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
15 changes: 5 additions & 10 deletions src/features/customReceipt/containers/CustomReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@ import { useExprContext } from 'src/utils/layout/ExprContext';
import { getFormHasErrors } from 'src/utils/validation/validation';

export function CustomReceipt() {
const page = useExprContext()?.current();
const customReceipt = useAppSelector(
(state) =>
state.formLayout.layouts &&
state.formLayout.uiConfig.receiptLayoutName &&
state.formLayout.layouts[state.formLayout.uiConfig.receiptLayoutName],
);
const receiptLayoutName = useAppSelector((state) => state.formLayout.uiConfig.receiptLayoutName);
const page = useExprContext()?.findLayout(receiptLayoutName);
const language = useAppSelector((state) => state.language.language);
const hasErrors = useAppSelector((state) => getFormHasErrors(state.formValidations.validations));

const [mainNodes, errorReportNodes] = React.useMemo(() => {
if (!customReceipt || !page) {
if (!page) {
return [[], []];
}
return hasErrors ? extractBottomButtons(page) : [page.children(), []];
}, [page, customReceipt, hasErrors]);
}, [page, hasErrors]);

if (!language || !customReceipt) {
if (!language || !page) {
return null;
}

Expand Down
8 changes: 6 additions & 2 deletions src/features/receipt/containers/ReceiptContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { screen } from '@testing-library/react';

import { dataTypes, instanceOwner, partyMember, partyTypesAllowed, userProfile } from 'src/__mocks__/constants';
import { getInstanceDataStateMock } from 'src/__mocks__/instanceDataStateMock';
import { getUiConfigStateMock } from 'src/__mocks__/uiConfigStateMock';
import { ReceiptContainer, returnInstanceMetaDataObject } from 'src/features/receipt/containers/ReceiptContainer';
import { MemoryRouterWithRedirectingRoot, renderWithProviders } from 'src/testUtils';
import type { ILayout } from 'src/layout/layout';
Expand Down Expand Up @@ -102,7 +103,7 @@ function getMockState({

const receiptLayout = receiptLayoutExist ? { receipt } : {};

const customReceipt = setCustomReceipt ? { hiddenFields: [], receiptLayoutName: 'receipt' } : {};
const customReceipt = setCustomReceipt ? { receiptLayoutName: 'receipt' } : {};

return {
organisationMetaData: {
Expand Down Expand Up @@ -138,7 +139,10 @@ function getMockState({
},
},
formLayout: {
uiConfig: customReceipt,
uiConfig: {
...getUiConfigStateMock(),
...customReceipt,
},
layouts: {
...receiptLayout,
},
Expand Down

0 comments on commit 6c08d37

Please sign in to comment.