Commit fbe456d2 authored by Ramesh Hettiarachchi's avatar Ramesh Hettiarachchi

Initial commit

parents
Pipeline #2297 failed with stages
{
"f9155ac790fd02fadcdeca367b02581c04a353aa6d5aa84409a59f6804c87acd": true,
"89ed26367cdb9b771858e026f2eb95bfdb90e5ae943e716575327ec325f39c44": true
}
\ No newline at end of file
node_modules/**/*
.expo/*
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/
web-report/
# macOS
.DS_Store
// Initialize some variables before react-native code would access them
var onmessage=null, self=global;
// Cache Node's original require as __debug__.require
global.__debug__={require: require};
// Prevent leaking process.versions from debugger process to
// worker because pure React Native doesn't do that and some packages as js-md5 rely on this behavior
Object.defineProperty(process, "versions", {
value: undefined
});
function getNativeModules() {
var NativeModules;
try {
// This approach is for old RN versions
NativeModules = global.require('NativeModules');
} catch (err) {
// ignore error and try another way for more recent RN versions
try {
var nativeModuleId;
var modules = global.__r.getModules();
var ids = Object.keys(modules);
for (var i = 0; i < ids.length; i++) {
if (modules[ids[i]].verboseName) {
var packagePath = new String(modules[ids[i]].verboseName);
if (packagePath.indexOf("react-native/Libraries/BatchedBridge/NativeModules.js") > 0) {
nativeModuleId = parseInt(ids[i], 10);
break;
}
}
}
if (nativeModuleId) {
NativeModules = global.__r(nativeModuleId);
}
}
catch (err) {
// suppress errors
}
}
return NativeModules;
}
// Originally, this was made for iOS only
var vscodeHandlers = {
'vscode_reloadApp': function () {
var NativeModules = getNativeModules();
if (NativeModules) {
NativeModules.DevMenu.reload();
}
},
'vscode_showDevMenu': function () {
var NativeModules = getNativeModules();
if (NativeModules) {
NativeModules.DevMenu.show();
}
}
};
process.on("message", function (message) {
if (message.data && vscodeHandlers[message.data.method]) {
vscodeHandlers[message.data.method]();
} else if(onmessage) {
onmessage(message);
}
});
var postMessage = function(message){
process.send(message);
};
if (!self.postMessage) {
self.postMessage = postMessage;
}
var importScripts = (function(){
var fs=require('fs'), vm=require('vm');
return function(scriptUrl){
var scriptCode = fs.readFileSync(scriptUrl, "utf8");
// Add a 'debugger;' statement to stop code execution
// to wait for the sourcemaps to be processed by the debug adapter
vm.runInThisContext('debugger;' + scriptCode, {filename: scriptUrl});
};
})();
// Worker is ran as nodejs process, so console.trace() writes to stderr and it leads to error in native app
// To avoid this console.trace() is overridden to print stacktrace via console.log()
// Please, see Node JS implementation: https://github.com/nodejs/node/blob/master/lib/internal/console/constructor.js
console.trace = (function() {
return function() {
try {
var err = {
name: 'Trace',
message: require('util').format.apply(null, arguments)
};
// Node uses 10, but usually it's not enough for RN app trace
Error.stackTraceLimit = 30;
Error.captureStackTrace(err, console.trace);
console.log(err.stack);
} catch (e) {
console.error(e);
}
};
})();
// As worker is ran in node, it breaks broadcast-channels package approach of identifying if it’s ran in node:
// https://github.com/pubkey/broadcast-channel/blob/master/src/util.js#L64
// To avoid it if process.toString() is called if will return empty string instead of [object process].
var nativeObjectToString = Object.prototype.toString;
Object.prototype.toString = function() {
if (this === process) {
return '';
} else {
return nativeObjectToString.call(this);
}
};
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
/* global __fbBatchedBridge, self, importScripts, postMessage, onmessage: true */
/* eslint no-unused-vars: 0 */
'use strict';
onmessage = function () {
var visibilityState;
var showVisibilityWarning = function () {
var hasWarned = false;
return function () {
// Wait until `YellowBox` gets initialized before displaying the warning.
if (hasWarned || console.warn.toString().includes('[native code]')) {
return;
}
hasWarned = true;
console.warn('Remote debugger is in a background tab which may cause apps to ' + 'perform slowly. Fix this by foregrounding the tab (or opening it in ' + 'a separate window).');
};
}();
var messageHandlers = {
executeApplicationScript: function (message, sendReply) {
for (var key in message.inject) {
self[key] = JSON.parse(message.inject[key]);
}
var error;
try {
importScripts(message.url);
} catch (err) {
error = err.message;
}
sendReply(null
/* result */
, error);
},
setDebuggerVisibility: function (message) {
visibilityState = message.visibilityState;
}
};
return function (message) {
if (visibilityState === 'hidden') {
showVisibilityWarning();
}
var object = message.data;
var sendReply = function (result, error) {
postMessage({
replyID: object.id,
result: result,
error: error
});
};
var handler = messageHandlers[object.method];
if (handler) {
// Special cased handlers
handler(object, sendReply);
} else {
// Other methods get called on the bridge
var returnValue = [[], [], [], 0];
var error;
try {
if (typeof __fbBatchedBridge === 'object') {
returnValue = __fbBatchedBridge[object.method].apply(null, object.arguments);
} else {
error = 'Failed to call function, __fbBatchedBridge is undefined';
}
} catch (err) {
error = err.message;
} finally {
sendReply(JSON.stringify(returnValue), error);
}
}
};
}();
// Notify debugger that we're done with loading
// and started listening for IPC messages
postMessage({workerLoaded:true});
\ No newline at end of file
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Android",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "launch",
"platform": "android",
"debuggerWorkerUrlPath": "${workspaceFolder}/.vscode/.react/debuggerWorker.js"
},
{
"name": "Attach to packager",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "attach",
"port": "19001"
}
]
}
\ No newline at end of file
import * as React from 'react';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import LoginScreen from './src/components/Screens/LoginScreen';
import { Provider } from 'react-redux';
import store from './src/store';
import DashBoardScreen from './src/components/Screens/DashBoardScreen';
import NavigationService from './src/navigationService';
const MainNavigator = createStackNavigator({
Login: { screen: LoginScreen },
DashBoard: { screen: DashBoardScreen }
},
{
initialRouteName: 'Login',
});
const App = createAppContainer(MainNavigator);
export default () => (
<Provider store={store}>
<App
ref={(navigatorRef) => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
</Provider>
);
{
"expo": {
"name": "React Native Test",
"slug": "react-native-test",
"privacy": "public",
"sdkVersion": "35.0.0",
"platforms": [
"ios",
"android",
"web"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
}
}
}
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@react-native-community/async-storage": "^1.6.2",
"axios": "^0.19.0",
"expo": "^35.0.0",
"react": "16.8.3",
"react-dom": "16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
"react-native-gesture-handler": "~1.3.0",
"react-native-progress": "^4.0.1",
"react-native-web": "^0.11.7",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^1.10.3",
"react-redux": "^7.1.1",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/react": "^16.8.23",
"@types/react-native": "^0.57.65",
"@types/react-redux": "^7.1.5",
"@types/redux": "^3.6.0",
"@types/redux-thunk": "^2.1.0",
"babel-preset-expo": "^7.1.0",
"typescript": "^3.6.3"
},
"private": true
}
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
import { SERVER_URL } from './config';
import { ErrorResponse, SuccessResponse } from './types';
const request = <T> (
url: string,
parameters?: { [x in string]: any },
userToken?:string,
config: undefined | AxiosRequestConfig = {}
) =>
axios
.post(SERVER_URL + 'api/medical/v1/' + url, parameters, {
...config,
headers:{
...config.headers,
[userToken?"Authorization":"Accept"]: userToken?"Bearer "+userToken:"application/json"
}
})
.then((response: AxiosResponse): T&SuccessResponse => ({
result: true,
...response.data
}))
.catch((err: AxiosError): ErrorResponse => ({
message: typeof err.response !== 'undefined' ? err.response.data.message : '',
result: false
}));
interface LoginResponse {
name: string;
token: string;
email: string;
reportAccess: string;
}
const authController = {
login: (username:string, password: string)=>request<LoginResponse>('login',{username,password}),
userDetails: (userToken:string)=>request<LoginResponse>("userDetails",{},userToken)
}
export default {
authController
}
\ No newline at end of file
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { AppState } from '../../rootReducer';
import { connect } from 'react-redux';
import { CommonState } from '../../store/App/types';
import { ThunkDispatch } from 'redux-thunk';
import { checkAuth } from '../../store/App/actions';
interface IProps extends CommonState {
onLoad:()=>void;
}
const mapStateToProps = (state: AppState) => ({
...state.common
});
const mapDispatchToProps = (dispatch:ThunkDispatch<{},{},any>)=>({
onLoad:()=>dispatch(checkAuth(true))
})
class DashBoardScreen extends React.Component<IProps> {
constructor(props: IProps) {
super(props);
if(!props.loggedUser){
props.onLoad();
}
}
public render() {
const { loggedUser } = this.props;
if(!loggedUser){
return null;
}
return (
<View style={styles.container}>
<Text>{loggedUser.name}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
paddingLeft: 16,
paddingRight: 16
}
});
export default connect(mapStateToProps,mapDispatchToProps)(DashBoardScreen);
import React from 'react';
import { StyleSheet, Text, View, TextInput, Button, ToolbarAndroid } from 'react-native';
import agent from '../../agent';
import { AppState } from '../../rootReducer';
import { ThunkDispatch } from 'redux-thunk';
import { connect } from 'react-redux';
import { changeUsername, changePassword } from '../../store/LoginScreen/actions';
import { LoginFormState } from '../../store/LoginScreen/types';
import { CircleSnail } from 'react-native-progress';
import { login, checkAuth } from '../../store/App/actions';
import { LoggedUser } from '../../types';
import { NavigationStackProp } from 'react-navigation-stack';
interface IProps extends LoginFormState {
onChangeUsername: (username: string) => void;
onChangePassword: (password: string) => void;
onSubmit: (username: string, password: string) => void;
onLoad: () => void;
loggedUser?: LoggedUser;
navigation: NavigationStackProp<{ }>;
}
const mapStateToProps = (state: AppState) => ({
...state.loginScreen,
...state.common
});
const mapDispatchToProps = (dispatch: ThunkDispatch<{}, {}, any>) => ({
onChangeUsername: (username: string) => dispatch(changeUsername(username)),
onChangePassword: (password: string) => dispatch(changePassword(password)),
onSubmit: (username: string, password: string) => dispatch(login(username, password)),
onLoad: () => dispatch(checkAuth(false))
});
class LoginScreen extends React.Component<IProps> {
constructor(props: IProps) {
super(props);
props.onLoad();
}
public render() {
const { username, password, onChangePassword, onChangeUsername, loading, loggedUser } = this.props;
if (loggedUser) {
return (
<View style={styles.container}>
<Text>You have already logged in</Text>
<Button title="DASHBOARD" onPress={this.handleClickDashBoard}/>
</View>
);
}
return (
<View style={styles.container}>
{loading ? (
<CircleSnail color={[ 'red', 'green', 'blue' ]} />
) : (
<React.Fragment>
<Text>Please fill below inputs</Text>
<TextInput
style={styles.textInput}
placeholder="Your Name"
value={username}
onChangeText={onChangeUsername}
/>
<TextInput
style={styles.textInput}
secureTextEntry={true}
placeholder="Your Password"
value={password}
onChangeText={onChangePassword}
/>
<Button onPress={this.handleLoginClicked} title="Login" />
</React.Fragment>
)}
</View>
);
}
protected handleLoginClicked = () => {
const { username, password, onSubmit } = this.props;
onSubmit(username, password);
};
protected handleClickDashBoard = ()=>{
const {navigation} = this.props;
navigation.navigate("DashBoard");
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
paddingLeft: 16,
paddingRight: 16
},
textInput: {
borderWidth: 2,
borderColor: '#e0e0e0',
borderStyle: 'solid',
width: '100%',
paddingLeft: 8,
marginTop: 8,
marginBottom: 8
}
});
export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen);
export const SERVER_URL = "http://shl.salespad.lk/healthcare/";
\ No newline at end of file
import { NavigationActions } from 'react-navigation';
let _navigator;
function setTopLevelNavigator(navigatorRef) {
_navigator = navigatorRef;
}
function navigate(routeName, params) {
_navigator.dispatch(
NavigationActions.navigate({
routeName,
params,
})
);
}
// add other navigation functions that you need and export them
export default {
navigate,
setTopLevelNavigator,
};
\ No newline at end of file
import { combineReducers } from "redux";
import loginScreen from "./store/LoginScreen/reducer";
import common from "./store/App/reducer";
const rootReducer = combineReducers({
loginScreen,
common
});
export type AppState = ReturnType<typeof rootReducer>;
export default rootReducer;
\ No newline at end of file
import { applyMiddleware,createStore, Middleware } from "redux";
import thunk from "redux-thunk";
import rootReducer from "./rootReducer";
let middleware: Middleware[] = [thunk];
const createStoreWithMiddleware = applyMiddleware(...middleware)(createStore);
export default createStoreWithMiddleware(rootReducer);
\ No newline at end of file