mirror of
https://github.com/mudabbir-ahmad/Project-MAD-crudler.git
synced 2026-10-08 04:40:20 +00:00
Made User Form section
This commit is contained in:
1 parent
d948f126df
commit
755d568090
8 files changed
+365
-61
No files matched your search
@@ -0,0 +1,128 @@
|
||||
import { Text } from "react-native";
|
||||
import { useState } from "react";
|
||||
import Icons from "../../UI/Icons";
|
||||
import Form from "../../UI/Form";
|
||||
import useLoad from "../../API/useLoad";
|
||||
|
||||
const defaultUser = {
|
||||
UserID: null,
|
||||
UserFirstname: null,
|
||||
UserLastname: null,
|
||||
UserEmail: null,
|
||||
UserRegistered: null,
|
||||
UserLevel: null,
|
||||
UserYearID: null,
|
||||
UserUsertypeID: null,
|
||||
UserImageURL: null,
|
||||
UserUsertypeName: null,
|
||||
UserYearName: null,
|
||||
};
|
||||
|
||||
const UserForm = ({ originalUser, onSubmit, onCancel }) => {
|
||||
// Initialisation -------------
|
||||
|
||||
const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years';
|
||||
const usertypesEndpoint = 'https://softwarehub.uk/unibase/api/usertypes';
|
||||
|
||||
const [years, , isYearsLoading] = useLoad(yearsEndpoint);
|
||||
const [usertypes, , isUsertypesLoading] = useLoad(usertypesEndpoint);
|
||||
|
||||
// State ----------------------
|
||||
|
||||
const [user, setUser] = useState(originalUser || {
|
||||
...defaultUser,
|
||||
UserID: Math.floor(100000 + Math.random() * 900000),
|
||||
UserImageURL: 'https://images.freeimages.com/images/small-preview/cf5/cellphone-1313194.jpg',
|
||||
UserRegistered: new Date().toISOString()
|
||||
});
|
||||
|
||||
// Handlers -------------------
|
||||
|
||||
const handleChange = (field, value) => {
|
||||
setUser({ ...user, [field]: value });
|
||||
};
|
||||
|
||||
const handleSubmit = () => onSubmit(user);
|
||||
|
||||
// View -----------------------
|
||||
|
||||
const submitLabel = originalUser ? 'Modify' : 'Add';
|
||||
const submitIcon = originalUser ? <Icons.Edit /> : <Icons.Add />;
|
||||
|
||||
const levels = [
|
||||
{ value: '4', label: 'Level 4' },
|
||||
{ value: '5', label: 'Level 5' },
|
||||
{ value: '6', label: 'Level 6' },
|
||||
{ value: '7', label: 'Level 7' }
|
||||
];
|
||||
|
||||
return (
|
||||
<Form
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={onCancel}
|
||||
submitLabel={submitLabel}
|
||||
submitIcon={submitIcon}
|
||||
>
|
||||
<Form.InputText
|
||||
label='First Name'
|
||||
value={user.UserFirstname}
|
||||
onChange={(value) => handleChange('UserFirstname', value)}
|
||||
/>
|
||||
|
||||
<Form.InputText
|
||||
label='Last Name'
|
||||
value={user.UserLastname}
|
||||
onChange={(value) => handleChange('UserLastname', value)}
|
||||
/>
|
||||
|
||||
<Form.InputText
|
||||
label='Email'
|
||||
value={user.UserEmail}
|
||||
onChange={(value) => handleChange('UserEmail', value)}
|
||||
/>
|
||||
|
||||
{isYearsLoading ? (
|
||||
<Text>Loading Levels...</Text>
|
||||
) : (
|
||||
<Form.InputSelect
|
||||
label='User Level'
|
||||
prompt='Select user level...'
|
||||
options={levels}
|
||||
value={user.UserLevel}
|
||||
onChange={(value) => handleChange('UserLevel', value)}
|
||||
isLoading={isYearsLoading}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Form.InputSelect
|
||||
label='Year/Cohort'
|
||||
value={user.UserYearID}
|
||||
onChange={(value) => handleChange('UserYearID', value)}
|
||||
prompt='Select year/cohort...'
|
||||
options={years}
|
||||
isLoading={isYearsLoading}
|
||||
/>
|
||||
|
||||
{isUsertypesLoading ? (
|
||||
<Text>Loading User Types...</Text>
|
||||
) : (
|
||||
<Form.InputSelect
|
||||
label='User Type'
|
||||
value={user.UserUsertypeID}
|
||||
onChange={(value) => handleChange('UserUsertypeID', value)}
|
||||
prompt='Select user type...'
|
||||
options={usertypes}
|
||||
isLoading={isUsertypesLoading}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Form.InputText
|
||||
label='Profile Image URL'
|
||||
value={user.UserImageURL}
|
||||
onChange={(value) => handleChange('UserImageURL', value)}
|
||||
/>
|
||||
</Form>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserForm;
|
||||
@@ -0,0 +1,32 @@
|
||||
import {StyleSheet, Text, View, Pressable} from "react-native";
|
||||
|
||||
const UserItem = ({user, onSelect}) => {
|
||||
// Initialisation -------------
|
||||
// State ----------------------
|
||||
// Handlers -------------------
|
||||
// View -----------------------
|
||||
|
||||
return (
|
||||
<Pressable key={user.UserCode} onPress={() => onSelect(user)}>
|
||||
<View style={styles.usersItem}>
|
||||
<Text style={styles.text}>
|
||||
{user.UserCode} {user.UserName}
|
||||
</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
usersItem: {
|
||||
paddingVertical: 15,
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: "lightgray",
|
||||
},
|
||||
text: {
|
||||
fontSize: 18,
|
||||
},
|
||||
});
|
||||
|
||||
export default UserItem;
|
||||
@@ -0,0 +1,32 @@
|
||||
import {StyleSheet, ScrollView} from "react-native";
|
||||
import UserItem from "./UserItem";
|
||||
import React from "react";
|
||||
|
||||
const UserList = ({modules, onSelect}) => {
|
||||
// Initialisation -------------
|
||||
// State ----------------------
|
||||
// Handlers -------------------
|
||||
// View -----------------------
|
||||
|
||||
return (
|
||||
<ScrollView style={styles.modulesContainer}>
|
||||
{modules.map((module) => {
|
||||
return (
|
||||
<UserItem
|
||||
module={module}
|
||||
key={module.ModuleCode}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
)
|
||||
})
|
||||
}
|
||||
</ScrollView>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
modulesContainer: {},
|
||||
});
|
||||
|
||||
export default UserList;
|
||||
@@ -0,0 +1,74 @@
|
||||
import {Alert, StyleSheet, Text, View} from "react-native";
|
||||
import FullWidthImage from "react-native-fullwidth-image";
|
||||
import {Button, ButtonTray} from "../../UI/Button";
|
||||
import Icons from "../../UI/Icons.js"
|
||||
|
||||
const UserView = ({module, onDelete, onModify}) => {
|
||||
// Initialisation -------------
|
||||
// State ----------------------
|
||||
// Handlers -------------------
|
||||
|
||||
const handleDelete = () => onDelete(module);
|
||||
|
||||
const requestDelete = () => {
|
||||
Alert.alert(
|
||||
'Delete Warning',
|
||||
`Are you sure you want to delete module ${module.ModuleCode} ${module.ModuleName}?`,
|
||||
[
|
||||
{text: 'cancel'},
|
||||
{text: 'Delete', onPress: handleDelete}
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// View -----------------------
|
||||
|
||||
return (<View style={styles.container}>
|
||||
<FullWidthImage source={{uri: module.ModuleImageURL}} style={styles.image}/>
|
||||
|
||||
<View style={styles.infoTray}>
|
||||
<Text style={styles.boldText}>View {module.ModuleCode} {module.ModuleName}</Text>
|
||||
<Text style={styles.text}>Level {module.ModuleLevel}</Text>
|
||||
<Text style={styles.text}>cohort {module.ModuleYearID}</Text>
|
||||
<Text style={styles.Text}>
|
||||
{module.ModuleLeaderID} <Text style={styles.dimText}>(Module Leader)</Text>
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<ButtonTray>
|
||||
<Button
|
||||
icon={<Icons.Edit/>}
|
||||
label={"Modify"}
|
||||
onClick={onModify}
|
||||
/>
|
||||
<Button
|
||||
icon={<Icons.Delete/>}
|
||||
label={"Delete"}
|
||||
// styleButton={{backgroundColor: 'mistyrose'}}
|
||||
// styleLabel={{color: 'red'}}
|
||||
onClick={requestDelete}
|
||||
/>
|
||||
</ButtonTray>
|
||||
|
||||
</View>);
|
||||
};
|
||||
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
gap: 15,
|
||||
}, infoTray: {
|
||||
gap: 5,
|
||||
}, image: {
|
||||
borderRadius: 3,
|
||||
}, text: {
|
||||
fontSize: 16,
|
||||
}, boldText: {
|
||||
fontSize: 16, fontWeight: 'bold',
|
||||
}, dimText: {
|
||||
color: "grey",
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
export default UserView;
|
||||
Reference in new issue
Block a user