diff --git a/src/components/entity/users/UserForm.js b/src/components/entity/users/UserForm.js index 8f3251a..e825f70 100644 --- a/src/components/entity/users/UserForm.js +++ b/src/components/entity/users/UserForm.js @@ -9,33 +9,29 @@ const defaultUser = { UserFirstname: null, UserLastname: null, UserEmail: null, - UserRegistered: null, - UserLevel: null, - UserYearID: null, UserUsertypeID: null, + UserYearID: null, UserImageURL: null, - UserUsertypeName: null, - UserYearName: null, }; const UserForm = ({ originalUser, onSubmit, onCancel }) => { // Initialisation ------------- - - const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years'; - const userEndpoint = 'https://softwarehub.uk/unibase/api/user'; - const [years, , isYearsLoading] = useLoad(yearsEndpoint); - const [users, , isUsersLoading] = useLoad(userEndpoint); + defaultUser.UserID = Math.floor(100000 + Math.random() * 900000); + defaultUser.UserImageURL = 'https://images.freeimages.com/images/small-preview/cf5/cellphone-1313194.jpg'; + + const usertypesEndpoint = 'https://softwarehub.uk/unibase/api/usertypes'; + const yearsEndpoint = 'https://softwarehub.uk/unibase/api/years'; // 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() - }); + + const [user, setUser] = useState(originalUser || defaultUser); + + const [usertypes, , isUsertypesLoading] = useLoad(usertypesEndpoint); + const [years, , isYearsLoading] = useLoad(yearsEndpoint); // Handlers ------------------- + const handleChange = (field, value) => { setUser({ ...user, [field]: value }); }; @@ -43,15 +39,19 @@ const UserForm = ({ originalUser, onSubmit, onCancel }) => { const handleSubmit = () => onSubmit(user); // View ----------------------- + const submitLabel = originalUser ? 'Modify' : 'Add'; const submitIcon = originalUser ? : ; - const levels = [ - { value: 4, label: 'Level 4' }, - { value: 5, label: 'Level 5' }, - { value: 6, label: 'Level 6' }, - { value: 7, label: 'Level 7' } - ]; + const usertypeOptions = usertypes.map((usertype) => ({ + value: usertype.UsertypeID, + label: usertype.UsertypeName + })); + + const yearOptions = years.map((year) => ({ + value: year.YearID, + label: year.YearName + })); return (
{ /> handleChange('UserLevel', value)} + label='User Type' + value={user.UserUsertypeID} + onChange={(value) => handleChange('UserUsertypeID', value)} + prompt={'Select user type...'} + options={usertypeOptions} + isLoading={isUsertypesLoading} /> - {isYearsLoading ? ( - Loading Years... - ) : ( - handleChange('UserYearID', value)} - prompt='Select year/cohort...' - options={years} - /> - )} - - {isUsersLoading ? ( - Loading User Types... - ) : ( - handleChange('UserUsertypeID', value)} - prompt='Select user type...' - options={users} - /> - )} + handleChange('UserYearID', value)} + prompt={'Select cohort year...'} + options={yearOptions} + isLoading={isYearsLoading} + /> handleChange('UserImageURL', value)} /> diff --git a/src/components/screens/UserAddScreen.js b/src/components/screens/UserAddScreen.js index d5afba1..d572cff 100644 --- a/src/components/screens/UserAddScreen.js +++ b/src/components/screens/UserAddScreen.js @@ -1,6 +1,6 @@ import {StyleSheet, Text, TextInput, View} from "react-native"; import Screen from "../layout/Screen"; -import ModuleForm from "../entity/modules/moduleForm"; +import UserForm from "../entity/users/UserForm"; export const UserAddScreen = ({navigation, route}) => { @@ -14,7 +14,7 @@ export const UserAddScreen = ({navigation, route}) => { // View ----------------------- return ( - + ); };