Skip to content

Commit

Permalink
* add editor configuration
Browse files Browse the repository at this point in the history
* add time-picker component
* add device info package
* add custom field option
  • Loading branch information
komelabbbas committed Sep 2, 2020
1 parent 92a3f1a commit f0bd63c
Show file tree
Hide file tree
Showing 16 changed files with 1,457 additions and 1,258 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
quote_type = single

[*.md]
trim_trailing_whitespace = false
7 changes: 4 additions & 3 deletions .prettierlc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
singleQuote: true,
trailingComma: 'all',
printWidth: 100,
parser: "flow",
arrowParens: "always",
parser: 'flow',
arrowParens: 'always',
tabWidth: 4,
};
semi: false
};
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "none",
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
20 changes: 20 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"jsx": "react-native",
"lib": [
"dom",
"esnext"
],
"moduleResolution": "node",
"noEmit": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"baseUrl": ".",
"paths": {
"@/*": [
"src/*"
]
}
}
}
1,709 changes: 912 additions & 797 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"eslint-plugin-flowtype": "^4.3.0",
"expo": "^37.0.0",
"expo-constants": "~9.0.0",
"expo-device": "~2.1.0",
"expo-file-system": "~8.1.0",
"expo-image-picker": "~8.1.0",
"expo-intent-launcher": "~8.1.0",
Expand Down
141 changes: 66 additions & 75 deletions src/api/request.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
// @flow

import { AsyncStorage } from 'react-native';
import { AsyncStorage } from 'react-native'
// import RNFetchBlob from 'rn-fetch-blob'

import { NavigationActions } from 'react-navigation';
import { store } from '../store';
import { env } from '../config';
import { NAVIGATION_PERSIST_KEY } from './consts/core';
import { ROUTES } from '../navigation/routes';
import { isIosPlatform, checkConnection, checkExpiredToken } from './helper';
import { resetIdToken } from '../features/authentication/actions';
import { NavigationActions } from 'react-navigation'
import { store } from '../store'
import { env } from '../config'
import { NAVIGATION_PERSIST_KEY } from './consts/core'
import { ROUTES } from '../navigation/routes'
import { checkConnection } from './helper'

type IProps = {
path: string,
method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE',
headers?: Object,
body?: Object,
};
body?: Object
}

export default class Request {
static async getIdToken() {
const data = await AsyncStorage.getItem(NAVIGATION_PERSIST_KEY);
const data = await AsyncStorage.getItem(NAVIGATION_PERSIST_KEY)

return data ? JSON.parse(data).auth.idToken : null;
return data ? JSON.parse(data).auth.idToken : null
}

static get(params) {
return this.request({ method: 'GET', ...params });
return this.request({ method: 'GET', ...params })
}

static post(params) {
return this.request({ method: 'POST', ...params });
return this.request({ method: 'POST', ...params })
}

static put(params) {
return this.request({ method: 'PUT', ...params });
return this.request({ method: 'PUT', ...params })
}

static delete(params) {
return this.request({ method: 'DELETE', ...params });
return this.request({ method: 'DELETE', ...params })
}

static patch(params) {
return this.request({ method: 'PATCH', ...params });
return this.request({ method: 'PATCH', ...params })
}
static async request({
path,
Expand All @@ -54,119 +53,111 @@ export default class Request {
imageName = '',
isAuthRequired = true,
isPing = null,
type = 'create',
type = 'create'
}: IProps) {
const reduxStore = store.getState();
const reduxStore = store.getState()

const { idToken, expiresIn = null } = reduxStore.auth;
const { endpointApi, company } = reduxStore.global;
const { idToken } = reduxStore.auth
const { endpointApi, company } = reduxStore.global

let apiUrl = (endpointApi !== null && typeof endpointApi !== 'undefined') ? endpointApi : env.ENDPOINT_API
let apiUrl =
endpointApi !== null && typeof endpointApi !== 'undefined'
? endpointApi
: env.ENDPOINT_API

if (isPing) {
apiUrl = isPing
}

const url = `${apiUrl}${path}`;
const url = `${apiUrl}${path}`
const isConnected = await checkConnection()

const isExpired = checkExpiredToken(expiresIn)

if (!isConnected) {
store.dispatch(
NavigationActions.navigate({
routeName: ROUTES.LOST_CONNECTION,
}),
);
return
}

if (isExpired && isAuthRequired) {
store.dispatch(resetIdToken());
store.dispatch(
NavigationActions.navigate({
routeName: ROUTES.AUTH,
}),
);
routeName: ROUTES.LOST_CONNECTION
})
)
return
}


const ID_TOKEN = await this.getIdToken();
const ID_TOKEN = await this.getIdToken()
const defaultHeaders = image
? {
Authorization: `Bearer ${idToken}` || `Bearer ${ID_TOKEN}`,
company: company ? company.id : 1,
Accept: 'application/json'
}
Authorization: `Bearer ${idToken}` || `Bearer ${ID_TOKEN}`,
company: company ? company.id : 1,
Accept: 'application/json'
}
: {
Authorization: `Bearer ${idToken}` || `Bearer ${ID_TOKEN}`,
'Content-Type': 'application/json',
company: company ? company.id : 1,
Accept: 'application/json'
};
Authorization: `Bearer ${idToken}` || `Bearer ${ID_TOKEN}`,
'Content-Type': 'application/json',
company: company ? company.id : 1,
Accept: 'application/json'
}

const formData = new FormData();
const formData = new FormData()

if (image) {
const uri = image.uri;
const uriParts = uri.split('.');
const fileType = uriParts[uriParts.length - 1];

formData.append(imageName, JSON.stringify({
name: `${imageName}.${fileType}`,
data: image.base64.trimRight()
}))
const uri = image.uri
const uriParts = uri.split('.')
const fileType = uriParts[uriParts.length - 1]

formData.append(
imageName,
JSON.stringify({
name: `${imageName}.${fileType}`,
data: image.base64.trimRight()
})
)

type && formData.append('type', type)

for (const key in body) {
if (body.hasOwnProperty(key)) {
formData.append(key, body[key]);
formData.append(key, body[key])
}
}
}

let options = {
method,
body: image ? formData : JSON.stringify(body),
headers: { ...defaultHeaders, ...headers },
};
headers: { ...defaultHeaders, ...headers }
}

return fetch(url, options).then((response) => {
return fetch(url, options).then(response => {
const {
headers: { map },
} = response;
headers: { map }
} = response

if (response.status === 500) {
throw response;
throw response
}

if (response.status === 401) {
store.dispatch(
NavigationActions.navigate({
routeName: ROUTES.AUTH,
}),
);
routeName: ROUTES.AUTH
})
)
}

if (response.status === 403 || response.status === 404) {

throw response;
throw response
}

if (response.ok) {
if (response.status === 204) {
return Promise.resolve();
return Promise.resolve()
} else {
if (fullResponse) {
return response;
return response
}

return response.json().then((v) => v);
return response.json().then(v => v)
}
}
throw response;
});
throw response
})
}
}
Loading

0 comments on commit f0bd63c

Please sign in to comment.