Commit e0326600 authored by Corbin Crutchley's avatar Corbin Crutchley Committed by Joe Haddad

form handler example: Update deps and fix build from dep update (#6732)

* form handler example: Update deps and fix build from dep update

* Ran lint error fixers

* Fixes errors that occur when commit occurs

* Commit linter fixes
parent 4fd794e8
......@@ -3,7 +3,11 @@ export default function Layout ({ children }) {
<>
{children}
<style jsx global>{`
body {font-family: Roboto, sans-serif; padding: 30px; color: #444;}
body {
font-family: Roboto, sans-serif;
padding: 30px;
color: #444;
}
`}</style>
</>
)
......
......@@ -202,9 +202,20 @@ export default () => {
for lounge in doorway for chew iPad power cord.
</p>
<style jsx>{`
h1 {margin-bottom: 5px;}
p {font-size: 18px; line-height: 30px; margin-top: 30px;}
.caption {color: #ccc; margin-top: 0; font-size: 14px; text-align: center;}
h1 {
margin-bottom: 5px;
}
p {
font-size: 18px;
line-height: 30px;
margin-top: 30px;
}
.caption {
color: #ccc;
margin-top: 0;
font-size: 14px;
text-align: center;
}
`}</style>
</Layout>
)
......
......@@ -4,8 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "next start -p 8000",
"start": "next start",
"dev": "node server.js",
"build": "next build"
},
......@@ -13,14 +12,14 @@
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.4",
"express": "^4.16.4",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"next-redux-wrapper": "^1.3.2",
"react-bootstrap": "^0.31.3",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
"next-redux-wrapper": "^2.1.0",
"react": "^16.8.4",
"react-bootstrap": "^0.32.4",
"react-dom": "^16.8.4",
"react-redux": "^6.0.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
}
}
import App, { Container } from 'next/app'
import React from 'react'
import { Provider } from 'react-redux'
import withRedux from 'next-redux-wrapper'
import { initStore } from '../store'
class MyApp extends App {
static async getInitialProps ({ Component, router, ctx }) {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
return { pageProps }
}
render () {
const { Component, pageProps, store } = this.props
return (
<Container>
<Provider store={store}>
<Component {...pageProps} />
</Provider>
</Container>
)
}
}
export default withRedux(initStore)(MyApp)
import React, { Component } from 'react'
import withRedux from 'next-redux-wrapper'
import Main from '../components'
import { connect } from 'react-redux'
import { initStore } from '../store'
import Main from '../components'
class Index extends Component {
render () {
......@@ -11,4 +10,4 @@ class Index extends Component {
}
}
export default withRedux(initStore, null)(Index)
export default connect()(Index)
......@@ -15,7 +15,7 @@ class CounterProvider extends Component {
})
}
increaseBy = (val) => {
increaseBy = val => {
this.setState({
count: this.state.count + val
})
......
......@@ -13,12 +13,18 @@ export default class about extends Component {
<h1>ABOUT</h1>
<p>Counter: {count}</p>
<button onClick={increase}>Increase</button>
<button onClick={() => {
increaseBy(15)
}}>Increase By 15</button>
<p><Link href='/'>
<a>Home</a>
</Link></p>
<button
onClick={() => {
increaseBy(15)
}}
>
Increase By 15
</button>
<p>
<Link href='/'>
<a>Home</a>
</Link>
</p>
</div>
)}
</CounterConsumer>
......
......@@ -14,9 +14,11 @@ export default class index extends Component {
<p>Counter: {count}</p>
<button onClick={increase}>Increase</button>
<button onClick={decrease}>Decrease</button>
<p><Link href='/about'>
<a>About</a>
</Link></p>
<p>
<Link href='/about'>
<a>About</a>
</Link>
</p>
</div>
)}
</CounterConsumer>
......
......@@ -3,7 +3,10 @@ const functions = require('firebase-functions')
const next = require('next')
var dev = process.env.NODE_ENV !== 'production'
var app = next({ dev, conf: { distDir: `${path.relative(process.cwd(), __dirname)}/next` } })
var app = next({
dev,
conf: { distDir: `${path.relative(process.cwd(), __dirname)}/next` }
})
var handle = app.getRequestHandler()
exports.next = functions.https.onRequest((req, res) => {
......
......@@ -5,14 +5,16 @@ export default () => {
fetchOptionsOverride (options) {
options.url = 'https://graphql-pokemon.now.sh'
},
operation: { query: `
operation: {
query: `
{
pokemon(name: "Pikachu") {
name
image
}
}
` }
`
}
})
const { data } = cacheValue
......
......@@ -15,7 +15,12 @@ export default class MyDocument extends Document {
const initialProps = await Document.getInitialProps(ctx)
return {
...initialProps,
styles: <>{initialProps.styles}{sheet.getStyleElement()}</>
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
)
}
} finally {
sheet.seal()
......
......@@ -5,7 +5,8 @@ export default () => (
<Box align='center' margin='large'>
<Heading>Grommet is awesome!</Heading>
<Paragraph>
Find out more at <Anchor href='https://v2.grommet.io/'>https://v2.grommet.io/</Anchor>
Find out more at{' '}
<Anchor href='https://v2.grommet.io/'>https://v2.grommet.io/</Anchor>
</Paragraph>
</Box>
)
......@@ -27,9 +27,7 @@ export default () => {
<Head>
<title>With Linaria</title>
</Head>
<Box>
Zero runtime CSS in JS
</Box>
<Box>Zero runtime CSS in JS</Box>
</React.Fragment>
)
}
......@@ -3,8 +3,8 @@ import { I18n } from '@lingui/react'
import { t, Trans } from '@lingui/macro'
const availableLanguageNames = {
'en': t`English`,
'sv': t`Swedish`
en: t`English`,
sv: t`Swedish`
}
const availableLanguages = Object.keys(availableLanguageNames)
......@@ -18,15 +18,27 @@ export default () => {
}
return (
<I18n>{({ i18n }) =>
<form onSubmit={onSubmit}>
<select key={i18n.language} name='lang' defaultValue={availableLanguages.find(lang => lang !== i18n.language)}>
{availableLanguages.map(lang => (
<option key={lang} value={lang} disabled={i18n.language === lang}>{i18n._(availableLanguageNames[lang])}</option>
))}
</select>
<button><Trans>Switch language</Trans></button>
</form>
}</I18n>
<I18n>
{({ i18n }) => (
<form onSubmit={onSubmit}>
<select
key={i18n.language}
name='lang'
defaultValue={availableLanguages.find(
lang => lang !== i18n.language
)}
>
{availableLanguages.map(lang => (
<option key={lang} value={lang} disabled={i18n.language === lang}>
{i18n._(availableLanguageNames[lang])}
</option>
))}
</select>
<button>
<Trans>Switch language</Trans>
</button>
</form>
)}
</I18n>
)
}
import React from 'react'
import { I18nProvider } from '@lingui/react'
export default (Component, defaultLang = 'en') => class WithLang extends React.Component {
static async getInitialProps (ctx) {
const language = ctx.query.lang || defaultLang
const [props, catalog] = await Promise.all([
Component.getInitialProps ? Component.getInitialProps(ctx) : {},
import(`../locale/${language}/messages.po`).then(m => m.default)
])
export default (Component, defaultLang = 'en') =>
class WithLang extends React.Component {
static async getInitialProps (ctx) {
const language = ctx.query.lang || defaultLang
const [props, catalog] = await Promise.all([
Component.getInitialProps ? Component.getInitialProps(ctx) : {},
import(`../locale/${language}/messages.po`).then(m => m.default)
])
return {
...props,
language,
catalogs: {
[language]: catalog
return {
...props,
language,
catalogs: {
[language]: catalog
}
}
}
}
render () {
return (
<I18nProvider language={this.props.language} catalogs={this.props.catalogs}>
<Component />
</I18nProvider>
)
render () {
return (
<I18nProvider
language={this.props.language}
catalogs={this.props.catalogs}
>
<Component />
</I18nProvider>
)
}
}
}
......@@ -3,12 +3,17 @@ import { Trans } from '@lingui/macro'
import withLang from '../components/withLang'
import LangSwitcher from '../components/LangSwitcher'
const Index = () =>
const Index = () => (
<div>
<Trans>Hello World.</Trans>
<Link href='/two'><a><Trans>Go to page 2</Trans></a></Link>
<Link href='/two'>
<a>
<Trans>Go to page 2</Trans>
</a>
</Link>
<br />
<LangSwitcher />
</div>
)
export default withLang(Index)
......@@ -2,11 +2,12 @@ import { Trans } from '@lingui/macro'
import withLang from '../components/withLang'
import LangSwitcher from '../components/LangSwitcher'
const Two = () =>
const Two = () => (
<div>
<Trans>Page two. </Trans>
<br />
<LangSwitcher />
</div>
)
export default withLang(Two)
......@@ -12,18 +12,19 @@ function Page ({ linkTo, title }) {
return stop
}, [])
return <div>
<h1>{title}</h1>
{useObserver(() => <Clock
lastUpdate={store.lastUpdate}
light={store.light}
/>)}
<nav>
<Link href={linkTo}>
<a>Navigate</a>
</Link>
</nav>
</div>
return (
<div>
<h1>{title}</h1>
{useObserver(() => (
<Clock lastUpdate={store.lastUpdate} light={store.light} />
))}
<nav>
<Link href={linkTo}>
<a>Navigate</a>
</Link>
</nav>
</div>
)
}
export default Page
......@@ -21,7 +21,7 @@ class MyMobxApp extends App {
constructor(props) {
super(props)
const isServer = !process.browser;
const isServer = !process.browser
this.mobxStore = isServer
? props.initialMobxState
: initializeStore(props.initialMobxState)
......
......@@ -35,7 +35,11 @@ export default () => (
<h1>SEO Added to Page</h1>
<p>Take a look at the head to see what has been added.</p>
<p>
Or checkout how <Link href='/jsonld'><a>JSON-LD</a></Link> (Structured Data) is added
Or checkout how{' '}
<Link href='/jsonld'>
<a>JSON-LD</a>
</Link>{' '}
(Structured Data) is added
</p>
</div>
)
export default () => (
<div className='hello'>
<p>
Hello World! Here's a secret shared with the client using Next env: <strong>{process.env.SECRET}</strong>, the secret is shared
at compile time, which means every reference to the secret is replaced
with its value
Hello World! Here's a secret shared with the client using Next env:{' '}
<strong>{process.env.SECRET}</strong>, the secret is shared at compile
time, which means every reference to the secret is replaced with its value
</p>
<style jsx>{`
.hello {
......
import { useState } from 'react'
import { Fabric } from 'office-ui-fabric-react/lib-commonjs/Fabric'
import { DefaultButton, PrimaryButton } from 'office-ui-fabric-react/lib-commonjs/Button'
import { Dialog, DialogType, DialogFooter } from 'office-ui-fabric-react/lib-commonjs/Dialog'
import {
DefaultButton,
PrimaryButton
} from 'office-ui-fabric-react/lib-commonjs/Button'
import {
Dialog,
DialogType,
DialogFooter
} from 'office-ui-fabric-react/lib-commonjs/Dialog'
export default () => {
const [isOpen, setIsOpen] = useState(false)
......@@ -10,7 +17,9 @@ export default () => {
return (
<Fabric>
<p>Welcome to next.js!</p>
<DefaultButton primary onClick={openDialog}>Open Dialog</DefaultButton>
<DefaultButton primary onClick={openDialog}>
Open Dialog
</DefaultButton>
<Dialog
hidden={!isOpen}
onDismiss={closeDialog}
......
......@@ -15,7 +15,12 @@ export default class MyDocument extends Document {
const initialProps = await Document.getInitialProps(ctx)
return {
...initialProps,
styles: <>{initialProps.styles}{sheet.getStyleElement()}</>
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
)
}
} finally {
sheet.seal()
......
......@@ -4,7 +4,9 @@ import { Alert, Illustration } from '@kiwicom/orbit-components'
export default () => {
return (
<React.Fragment>
<Alert type='success' spaceAfter='large'>It Works!</Alert>
<Alert type='success' spaceAfter='large'>
It Works!
</Alert>
<Illustration name='Success' />
</React.Fragment>
)
......
......@@ -6,9 +6,9 @@ function Items () {
return (
<ul>
{state.items.map((item) =>
{state.items.map(item => (
<li key={item.id}>{item.title}</li>
)}
))}
</ul>
)
}
......
......@@ -13,13 +13,16 @@ class Index extends React.Component {
const overmind = createOvermindSSR(config)
overmind.state.page = 'Index'
overmind.state.items = [{
id: 0,
title: 'foo'
}, {
id: 1,
title: 'bar'
}]
overmind.state.items = [
{
id: 0,
title: 'foo'
},
{
id: 1,
title: 'bar'
}
]
return {
mutations: overmind.hydrate()
......
......@@ -30,26 +30,33 @@ export default class Index extends React.Component {
</button>
{this.state.opened && (
<UniversalPortal selector='#modal'>
<div style={{
position: 'fixed',
backgroundColor: 'rgba(0, 0, 0, 0.7)',
top: 0,
right: 0,
bottom: 0,
left: 0
}}>
<div style={{
backgroundColor: 'white',
position: 'absolute',
top: '10%',
right: '10%',
bottom: '10%',
left: '10%',
padding: '1em'
}}>
<div
style={{
position: 'fixed',
backgroundColor: 'rgba(0, 0, 0, 0.7)',
top: 0,
right: 0,
bottom: 0,
left: 0
}}
>
<div
style={{
backgroundColor: 'white',
position: 'absolute',
top: '10%',
right: '10%',
bottom: '10%',
left: '10%',
padding: '1em'
}}
>
<p>
This modal is rendered using{' '}
<a href='https://www.npmjs.com/package/@jesstelford/react-portal-universal'><code>@jesstelford/react-portal-universal</code></a>.
<a href='https://www.npmjs.com/package/@jesstelford/react-portal-universal'>
<code>@jesstelford/react-portal-universal</code>
</a>
.
</p>
<button type='button' onClick={this.close}>
Close Modal
......
......@@ -22,7 +22,10 @@ export default class MyApp extends App {
htmlAttributes={{ lang: 'en' }}
title='Hello next.js!'
meta={[
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{
name: 'viewport',
content: 'width=device-width, initial-scale=1'
},
{ property: 'og:title', content: 'Hello next.js!' }
]}
/>
......
......@@ -29,9 +29,7 @@ export default class extends Document {
render () {
return (
<html {...this.helmetHtmlAttrComponents}>
<Head>
{this.helmetHeadComponents}
</Head>
<Head>{this.helmetHeadComponents}</Head>
<body {...this.helmetBodyAttrComponents}>
<Main />
<NextScript />
......
......@@ -20,12 +20,12 @@ export default class JssDocument extends Document {
return {
...initialProps,
styles: <>
{initialProps.styles}
<style id='server-side-styles'>
{registry.toString()}
</style>
</>
styles: (
<>
{initialProps.styles}
<style id='server-side-styles'>{registry.toString()}</style>
</>
)
}
}
}
......@@ -38,6 +38,10 @@ function mapStateToProps (state) {
const { count } = state
return { count }
}
const mapDispatchToProps = dispatch => bindActionCreators({ incrementCount, decrementCount, resetCount }, dispatch)
const mapDispatchToProps = dispatch =>
bindActionCreators({ incrementCount, decrementCount, resetCount }, dispatch)
export default connect(mapStateToProps, mapDispatchToProps)(Counter)
export default connect(
mapStateToProps,
mapDispatchToProps
)(Counter)
......@@ -27,4 +27,7 @@ class Index extends React.Component {
}
}
const mapDispatchToProps = { startClock }
export default connect(null, mapDispatchToProps)(Index)
export default connect(
null,
mapDispatchToProps
)(Index)
......@@ -44,7 +44,9 @@ export default (ComposedComponent, options = {}) => {
render () {
return (
<ReactRelayContext.Provider value={{ environment: this.environment, variables: {} }}>
<ReactRelayContext.Provider
value={{ environment: this.environment, variables: {} }}
>
<ComposedComponent {...this.props} />
</ReactRelayContext.Provider>
)
......
......@@ -46,7 +46,9 @@ export default (ComposedComponent, options = {}) => {
render () {
return (
<ReactRelayContext.Provider value={{ environment: this.environment, variables: {} }}>
<ReactRelayContext.Provider
value={{ environment: this.environment, variables: {} }}
>
<ComposedComponent {...this.props} />
</ReactRelayContext.Provider>
)
......
......@@ -7,10 +7,11 @@ Router.events.on('routeChangeComplete', url => {
window.analytics.page(url)
})
const Page = ({ children }) =>
const Page = ({ children }) => (
<div>
<Header />
{children}
</div>
)
export default Page
import 'semantic-ui-css/semantic.min.css'
import { Modal,
Button,
Icon
} from 'semantic-ui-react'
import { Modal, Button, Icon } from 'semantic-ui-react'
import SmallImage from './SmallImage.png'
import LargeImage from './LargeImage.png'
......@@ -13,24 +10,26 @@ export default () => (
<Icon size='massive' name='world' />
<div className='separator' />
<Modal trigger={<Button>Show Modal</Button>}>
<Modal.Header><em>publicPath</em> should be set to <em>/_next/static/</em></Modal.Header>
<Modal.Header>
<em>publicPath</em> should be set to <em>/_next/static/</em>
</Modal.Header>
<Modal.Content>
<Modal.Description>
<div className='wrapper'>
<div className='row'>
<p>
Larger content should be still availble as a fallback
to <em>fileLoader</em> but
it should not polute <em>/.next/static/css</em> folder.
You should see two images below.
One, smaller, loaded as data url, and one, bigger, loaded
Larger content should be still availble as a fallback to{' '}
<em>fileLoader</em> but it should not polute{' '}
<em>/.next/static/css</em> folder. You should see two images
below. One, smaller, loaded as data url, and one, bigger, loaded
via url.
</p>
</div>
<div className='row'>
<img src={SmallImage} />
<p>
A small image should be loaded as data url: <em>{SmallImage.substr(0, 100)}...</em>
A small image should be loaded as data url:{' '}
<em>{SmallImage.substr(0, 100)}...</em>
</p>
</div>
......@@ -41,8 +40,8 @@ export default () => (
</p>
</div>
<p className='border'>
You should also still be able to load regular css.
This text should have border.
You should also still be able to load regular css. This text
should have border.
</p>
</div>
</Modal.Description>
......
......@@ -62,7 +62,9 @@ export default class MyApp extends App {
<p>
<a
href='#'
onClick={() => Sentry.showReportDialog({ eventId: this.state.errorEventId })}
onClick={() =>
Sentry.showReportDialog({ eventId: this.state.errorEventId })
}
>
📣 Report this error
</a>
......@@ -70,7 +72,9 @@ export default class MyApp extends App {
<p>
<a
href='#'
onClick={() => { window.location.reload(true) }}
onClick={() => {
window.location.reload(true)
}}
>
Or, try reloading the page
</a>
......
......@@ -30,8 +30,16 @@ class Index extends React.Component {
<div>
<h2>Index page</h2>
<ul>
<li><a href='#' onClick={this.raiseErrorInRender}>Raise the error in render</a></li>
<li><a href='#' onClick={this.raiseErrorInUpdate}>Raise the error in componentDidUpdate</a></li>
<li>
<a href='#' onClick={this.raiseErrorInRender}>
Raise the error in render
</a>
</li>
<li>
<a href='#' onClick={this.raiseErrorInUpdate}>
Raise the error in componentDidUpdate
</a>
</li>
<li>
<Link href={{ pathname: '/', query: { raiseError: '1' } }}>
<a>Raise error in getInitialProps of client-loaded page</a>
......
......@@ -21,10 +21,12 @@ module.exports = (release = process.env.SENTRY_RELEASE) => {
sentryOptions.transport = sentryTransport
// Instead, dump the errors to the console
sentryOptions.integrations = [new Sentry.Integrations.Debug({
// Trigger DevTools debugger instead of using console.log
debugger: false
})]
sentryOptions.integrations = [
new Sentry.Integrations.Debug({
// Trigger DevTools debugger instead of using console.log
debugger: false
})
]
}
Sentry.init(sentryOptions)
......@@ -32,7 +34,7 @@ module.exports = (release = process.env.SENTRY_RELEASE) => {
return {
Sentry,
captureException: (err, ctx) => {
Sentry.configureScope((scope) => {
Sentry.configureScope(scope => {
if (err.message) {
// De-duplication currently doesn't work correctly for SSR / browser errors
// so we force deduplication by error message if it is present
......@@ -75,7 +77,9 @@ module.exports = (release = process.env.SENTRY_RELEASE) => {
}
if (errorInfo) {
Object.keys(errorInfo).forEach(key => scope.setExtra(key, errorInfo[key]))
Object.keys(errorInfo).forEach(key =>
scope.setExtra(key, errorInfo[key])
)
}
}
})
......
......@@ -15,7 +15,13 @@ class CustomKeygenEditor extends React.Component {
this.initialValue = Plain.deserialize(props.content)
}
render () {
return <Editor placeholder='Enter some plain text...' defaultValue={this.initialValue} style={this.props.style} />
return (
<Editor
placeholder='Enter some plain text...'
defaultValue={this.initialValue}
style={this.props.style}
/>
)
}
}
......
......@@ -3,7 +3,8 @@ import Link from 'next/link'
import CustomKeygenEditor from './CustomKeygenEditor'
const content = {
'first-editor': 'This example shows how to have multiple instances of the editor.',
'first-editor':
'This example shows how to have multiple instances of the editor.',
'second-editor': 'Without a custom key generator, you could not focus here.'
}
......@@ -15,7 +16,12 @@ class MultipleEditors extends React.Component {
<a>Go to Home</a>
</Link>
{Object.keys(content).map((key, idx) => (
<CustomKeygenEditor key={idx} uniqueId={key} content={content[key]} style={{ margin: 20 }} />
<CustomKeygenEditor
key={idx}
uniqueId={key}
content={content[key]}
style={{ margin: 20 }}
/>
))}
</React.Fragment>
)
......
......@@ -15,7 +15,12 @@ export default class MyDocument extends Document {
const initialProps = await Document.getInitialProps(ctx)
return {
...initialProps,
styles: <>{initialProps.styles}{sheet.getStyleElement()}</>
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
)
}
} finally {
sheet.seal()
......
export default () => (
<div>
<p>Environment variable process.env.TEST is "{process.env.TEST}"</p>
<p>Custom environment variables process.env.BACKEND_URL is "{process.env.BACKEND_URL}"</p>
<p>
Custom environment variables process.env.BACKEND_URL is "
{process.env.BACKEND_URL}"
</p>
</div>
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment