Skip to content

Commit

Permalink
Merge pull request beightone#1 from vtex-apps/typings-test
Browse files Browse the repository at this point in the history
Changes to avoid typing problems
  • Loading branch information
Fabiana Ferreira Fonseca authored Jul 1, 2020
2 parents 54f0d02 + 1634bf0 commit a8b649e
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 24 deletions.
12 changes: 12 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "vtex",
"root": true,
"env": {
"node": true,
"es6": true,
"jest": true
},
"rules": {
"react/prefer-stateless-function": false
}
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ docs/_book/
npm-debug.log
.build/
lib
.eslintrc
base
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

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
- Problems with typings and lint
11 changes: 11 additions & 0 deletions react/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "vtex-react/io",
"env": {
"browser": true,
"es6": true,
"jest": true
},
"rules": {
"react/prefer-stateless-function": false
}
}
17 changes: 6 additions & 11 deletions react/components/CustomButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ 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)
}
/**
* 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, {}> {
render() {
const { items } = this.props

Expand Down
2 changes: 0 additions & 2 deletions react/components/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { Component } from 'react'

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

class Table extends Component<TableProps> {
constructor(props: any) {
super(props)
Expand Down
10 changes: 4 additions & 6 deletions react/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React, { Component } from 'react'

import CustomButton from './components/CustomButton'
import { OrderForm } from './typings/orderForm'

class CheckoutButtonExample extends Component<
CheckoutButtonExampleProps,
CheckoutButtonExampleState
> {
class CheckoutButtonExample extends Component<{}, CheckoutButtonExampleState> {
/**
* This component is the one that is referenced in the extension point. To use it
* as an example, we add an event listener, which updates the state every time the
Expand All @@ -20,14 +16,16 @@ class CheckoutButtonExample extends Component<
}
}

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

render() {
this.listenOrderFormUpdated()
console.log(window.vtex.i18n.getLocale())

return <CustomButton {...this.state.orderForm!} />
}
}
Expand Down
2 changes: 1 addition & 1 deletion react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"include": [
"./**/*.tsx",
"typings.d.ts"
"./**/*.d.ts"
],
"exclude": [
"node_modules"
Expand Down
10 changes: 7 additions & 3 deletions react/typings/orderForm.d.ts → react/typings/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
export interface OrderFormContext {
interface Window extends Window {
vtex: any
}

interface OrderFormContext {
orderForm: OrderForm
loading: boolean
}

export interface OrderFormItem {
interface OrderFormItem {
additionalInfo: ItemAdditionalInfo
availability: string
detailUrl: string
Expand Down Expand Up @@ -34,7 +38,7 @@ interface SKUSpecification {
fieldValues: string[]
}

export interface OrderForm {
interface OrderForm {
id: string
items: OrderFormItem[]
marketingData: MarketingData
Expand Down

0 comments on commit a8b649e

Please sign in to comment.