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 userEndpoint = 'https://softwarehub.uk/unibase/api/user';
const [years, , isYearsLoading] = useLoad(yearsEndpoint);
const [users, , isUsersLoading] = useLoad(userEndpoint);
// 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 ?