updated user item to show user type name, added levels to userform so that it shows which level the user is in rather than just the id

This commit is contained in:
bobbert committed 2025-12-07 18:48:43 +00:00
1 parent a64793ffb5
commit ffc227fc88
2 files changed
+36 -8

No files matched your search

+20 -3
View File
@@ -11,6 +11,7 @@ const defaultUser = {
UserEmail: null, UserEmail: null,
UserUsertypeID: null, UserUsertypeID: null,
UserYearID: null, UserYearID: null,
UserLevel: null,
UserImageURL: null, UserImageURL: null,
}; };
@@ -20,14 +21,22 @@ const UserForm = ({ originalUser, onSubmit, onCancel }) => {
defaultUser.UserID = Math.floor(100000 + Math.random() * 900000); defaultUser.UserID = Math.floor(100000 + Math.random() * 900000);
defaultUser.UserImageURL = 'https://images.freeimages.com/images/small-preview/cf5/cellphone-1313194.jpg'; defaultUser.UserImageURL = 'https://images.freeimages.com/images/small-preview/cf5/cellphone-1313194.jpg';
const usertypesEndpoint = 'https://softwarehub.uk/unibase/api/usertypes'; const userTypesEndpoint = 'https://softwarehub.uk/unibase/api/usertypes';
const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years'; const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years';
const levels = [
{ value: 3, label: '3 (Foundation)' },
{ value: 4, label: '4 (First Year)' },
{ value: 5, label: '5 (Second Year)' },
{ value: 6, label: '6 (Third Year)' },
{ value: 7, label: '7 (Masters)' },
];
// State ---------------------- // State ----------------------
const [user, setUser] = useState(originalUser || defaultUser); const [user, setUser] = useState(originalUser || defaultUser);
const [usertypes, , isUsertypesLoading] = useLoad(usertypesEndpoint); const [userTypes, , isUsertypesLoading] = useLoad(userTypesEndpoint);
const [years, , isYearsLoading] = useLoad(yearsEndpoint); const [years, , isYearsLoading] = useLoad(yearsEndpoint);
// Handlers ------------------- // Handlers -------------------
@@ -43,7 +52,7 @@ const UserForm = ({ originalUser, onSubmit, onCancel }) => {
const submitLabel = originalUser ? 'Modify' : 'Add'; const submitLabel = originalUser ? 'Modify' : 'Add';
const submitIcon = originalUser ? <Icons.Edit /> : <Icons.Add />; const submitIcon = originalUser ? <Icons.Edit /> : <Icons.Add />;
const usertypeOptions = usertypes.map((usertype) => ({ const usertypeOptions = userTypes.map((usertype) => ({
value: usertype.UsertypeID, value: usertype.UsertypeID,
label: usertype.UsertypeName label: usertype.UsertypeName
})); }));
@@ -87,6 +96,14 @@ const UserForm = ({ originalUser, onSubmit, onCancel }) => {
isLoading={isUsertypesLoading} isLoading={isUsertypesLoading}
/> />
<Form.InputSelect
label='Level'
value={user.UserLevel}
onChange={(value) => handleChange('UserLevel', value)}
prompt={'Select level...'}
options={levels}
/>
<Form.InputSelect <Form.InputSelect
label='Cohort Year' label='Cohort Year'
value={user.UserYearID} value={user.UserYearID}
+16 -5
View File
@@ -1,16 +1,27 @@
import { StyleSheet, Text, View, Pressable } from "react-native"; import { StyleSheet, Text, View, Pressable } from "react-native";
import useLoad from "../../API/useLoad";
const UserItem = ({ user, onSelect }) => { const UserItem = ({ user, onSelect }) => {
// Initialisation ------------- // Initialisation -------------
// State ----------------------
// Handlers -------------------
// View -----------------------
const usertypesEndpoint = 'https://softwarehub.uk/unibase/api/usertypes';
const [usertypes] = useLoad(usertypesEndpoint);
const getUserTypeName = (usertypeID) => {
const usertype = usertypes.find(type => type.UsertypeID === usertypeID);
return usertype ? usertype.UsertypeName : "Unknown";
};
const usertypeName = getUserTypeName(user.UserUsertypeID);
// State ----------------------
// Handlers -------------------
// View -----------------------
return ( return (
<Pressable key={user.UserID} onPress={() => onSelect(user)}> <Pressable key={user.UserID} onPress={() => onSelect(user)}>
<View style={styles.userItem}> <View style={styles.userItem}>
<Text style={styles.text}> <Text style={styles.text}>
{user.UserFirstname} {user.UserLastname} {user.UserFirstname} {user.UserLastname} ({usertypeName})
</Text> </Text>
</View> </View>
</Pressable> </Pressable>