Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
SamratSahoo committed Nov 13, 2024
1 parent 62978b3 commit 0a09307
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 147 deletions.
5 changes: 1 addition & 4 deletions mobile/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ export default function App() {
name={Screens.USER_DASHBOARD_SCREEN}
component={UserDashboardScreen}
/>
<Stack.Screen
name={Screens.USER_SETTINGS}
component={UserSettings}
/>
<Stack.Screen name={Screens.USER_SETTINGS} component={UserSettings} />
<Stack.Screen
name={Screens.ADMIN_DASHBOARD_SCREEN}
component={AdminDashboardScreen}
Expand Down
4 changes: 2 additions & 2 deletions mobile/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const userCreateUser = async (
lastName?: string,
handlerType?: HandlerType,
profileImage?: string,
annualPetVisitDay?: Date,
annualPetVisitDay?: Date
) => {
return internalRequest<User>({
url: userUserUrl,
Expand Down Expand Up @@ -53,7 +53,7 @@ export const userUpdateUser = async (
profileImage?: string,
nextPrescriptionReminder?: Date,
userCreation?: boolean,
unsubscribeEmail?: boolean,
unsubscribeEmail?: boolean
) => {
const user = internalRequest<User>({
url: userUserUrl,
Expand Down
6 changes: 2 additions & 4 deletions mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"infoPlist": {
Expand Down Expand Up @@ -54,4 +52,4 @@
"package": "org.healing4heroes"
}
}
}
}
9 changes: 7 additions & 2 deletions mobile/components/DashboardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ const DashboardHeader = ({
<Text style={styles.profileName}>
{userInfo?.firstName} {userInfo?.lastName}
</Text>
<IconButton icon={
<MaterialCommunityIcons name="account-settings" size={26} color="#3F3BED" />
<IconButton
icon={
<MaterialCommunityIcons
name="account-settings"
size={26}
color="#3F3BED"
/>
}
callbackFunction={() => {
navigationProp.navigate(Screens.USER_SETTINGS);
Expand Down
2 changes: 1 addition & 1 deletion mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@
},
"private": true,
"type": "commonjs"
}
}
29 changes: 16 additions & 13 deletions mobile/screens/Banners/CampGraceBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
import dayjs from "dayjs";

const CampGraceBanner = () => {
const isCampGraceDay = new Date().getMonth() === 3 && new Date().getDate() === 13;

if (!isCampGraceDay) return null;
const isCampGraceDay =
new Date().getMonth() === 3 && new Date().getDate() === 13;

return (
<View style={styles.banner}>
<Text style={styles.title}>Countdown to Camp Grace!</Text>
<Text style={styles.message}>
Get ready for a 4-Day advanced training at Camp Grace in Mobile, Alabama! Enjoy free cabin accommodations, fishing, kayaking, and group cooking sessions. Just bring bedding for a twin bed. See you soon!
</Text>
</View>
);
if (!isCampGraceDay) return null;

return (
<View style={styles.banner}>
<Text style={styles.title}>Countdown to Camp Grace!</Text>
<Text style={styles.message}>
Get ready for a 4-Day advanced training at Camp Grace in Mobile,
Alabama! Enjoy free cabin accommodations, fishing, kayaking, and group
cooking sessions. Just bring bedding for a twin bed. See you soon!
</Text>
</View>
);
};

const styles = StyleSheet.create({
banner: {
borderRadius: 10,
Expand All @@ -39,7 +42,7 @@ const styles = StyleSheet.create({
fontSize: 12,
fontWeight: "400",
textAlign: "center",
}
},
});

export default CampGraceBanner;
7 changes: 4 additions & 3 deletions mobile/screens/User/UserDashboardScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function UserDashboardScreen(props: any) {
);
return;
}

if (today >= new Date(userInformation?.nextPrescriptionReminder)) {
addToModalQueue(
"prescription",
Expand Down Expand Up @@ -226,15 +226,16 @@ export default function UserDashboardScreen(props: any) {

if (
new Date(animal?.dateOfBirth as Date).getMonth() ===
new Date().getMonth() &&
new Date().getMonth() &&
new Date(animal?.dateOfBirth as Date).getDate() === new Date().getDate()
) {
addToModalQueue(
"birthday",
`Happy birthday ${animal.name}!!! \uE312`,
`${animal.name} turned ${calculateAge(
new Date(animal.dateOfBirth ?? "")
)} year${calculateAge(new Date(animal.dateOfBirth ?? "")) !== 1 ? "s" : ""
)} year${
calculateAge(new Date(animal.dateOfBirth ?? "")) !== 1 ? "s" : ""
} old today!`
);
}
Expand Down
233 changes: 115 additions & 118 deletions mobile/screens/User/UserSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,135 +1,132 @@
import React from 'react';
import { View, Text } from 'react-native';
import { StyleSheet, Switch } from 'react-native';
import { useEffect, useState } from 'react';
import React from "react";
import { View, Text } from "react-native";
import { StyleSheet, Switch } from "react-native";
import { useEffect, useState } from "react";
import { User } from "../../utils/types";
import { userGetUserInfo } from "../../actions/User";
import { ErrorWrapper, endOfExecutionHandler } from "../../utils/error";
import BaseOverlay from "../../components/Overlays/BaseOverlay";
import ErrorBox from "../../components/ErrorBox";
import IconButton from "../../components/IconButton";
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { Screens } from '../../utils/types';
import { userUpdateUser } from '../../actions/User';
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { Screens } from "../../utils/types";
import { userUpdateUser } from "../../actions/User";

export default function UserSettings(props: any) {
const [error, setError] = useState<string>("");
const [userInfo, setUserInfo] = useState<User | null>(null);
const [error, setError] = useState<string>("");
const [userInfo, setUserInfo] = useState<User | null>(null);

useEffect(() => {
async function getUserInfo() {
try {
const user: User = (await ErrorWrapper({
functionToExecute: userGetUserInfo,
errorHandler: setError,
})) as User;
if (user.unsubscribeEmail === undefined) {
user.unsubscribeEmail = false;
await userUpdateUser(
user.roles,
user.birthday,
user.firstName,
user.lastName,
user.handlerType,
user.address,
user.annualPetVisitDay,
user.profileImage,
user.nextPrescriptionReminder,
false,
user.unsubscribeEmail,
);
}
setUserInfo(user);
} catch (error) {
endOfExecutionHandler(error as Error);
}
}
getUserInfo().catch();
}, []);


const toggleSwitch = async () => {
// Change userInfo on this page and change in database
const updatedUserInfo = {
...userInfo,
unsubscribeEmail: !userInfo?.unsubscribeEmail
}
setUserInfo(updatedUserInfo as User);
await userUpdateUser(
updatedUserInfo.roles,
updatedUserInfo.birthday,
updatedUserInfo.firstName,
updatedUserInfo.lastName,
updatedUserInfo.handlerType,
updatedUserInfo.address,
updatedUserInfo.annualPetVisitDay,
updatedUserInfo.profileImage,
updatedUserInfo.nextPrescriptionReminder,
useEffect(() => {
async function getUserInfo() {
try {
const user: User = (await ErrorWrapper({
functionToExecute: userGetUserInfo,
errorHandler: setError,
})) as User;
if (user.unsubscribeEmail === undefined) {
user.unsubscribeEmail = false;
await userUpdateUser(
user.roles,
user.birthday,
user.firstName,
user.lastName,
user.handlerType,
user.address,
user.annualPetVisitDay,
user.profileImage,
user.nextPrescriptionReminder,
false,
updatedUserInfo.unsubscribeEmail,
);
user.unsubscribeEmail
);
}
setUserInfo(user);
} catch (error) {
endOfExecutionHandler(error as Error);
}
}
getUserInfo().catch();
}, []);

return (
<BaseOverlay
header={
<View style={styles.header}>
<Text>{/* This is just to align the text */}</Text>
<Text style={styles.headerText}>User Settings</Text>
<IconButton
callbackFunction={() => {
props.navigation.navigate(Screens.USER_DASHBOARD_SCREEN);
}}
icon={
<MaterialCommunityIcons name="home" size={26} color="#3F3BED" />
}
/>
</View>
}
const toggleSwitch = async () => {
// Change userInfo on this page and change in database
const updatedUserInfo = {
...userInfo,
unsubscribeEmail: !userInfo?.unsubscribeEmail,
};
setUserInfo(updatedUserInfo as User);
await userUpdateUser(
updatedUserInfo.roles,
updatedUserInfo.birthday,
updatedUserInfo.firstName,
updatedUserInfo.lastName,
updatedUserInfo.handlerType,
updatedUserInfo.address,
updatedUserInfo.annualPetVisitDay,
updatedUserInfo.profileImage,
updatedUserInfo.nextPrescriptionReminder,
false,
updatedUserInfo.unsubscribeEmail
);
};

body={
<View style={styles.container}>
<View style={styles.setting}>
<Text style={styles.settingText}>Unsubscribe from Emails?</Text>
<Switch
trackColor={{ false: "#EBEBE4", true: "#32CD32" }}
thumbColor={"#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={userInfo?.unsubscribeEmail}
/>
</View>
</View>
return (
<BaseOverlay
header={
<View style={styles.header}>
<Text>{/* This is just to align the text */}</Text>
<Text style={styles.headerText}>User Settings</Text>
<IconButton
callbackFunction={() => {
props.navigation.navigate(Screens.USER_DASHBOARD_SCREEN);
}}
icon={
<MaterialCommunityIcons name="home" size={26} color="#3F3BED" />
}

footer={<ErrorBox errorMessage={error} />}
/>
);
/>
</View>
}
body={
<View style={styles.container}>
<View style={styles.setting}>
<Text style={styles.settingText}>Unsubscribe from Emails?</Text>
<Switch
trackColor={{ false: "#EBEBE4", true: "#32CD32" }}
thumbColor={"#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={userInfo?.unsubscribeEmail}
/>
</View>
</View>
}
footer={<ErrorBox errorMessage={error} />}
/>
);
}

const styles = StyleSheet.create({
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 30,
},
headerText: {
fontSize: 24,
fontWeight: 'bold',
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
setting: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 20,
},
settingText: {
paddingRight: 15,
}
});
header: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
marginBottom: 30,
},
headerText: {
fontSize: 24,
fontWeight: "bold",
},
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
setting: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
marginBottom: 20,
},
settingText: {
paddingRight: 15,
},
});

0 comments on commit 0a09307

Please sign in to comment.