Skip to content

Commit

Permalink
Merge pull request #15 from vtex-apps/fix/bankinvoice-url-not-logged-in
Browse files Browse the repository at this point in the history
Parse bank invoice url before displaying it
  • Loading branch information
kaisermann authored Nov 16, 2020
2 parents f64151d + 069a03b commit b295552
Show file tree
Hide file tree
Showing 10 changed files with 959 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .vtexignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ src/
package.json
README.md
CHANGELOG.md
**/__tests__
**/__mocks__
**/*.test.*
react/testUtils/**
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]
### Fixed
- Redirect to login when trying to print bank invoice while not logged-in.

## [1.1.0] - 2020-05-11

Expand Down
8 changes: 7 additions & 1 deletion react/PaymentMethod.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { FunctionComponent, useState } from 'react'
import { InjectedIntlProps, injectIntl, defineMessages } from 'react-intl'
import { useRuntime } from 'vtex.render-runtime'

import AdditionalInfo from './AdditionalInfo'
import ButtonLink from './ButtonLink'
import Price from './FormattedPrice'
import InfoIcon from './icons/Info'
import { parseBankInvoiceUrl } from './utils'

const messages = defineMessages({
creditcard: { id: 'store/payments.creditcard', defaultMessage: '' },
Expand Down Expand Up @@ -44,6 +46,7 @@ const PaymentMethod: FunctionComponent<Props & InjectedIntlProps> = ({
currency,
intl,
}) => {
const { rootPath } = useRuntime()
const [isOpen, setIsOpen] = useState(false)
const hasLastDigits = !!payment.lastDigits
const isBankInvoice = payment.group === 'bankInvoice'
Expand Down Expand Up @@ -82,7 +85,10 @@ const PaymentMethod: FunctionComponent<Props & InjectedIntlProps> = ({
</div>
{isBankInvoice && payment.url && (
<div className="mt5">
<ButtonLink to={payment.url} variation="primary" openNewWindow>
<ButtonLink
to={parseBankInvoiceUrl({ url: payment.url, rootPath })}
variation="primary"
openNewWindow>
{intl.formatMessage(messages.print, {
paymentSystemName: payment.paymentSystemName,
})}
Expand Down
14 changes: 10 additions & 4 deletions react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"lodash": "^4.17.11",
"react-intl": "^2.7.2",
"react-resize-detector": "^3.4.0",
"recompose": "^0.30.0"
Expand Down Expand Up @@ -28,14 +27,21 @@
"tslint": "^5.12.1",
"tslint-config-vtex": "^2.1.0",
"tslint-eslint-rules": "^5.4.0",
"typescript": "3.5.2",
"typescript-babel-jest": "^1.0.5"
"typescript": "3.9.7",
"typescript-babel-jest": "^1.0.5",
"vtex.address-form": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.address-form@4.6.3/public/_types/react",
"vtex.css-handles": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles",
"vtex.my-account-commons": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.my-account-commons@1.5.2/public/@types/vtex.my-account-commons",
"vtex.profile-form": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.profile-form@3.3.3/public/_types/react",
"vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.124.3/public/@types/vtex.render-runtime",
"vtex.shipping-estimate-translator": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.shipping-estimate-translator@2.2.2/public/@types/vtex.shipping-estimate-translator",
"vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.133.2/public/@types/vtex.styleguide"
},
"resolutions": {
"babel-core": "^7.0.0-bridge.0"
},
"scripts": {
"lint": "tsc --noEmit && eslint --quiet --fix --ext ts,tsx .",
"lint": "eslint --quiet --fix --ext ts,tsx .",
"test": "vtex-test-tools test"
},
"version": "1.1.0"
Expand Down
6 changes: 4 additions & 2 deletions react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"extends": "@vtex/tsconfig",
"compilerOptions": {
"noEmitOnError": false,
"typeRoots": ["node_modules/@types"],
"types": ["node", "jest"]
"lib": ["dom"],
"module": "esnext",
"moduleResolution": "node",
"target": "es2017"
},
"include": ["./typings/*.d.ts", "./**/*.tsx", "./**/*.ts"]
}
4 changes: 4 additions & 0 deletions react/typings/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
declare interface Window {
__RUNTIME__: any
}

interface OrderGroup {
orders: Order[]
totalDeliveryParcels: Parcel[]
Expand Down
24 changes: 0 additions & 24 deletions react/typings/render.d.ts

This file was deleted.

17 changes: 17 additions & 0 deletions react/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,20 @@ export const orderSplitMessage = ({

return intl.formatMessage(message, { deliveries, pickups, takeaways })
}

export function parseBankInvoiceUrl({
url,
rootPath = '',
}: {
url: string
rootPath?: string
}) {
const isEncrypted = Boolean(url.match(/(\*.\*.)+\*\w\*/g))
if (!isEncrypted) return url

const encodedPath = encodeURIComponent(
window.location.pathname + window.location.search
)

return `${rootPath}/login?returnUrl=${encodedPath}`
}
36 changes: 32 additions & 4 deletions react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6915,10 +6915,10 @@ typescript-babel-jest@^1.0.5:
babel-jest "20.0.3"
typescript "^2.4.1"

typescript@3.5.2:
version "3.5.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.2.tgz#a09e1dc69bc9551cadf17dba10ee42cf55e5d56c"
integrity sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==
typescript@3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

typescript@^2.4.1:
version "2.9.2"
Expand Down Expand Up @@ -7046,6 +7046,34 @@ verror@1.10.0:
core-util-is "1.0.2"
extsprintf "^1.2.0"

"vtex.address-form@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.address-form@4.6.3/public/_types/react":
version "0.0.0"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.address-form@4.6.3/public/_types/react#fa7a0347e046eab3dd768998fc9252b2c0dd5aef"

"vtex.css-handles@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles":
version "0.4.4"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles#8c45c6decf9acd2b944e07261686decff93d6422"

"vtex.my-account-commons@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.my-account-commons@1.5.2/public/@types/vtex.my-account-commons":
version "1.5.2"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.my-account-commons@1.5.2/public/@types/vtex.my-account-commons#71beef3822cd90f459b83fdd23a2ababcfc58e11"

"vtex.profile-form@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.profile-form@3.3.3/public/_types/react":
version "0.0.0"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.profile-form@3.3.3/public/_types/react#fa7a0347e046eab3dd768998fc9252b2c0dd5aef"

"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.124.3/public/@types/vtex.render-runtime":
version "8.124.3"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.124.3/public/@types/vtex.render-runtime#8158e34bd24b4a51cb5d463eeef4e37af626c2d5"

"vtex.shipping-estimate-translator@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.shipping-estimate-translator@2.2.2/public/@types/vtex.shipping-estimate-translator":
version "2.2.2"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.shipping-estimate-translator@2.2.2/public/@types/vtex.shipping-estimate-translator#0daa482f261e7c40a06c27be07e9e5b9d70cf063"

"vtex.styleguide@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.133.2/public/@types/vtex.styleguide":
version "9.133.2"
resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.133.2/public/@types/vtex.styleguide#0b2020bfe4732e76f7dc6fcff4a77ba81f211c5d"

w3c-hr-time@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz#82ac2bff63d950ea9e3189a58a65625fedf19045"
Expand Down
Loading

0 comments on commit b295552

Please sign in to comment.