diff --git a/front/pages/_app.tsx b/front/pages/_app.tsx index d3d5f77c..6b63a4fd 100644 --- a/front/pages/_app.tsx +++ b/front/pages/_app.tsx @@ -1,33 +1,28 @@ import App, { Container, NextAppContext } from 'next/app' import Head from 'next/head' -import React, { Component as ReactComponent } from 'react' +import React from 'react' import { Provider } from 'react-redux' +import { Option } from 'tsoption' import { AppContext } from '@front/domain/AppContext' -import { Store } from '@front/domain/store/Store' +import { WithReduxProps } from '@front/domain/store/WithReduxProps' import { withReduxStore } from '@front/domain/store/withReduxStore' -interface Props { - reduxStore: Store - pageProps: any - Component: ReactComponent -} - -class OncohelpWeb extends App { - public static getInitialProps(context: NextAppContext) { - const ctx: AppContext = context.ctx as any +class CheckmoneyWeb extends App { + public static getInitialProps(appContext: NextAppContext) { + const ctx: AppContext = appContext.ctx as any - if (ctx.req && ctx.req.cookies) { - // TODO: option - const token: string | undefined = ctx.req.cookies.token + const token = Option.of(ctx) + .map(context => context.req) + .map(request => request.cookies) + .map(cookies => cookies.token) - if (token) { - // TODO: - // ctx.reduxStore.dispatch(setToken(token)) - } + if (token.nonEmpty()) { + // TODO: + // ctx.reduxStore.dispatch(setToken(token)) } - return App.getInitialProps(context) + return App.getInitialProps(appContext) } public render() { @@ -46,4 +41,4 @@ class OncohelpWeb extends App { } } -export default withReduxStore(OncohelpWeb) +export default withReduxStore(CheckmoneyWeb) diff --git a/front/src/domain/store/WithReduxProps.ts b/front/src/domain/store/WithReduxProps.ts new file mode 100644 index 00000000..92f40e57 --- /dev/null +++ b/front/src/domain/store/WithReduxProps.ts @@ -0,0 +1,5 @@ +import { Store } from './Store' + +export interface WithReduxProps { + reduxStore: Store +} diff --git a/front/src/domain/store/withReduxStore.tsx b/front/src/domain/store/withReduxStore.tsx index d6c7068f..8218a4f0 100644 --- a/front/src/domain/store/withReduxStore.tsx +++ b/front/src/domain/store/withReduxStore.tsx @@ -1,13 +1,17 @@ -import React from 'react' +import App, { AppProps, DefaultAppIProps, NextAppContext } from 'next/app' +import React, { ComponentType } from 'react' import { AppContext } from '../AppContext' import { getOrCreateStore } from './getOrCreateStore' import { Store } from './Store' +import { WithReduxProps } from './WithReduxProps' -import { NextAppContext } from 'next/app' +type NextProps = AppProps & DefaultAppIProps -export const withReduxStore = (App: any) => { - return class AppWithRedux extends React.Component { +export const withReduxStore = ( + Application: ComponentType, +) => { + return class AppWithRedux extends React.Component { public static async getInitialProps(appContext: NextAppContext) { const reduxStore = getOrCreateStore() const context: AppContext = appContext.ctx as any @@ -33,7 +37,7 @@ export const withReduxStore = (App: any) => { } public render() { - return + return } } } diff --git a/package.json b/package.json index bb0aa49a..2af9a1bc 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "circular": "madge --circular --extensions ts ./ --tsConfig tsconfig.madge.json" }, "dependencies": { - "tsconfig-paths": "^3.7.0" + "tsconfig-paths": "^3.7.0", + "tsoption": "^0.7.0" }, "devDependencies": { "@commitlint/cli": "^7.2.1",