Merge pull request #4 from instat/ott-67-project-configuration

Ott 67 project configuration
keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Andrey Razdorskiy 6 years ago committed by GitHub
commit 64e0609013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .eslintignore
  2. 14
      .storybook/main.js
  3. 47
      .storybook/preview-head.html
  4. 7
      .storybook/preview.js
  5. 22
      codegen.yml
  6. 2
      commitlint.config.js
  7. 13
      package.json
  8. 8
      src/api/operations/User/queries.graphql
  9. 3
      src/api/operations/User/queries.tsx
  10. 7
      src/config/authKeys.tsx
  11. 2
      src/config/index.tsx
  12. 3
      src/config/pages.tsx
  13. 2
      src/config/routes.tsx
  14. 7
      src/helpers/callApi/checkStatus.tsx
  15. 6
      src/helpers/callApi/clearUserAuthInfo.tsx
  16. 29
      src/helpers/callApi/getRequestConfig.tsx
  17. 3
      src/helpers/callApi/getResponseData.tsx
  18. 36
      src/helpers/callApi/index.tsx
  19. 1
      src/helpers/callApi/loadIdToken.tsx
  20. 22
      src/helpers/callApi/logoutIfUnauthorized.tsx
  21. 1
      src/helpers/callApi/parseJSON.tsx
  22. 11
      src/helpers/callApi/removeCookie.tsx
  23. 11
      src/helpers/callApi/types.tsx
  24. 2
      src/helpers/index.tsx
  25. 11
      src/index.tsx
  26. 1
      src/react-app-env.d.ts
  27. 0
      src/requests/index.tsx
  28. 0
      src/requests/login.tsx
  29. 1
      src/serviceWorker.ts
  30. 3
      src/types/index.tsx

@ -1,4 +0,0 @@
src/types/*
src/api/operations/**/*.tsx
src/react-app-env.d.ts
src/serviceWorker.ts

@ -3,12 +3,10 @@ module.exports = {
addons: [
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/preset-create-react-app',
{
name: "@storybook/addon-docs",
options: {
configureJSX: true,
},
},
'@storybook/addon-docs',
'storybook-addon-styled-component-theme/dist/register',
],
};
presets: [
'@storybook/preset-create-react-app',
]
}

@ -0,0 +1,47 @@
<link
href='https://fonts.googleapis.com/css?family=PT+Sans:400,700&amp;amp;subset=cyrillic,latin'
rel='stylesheet' type='text/css'/>
<style>
*, *:before, *:after {
box-sizing: border-box;
}
body {
min-height: 100vh;
margin: 20;
padding: 20;
font-family: Montserrat, Tahoma, sans-serif;
font-size: 12px;
line-height: 12px;
color: #000;
}
h1, h2, h3, h4, h5, h6, p, ul, li {
margin: 0;
padding: 0;
font-size: 12px;
line-height: 12px;
}
ul, li {
list-style: none;
}
a {
text-decoration: none;
color: #000;
}
fieldset {
margin: 0;
min-width: 0;
padding: 0;
border: 0;
}
button, input, select, textarea {
font-family: inherit;
font-size: inherit;
line-height: inherit;
}
</style>

@ -0,0 +1,7 @@
import { addDecorator } from '@storybook/react'
import { withThemesProvider } from 'storybook-addon-styled-component-theme'
import { lightTheme, darkTheme } from '../src/features/Theme/config'
const themes = [darkTheme, lightTheme]
addDecorator(withThemesProvider(themes))

@ -1,22 +0,0 @@
overwrite: true
schema: ''
documents: src/api/operations/**/*.graphql
generates:
src/types/index.tsx:
plugins:
- typescript
src/:
preset:
near-operation-file
presetConfig:
extension: .tsx
baseTypesPath: types
plugins:
- typescript-operations
- typescript-react-apollo
config:
withComponent: false
withHOC: false
withHooks: true
config:
typesPrefix: T

@ -2,7 +2,7 @@ const Configuration = {
extends: ['@commitlint/config-conventional'],
/** Any rules defined here will override rules from
* @commitlint/config-conventional **/
* @commitlint/config-conventional */
rules: {
'body-max-length': [2, 'always', 120],
'body-min-length': [2, 'always', 3],

@ -3,22 +3,16 @@
"version": "0.1.0",
"private": true,
"scripts": {
"prestart ": "yarn generate",
"start": "react-scripts start",
"build": "GENERATE_SOURCEMAP=false react-scripts build && gzipper --verbose ./build",
"test": "react-scripts test --testMatch '**/__tests__/*' --passWithNoTests --watchAll=false",
"test:watch": "react-scripts test --testMatch '**/__tests__/*'",
"eject": "react-scripts eject",
"generate": "graphql-codegen --config codegen.yml",
"lint": "eslint 'src/**/*.{ts,tsx}'",
"storybook": "start-storybook -p 9009 -s public",
"build-storybook": "build-storybook -s public"
},
"dependencies": {
"@apollo/react-common": "^3.1.4",
"@apollo/react-hooks": "^3.1.5",
"apollo-boost": "^0.4.9",
"graphql": "^15.0.0",
"lodash": "^4.17.15",
"react": "^16.13.1",
"react-dom": "^16.13.1",
@ -27,12 +21,6 @@
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@graphql-codegen/cli": "1.15.0",
"@graphql-codegen/import-types-preset": "^1.15.0",
"@graphql-codegen/near-operation-file-preset": "^1.15.0",
"@graphql-codegen/typescript": "1.15.0",
"@graphql-codegen/typescript-operations": "1.15.0",
"@graphql-codegen/typescript-react-apollo": "1.15.0",
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-docs": "^5.3.19",
"@storybook/addon-links": "^5.3.19",
@ -62,6 +50,7 @@
"gzipper": "^3.7.0",
"husky": "^4.2.5",
"lint-staged": "^10.2.7",
"storybook-addon-styled-component-theme": "^1.3.0",
"ts-loader": "^7.0.5",
"typescript": "^3.9.3"
},

@ -1,8 +0,0 @@
query User {
__schema {
types {
name
kind
}
}
}

@ -1,3 +0,0 @@
// autgenerated using https://graphql-code-generator.com/
export {}

@ -0,0 +1,7 @@
export const AUTH_KEYS = {
authUser: 'AuthUser',
backLocation: 'backLocation',
cookieToken: 'token',
headerToken: 'x-auth-token',
idToken: 'id_token',
}

@ -1 +1,3 @@
export * from './routes'
export * from './pages'
export * from './authKeys'

@ -0,0 +1,3 @@
export const PAGES = {
login: '/login',
}

@ -1,2 +1,2 @@
export const API_ROOT = ''
export const GRAPHQL = `${API_ROOT}/graphql`
export const DATA_URL = `${API_ROOT}/data`

@ -0,0 +1,7 @@
export const checkStatus = (response: Response) => {
if (!response.ok) {
return Promise.reject(new Error(response.statusText))
}
return Promise.resolve(response)
}

@ -0,0 +1,6 @@
import { AUTH_KEYS } from 'config'
export const clearUserAuthInfo = () => {
localStorage.removeItem(AUTH_KEYS.idToken)
localStorage.removeItem(AUTH_KEYS.authUser)
}

@ -0,0 +1,29 @@
import { AUTH_KEYS } from 'config'
import { loadIdToken } from './loadIdToken'
import { TRequestConfig } from './types'
export const getRequestConfig = (
config: TRequestConfig,
signal?: AbortSignal,
) => {
const requestConfig = {
...config,
headers: config.headers || new Headers(),
method: config.method || 'POST',
signal,
}
if (config.body) {
requestConfig.body = JSON.stringify(config.body)
requestConfig.headers.set('Content-Type', 'application/json')
}
const token = loadIdToken()
if (token) {
requestConfig.headers.set(AUTH_KEYS.headerToken, token)
}
return requestConfig
}

@ -0,0 +1,3 @@
export const getResponseData = (proc: string) => (response: any) => (
response?.data?.[0]?.[proc]
)

@ -0,0 +1,36 @@
import { TCallApi } from './types'
import { parseJSON } from './parseJSON'
import { checkStatus } from './checkStatus'
import { getRequestConfig } from './getRequestConfig'
import { logoutIfUnauthorized } from './logoutIfUnauthorized'
export const callApiBase = ({
abortSignal,
config,
url,
}: TCallApi) => {
const requestConfig = getRequestConfig(config, abortSignal)
// eslint-disable-next-line no-console
console.log(
'%c callApi from module - config ',
'color: white; background-color: #95B46A',
config,
)
return fetch(url, requestConfig)
}
export const callApi = ({
abortSignal,
config,
url,
}: TCallApi) => (
callApiBase({
abortSignal,
config,
url,
}).then(checkStatus)
.then(parseJSON)
.catch(logoutIfUnauthorized)
)

@ -0,0 +1 @@
export const loadIdToken = () => localStorage.getItem('id_token')

@ -0,0 +1,22 @@
import { AUTH_KEYS, PAGES } from 'config'
import { removeCookie } from './removeCookie'
import { clearUserAuthInfo } from './clearUserAuthInfo'
export const logoutIfUnauthorized = (error: Error) => {
if (error.message === 'Unauthorized') {
clearUserAuthInfo()
removeCookie(AUTH_KEYS.cookieToken)
const { pathname } = window.location
if (pathname !== PAGES.login) {
localStorage.setItem(AUTH_KEYS.backLocation, pathname)
window.location.pathname = PAGES.login
}
}
// eslint-disable-next-line no-console
console.error(error)
return Promise.reject(error)
}

@ -0,0 +1 @@
export const parseJSON = (response: Response) => response.json()

@ -0,0 +1,11 @@
export const removeCookie = (
name: string,
domain: string = '.instatscout.com',
) => {
document.cookie = `
${name}=;
expires='Thu, 01 Jan 1970 00:00:00 UTC';
path=/;
domain=${domain}
`
}

@ -0,0 +1,11 @@
export type TRequestConfig = {
body?: any,
headers?: Headers,
method?: string,
}
export type TCallApi = {
abortSignal?: AbortSignal,
config: TRequestConfig,
url: string,
}

@ -1 +1 @@
export {}
export * from './callApi'

@ -1,22 +1,13 @@
import React from 'react'
import ReactDOM from 'react-dom'
import ApolloClient from 'apollo-boost'
import { ApolloProvider } from '@apollo/react-hooks'
import { GRAPHQL } from 'config'
import { App } from 'features/App'
import * as serviceWorker from './serviceWorker'
const client = new ApolloClient({
uri: GRAPHQL,
})
ReactDOM.render(
<React.StrictMode>
<ApolloProvider client={client}>
<App />
</ApolloProvider>
<App />
</React.StrictMode>,
document.getElementById('root'),
)

@ -1 +1,2 @@
// eslint-disable-next-line spaced-comment
/// <reference types="react-scripts" />

@ -1,3 +1,4 @@
/* eslint-disable */
// This optional code is used to register a service worker.
// register() is not called by default.

@ -1,3 +0,0 @@
// autgenerated using https://graphql-code-generator.com/
export {}
Loading…
Cancel
Save