diff --git a/contexts/LoginContext.tsx b/contexts/LoginContext.tsx deleted file mode 100644 index 8744bc0..0000000 --- a/contexts/LoginContext.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import { createContext } from "react"; - -export const LoginContext = createContext({ - devEnvironment: true, - setDevEnvironment: (value: boolean) => {}, -}); diff --git a/types.d.ts b/types.d.ts index 4e33ea9..10eacaf 100644 --- a/types.d.ts +++ b/types.d.ts @@ -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 { diff --git a/views/ConfigureScreen.tsx b/views/ConfigureScreen.tsx index d31c95f..202ba7b 100644 --- a/views/ConfigureScreen.tsx +++ b/views/ConfigureScreen.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useContext } from "react"; +import React, { useState, useEffect } from "react"; import { Image, FlatList, @@ -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 @@ -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(); @@ -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"}]`, @@ -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 + '"')}]}]`, @@ -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 @@ -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], }; @@ -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); @@ -271,9 +275,6 @@ export const ConfigureScreen = ({ navigation, route }) => { const [accesses, setAccesses] = useState([]); const [scanTerminal, setScanTerminal] = useState(""); - // Environment variables - const { devEnvironment } = useContext(LoginContext); - // Init useEffect(() => { scannerInit(route.params.token); diff --git a/views/ListTab.tsx b/views/ListTab.tsx index 2e2ed13..0f855ce 100644 --- a/views/ListTab.tsx +++ b/views/ListTab.tsx @@ -136,7 +136,7 @@ export const ListTab = ({ route }) => { )} keyExtractor={(item) => item._id} /> - + ); }; diff --git a/views/LoginScreen.tsx b/views/LoginScreen.tsx index 4ccba7d..d5b124a 100644 --- a/views/LoginScreen.tsx +++ b/views/LoginScreen.tsx @@ -1,4 +1,4 @@ -import { useContext, useState } from "react"; +import { useState } from "react"; import { View, Text, @@ -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 @@ -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`, @@ -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); @@ -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); @@ -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 ( - - - Environment: {devEnvironment ? "dev" : "prod"} - + Environment: {devEnvironment ? "dev" : "prod"} + + + setEmail(email)} + placeholder="Enter email" + style={loginStyles.textInput} /> - - setEmail(email)} - placeholder="Enter email" - style={loginStyles.textInput} - /> - {validateEmail(email) && ( - <> - [ - { - opacity: pressed ? 0.6 : 1.0, - }, - sharedStyles.pinkButton, - ]} - onPress={() => { - sendCode(email); - setShowCode(true); - }} - > - Send code - - [ - { - opacity: pressed ? 0.6 : 1.0, - }, - sharedStyles.pinkButton, - ]} - onPress={() => { - devConnect(email); - }} - > - Dev connect - - - )} - {showCode && ( - ( - - {symbol || (isFocused ? : null)} - - )} - /> - )} - {value.length == CELL_COUNT && ( + {validateEmail(email) && ( + <> [ { @@ -206,33 +150,84 @@ export const LoginScreen = ({ navigation }) => { sharedStyles.pinkButton, ]} onPress={() => { - verifyCode(email, value); + sendCode(email); + setShowCode(true); }} > - Confirm + Send code - )} - {showCode && ( - <> - - Did not receive? - [ - { - opacity: pressed ? 0.6 : 1.0, - }, - ]} - onPress={() => { - sendCode(email); - }} - > - Resend code - - - - )} - - - + [ + { + opacity: pressed ? 0.6 : 1.0, + }, + sharedStyles.pinkButton, + ]} + onPress={() => { + devConnect(email); + }} + > + Dev connect + + + )} + {showCode && ( + ( + + {symbol || (isFocused ? : null)} + + )} + /> + )} + {value.length == CELL_COUNT && ( + [ + { + opacity: pressed ? 0.6 : 1.0, + }, + sharedStyles.pinkButton, + ]} + onPress={() => { + verifyCode(email, value); + }} + > + Confirm + + )} + {showCode && ( + <> + + Did not receive? + [ + { + opacity: pressed ? 0.6 : 1.0, + }, + ]} + onPress={() => { + sendCode(email); + }} + > + Resend code + + + + )} + + ); }; diff --git a/views/ScanBottomSheet.tsx b/views/ScanBottomSheet.tsx index 780ea43..59286a2 100644 --- a/views/ScanBottomSheet.tsx +++ b/views/ScanBottomSheet.tsx @@ -1,4 +1,3 @@ -import { Button } from "@rneui/themed"; import React, { forwardRef, useCallback, @@ -24,14 +23,16 @@ import scanStyles from "../styles/scan"; import sharedStyles from "../styles/shared"; import { KentoEntity, EnrichedUser } from "../types"; import { devEndpoint, prodEndpoint } from "../constants"; -import { LoginContext } from "../contexts/LoginContext"; type Ref = { displayComponent: () => void; }; type Props = {}; -export const ScanBottomSheet = forwardRef((props, ref) => { +export const ScanBottomSheet = forwardRef((props, ref) => { + // Access the route prop here + const { route } = props; + // Context const { enrichedUsers, @@ -51,6 +52,8 @@ export const ScanBottomSheet = forwardRef((props, ref) => { const displayComponent = () => { handlePresentModalPress(); + setOffers([]); + setDisplayOffers(false); }; React.useImperativeHandle(ref, () => ({ displayComponent })); @@ -76,6 +79,8 @@ export const ScanBottomSheet = forwardRef((props, ref) => { }; const KentoEntityItem = (props: { kentoEntity: KentoEntity }) => ( + {props.kentoEntity.price === undefined || + props.kentoEntity.price === "FREE"} [ { @@ -83,7 +88,11 @@ export const ScanBottomSheet = forwardRef((props, ref) => { }, ]} onPress={() => { - if (!props.kentoEntity.isUsed) { + if ( + (props.kentoEntity.price === undefined || + props.kentoEntity.price === "FREE") && + !props.kentoEntity.isUsed + ) { selectItem(props.kentoEntity); } }} @@ -102,12 +111,15 @@ export const ScanBottomSheet = forwardRef((props, ref) => { validated - ) : ( + ) : props.kentoEntity.price === undefined || + props.kentoEntity.price === "FREE" ? ( + ) : ( + unusable )} ((props, ref) => { marginTop: 5, marginBottom: 5, }} - source={imageDict[props.kentoEntity.accessKentoType]} + source={imageDict[props.kentoEntity.access_type]} /> - {props.kentoEntity.accessName} + {props.kentoEntity.access_name} + {props.kentoEntity.price !== undefined && ( + + {props.kentoEntity.price} + + )} @@ -129,12 +146,21 @@ export const ScanBottomSheet = forwardRef((props, ref) => { // Functions const validateSelection = () => { var newEnrichedUsers: EnrichedUser[] = Object.assign([], enrichedUsers); - for (const KentoEntity of newEnrichedUsers[selectedUserIndex] + for (const kentoEntity of newEnrichedUsers[selectedUserIndex] .kentoEntities) { - if (KentoEntity.isSelect) { - KentoEntity.isUsed = true; - KentoEntity.isSelect = false; - KentoEntity.toUpdate = true; + if (kentoEntity.isSelect) { + kentoEntity.isUsed = true; + kentoEntity.isSelect = false; + kentoEntity.toUpdate = true; + } + } + for (let [index, kentoEntity] of offers.entries()) { + if (kentoEntity.isSelect) { + kentoEntity.isUsed = true; + kentoEntity.isSelect = false; + kentoEntity.toUpdate = true; + newEnrichedUsers[selectedUserIndex].kentoEntities.push(kentoEntity); + delete offers[index]; } } setEnrichedUsers(newEnrichedUsers); @@ -148,11 +174,16 @@ export const ScanBottomSheet = forwardRef((props, ref) => { ) => { var myHeaders = new Headers(); myHeaders.append("Authorization", `Bearer ${token}`); - console.log(token); + // myHeaders.append( + // "Authorization", + // `Bearer 1687187724797x532446159231898940` + // ); var formdata = new FormData(); formdata.append("owner_email", owner_email); formdata.append("event_id", event_id); + // formdata.append("owner_email", "axel.duheme@gmail.com"); + // formdata.append("event_id", "1686509948185x333270189445742600"); var requestOptions: RequestInit = { method: "POST", @@ -161,16 +192,17 @@ export const ScanBottomSheet = forwardRef((props, ref) => { redirect: "follow", }; - console.log(JSON.stringify(formdata)); - console.log(JSON.stringify(myHeaders)); + console.log(`devEnvironment: ${route.params.devEnvironment}`); try { const response = await fetch( - `${devEnvironment ? devEndpoint : prodEndpoint}/wf/get-user-guestlists`, + `${ + route.params.devEnvironment ? devEndpoint : prodEndpoint + }/wf/get-user-guestlists`, requestOptions ); const json = await response.json(); - console.log(`json: ${json}`); + console.log(`json: ${JSON.stringify(json)}`); if ("entities_text" in json.response) { const offers: [KentoEntity] = JSON.parse(json.response.entities_text); console.log( @@ -183,9 +215,6 @@ export const ScanBottomSheet = forwardRef((props, ref) => { } }; - // Environment variables - const { devEnvironment } = useContext(LoginContext); - // Variables const [offers, setOffers] = useState([]); const [displayOffers, setDisplayOffers] = useState(false); @@ -200,20 +229,6 @@ export const ScanBottomSheet = forwardRef((props, ref) => { index={1} snapPoints={snapPoints} > - {/* [ - { - opacity: pressed ? 0.6 : 1.0, - }, - { alignItems: "flex-end", marginRight: "5%" }, - ]} - onPress={() => { - handleCloseModalPress(); - }} - > - - */} - {selectedUserIndex != -1 ? ( <> ((props, ref) => { }, enrichedUsers[selectedUserIndex].kentoEntities.filter( (item: KentoEntity) => item.isSelect - ).length > 0 + ).length + + offers.filter((item: KentoEntity) => item.isSelect) + .length > + 0 ? scanStyles.pinkButton : scanStyles.greyButton, ]} @@ -300,7 +318,10 @@ export const ScanBottomSheet = forwardRef((props, ref) => { {enrichedUsers[selectedUserIndex].kentoEntities.filter( (item: KentoEntity) => item.isSelect - ).length > 0 + ).length + + offers.filter((item: KentoEntity) => item.isSelect) + .length > + 0 ? "Validate" : `Select pass to validate`} diff --git a/views/ScanScreen.tsx b/views/ScanScreen.tsx index 8c05aa3..19b45e1 100644 --- a/views/ScanScreen.tsx +++ b/views/ScanScreen.tsx @@ -1,12 +1,11 @@ import { createBottomTabNavigator } from "@react-navigation/bottom-tabs"; -import React, { useContext, useEffect, useState } from "react"; +import React, { useEffect, useState } from "react"; import Ionicons from "react-native-vector-icons/Ionicons"; import { ScanScreenContext } from "../contexts/ScanScreenContext"; import { Access, KentoEntity, EnrichedUser, UpdatedEntity } from "../types"; import { ListTab } from "./ListTab"; import { CameraTab } from "./CameraTab"; import { devEndpoint, prodEndpoint } from "../constants"; -import { LoginContext } from "../contexts/LoginContext"; const Tab = createBottomTabNavigator(); @@ -27,9 +26,6 @@ export const ScanScreen = ({ navigation, route }) => { Date.now() ); - // Environment variables - const { devEnvironment } = useContext(LoginContext); - // Functions const participantListUpdate = async ( kentoEntityIds: string[], @@ -66,7 +62,7 @@ export const ScanScreen = ({ navigation, route }) => { try { const response = await fetch( `${ - devEnvironment ? devEndpoint : prodEndpoint + route.params.devEnvironment ? devEndpoint : prodEndpoint }/wf/participant-list-update`, requestOptions );