mirror of
https://github.com/mudabbir-ahmad/Project-MAD-crudler.git
synced 2026-10-07 20:40:20 +00:00
Added handlers to fetch user type correctly for data stored in local state rather than on database, added cohort to user view, updated default image used for userform.
This commit is contained in:
1 parent
3035ddd5b1
commit
58823019a7
2 files changed
+27
-2
No files matched your search
@@ -19,7 +19,7 @@ const UserForm = ({originalUser, onSubmit, onCancel}) => {
|
|||||||
// Initialisation -------------
|
// Initialisation -------------
|
||||||
|
|
||||||
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.generated.photos/tZmcC6WnzFmgAwRMsBnGYcmaj_NSktxhYzBfTqej_Lo/rs:fit:256:256/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92M18w/MDE3MjYzLmpwZw.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';
|
||||||
|
|||||||
@@ -2,12 +2,17 @@ import {Alert, StyleSheet, Text, View} from "react-native";
|
|||||||
import FullWidthImage from "react-native-fullwidth-image";
|
import FullWidthImage from "react-native-fullwidth-image";
|
||||||
import {Button, ButtonTray} from "../../UI/Button";
|
import {Button, ButtonTray} from "../../UI/Button";
|
||||||
import Icons from "../../UI/Icons.js";
|
import Icons from "../../UI/Icons.js";
|
||||||
|
import useLoad from "../../API/useLoad";
|
||||||
|
|
||||||
const UserView = ({user, onDelete, onModify}) => {
|
const UserView = ({user, onDelete, onModify}) => {
|
||||||
// Initialisation -------------
|
// Initialisation -------------
|
||||||
|
|
||||||
const fullName = `${user.UserFirstname} ${user.UserLastname}`;
|
const fullName = `${user.UserFirstname} ${user.UserLastname}`;
|
||||||
|
|
||||||
|
const userTypesEndpoint = 'https://softwarehub.uk/unibase/api/usertypes';
|
||||||
|
const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years';
|
||||||
|
|
||||||
|
|
||||||
const levels = [
|
const levels = [
|
||||||
{value: 3, label: '3 (Foundation)'},
|
{value: 3, label: '3 (Foundation)'},
|
||||||
{value: 4, label: '4 (First Year)'},
|
{value: 4, label: '4 (First Year)'},
|
||||||
@@ -17,6 +22,10 @@ const UserView = ({user, onDelete, onModify}) => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
// State ----------------------
|
// State ----------------------
|
||||||
|
|
||||||
|
const [userTypes] = useLoad(userTypesEndpoint);
|
||||||
|
const [years] = useLoad(yearsEndpoint);
|
||||||
|
|
||||||
// Handlers -------------------
|
// Handlers -------------------
|
||||||
|
|
||||||
const handleDelete = () => onDelete(user);
|
const handleDelete = () => onDelete(user);
|
||||||
@@ -34,6 +43,21 @@ const UserView = ({user, onDelete, onModify}) => {
|
|||||||
|
|
||||||
const userLevelLabel = levels.find(level => level.value === user.UserLevel)?.label || 'Unknown Level';
|
const userLevelLabel = levels.find(level => level.value === user.UserLevel)?.label || 'Unknown Level';
|
||||||
|
|
||||||
|
const getUserType = (usertypeID) => {
|
||||||
|
if (!usertypeID) return "Unknown";
|
||||||
|
const usertype = userTypes.find(type => type.UsertypeID === usertypeID);
|
||||||
|
return usertype ? usertype.UsertypeName : usertypeID;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getYear = (yearID) => {
|
||||||
|
if (!yearID) return "Unknown";
|
||||||
|
const year = years.find(y => y.YearID === yearID);
|
||||||
|
return year ? year.YearName : yearID;
|
||||||
|
};
|
||||||
|
|
||||||
|
const yearName = getYear(user.UserYearID);
|
||||||
|
const userTypeName = getUserType(user.UserUsertypeID);
|
||||||
|
|
||||||
// View -----------------------
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -45,8 +69,9 @@ const UserView = ({user, onDelete, onModify}) => {
|
|||||||
<Text style={styles.text}>{user.UserEmail}</Text>
|
<Text style={styles.text}>{user.UserEmail}</Text>
|
||||||
<Text style={styles.text}>Level {userLevelLabel}</Text>
|
<Text style={styles.text}>Level {userLevelLabel}</Text>
|
||||||
<Text style={styles.text}>
|
<Text style={styles.text}>
|
||||||
{user.UserUsertypeName || 'Unknown Type'} <Text style={styles.dimText}>(User Type)</Text>
|
{user.UserUsertypeName || userTypeName} <Text style={styles.dimText}>(User Type)</Text>
|
||||||
</Text>
|
</Text>
|
||||||
|
<Text style={styles.text}>Cohort {yearName}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<ButtonTray>
|
<ButtonTray>
|
||||||
|
|||||||
Reference in new issue
Block a user