Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KamogeloMoeketse committed Aug 6, 2024
1 parent c3c7af7 commit d031583
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 92 deletions.
98 changes: 13 additions & 85 deletions frontend/occupi-mobile4/screens/Login/SetDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { useColorScheme } from 'react-native';
import { heightPercentageToDP as hp } from 'react-native-responsive-screen';
import GradientButton from '@/components/GradientButton';
import LoadingGradientButton from '@/components/LoadingGradientButton';
import { updateDetails } from '@/utils/user';
import { extractDateFromTimestamp } from '@/utils/utils';

const COLORS = {
white: '#FFFFFF',
Expand All @@ -47,20 +49,14 @@ const SIZES = {
};

const SetDetails = () => {
const [selectedGenderIndex, setSelectedGenderIndex] = useState(1);
const [selectedGenderIndex, setSelectedGenderIndex] = useState('');
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [employeeId, setEmployeeId] = useState('');
const [phoneNumber, setPhoneNumber] = useState('');
const [pronouns, setPronouns] = useState('');
const [date, setDate] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
let colorScheme = 'light';
const apiUrl = process.env.EXPO_PUBLIC_DEVELOP_API_URL;
const getUserDetailsUrl= process.env.EXPO_PUBLIC_GET_USER_DETAILS;
const updateDetailsUrl = process.env.EXPO_PUBLIC_UPDATE_USER_DETAILS;
console.log(apiUrl, getUserDetailsUrl, updateDetailsUrl);

const showDatePicker = () => {
setDatePickerVisibility(true);
Expand All @@ -70,94 +66,27 @@ const SetDetails = () => {
setDatePickerVisibility(false);
};

const handleConfirm = (selectedDate) => {
setDate(selectedDate);
const handleConfirm = (selectedDate: string) => {
console.log('selected',extractDateFromTimestamp(selectedDate));
setDate(extractDateFromTimestamp(selectedDate));
hideDatePicker();
};

const onSave = async () => {
const body = {
"email": email,
"details": {
"contactNo": phoneNumber,
"gender": "Male",
"name": name,
"pronouns": pronouns
}
};
// console.log(JSON.stringify(body));
setIsLoading(true);
try {
let authToken = await SecureStore.getItemAsync('Token');
const response = await fetch(`${apiUrl}${updateDetailsUrl}`, {
method: 'PUT',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Authorization': `${authToken}`
},
body: JSON.stringify(body),
credentials: "include"
});
const data = await response.json();
console.log(data);
if (response.ok) {
console.log(response);
setIsLoading(false);
alert('Details updated successfully');
} else {
console.log(data);
setIsLoading(false);
}
} catch (error) {
setIsLoading(false);
console.error('Error:', error);
// setResponse('An error occurred');
}

try {
let authToken = await SecureStore.getItemAsync('Token');
const response = await fetch(`${apiUrl}${getUserDetailsUrl}?email=${email}`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Authorization': `${authToken}`
},
credentials: "include"
});
const data = await response.json();
if (response.ok) {
saveUserData(JSON.stringify(data));
console.log(data);
} else {
console.log(data);
}
} catch (error) {
console.error('Error:', error);
}
const response = await updateDetails(name,date,selectedGenderIndex,phoneNumber,pronouns)
console.log(response);
setIsLoading(false);
};
console.log(selectedGenderIndex);

async function saveUserData(value) {
await SecureStore.setItemAsync('UserData', value);
}

return (
<SafeAreaView
style={colorScheme === 'dark' ? styles.containerdark : styles.containerlight}
>
<ScrollView contentContainerStyle={styles.contentContainer}>
<View style={styles.header}>
<Icon
as={Feather}
name={"chevron-left"}
size="xl"
color={colorScheme === 'dark' ? 'white' : 'black'}
onPress={() => router.replace('/settings')}
/>
<Text style={[styles.headerTitle, colorScheme === 'dark' ? styles.textdark : styles.textlight]}>
Account Details
My account
</Text>
<MaterialIcons
name="person-outline"
Expand All @@ -166,7 +95,6 @@ const SetDetails = () => {
style={styles.icon}
/>
</View>
<View pt="$20" flexDirection='column' justifyContent='center'>

<Text style={colorScheme === 'dark' ? styles.labeldark : styles.labellight}>Full name</Text>
<TextInput
Expand Down Expand Up @@ -194,7 +122,7 @@ const SetDetails = () => {
/>

<Text style={colorScheme === 'dark' ? styles.labeldark : styles.labellight}>Gender</Text>
<RadioGroup mb="$4" onChange={(index) => setSelectedGenderIndex(index)}>
<RadioGroup mb="$4" value={selectedGenderIndex} onChange={(index) => setSelectedGenderIndex(index)}>
<VStack flexDirection="row" justifyContent="space-between" space="sm">
<Radio
backgroundColor={colorScheme === 'dark' ? '#5A5A5A' : '#f2f2f2'}
Expand All @@ -203,6 +131,7 @@ const SetDetails = () => {
borderColor="#f2f2f2"
h={hp('5%')}
px="$4"

>
<RadioLabel color={colorScheme === 'dark' ? 'white' : 'black'}>Male</RadioLabel>
<RadioIndicator ml="$2">
Expand Down Expand Up @@ -257,11 +186,10 @@ const SetDetails = () => {
) : (
<GradientButton
onPress={onSave}
text="Next"
text="Save"
/>
)
}
</View>

</ScrollView>
</SafeAreaView>
Expand Down
2 changes: 1 addition & 1 deletion frontend/occupi-mobile4/screens/Login/SplashScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function SplashScreen() {
useEffect(() => {
const timer = setTimeout(() => {
setSelectedIndex(1); // Assuming Onboarding1 is at index 1
router.replace('/settings'); // Navigate to Onboarding1 screen
router.replace('/welcome'); // Navigate to Onboarding1 screen
}, 5000); // 8 seconds

return () => clearTimeout(timer); // Clean up timer on component unmount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const Notifications = () => {

return (

<View pt="$20" px="$4" flex={1} flexDirection="column" backgroundColor={currentTheme === 'dark' ? '$black' : '$white'}>
<View pt="$20" px="$2" flex={1} flexDirection="column" backgroundColor={currentTheme === 'dark' ? '$black' : '$white'}>
<View flexDirection='row' justifyContent='space-between' mb="$2">
<Text fontWeight="$bold" fontSize={28} color={currentTheme === 'dark' ? '$white' : '$black'}>Notifications</Text>
<View style={{ backgroundColor: `${accentColour}`, alignItems: 'center', padding: 8, borderRadius: 12 }}>
Expand Down
2 changes: 1 addition & 1 deletion frontend/occupi-mobile4/screens/Settings/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const Profile = () => {


const onSave = async () => {
const response = await updateDetails(name,date,selectedGenderIndex,phoneNumber,pronouns, employeeId)
const response = await updateDetails(name,date,selectedGenderIndex,phoneNumber,pronouns)
toast.show({
placement: 'top',
render: ({ id }) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/occupi-mobile4/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export async function verifyUserOtpRegister(email: string, otp: string) {
});
if (response.status === 200) {
console.log('responseee',response);
setState('logged_out');
router.replace('/set-details');
router.replace('/login');
return response.message;
}
else {
Expand Down
10 changes: 7 additions & 3 deletions frontend/occupi-mobile4/utils/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UpdateDetailsReq } from "@/models/requests";
import { getUserDetails, getNotificationSettings, getSecuritySettings, updateSecuritySettings, updateNotificationSettings, updateUserDetails } from "../services/apiservices";
import { storeUserData, storeNotificationSettings, getUserData, storeSecuritySettings } from "../services/securestore";
import { storeUserData, storeNotificationSettings, getUserData, storeSecuritySettings, setState } from "../services/securestore";
import { router } from 'expo-router';
import * as SecureStore from 'expo-secure-store';

Expand Down Expand Up @@ -112,8 +112,9 @@ export async function updateSecurity(type: string, values: any) {
}
}

export async function updateDetails(name: string, dob: string, gender: string, cellno: string, pronouns: string, employeeid: string) {
export async function updateDetails(name: string, dob: string, gender: string, cellno: string, pronouns: string) {
const email = await SecureStore.getItemAsync('Email');
const state = await SecureStore.getItemAsync('AppState');
try {
const request : UpdateDetailsReq = {
session_email: email,
Expand All @@ -122,11 +123,14 @@ export async function updateDetails(name: string, dob: string, gender: string, c
gender: gender,
number: cellno,
pronouns: pronouns,
employeeid: employeeid
}
const response = await updateUserDetails(request);
if (response.status === 200) {
console.log(response);
if (state === "verify_otp_register") {
setState("logged_out");
router.replace('login');
}
router.replace('/settings')
return "Details updated successfully"
}
Expand Down

0 comments on commit d031583

Please sign in to comment.