Skip to content

Commit

Permalink
testing window type
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabiana Fonseca committed Jun 26, 2020
1 parent 54f0d02 commit e54983d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
20 changes: 8 additions & 12 deletions react/components/CustomButton.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import React, { Component } from 'react'

import Table from './Table'

import { OrderFormItem } from '../typings/orderForm'

class CustomButton extends Component<CustomButtonProps, CustomButtonState> {
/**
* This component is responsible for rendering the custom button itself. For instance,
* we use it to render a table that contains the name of the items that are in the
* order form.
*/
constructor(props: any) {
super(props)
}
render() {
/**
* This component is responsible for rendering the custom button itself. For instance,
* we use it to render a table that contains the name of the items that are in the
* order form.
*/
class CustomButton extends Component<CustomButtonProps, {}> {
public render() {
const { items } = this.props

return items ? (
Expand All @@ -31,6 +27,6 @@ interface CustomButtonProps {
items: OrderFormItem[]
}

interface CustomButtonState {}
// interface CustomButtonState {}

export default CustomButton
13 changes: 8 additions & 5 deletions react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React, { Component } from 'react'
import CustomButton from './components/CustomButton'
import { OrderForm } from './typings/orderForm'

class CheckoutButtonExample extends Component<
CheckoutButtonExampleProps,
class CheckoutButtonExample extends React.Component<
{},
CheckoutButtonExampleState
> {
/**
Expand All @@ -20,19 +20,22 @@ class CheckoutButtonExample extends Component<
}
}

listenOrderFormUpdated = () => {
public listenOrderFormUpdated() {
$(window).on('orderFormUpdated.vtex', (_: any, orderForm: OrderForm) =>
this.setState({ orderForm })
)
}

render() {
public render() {
this.listenOrderFormUpdated()

console.log(window.vtex.i18n.getLocale())

return <CustomButton {...this.state.orderForm!} />
}
}

interface CheckoutButtonExampleProps {}
// interface CheckoutButtonExampleProps {}

interface CheckoutButtonExampleState {
orderForm: OrderForm | null
Expand Down
4 changes: 4 additions & 0 deletions react/typings/orderForm.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
declare global {
type Window = any
}

export interface OrderFormContext {
orderForm: OrderForm
loading: boolean
Expand Down

0 comments on commit e54983d

Please sign in to comment.