Skip to content

Commit

Permalink
adding account setting frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
rhit-norflwe committed Jan 7, 2025
1 parent 8768ccb commit ea70fa4
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MealTracking from './mealTracker';
import Notes from './notes';
import Finance from './finance';
import CalendarEvents from './calendarEvents';
import AccountSetting from './accountSetting';
import { createStackNavigator, StackHeaderProps } from '@react-navigation/stack';
import { RootStackParamList } from '@/components/Types';
import AddCalendarEvents from './addCalendarEvents';
Expand Down Expand Up @@ -42,6 +43,9 @@ const CustomTopBar = ({ navigation }: StackHeaderProps) => {
<TouchableOpacity onPress={() => navigation.navigate('notes')}>
<Ionicons name="pencil-outline" size={28} color="black" />
</TouchableOpacity>
<TouchableOpacity onPress={() => navigation.navigate('accountSetting')}>
<Ionicons name="person-circle-outline" size={28} color="black" />
</TouchableOpacity>
</View>
);
};
Expand All @@ -61,6 +65,7 @@ export default function Layout() {
<Stack.Screen name="mealTracker" component={MealTracking} />
<Stack.Screen name="notes" component={Notes} />
<Stack.Screen name="finance" component={Finance} />
<Stack.Screen name="accountSetting" component={AccountSetting} />
<Stack.Screen name="addFinanceEvents" component={AddFinanceEvents} />
<Stack.Screen name="calendarEvents" component={CalendarEvents} />
<Stack.Screen name="addCalendarEvents" component={AddCalendarEvents} />
Expand Down
116 changes: 116 additions & 0 deletions app/accountSetting.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, { useCallback, useState } from 'react';

Check failure on line 1 in app/accountSetting.tsx

View workflow job for this annotation

GitHub Actions / lint-ts

'useCallback' is defined but never used
import { View, Text, TextInput, TouchableOpacity, StyleSheet } from 'react-native';
import { cLog } from './log';

Check failure on line 3 in app/accountSetting.tsx

View workflow job for this annotation

GitHub Actions / lint-ts

'cLog' is defined but never used
import { IPAddr } from './constants';
import axios from 'axios';
import { useFocusEffect } from '@react-navigation/native';

Check failure on line 6 in app/accountSetting.tsx

View workflow job for this annotation

GitHub Actions / lint-ts

'useFocusEffect' is defined but never used
import GenericViewPageForm from './viewEventPage';

Check failure on line 7 in app/accountSetting.tsx

View workflow job for this annotation

GitHub Actions / lint-ts

'GenericViewPageForm' is defined but never used

export default function AccountSetting () {
const initialData = { userId: 1, name: "", username: "", email: "" };

const [formData, setFormData] = useState(initialData);

const handleSave = async () => {
try {
// Add current date to formData
const currentDate = new Date().toISOString().split('T')[0]; // Get current date in ISO format (e.g., 2024-06-14T10:00:00.000Z)
const currentTime = new Date().toTimeString().split(' ')[0];
const updatedFormData = {
...formData,
event_date: currentDate, // Add date field
event_time: currentTime, // Add time field
};
const hit = IPAddr + '/add_note'; // Backend endpoint
const response = await axios.put(hit, updatedFormData); // Send request with updated data

console.log('Note saved successfully: ' + response.data);
} catch (error) {
console.error('Error saving note:', error);
}
};

const handleChange = (name: string, value: string) => {
setFormData({ ...formData, [name]: value });
};

return (
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.title}>Name</Text>
<TextInput
value={formData.name} // Set value to formData.text to make it controlled
onChangeText={(text) => handleChange("text", text)} // Handle text changes
style={styles.textInput}
placeholder="name"
multiline={true}
/>
<Text style={styles.title}>Username</Text>
<TextInput
value={formData.username} // Set value to formData.text to make it controlled
onChangeText={(text) => handleChange("text", text)} // Handle text changes
style={styles.textInput}
placeholder="username"
multiline={true}
/>
<Text style={styles.title}>Email</Text>
<TextInput
value={formData.email} // Set value to formData.text to make it controlled
onChangeText={(text) => handleChange("text", text)} // Handle text changes
style={styles.textInput}
placeholder="email"
multiline={true}
/>
</View>
<View style={styles.footer}>
<TouchableOpacity style={styles.saveButton} onPress={handleSave}>
<Text style={styles.saveButtonText}>Save</Text>
</TouchableOpacity>
</View>
</View>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingHorizontal: 20,
},
header: {
alignItems: 'center',
},
title: {
fontSize: 32,
fontWeight: 'bold',
marginBottom: 20,
textAlign: 'left',
},
textInput: {
height: 50,
width: '100%',
borderColor: '#ccc',
borderWidth: 1,
borderRadius: 8,
padding: 10,
textAlignVertical: 'top',
},
footer: {
alignItems: 'flex-end',
marginTop: 20,
},
saveButton: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#65558f',
borderRadius: 8,
paddingVertical: 15,
paddingHorizontal: 50,
justifyContent: 'center',
},
saveButtonText: {
fontSize: 18,
fontWeight: 'bold',
color: '#eee',
},
});
1 change: 1 addition & 0 deletions components/Types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type RootStackParamList = {
'mealTracker': undefined;
'notes': undefined;
'finance': undefined;
'accountSetting': undefined;
'addFinanceEvents': undefined,
'calendarEvents': undefined;
'addCalendarEvents': undefined;
Expand Down

0 comments on commit ea70fa4

Please sign in to comment.