Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified backend/CheckInApp/bin/Debug/net7.0/CheckInApp.dll
Binary file not shown.
Binary file modified backend/CheckInApp/bin/Debug/net7.0/CheckInApp.pdb
Binary file not shown.
138 changes: 66 additions & 72 deletions frontend/CheckInApp/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,91 @@
* @format
*/

import React, {FC, useEffect, useState} from 'react';
import {
Alert,
AppState,
AppStateStatus,
Button,
StyleSheet,
Text,
View,
} from 'react-native';
import React, { FC, useEffect, useState } from 'react';
import { Alert, AppState, AppStateStatus, Button, Text, View } from 'react-native';
import { UserInfo, UserService } from './user.service';

import {UserInfo, UserService} from './user.service';

function forceRenderHook() {
const [count, setCount] = useState(0);
return () => setCount(count + 1);
}

const HomeScreen: FC<{userInfo: UserInfo}> = ({userInfo}) => {
const forceRender = forceRenderHook();
const HomeScreen: FC<{
userInfo: UserInfo | null;
onCheckIn: () => Promise<void>;
onCheckOut: () => Promise<void>;
}> = ({ userInfo, onCheckIn, onCheckOut }) => {
const canCheckIn =
userInfo.lastCheckIn == null ||
userInfo?.lastCheckIn == null ||
(userInfo.lastCheckIn.timeIn != null &&
userInfo.lastCheckIn.timeOut != null);

return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text style={{color: canCheckIn ? 'red' : 'green'}}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={{ color: canCheckIn ? 'red' : 'green' }}>
{canCheckIn ? 'User is checked-out' : 'User is checked-in'}
</Text>
<Text style={{color: canCheckIn ? 'red' : 'green'}}>
<Text style={{ color: canCheckIn ? 'red' : 'green' }}>
{JSON.stringify(userInfo || {}, null, 4)}
</Text>
{canCheckIn && (
<Button
onPress={() => {
UserService.CheckIn().then(response => {
if (response.success) {
userInfo!.lastCheckIn = response.data;
forceRender();
} else {
Alert.alert(response.data || 'Unknown error');
if (response.data === 'You must be checked in to checkout') {
return UserService.UserInfo().then(r => {
if (r.success) {
userInfo!.lastCheckIn = r.data.lastCheckIn;
forceRender();
}
});
}
}
});
}}
title={'Check-In'}
/>
<Button onPress={onCheckIn} title={'Check-In'} />
)}

{!canCheckIn && (
<Button
onPress={() => {
UserService.CheckOut().then(response => {
if (response.success) {
userInfo!.lastCheckIn = response.data;
forceRender();
} else {
Alert.alert(response.data || 'Unknown error');
if (response.data === 'You were forced checkout') {
return UserService.UserInfo().then(r => {
if (r.success) {
userInfo!.lastCheckIn = r.data.lastCheckIn;
forceRender();
}
});
}
}
});
}}
title={'Checkout'}
/>
<Button onPress={onCheckOut} title={'CheckOut'} />
)}
</View>
);
};

function App(): JSX.Element {
const [userInfo, setUserInfo] = useState({});
const App: FC = () => {
const [userInfo, setUserInfo] = useState<UserInfo | null>(null);

const handleCheckIn = async () => {
const response = await UserService.CheckIn();
if (response.success) {
setUserInfo(prevUserInfo => ({
...prevUserInfo,
email: prevUserInfo?.email || "", // provide default value if undefined
lastCheckIn: response.data
}));
} else {
Alert.alert(response.data || 'Unknown error');
if (response.data === 'You must be checked in to checkout') {
const r = await UserService.UserInfo();
if (r.success) {
setUserInfo(prevUserInfo => ({
...prevUserInfo,
email: prevUserInfo?.email || "", // Ensure email field is always set
lastCheckIn: r.data.lastCheckIn
}));
}
}
}

};

const handleCheckOut = async () => {
const response = await UserService.CheckOut();
if (response.success) {
setUserInfo(prevUserInfo => ({
...prevUserInfo,
email: prevUserInfo?.email || "", // Ensure email field is always set
lastCheckIn: response.data
}));
} else {
Alert.alert(response.data || 'Unknown error');
if (response.data === 'You were forced checkout') {
const r = await UserService.UserInfo();
if (r.success) {
setUserInfo(prevUserInfo => ({
...prevUserInfo,
email: prevUserInfo?.email || "", // Ensure email field is always set
lastCheckIn: r.data.lastCheckIn
}));
}
}
}
};


useEffect(() => {
const appStateChangedHandler = async (state: AppStateStatus) => {
console.log('AppStateStatus', state);
if (state === 'active') {
const r = await UserService.UserInfo();
if (r.success) {
Expand All @@ -105,14 +100,13 @@ function App(): JSX.Element {
}
};
const handler = AppState.addEventListener('change', appStateChangedHandler);
// app launch
appStateChangedHandler(AppState.currentState);
return () => {
handler.remove();
};
}, []);

return <HomeScreen userInfo={userInfo} />;
}
return <HomeScreen userInfo={userInfo} onCheckIn={handleCheckIn} onCheckOut={handleCheckOut} />;
};

export default App;
6 changes: 4 additions & 2 deletions frontend/CheckInApp/ios/CheckInApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 7FAQS7D3VT;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = CheckInApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -498,7 +499,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.bowen.checkin;
PRODUCT_NAME = CheckInApp;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -513,6 +514,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 7FAQS7D3VT;
INFOPLIST_FILE = CheckInApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -524,7 +526,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.bowen.checkin;
PRODUCT_NAME = CheckInApp;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
3 changes: 3 additions & 0 deletions frontend/CheckInApp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"compilerOptions": {
"jsx": "react-native"
},
"extends": "@tsconfig/react-native/tsconfig.json"
}