Skip to content

Commit

Permalink
🔥 [open-formulieren/open-forms#4544] Removed LiteralsProvider from Bu…
Browse files Browse the repository at this point in the history
…ttonsToolbar

Removed literals property from ButtonsToolbar, and moved LiteralsProvider from ButtonsToolbar to SubmitRow
  • Loading branch information
robinmolen committed Oct 9, 2024
1 parent 629df27 commit 11ab95f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 66 deletions.
84 changes: 40 additions & 44 deletions src/components/ButtonsToolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import React from 'react';

import AbortButton from 'components/AbortButton';
import {OFButton} from 'components/Button';
import {Literal, LiteralsProvider} from 'components/Literal';
import {Literal} from 'components/Literal';
import Loader from 'components/Loader';
import PreviousLink from 'components/PreviousLink';
import {Toolbar, ToolbarList} from 'components/Toolbar';
import {SUBMISSION_ALLOWED} from 'components/constants';

const ButtonsToolbar = ({
literals,
canSubmitStep,
canSubmitForm,
canSuspendForm,
Expand All @@ -27,56 +26,53 @@ const ButtonsToolbar = ({

return (
<>
<LiteralsProvider literals={literals}>
<Toolbar modifiers={['mobile-reverse-order', 'bottom']}>
<Toolbar modifiers={['mobile-reverse-order', 'bottom']}>
<ToolbarList>
{previousPage && (
<PreviousLink to={previousPage} onClick={onNavigatePrevPage} position="end" />
)}
</ToolbarList>
<ToolbarList>
{/* TODO: refactor: `const canSuspendForm = onFormSave === undefined` - this does not
need to be its own prop */}
{canSuspendForm && (
<OFButton
type="button"
appearance="secondary-action-button"
name="save"
onClick={onFormSave}
>
<Literal name="saveText" />
</OFButton>
)}
{showSubmitButton && (
<OFButton
type="submit"
appearance="primary-action-button"
name="next"
disabled={!canSubmitStep}
>
{isCheckingLogic ? (
<Loader modifiers={['centered', 'only-child', 'small', 'gray']} />
) : (
<Literal name="nextText" />
)}
</OFButton>
)}
</ToolbarList>
</Toolbar>
{!hideAbortButton && (
<Toolbar modifiers={['bottom', 'reverse']}>
<ToolbarList>
{previousPage && (
<PreviousLink to={previousPage} onClick={onNavigatePrevPage} position="end" />
)}
</ToolbarList>
<ToolbarList>
{/* TODO: refactor: `const canSuspendForm = onFormSave === undefined` - this does not
need to be its own prop */}
{canSuspendForm && (
<OFButton
type="button"
appearance="secondary-action-button"
name="save"
onClick={onFormSave}
>
<Literal name="saveText" />
</OFButton>
)}
{showSubmitButton && (
<OFButton
type="submit"
appearance="primary-action-button"
name="next"
disabled={!canSubmitStep}
>
{isCheckingLogic ? (
<Loader modifiers={['centered', 'only-child', 'small', 'gray']} />
) : (
<Literal name="nextText" />
)}
</OFButton>
)}
<AbortButton isAuthenticated={isAuthenticated} onDestroySession={onDestroySession} />
</ToolbarList>
</Toolbar>
{!hideAbortButton && (
<Toolbar modifiers={['bottom', 'reverse']}>
<ToolbarList>
<AbortButton isAuthenticated={isAuthenticated} onDestroySession={onDestroySession} />
</ToolbarList>
</Toolbar>
)}
</LiteralsProvider>
)}
</>
);
};

ButtonsToolbar.propTypes = {
literals: PropTypes.object,
canSubmitStep: PropTypes.bool.isRequired,
canSubmitForm: PropTypes.string.isRequired,
canSuspendForm: PropTypes.bool.isRequired,
Expand Down
11 changes: 4 additions & 7 deletions src/components/ButtonsToolbar/test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {act} from 'react-dom/test-utils';
import {IntlProvider} from 'react-intl';
import {MemoryRouter} from 'react-router-dom';

import {LiteralsProvider} from 'components/Literal';
import {SUBMISSION_ALLOWED} from 'components/constants';

import ButtonsToolbar from './index';
Expand Down Expand Up @@ -37,7 +38,9 @@ const LITERALS = {

const Wrap = ({children}) => (
<IntlProvider locale="nl" messages={messagesNL}>
<MemoryRouter>{children}</MemoryRouter>
<MemoryRouter>
<LiteralsProvider literals={LITERALS}>{children}</LiteralsProvider>
</MemoryRouter>
</IntlProvider>
);

Expand All @@ -48,7 +51,6 @@ it('Last step of submittable form, button is present', () => {
root.render(
<Wrap>
<ButtonsToolbar
literals={LITERALS}
canSubmitStep={true}
canSubmitForm={SUBMISSION_ALLOWED.yes}
canSuspendForm={true}
Expand Down Expand Up @@ -80,7 +82,6 @@ it('Last step of non-submittable form with overview, button is present', () => {
root.render(
<Wrap>
<ButtonsToolbar
literals={LITERALS}
canSubmitStep={true}
canSubmitForm={SUBMISSION_ALLOWED.noWithOverview}
canSuspendForm={true}
Expand Down Expand Up @@ -112,7 +113,6 @@ it('Last step of non-submittable form without overview, button is NOT present',
root.render(
<Wrap>
<ButtonsToolbar
literals={LITERALS}
canSubmitStep={true}
canSubmitForm={SUBMISSION_ALLOWED.noWithoutOverview}
canSuspendForm={true}
Expand Down Expand Up @@ -143,7 +143,6 @@ it('Non-last step of non-submittable form without overview, button IS present',
root.render(
<Wrap>
<ButtonsToolbar
literals={LITERALS}
canSubmitStep={true}
canSubmitForm={SUBMISSION_ALLOWED.noWithoutOverview}
canSuspendForm={true}
Expand Down Expand Up @@ -174,7 +173,6 @@ it('Suspending form allowed, button is present', () => {
renderTest(
<Wrap>
<ButtonsToolbar
literals={LITERALS}
canSubmitStep={true}
canSubmitForm={SUBMISSION_ALLOWED.yes}
canSuspendForm={true}
Expand All @@ -198,7 +196,6 @@ it('Suspending form not allowed, button is NOT present', () => {
renderTest(
<Wrap>
<ButtonsToolbar
literals={LITERALS}
canSubmitStep={true}
canSubmitForm={SUBMISSION_ALLOWED.yes}
canSuspendForm={false}
Expand Down
1 change: 0 additions & 1 deletion src/components/FormStep/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,6 @@ const FormStep = ({form, submission, onLogicChecked, onStepSubmitted, onDestroyS
/>
{config.debug ? <FormStepDebug data={getCurrentFormData()} /> : null}
<ButtonsToolbar
literals={formStep.literals}
canSubmitStep={canSubmit}
canSubmitForm={submission.submissionAllowed}
canSuspendForm={form.suspensionAllowed}
Expand Down
32 changes: 18 additions & 14 deletions src/components/appointments/SubmitRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,34 @@ import React from 'react';
import {useNavigate} from 'react-router-dom';

import ButtonsToolbar from 'components/ButtonsToolbar';
import {LiteralsProvider} from 'components/Literal';
import {SUBMISSION_ALLOWED} from 'components/constants';

const SubmitRow = ({canSubmit, nextText, previousText = '', navigateBackTo = ''}) => {
const navigate = useNavigate();

return (
<ButtonsToolbar
<LiteralsProvider
literals={{
nextText: {resolved: nextText},
previousText: {resolved: previousText},
}}
canSubmitStep={canSubmit}
canSubmitForm={SUBMISSION_ALLOWED.yes}
canSuspendForm={false}
isAuthenticated={false} // TODO -> if authenticated (for prefill), logout must be shown
isLastStep={false}
isCheckingLogic={false}
loginRequired={false}
hideAbortButton
previousPage={navigateBackTo ? `../${navigateBackTo}` : ''}
onFormSave={() => {}}
onNavigatePrevPage={navigateBackTo ? () => navigate(`../${navigateBackTo}`) : undefined}
onDestroySession={() => {}}
/>
>
<ButtonsToolbar
canSubmitStep={canSubmit}
canSubmitForm={SUBMISSION_ALLOWED.yes}
canSuspendForm={false}
isAuthenticated={false} // TODO -> if authenticated (for prefill), logout must be shown
isLastStep={false}
isCheckingLogic={false}
loginRequired={false}
hideAbortButton
previousPage={navigateBackTo ? `../${navigateBackTo}` : ''}
onFormSave={() => {}}

Check warning on line 29 in src/components/appointments/SubmitRow.js

View check run for this annotation

Codecov / codecov/patch

src/components/appointments/SubmitRow.js#L29

Added line #L29 was not covered by tests
onNavigatePrevPage={navigateBackTo ? () => navigate(`../${navigateBackTo}`) : undefined}
onDestroySession={() => {}}

Check warning on line 31 in src/components/appointments/SubmitRow.js

View check run for this annotation

Codecov / codecov/patch

src/components/appointments/SubmitRow.js#L31

Added line #L31 was not covered by tests
/>
</LiteralsProvider>
);
};

Expand Down

0 comments on commit 11ab95f

Please sign in to comment.