Skip to content

Commit

Permalink
♻️ [#454] Refactor ChooseProductStep to use EditGridItem component
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Oct 19, 2023
1 parent d36c30e commit aa6fe70
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/components/EditGrid/EditGridItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';

import {getBEMClassName} from 'utils';

const EditGridItem = ({heading, body, buttons}) => {
const EditGridItem = ({heading, children: body, buttons}) => {
return (
<div className={getBEMClassName('editgrid__group')}>
<div className={getBEMClassName('editgrid__group-label')}>{heading}</div>
Expand All @@ -15,7 +15,7 @@ const EditGridItem = ({heading, body, buttons}) => {

EditGridItem.propTypes = {
heading: PropTypes.string.isRequired,
body: PropTypes.node,
children: PropTypes.node,
buttons: PropTypes.node,
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/EditGrid/EditGridItem.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export default {
title: 'Pure React components / EditGrid / Item',
component: EditGridItemComponent,
argTypes: {
body: {control: false},
children: {control: false},
buttons: {control: false},
},
args: {
heading: 'Item heading',
body: <Body>Item body, typically form fields</Body>,
children: <Body>Item body, typically form fields</Body>,
buttons: (
<EditGridButtonGroup>
<Button variant="primary">Save</Button>
Expand Down
38 changes: 19 additions & 19 deletions src/components/appointments/steps/ChooseProductStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {toFormikValidationSchema} from 'zod-formik-adapter';

import Button from 'components/Button';
import {CardTitle} from 'components/Card';
import {EditGridButtonGroup, EditGridItem} from 'components/EditGrid';
import FAIcon from 'components/FAIcon';
import {Toolbar, ToolbarList} from 'components/Toolbar';
import useQuery from 'hooks/useQuery';
import useTitle from 'hooks/useTitle';
import {getBEMClassName} from 'utils';
Expand Down Expand Up @@ -119,31 +119,31 @@ const ProductWrapper = ({index, numProducts, onRemove, children}) => {
if (!supportsMultipleProducts) {
return <>{children}</>;
}

const buttonRow = numProducts > 1 && (
<EditGridButtonGroup>
<Button type="button" variant="danger" onClick={onRemove}>
<FormattedMessage
description="Appointments: remove product/service button text"
defaultMessage="Remove"
/>
</Button>
</EditGridButtonGroup>
);

return (
<div className={getBEMClassName('editgrid__group')}>
<div className={getBEMClassName('editgrid__group-label')}>
<EditGridItem
heading={
<FormattedMessage
description="Appointments: single product label/header"
defaultMessage="Product {number}/{total}"
values={{number: index + 1, total: numProducts}}
/>
</div>

}
buttons={buttonRow}
>
{children}

{numProducts > 1 && (
<Toolbar modifiers={['reverse']}>
<ToolbarList>
<Button type="button" variant="danger" onClick={onRemove}>
<FormattedMessage
description="Appointments: remove product/service button text"
defaultMessage="Remove"
/>
</Button>
</ToolbarList>
</Toolbar>
)}
</div>
</EditGridItem>
);
};

Expand Down

0 comments on commit aa6fe70

Please sign in to comment.