Skip to content

Commit

Permalink
feat/fix: see offers + dev/prod toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
pcournut committed Jul 4, 2023
1 parent 7cfd3f5 commit f10c660
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 166 deletions.
6 changes: 0 additions & 6 deletions contexts/LoginContext.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export interface KentoEntity {
owner: string?;
owner_email: string
scan_terminal: string
access_name?: string
access_type?: string
price?: string
isUsed?: boolean
isSelect?: boolean
toUpdate? : boolean
accessName?: string
accessKentoType?: string
price?: string
}

export interface UpdatedEntity {
Expand Down
21 changes: 11 additions & 10 deletions views/ConfigureScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useContext } from "react";
import React, { useState, useEffect } from "react";
import {
Image,
FlatList,
Expand All @@ -12,7 +12,6 @@ import configureStyles from "../styles/configure";
import { Event, Access, KentoEntity, User, EnrichedUser } from "../types";
import { Feather } from "@expo/vector-icons";
import { devEndpoint, prodEndpoint } from "../constants";
import { LoginContext } from "../contexts/LoginContext";

export const ConfigureScreen = ({ navigation, route }) => {
// Functions
Expand All @@ -26,9 +25,12 @@ export const ConfigureScreen = ({ navigation, route }) => {
redirect: "follow",
};

console.log(route.params.devEnvironment);
try {
const response = await fetch(
`${devEnvironment ? devEndpoint : prodEndpoint}/wf/scanner-init`,
`${
route.params.devEnvironment ? devEndpoint : prodEndpoint
}/wf/scanner-init`,
requestOptions
);
const json = await response.json();
Expand Down Expand Up @@ -64,7 +66,7 @@ export const ConfigureScreen = ({ navigation, route }) => {
try {
const kentoEntityResponse = await fetch(
`${
devEnvironment ? devEndpoint : prodEndpoint
route.params.devEnvironment ? devEndpoint : prodEndpoint
}/obj/KentoEntity?cursor=${cursor}&api_token=${token}&constraints=[{ "key": "access","constraint_type":"in","value":[${accesses.map(
({ _id }) => '"' + _id + '"'
)}]},{ "key": "status","constraint_type":"equals","value":"confirmed"}]`,
Expand All @@ -80,7 +82,7 @@ export const ConfigureScreen = ({ navigation, route }) => {
console.log(`kentoEntites :${kentoEntities.length}`);
const userResponse = await fetch(
`${
devEnvironment ? devEndpoint : prodEndpoint
route.params.devEnvironment ? devEndpoint : prodEndpoint
}/obj/User?api_token=${token}&cursor=${cursor}&constraints=[{ "key": "_id", "constraint_type": "in", "value": [${kentoEntities
.filter((item: KentoEntity) => item.owner !== undefined)
.map(({ owner }) => '"' + owner + '"')}]}]`,
Expand All @@ -104,8 +106,8 @@ export const ConfigureScreen = ({ navigation, route }) => {
var access: Access = accesses.find(
(access) => access._id === kentoEntity.access
);
kentoEntity.accessName = access.name;
kentoEntity.accessKentoType = access.kento_type;
kentoEntity.access_name = access.name;
kentoEntity.access_type = access.kento_type;
var userIndex = enrichedUsers.findIndex(
// (user) => user._id === kentoEntity.owner
(user) => user.email === kentoEntity.owner_email
Expand All @@ -121,6 +123,7 @@ export const ConfigureScreen = ({ navigation, route }) => {
// In case the user has not registered, his email is his user ID
_id: kentoEntity.owner_email,
email: kentoEntity.owner_email,
first_name: "",
last_name: kentoEntity.owner_email,
kentoEntities: [kentoEntity],
};
Expand Down Expand Up @@ -178,6 +181,7 @@ export const ConfigureScreen = ({ navigation, route }) => {
enrichedUsers: enrichedUsers,
scanTerminal: scanTerminal,
selectedEvent: selectedEvent._id,
devEnvironment: route.params.devEnvironment,
});
} catch (error) {
console.log("error", error);
Expand Down Expand Up @@ -271,9 +275,6 @@ export const ConfigureScreen = ({ navigation, route }) => {
const [accesses, setAccesses] = useState<Access[]>([]);
const [scanTerminal, setScanTerminal] = useState<string>("");

// Environment variables
const { devEnvironment } = useContext(LoginContext);

// Init
useEffect(() => {
scannerInit(route.params.token);
Expand Down
2 changes: 1 addition & 1 deletion views/ListTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const ListTab = ({ route }) => {
)}
keyExtractor={(item) => item._id}
/>
<ScanBottomSheet ref={ref}></ScanBottomSheet>
<ScanBottomSheet route={route} ref={ref}></ScanBottomSheet>
</View>
);
};
203 changes: 99 additions & 104 deletions views/LoginScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useState } from "react";
import { useState } from "react";
import {
View,
Text,
Expand All @@ -16,7 +16,6 @@ import {
useClearByFocusCell,
} from "react-native-confirmation-code-field";
import { devEndpoint, prodEndpoint } from "../constants";
import { LoginContext } from "../contexts/LoginContext";

export const LoginScreen = ({ navigation }) => {
// Functions
Expand Down Expand Up @@ -53,6 +52,8 @@ export const LoginScreen = ({ navigation }) => {
redirect: "follow",
};

console.log(JSON.stringify(formdata));

try {
const response = await fetch(
`${devEnvironment ? devEndpoint : prodEndpoint}/wf/login`,
Expand All @@ -63,6 +64,7 @@ export const LoginScreen = ({ navigation }) => {
navigation.navigate("Configure", {
user_id: json.response.user_id,
token: json.response.token,
devEnvironment: devEnvironment,
});
} catch (error) {
console.log("error", error);
Expand All @@ -89,6 +91,7 @@ export const LoginScreen = ({ navigation }) => {
navigation.navigate("Configure", {
user_id: json.response.user_id,
token: json.response.token,
devEnvironment: devEnvironment,
});
} catch (error) {
console.log("error", error);
Expand Down Expand Up @@ -117,87 +120,28 @@ export const LoginScreen = ({ navigation }) => {

// Environment variables
const [devEnvironment, setDevEnvironment] = useState(true);
const toggleSwitch = () =>
setDevEnvironment((previousState) => !previousState);
const toggleSwitch = () => setDevEnvironment(!devEnvironment);

return (
<LoginContext.Provider
value={{
devEnvironment,
setDevEnvironment,
}}
>
<SafeAreaView style={{ flex: 1 }}>
<Text>Environment: {devEnvironment ? "dev" : "prod"}</Text>
<Switch
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={devEnvironment ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={devEnvironment}
<SafeAreaView style={{ flex: 1 }}>
<Text>Environment: {devEnvironment ? "dev" : "prod"}</Text>
<Switch
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={devEnvironment ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={devEnvironment}
/>
<View style={sharedStyles.container}>
<TextInput
value={email}
onChangeText={(email) => setEmail(email)}
placeholder="Enter email"
style={loginStyles.textInput}
/>
<View style={sharedStyles.container}>
<TextInput
value={email}
onChangeText={(email) => setEmail(email)}
placeholder="Enter email"
style={loginStyles.textInput}
/>

{validateEmail(email) && (
<>
<Pressable
style={({ pressed }) => [
{
opacity: pressed ? 0.6 : 1.0,
},
sharedStyles.pinkButton,
]}
onPress={() => {
sendCode(email);
setShowCode(true);
}}
>
<Text style={sharedStyles.textPinkButton}>Send code</Text>
</Pressable>
<Pressable
style={({ pressed }) => [
{
opacity: pressed ? 0.6 : 1.0,
},
sharedStyles.pinkButton,
]}
onPress={() => {
devConnect(email);
}}
>
<Text style={sharedStyles.textPinkButton}>Dev connect</Text>
</Pressable>
</>
)}
{showCode && (
<CodeField
ref={ref}
{...props}
// Use `caretHidden={false}` when users can't paste a text value, because context menu doesn't appear
value={value}
onChangeText={setValue}
cellCount={CELL_COUNT}
rootStyle={loginStyles.codeFieldRoot}
keyboardType="number-pad"
textContentType="oneTimeCode"
renderCell={({ index, symbol, isFocused }) => (
<Text
key={index}
style={[loginStyles.cell, isFocused && loginStyles.focusCell]}
onLayout={getCellOnLayoutHandler(index)}
>
{symbol || (isFocused ? <Cursor /> : null)}
</Text>
)}
/>
)}
{value.length == CELL_COUNT && (
{validateEmail(email) && (
<>
<Pressable
style={({ pressed }) => [
{
Expand All @@ -206,33 +150,84 @@ export const LoginScreen = ({ navigation }) => {
sharedStyles.pinkButton,
]}
onPress={() => {
verifyCode(email, value);
sendCode(email);
setShowCode(true);
}}
>
<Text style={sharedStyles.textPinkButton}>Confirm</Text>
<Text style={sharedStyles.textPinkButton}>Send code</Text>
</Pressable>
)}
{showCode && (
<>
<View style={sharedStyles.containerRow}>
<Text style={loginStyles.greyText}>Did not receive?</Text>
<Pressable
style={({ pressed }) => [
{
opacity: pressed ? 0.6 : 1.0,
},
]}
onPress={() => {
sendCode(email);
}}
>
<Text style={loginStyles.pinkText}>Resend code</Text>
</Pressable>
</View>
</>
)}
</View>
</SafeAreaView>
</LoginContext.Provider>
<Pressable
style={({ pressed }) => [
{
opacity: pressed ? 0.6 : 1.0,
},
sharedStyles.pinkButton,
]}
onPress={() => {
devConnect(email);
}}
>
<Text style={sharedStyles.textPinkButton}>Dev connect</Text>
</Pressable>
</>
)}
{showCode && (
<CodeField
ref={ref}
{...props}
// Use `caretHidden={false}` when users can't paste a text value, because context menu doesn't appear
value={value}
onChangeText={setValue}
cellCount={CELL_COUNT}
rootStyle={loginStyles.codeFieldRoot}
keyboardType="number-pad"
textContentType="oneTimeCode"
renderCell={({ index, symbol, isFocused }) => (
<Text
key={index}
style={[loginStyles.cell, isFocused && loginStyles.focusCell]}
onLayout={getCellOnLayoutHandler(index)}
>
{symbol || (isFocused ? <Cursor /> : null)}
</Text>
)}
/>
)}
{value.length == CELL_COUNT && (
<Pressable
style={({ pressed }) => [
{
opacity: pressed ? 0.6 : 1.0,
},
sharedStyles.pinkButton,
]}
onPress={() => {
verifyCode(email, value);
}}
>
<Text style={sharedStyles.textPinkButton}>Confirm</Text>
</Pressable>
)}
{showCode && (
<>
<View style={sharedStyles.containerRow}>
<Text style={loginStyles.greyText}>Did not receive?</Text>
<Pressable
style={({ pressed }) => [
{
opacity: pressed ? 0.6 : 1.0,
},
]}
onPress={() => {
sendCode(email);
}}
>
<Text style={loginStyles.pinkText}>Resend code</Text>
</Pressable>
</View>
</>
)}
</View>
</SafeAreaView>
);
};
Loading

0 comments on commit f10c660

Please sign in to comment.