Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #16 from saucelabs/feat/add-failed-api
Browse files Browse the repository at this point in the history
Feat/add failed api
  • Loading branch information
wswebcreation authored May 5, 2022
2 parents a5f87d4 + 5bb1dd9 commit 86e4cdd
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 85 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ android {
applicationId "com.saucelabs.mydemoapp.rn"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 230
versionName "1.2.0"
versionCode 240
versionName "1.2.1"
// For the QR-code scanner
missingDimensionStrategy 'react-native-camera', 'general'
}
Expand Down
4 changes: 2 additions & 2 deletions ios/MyRNDemoApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.0</string>
<string>1.2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -34,7 +34,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>150</string>
<string>157</string>
<key>LSRequiresIPhoneOS</key>
<true />
<key>NSAppTransportSecurity</key>
Expand Down
4 changes: 2 additions & 2 deletions ios/MyRNDemoAppTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.0</string>
<string>1.2.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>150</string>
<string>157</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "my-demo-app-rn",
"version": "1.2.0",
"version": "1.2.1",
"private": true,
"scripts": {
"android.clean": "cd android && ./gradlew clean && cd .. ",
Expand Down
63 changes: 33 additions & 30 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwagLabsStatusBar from './components/StatusBar';
import Linking from './navigation/Linking';
import {StoreProvider} from './store/Store';
import {Text} from 'react-native';
import {IS_IOS} from './utils/Constants';

//Ignore all log notifications
LogBox.ignoreAllLogs();
Expand All @@ -31,36 +32,38 @@ const App = () => {
false;

useEffect(() => {
// We call stop to support hot-swap during development.
// This call will be ignored silently for the initial app launch.
TestFairy.stop();
/////////////////////////////////////////////////////////////////////////////////////////
//
// Launch a TestFairy session. The session url will be in the logs for you to navigate.
// Optionally, specify a private cloud endpoint if it applies to you.
//
// When TestFairy launches a session, these will be listened collected until the session
// is stopped or app is closed:
//
// - logs
// - crashes
// - video recording
// - http network events
// - feedbacks via forms launched when the users shakes their device
// - custom attributes set in the code w/ TestFairy.setAttribute()
// - events sent in the code w/ TestFairy.addEvent()
//
// and many others.
//
// All of this data will be available in your TestFairy web dashboard as well as
// the REST API.
//
/////////////////////////////////////////////////////////////////////////////////////////
// TestFairy.setServerEndpoint("https://your.privatecloud.example.com") // Private cloud only
TestFairy.begin(process.env.TESTFAIRY_TOKEN);
// Swap this line with the above if you don't want to record a session but still need
// the shake gesture detection for the feedbacks.
// TestFairy.installFeedbackHandler(process.env['TESTFAIRY_TOKEN']);
if (!IS_IOS) {
// We call stop to support hot-swap during development.
// This call will be ignored silently for the initial app launch.
TestFairy.stop();
/////////////////////////////////////////////////////////////////////////////////////////
//
// Launch a TestFairy session. The session url will be in the logs for you to navigate.
// Optionally, specify a private cloud endpoint if it applies to you.
//
// When TestFairy launches a session, these will be listened collected until the session
// is stopped or app is closed:
//
// - logs
// - crashes
// - video recording
// - http network events
// - feedbacks via forms launched when the users shakes their device
// - custom attributes set in the code w/ TestFairy.setAttribute()
// - events sent in the code w/ TestFairy.addEvent()
//
// and many others.
//
// All of this data will be available in your TestFairy web dashboard as well as
// the REST API.
//
/////////////////////////////////////////////////////////////////////////////////////////
// TestFairy.setServerEndpoint("https://your.privatecloud.example.com") // Private cloud only
TestFairy.begin(process.env.TESTFAIRY_TOKEN);
// Swap this line with the above if you don't want to record a session but still need
// the shake gesture detection for the feedbacks.
// TestFairy.installFeedbackHandler(process.env['TESTFAIRY_TOKEN']);
}
}, []);

return (
Expand Down
28 changes: 24 additions & 4 deletions src/components/DcButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,32 @@ const DcButtons = ({
{LOCATION.EU.label}
</Text>
</Pressable>
<Pressable
style={[styles.dcButton, dc === DcEnum.US ? styles.active : {}]}
onPress={() => selectDc(DcEnum.US)}>
<Text style={[dc === DcEnum.US ? styles.activeText : {}]}>
{LOCATION.US.label}
</Text>
</Pressable>
<Pressable
style={[
styles.dcButton,
dc === DcEnum.UNAUTHORIZED ? styles.active : {},
]}
onPress={() => selectDc(DcEnum.UNAUTHORIZED)}>
<Text style={[dc === DcEnum.UNAUTHORIZED ? styles.activeText : {}]}>
{LOCATION.UNAUTHORIZED.label}
</Text>
</Pressable>
<Pressable
style={[
styles.dcButton,
styles.borderRight,
dc === DcEnum.US ? styles.active : {},
dc === DcEnum.NOT_FOUND ? styles.active : {},
]}
onPress={() => selectDc(DcEnum.US)}>
<Text style={[dc === DcEnum.US ? styles.activeText : {}]}>
{LOCATION.US.label}
onPress={() => selectDc(DcEnum.NOT_FOUND)}>
<Text style={[dc === DcEnum.NOT_FOUND ? styles.activeText : {}]}>
{LOCATION.NOT_FOUND.label}
</Text>
</Pressable>
</View>
Expand All @@ -43,14 +60,17 @@ const styles = StyleSheet.create({
display: 'flex',
flexDirection: 'row',
marginVertical: 10,
justifyContent: 'space-between',
},
dcButton: {
borderWidth: 1,
borderColor: Colors.lightGray,
paddingVertical: 12,
justifyContent: 'center',
alignItems: 'center',
// flex: 1,
flexGrow: 1,
flexBasis: 1,
},
borderLeft: {
borderTopLeftRadius: 4,
Expand Down
44 changes: 36 additions & 8 deletions src/containers/ApiCallsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ const ApiCallsPage = () => {
const [devicesList, setDevicesList] = useState<DevicesInterface[] | null>(
null,
);
const [errorMessage, setErrorMessage] = useState<Error | null>(null);
const numColumns = 2;
useEffect(() => {
getDevices(dc).then(devices => {
if (devices) {
setDevicesList(devices);
}
});
setErrorMessage(null);
getDevices(dc)
.then(devices => {
if (devices) {
setDevicesList(devices);
}
})
.catch(error => {
setErrorMessage(error);
});
}, [dc]);
const selectDc = (dataCenter: DcEnum) => {
setDevicesList(null);
Expand Down Expand Up @@ -47,9 +53,17 @@ const ApiCallsPage = () => {
numColumns={numColumns}
keyExtractor={item => item.id}
ListEmptyComponent={
<View style={styles.emptyContainer}>
<Text>Loading devices</Text>
</View>
errorMessage ? (
<View style={styles.errorContainer}>
<Text style={styles.errorText}>
{errorMessage?.message || 'Network request failed'}
</Text>
</View>
) : (
<View style={styles.emptyContainer}>
<Text style={styles.loadingText}>Loading devices</Text>
</View>
)
}
showsVerticalScrollIndicator={false}
/>
Expand All @@ -74,12 +88,26 @@ const styles = StyleSheet.create({
paddingVertical: 0,
flex: 0,
},
errorContainer: {
backgroundColor: Colors.slRed,
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
errorText: {
color: Colors.white,
fontSize: 20,
},
emptyContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 20,
},
loadingText: {
fontSize: 20,
},
flatListContainer: {
flex: 3,
paddingHorizontal: 15,
Expand Down
20 changes: 14 additions & 6 deletions src/containers/CartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Button from '../components/Button';
import {testProperties} from '../config/TestProperties';
import I18n from '../config/I18n';
import {parseDeepLinkProductData} from '../utils/DeepLinking';
import {addSwagItem, checkoutCart, removeSwagItem} from '../data/apiCalls';

type CartProps = {
navigation: StackNavigationProp<CartStackParamList, ROUTES.CART>;
Expand Down Expand Up @@ -51,12 +52,18 @@ const CartPage = ({navigation, route}: CartProps) => {
}
}, [dispatch, items, route]);

const addItem = (cartItem: CartItemInterface) =>
const addItem = (cartItem: CartItemInterface) => {
dispatch(addProductToCart(cartItem));
const deleteItem = (cartItem: CartItemInterface) =>
addSwagItem(cartItem);
};
const deleteItem = (cartItem: CartItemInterface) => {
dispatch(deleteProductFromCart(cartItem));
const removeItem = (cartItem: CartItemInterface) =>
removeSwagItem(cartItem);
};
const removeItem = (cartItem: CartItemInterface) => {
dispatch(removeProductFromCart(cartItem));
removeSwagItem(cartItem);
};

return (
<View style={styles.container}>
Expand Down Expand Up @@ -110,11 +117,12 @@ const CartPage = ({navigation, route}: CartProps) => {
</ScrollView>
{cartContent.totalAmount > 0 && (
<CheckoutFooter
onPress={() =>
onPress={() => {
checkoutCart(cartContent);
isLoggedIn
? navigation.navigate(ROUTES.CHECKOUT_ADDRESS)
: navigation.navigate(ROUTES.LOGIN)
}
: navigation.navigate(ROUTES.LOGIN);
}}
title={I18n.t('cart.filledCartButtonText')}
totalNumber={cartContent.totalAmount}
totalPrice={cartContent.totalPrice}
Expand Down
15 changes: 14 additions & 1 deletion src/containers/ProductPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useContext, useState} from 'react';
import React, {useContext, useEffect, useState} from 'react';
import {Image, ScrollView, StyleSheet, Text, View} from 'react-native';
import {ROUTES} from '../navigation/Routes';
import {StoreFlowStackParamList} from '../navigation/types';
Expand All @@ -22,6 +22,7 @@ import {ITEM_COLOR_TYPE, ITEM_COLORS} from '../data/inventoryData';
import I18n from '../config/I18n';
import {testProperties} from '../config/TestProperties';
import {StackNavigationProp} from '@react-navigation/stack';
import {addSwagItem, getSwagItem} from '../data/apiCalls';

type ProductProps = {
navigation: StackNavigationProp<StoreFlowStackParamList, ROUTES.STORE>;
Expand Down Expand Up @@ -77,10 +78,22 @@ const ProductPage = ({navigation, route}: ProductProps) => {
selectedColor,
}),
);
addSwagItem({
...selectedProduct,
amount: counterAmount,
selectedColor,
});
}
};
const changeColor = (color: ITEM_COLOR_TYPE) => setSelectedColor(color);

useEffect(() => {
async function fetchData() {
return getSwagItem(id);
}
fetchData();
});

return (
<ScrollView
style={styles.container}
Expand Down
10 changes: 9 additions & 1 deletion src/containers/StorePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useContext, useState} from 'react';
import React, {useContext, useEffect, useState} from 'react';
import {FlatList, StyleSheet, View} from 'react-native';
import {StackNavigationProp} from '@react-navigation/stack';
import {Colors} from '../styles/Colors';
Expand All @@ -14,6 +14,7 @@ import {ROUTES} from '../navigation/Routes';
import {StoreContext} from '../store/Store';
import {updateSorting} from '../store/actions/ProductStoreActions';
import I18n from '../config/I18n';
import {initCall} from '../data/apiCalls';

type StoreProps = {
navigation: StackNavigationProp<StoreFlowStackParamList, ROUTES.STORE>;
Expand All @@ -34,6 +35,13 @@ const StorePage = ({navigation}: StoreProps) => {
const openProductDetails = (id: number) =>
navigation.push(ROUTES.PRODUCT, {id});

useEffect(() => {
async function fetchData() {
return initCall();
}
fetchData();
});

return (
<View
style={styles.container}
Expand Down
Loading

0 comments on commit 86e4cdd

Please sign in to comment.