Last active
August 4, 2021 04:00
-
-
Save jasonleehodges/72a5d98ed9856935be92eb7032ba01c1 to your computer and use it in GitHub Desktop.
CreateProspect composed from UserForm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Contact, UserForm } from '../user-form/userForm'; | |
| import React, {FC, useState} from 'react'; | |
| export const CreateProspect: FC = () => { | |
| const [user, setUser] = useState<Contact>({ | |
| name: '', | |
| email: '', | |
| phoneNumber: '', | |
| referredBy: '' | |
| }); | |
| const setValue = (property: keyof Contact) => | |
| (e: React.ChangeEvent<HTMLInputElement>) => | |
| setUser((user) => ({ ...user, [property]: e.target.value })); | |
| return ( | |
| <UserForm user={user} setUser={setValue}> | |
| <label>Referred By</label> | |
| <input value={user.referredBy} onChange={setValue('referredBy')} /> | |
| </UserForm> | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, {FC, useState} from 'react'; | |
| import { Contact, UserForm } from '../user-form/userForm'; | |
| import { teamService } from './services'; | |
| import styles from './createUser.module.css'; | |
| export const CreateTeamMember: FC = () => { | |
| const [user, setUser] = useState<Contact>({ | |
| name: '', | |
| email: '', | |
| phoneNumber: '', | |
| role: '' | |
| }); | |
| const setValue = (property: keyof Contact) => | |
| (e: React.ChangeEvent<HTMLInputElement>) => | |
| setUser((user) => ({ ...user, [property]: e.target.value })); | |
| const handleSubmit = () => { | |
| teamService.syncAndSubmit(user); | |
| } | |
| return ( | |
| <UserForm user={user} setUser={setValue} className={styles.create__team__member}> | |
| <label>Role</label> | |
| <input value={user.role} onChange={setValue('role')} /> | |
| <button value={user.role} onClick={handleSubmit} >Submit</button> | |
| </UserForm> | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment