Skip to content

Commit

Permalink
add see offers
Browse files Browse the repository at this point in the history
  • Loading branch information
pcournut committed Jul 4, 2023
1 parent d6cd0e1 commit 7cfd3f5
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 12 deletions.
2 changes: 2 additions & 0 deletions contexts/ScanScreenContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export const ScanScreenContext = createContext({
setEnrichedUsers: (value: EnrichedUser[]) => {},
selectedUserIndex: 0,
setSelectedUserIndex: (value: number) => {},
token: "",
selectedEvent: "",
});
11 changes: 6 additions & 5 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ export interface KentoEntity {
toUpdate? : boolean
accessName?: string
accessKentoType?: string
price?: string
}

export interface UpdatedEntity {
_id: string
access: string
owner: User
scan_terminal: string?
scan_date: string?
scan_terminal?: string
scan_date?: string
}

export interface Email {
Expand All @@ -45,13 +46,13 @@ export interface User {
_id: string
first_name: string
last_name: string
authentication: Authentication?;
email: string?
authentication?: Authentication
email?: string
}

export interface EnrichedUser {
_id: string
first_name: string?;
first_name?: string
last_name: string
email: string
kentoEntities: [KentoEntity]
Expand Down
1 change: 1 addition & 0 deletions views/ConfigureScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const ConfigureScreen = ({ navigation, route }) => {
nKentoEntities: nKentoEntities,
enrichedUsers: enrichedUsers,
scanTerminal: scanTerminal,
selectedEvent: selectedEvent._id,
});
} catch (error) {
console.log("error", error);
Expand Down
99 changes: 92 additions & 7 deletions views/ScanBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, {
useContext,
useMemo,
useRef,
useState,
} from "react";

import {
Expand All @@ -22,6 +23,8 @@ import Colors from "../colors";
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;
Expand All @@ -30,8 +33,13 @@ type Props = {};

export const ScanBottomSheet = forwardRef<Ref, Props>((props, ref) => {
// Context
const { enrichedUsers, setEnrichedUsers, selectedUserIndex } =
useContext(ScanScreenContext);
const {
enrichedUsers,
setEnrichedUsers,
selectedUserIndex,
token,
selectedEvent,
} = useContext(ScanScreenContext);

// BottomSheetModalProvider params
const bottomSheetModalRef = useRef<BottomSheetModal>(null);
Expand Down Expand Up @@ -133,6 +141,57 @@ export const ScanBottomSheet = forwardRef<Ref, Props>((props, ref) => {
handleCloseModalPress();
};

const getUserGuestlists = async (
token: string,
owner_email: string,
event_id: string
) => {
var myHeaders = new Headers();
myHeaders.append("Authorization", `Bearer ${token}`);
console.log(token);

var formdata = new FormData();
formdata.append("owner_email", owner_email);
formdata.append("event_id", event_id);

var requestOptions: RequestInit = {
method: "POST",
headers: myHeaders,
body: formdata,
redirect: "follow",
};

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

try {
const response = await fetch(
`${devEnvironment ? devEndpoint : prodEndpoint}/wf/get-user-guestlists`,
requestOptions
);
const json = await response.json();
console.log(`json: ${json}`);
if ("entities_text" in json.response) {
const offers: [KentoEntity] = JSON.parse(json.response.entities_text);
console.log(
`entities: ${JSON.stringify(JSON.parse(json.response.entities_text))}`
);
setOffers(JSON.parse(json.response.entities_text));
}
} catch (error) {
console.log("error", error);
}
};

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

// Variables
const [offers, setOffers] = useState<KentoEntity[]>([]);
const [displayOffers, setDisplayOffers] = useState(false);
const toggleSwitch = () =>
setDisplayOffers((previousState) => !previousState);

return (
<BottomSheetModalProvider>
<View style={sharedStyles.container}>
Expand All @@ -141,7 +200,7 @@ export const ScanBottomSheet = forwardRef<Ref, Props>((props, ref) => {
index={1}
snapPoints={snapPoints}
>
<Pressable
{/* <Pressable
style={({ pressed }) => [
{
opacity: pressed ? 0.6 : 1.0,
Expand All @@ -153,10 +212,29 @@ export const ScanBottomSheet = forwardRef<Ref, Props>((props, ref) => {
}}
>
<AntDesign name="close" size={24} color="black" />
</Pressable>
</Pressable> */}

{selectedUserIndex != -1 ? (
<>
<Pressable
style={{ alignItems: "flex-end", marginRight: "5%" }}
onPress={() => {
toggleSwitch();
if (!displayOffers) {
getUserGuestlists(
token,
enrichedUsers[selectedUserIndex].email,
selectedEvent
);
}
}}
>
<Text
style={{ fontWeight: "600", textDecorationLine: "underline" }}
>
{displayOffers ? "See passes" : "See offers"}
</Text>
</Pressable>
<Text
style={{
fontSize: 16,
Expand All @@ -180,13 +258,20 @@ export const ScanBottomSheet = forwardRef<Ref, Props>((props, ref) => {
>
{enrichedUsers[selectedUserIndex].email}
</Text>

<ScrollView
horizontal={true}
style={{ width: "90%", marginLeft: "5%" }}
>
{enrichedUsers[selectedUserIndex].kentoEntities.map((item) => (
<KentoEntityItem key={item._id} kentoEntity={item} />
))}
{displayOffers
? offers.map((item) => (
<KentoEntityItem key={item._id} kentoEntity={item} />
))
: enrichedUsers[selectedUserIndex].kentoEntities.map(
(item) => (
<KentoEntityItem key={item._id} kentoEntity={item} />
)
)}
</ScrollView>
<View
style={{
Expand Down
6 changes: 6 additions & 0 deletions views/ScanScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const listName = "List";

export const ScanScreen = ({ navigation, route }) => {
// Context variables
const [token, setToken] = useState(route.params.token);
const [selectedEvent, setSelectedEvent] = useState(
route.params.selectedEvent
);
const [enrichedUsers, setEnrichedUsers] = useState<EnrichedUser[]>(
route.params.enrichedUsers
);
Expand Down Expand Up @@ -168,6 +172,8 @@ export const ScanScreen = ({ navigation, route }) => {
setEnrichedUsers,
selectedUserIndex,
setSelectedUserIndex,
token,
selectedEvent,
}}
>
<Tab.Navigator
Expand Down

0 comments on commit 7cfd3f5

Please sign in to comment.