Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/bahl aryan/log in #36

Merged
merged 7 commits into from
Sep 13, 2024
Merged
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
2 changes: 1 addition & 1 deletion App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const App = (props) => {
const searchParams = new URL(event.url).searchParams;
const token = searchParams.get('token');
if (token) {
dispatch(setToken(token))
const decoded = decodeToken(token);
console.log("token", token, "decoded token", decoded);
console.log(decoded.roles);
Expand All @@ -83,6 +82,7 @@ const App = (props) => {
setDeepLinkHandled(false);
} else {
console.log('dispatched')
dispatch(setToken(token));
dispatch(setRoles(decoded.roles));
setDeepLinkHandled(true);
}
Expand Down
2 changes: 1 addition & 1 deletion api/postCheckIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from "axios";
export const postCheckIn = async(token, eventId, qrCode) => {
const payload = { eventId, qrCode }
try {
const response = await axios.post('https://api.reflectionsprojections.org/staff/scan/', payload, {
const response = await axios.post('https://api.reflectionsprojections.org/scan/staff/', payload, {
headers: {
Authorization: token
}
Expand Down
2 changes: 1 addition & 1 deletion navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const AppNavigator: React.FC = () => {
case "AdminScanner":
return (
<MaterialCommunityIcons
name="camera"
name="qrcode-scan"
color={focused ? ACTIVE_COLOR : INACTIVE_COLOR}
size={35}
/>
Expand Down
37 changes: 21 additions & 16 deletions screens/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NavigationProp, ParamListBase } from "@react-navigation/native";
import { useAppSelector } from "../redux/hooks";
import { RootState } from "../redux/store";
import Colors from "../constants/Colors";
import { useState } from "react";

import ScreenImage from "../assets/SVGs/login/LoginScreen.svg";

Expand All @@ -27,28 +28,32 @@ const { width, height } = Dimensions.get("window");
const Login: React.FC<LoginProps> = ({ navigation }) => {
const token = useAppSelector((state: RootState) => state.token);
const roles = useAppSelector((state: RootState) => state.roles);
const [loggedIn, setLoggedIn] = useState(false);

useEffect(() => {
if (token && roles.includes('USER')) {
navigation.navigate("Main");
setLoggedIn(true);
}
}, [token, navigation]);
}, [token, roles, navigation]);

const handleLoginPress = () => {
WebBrowser.openAuthSessionAsync(
`${authUrl}?redirect_uri=${redirectURL}`,
redirectURL
)
.then((result) => {
if (result.type === "success") {
console.log("opening url for log in ")
Linking.openURL(result.url);
}
})
.catch((err) => {
console.error("Failed to open URL:", err.message);
alert("Failed to open URL");
});
if(loggedIn) {
navigation.navigate("Main");
} else {
WebBrowser.openAuthSessionAsync(
`${authUrl}?redirect_uri=${redirectURL}`,
redirectURL
)
.then((result) => {
if (result.type === "success") {
Linking.openURL(result.url);
}
})
.catch((err) => {
console.error("Failed to open URL:", err.message);
alert("Failed to open URL");
});
}
};

return (
Expand Down
9 changes: 7 additions & 2 deletions screens/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const Profile: React.FC = () => {
<SafeAreaView style={styles.safeArea}>
<Background style={styles.background} height={height} width={width} preserveAspectRatio="none"/>
<Logout style={styles.logout} width={'35%'} height={'5%'} preserveAspectRatio="none" onPress={handleLogOut}/>
{attendee && qrcode &&
{(attendee && qrcode) ? (
<View style={styles.qrContainer}>
<View style={styles.qrFrameContainer}>
{foodWave == 1 ? (
Expand All @@ -145,7 +145,12 @@ const Profile: React.FC = () => {
</View>
<StyledText variant="profileText" color={Colors.WHITE} style={styles.profileText}>{attendee.name}</StyledText>
<FoodWaveSVG foodWave={foodWave} />
</View>}
</View>):
(
<View style={styles.qrContainer}>
<StyledText variant="profileText" color={Colors.WHITE} fontSize={24}>Please register on the R|P Website!</StyledText>
</View>
)}
</SafeAreaView>
);
};
Expand Down
9 changes: 8 additions & 1 deletion screens/Shop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Shop: React.FC = () => {
<Text style={styles.points}>Your Points:</Text>
<Image
source={require("../assets/pixel.png")}
style={styles.tokenImage}
style={styles.tokenImage2}
/>
<Text style={styles.myPoints}>x{userPoints}</Text>
</View>
Expand Down Expand Up @@ -119,6 +119,7 @@ const styles = StyleSheet.create({
alignItems: "center",
justifyContent: "center",
marginBottom: 20,

},
points: {
fontSize: 17,
Expand All @@ -132,10 +133,16 @@ const styles = StyleSheet.create({
fontFamily: "PressStart2P_400Regular",
color: Colors.YELLOW,
},
tokenImage2: {
width: 30,
height: 30,
marginRight: 5,
},
tokenImage: {
width: 30,
height: 30,
marginRight: 5,
marginLeft: 10
},
photoContainer: {
flex: 1,
Expand Down
Loading