Skip to content

Commit

Permalink
Merge pull request #24 from vtex-apps/feature-css-handles
Browse files Browse the repository at this point in the history
Add CSS Handles 'updateOrderButton', 'myOrdersButton', and 'cancelOrderButton' on OrderOptions
  • Loading branch information
Breno Calazans authored Mar 25, 2021
2 parents 99835b6 + e6da090 commit 1ac2536
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- CSS Handles `updateOrderButton`, `myOrdersButton`, and `cancelOrderButton` on `OrderOptions`.

## [1.2.0] - 2021-03-10

Expand Down
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ In order to apply CSS customizations in this and other blocks, follow the instru
| `paymentGroup` |
| `paymentValue` |
| `addressContainer` |
| `updateOrderButton` |
| `myOrdersButton` |
| `cancelOrderButton` |

## Contributors ✨

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"test": "cd ./react && yarn test",
"lint:locales": "intl-equalizer",
"locales:fix": "intl-equalizer --fix",
"verify": "yarn lint && yarn lint:locales && yarn test"
"verify": "yarn lint:locales && yarn test"
},
"husky": {
"hooks": {
"pre-commit": "yarn lint && yarn lint:locales && yarn locales:fix",
"pre-commit": "yarn lint:locales && yarn locales:fix",
"pre-push": "yarn verify"
}
},
Expand Down
85 changes: 49 additions & 36 deletions react/OrderOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FunctionComponent } from 'react'
import { InjectedIntlProps, injectIntl, defineMessages } from 'react-intl'
import { useCssHandles } from 'vtex.css-handles'

import ButtonLink from './ButtonLink'

Expand Down Expand Up @@ -28,56 +29,68 @@ interface Props {
orderId?: string
}

const CSS_HANDLES = [
'updateOrderButton',
'myOrdersButton',
'cancelOrderButton',
] as const

const OrderOptions: FunctionComponent<Props & InjectedIntlProps> = ({
allowCancellation,
takeaway,
intl,
className = '',
fullWidth,
orderId,
}) => (
<div className={`${className} flex flex-wrap justify-center flex-nowrap-m`}>
<div className="mr5-ns mb5-s mb0-m w-100 w-auto-m">
{takeaway ? (
<ButtonLink variation="secondary" fullWidth={fullWidth} to="">
{intl.formatMessage(messages.printReceiptButton)}
</ButtonLink>
) : (
<ButtonLink
variation="secondary"
fullWidth={fullWidth}
to={`/account#/orders/${orderId}/edit`}>
{intl.formatMessage(messages.updateButton)}
</ButtonLink>
)}
</div>
{!takeaway && (
<div className="mr5-ns mb5-s mb0-m w-100 w-auto-m">
<ButtonLink
variation="secondary"
fullWidth={fullWidth}
to="/account#/orders/">
{intl.formatMessage(messages.myOrdersButton)}
</ButtonLink>
</div>
)}
{allowCancellation && (
<div className="w-100 w-auto-m">
}) => {
const handles = useCssHandles(CSS_HANDLES)

return (
<div className={`${className} flex flex-wrap justify-center flex-nowrap-m`}>
<div
className={`${handles.updateOrderButton} mr5-ns mb5-s mb0-m w-100 w-auto-m`}>
{takeaway ? (
<ButtonLink variation="danger-tertiary" fullWidth={fullWidth} to="">
{intl.formatMessage(messages.takeAwayCancelButton)}
<ButtonLink variation="secondary" fullWidth={fullWidth} to="">
{intl.formatMessage(messages.printReceiptButton)}
</ButtonLink>
) : (
<ButtonLink
variation="danger-tertiary"
variation="secondary"
fullWidth={fullWidth}
to={`/account#/orders/${orderId}/cancel`}>
{intl.formatMessage(messages.cancelButton)}
to={`/account#/orders/${orderId}/edit`}>
{intl.formatMessage(messages.updateButton)}
</ButtonLink>
)}
</div>
)}
</div>
)
{!takeaway && (
<div
className={`${handles.myOrdersButton} mr5-ns mb5-s mb0-m w-100 w-auto-m`}>
<ButtonLink
variation="secondary"
fullWidth={fullWidth}
to="/account#/orders/">
{intl.formatMessage(messages.myOrdersButton)}
</ButtonLink>
</div>
)}
{allowCancellation && (
<div className={`${handles.cancelOrderButton} w-100 w-auto-m`}>
{takeaway ? (
<ButtonLink variation="danger-tertiary" fullWidth={fullWidth} to="">
{intl.formatMessage(messages.takeAwayCancelButton)}
</ButtonLink>
) : (
<ButtonLink
variation="danger-tertiary"
fullWidth={fullWidth}
to={`/account#/orders/${orderId}/cancel`}>
{intl.formatMessage(messages.cancelButton)}
</ButtonLink>
)}
</div>
)}
</div>
)
}

export default injectIntl(OrderOptions)

0 comments on commit 1ac2536

Please sign in to comment.