import {StyleSheet, Text, TextInput, View} from "react-native"; import {useState} from "react"; import Icons from "../../UI/Icons"; import Form from "../../UI/Form"; const defaultModule = { ModuleID: null, ModuleCode: null, ModuleName: null, ModuleLevel: null, ModuleLeaderID: null, ModuleLeaderName: null, ModuleImage: null, }; const ModuleForm = ({originalModule, onSubmit, onCancel}) => { // Initialisation ------------- defaultModule.ModuleID = Math.floor(100000 + Math.random() * 900000); defaultModule.ModuleImage = 'https://images.freeimages.com/images/small-preview/cf5/cellphone-1313194.jpg'; 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 ---------------------- const [module, setModule] = useState(originalModule || defaultModule); // Handlers ------------------- const handleChange = (field, value) => { setModule({...module, [field]: value}) }; const handleSubmit = () => onSubmit(module); // View ----------------------- const submitLabel = originalModule ? 'Modify' : 'Add'; const submitIcon = originalModule ? : ; return (
handleChange('ModuleCode', value)} /> handleChange('ModuleName', value)} /> handleChange('ModuleLevel', value)} /> handleChange('ModuleLeaderName', value)} /> handleChange('ModuleImage', value)} /> {/* This is to test whether the correct Data was being stored in Local State */} {/* {module.ModuleCode} {module.ModuleName} */} ); }; const styles = StyleSheet.create({ formContainer: {}, item: {}, }); export default ModuleForm;