Created
April 28, 2021 14:57
-
-
Save KillianPiccerelle/de7ed477355542568c1462b016214f42 to your computer and use it in GitHub Desktop.
Want take value of textInput in const renderInner and send to post request onPress Button (sendEvent() function)
This file contains 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, {useEffect} from 'react'; | |
import { | |
Text, | |
View, | |
StyleSheet, | |
FlatList, | |
Button, | |
TextInput, | |
} from 'react-native'; | |
import {useDispatch} from 'react-redux'; | |
import {useSelector} from 'react-redux'; | |
import {IconButton} from 'react-native-paper'; | |
import BottomSheet from 'reanimated-bottom-sheet'; | |
import Animated from 'react-native-reanimated'; | |
import {fetchEvents} from '../../../API/events'; | |
import {sendEvent} from '../../../API/events'; | |
import {postEvents} from '../../../redux/selectors'; | |
import {getEvents} from '../../../redux/selectors'; | |
import AgendaListItem from './agendaListItem'; | |
const agendaList = () => { | |
const dispatch = useDispatch(); | |
const events = useSelector(getEvents); | |
useEffect(() => { | |
fetchEvents(dispatch); | |
}, []); | |
const _renderItem = ({item}) => { | |
return <AgendaListItem item={item} />; | |
}; | |
const renderInner = () => ( | |
<View style={styles.panel}> | |
<View style={{alignItems: 'center'}}> | |
<Text style={styles.panelTitle}>Ajouter un événement</Text> | |
<Text style={styles.panelSubtitle}> | |
Remplissez et cliquez sur "sauvegarder" pour enregistrer. | |
</Text> | |
<TextInput placeholder="Email" /> | |
<TextInput secureTextEntry={true} placeholder="Password" /> | |
<Button title="Sauvegarder" onPress={() => sendEvent()} /> | |
</View> | |
</View> | |
); | |
const renderHeader = () => ( | |
<View style={styles.header}> | |
<View style={styles.panelHeader}> | |
<View style={styles.panelHandle} /> | |
</View> | |
</View> | |
); | |
bs = React.createRef(); | |
fall = new Animated.Value(1); | |
return ( | |
<View style={styles.container}> | |
<FlatList | |
data={events} | |
renderItem={_renderItem} | |
ItemSeparatorComponent={() => <View style={styles.separator} />} | |
/> | |
<BottomSheet | |
ref={bs} | |
snapPoints={[450, 0]} | |
renderContent={renderInner} | |
renderHeader={renderHeader} | |
initialSnap={1} | |
callbackNode={fall} | |
enabledGestureInteraction={true} | |
/> | |
<View style={styles.iconButton}> | |
<IconButton | |
icon="plus" | |
size={40} | |
onPress={() => bs.current.snapTo(0)} | |
/> | |
</View> | |
</View> | |
); | |
}; | |
const styles = StyleSheet.create({ | |
container: { | |
width: '100%', | |
height: '100%', | |
backgroundColor: '#024893', | |
alignItems: 'center', | |
}, | |
separator: { | |
height: 4, | |
}, | |
iconButton: { | |
position: 'absolute', | |
top: '87%', | |
left: '75%', | |
zIndex: 10, | |
width: 60, | |
height: 60, | |
backgroundColor: 'white', | |
borderRadius: 50, | |
justifyContent: 'center', | |
alignItems: 'center', | |
}, | |
header: { | |
backgroundColor: '#FFFFFF', | |
shadowColor: '#333333', | |
shadowOffset: {width: -1, height: -3}, | |
shadowRadius: 2, | |
shadowOpacity: 0.4, | |
// elevation: 5, | |
paddingTop: 20, | |
borderTopLeftRadius: 20, | |
borderTopRightRadius: 20, | |
}, | |
panel: { | |
padding: 20, | |
backgroundColor: '#FFFFFF', | |
paddingTop: 25, | |
height: 450, | |
// borderTopLeftRadius: 20, | |
// borderTopRightRadius: 20, | |
// shadowColor: '#000000', | |
// shadowOffset: {width: 0, height: 0}, | |
// shadowRadius: 5, | |
// shadowOpacity: 0.4, | |
}, | |
panelHeader: { | |
alignItems: 'center', | |
}, | |
panelHandle: { | |
width: 40, | |
height: 8, | |
borderRadius: 4, | |
backgroundColor: '#00000040', | |
marginBottom: 10, | |
}, | |
panelTitle: { | |
fontSize: 27, | |
height: 35, | |
}, | |
panelSubtitle: { | |
fontSize: 14, | |
color: 'gray', | |
height: 30, | |
marginBottom: 10, | |
}, | |
panelButtonTitle: { | |
fontSize: 17, | |
fontWeight: 'bold', | |
color: 'white', | |
}, | |
}); | |
export default agendaList; |
This file contains 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 axios from 'axios'; | |
import {fetchEventsAction} from '../../redux/actions'; | |
import {API_URL} from '@env'; | |
const ENDPOINT_EVENTS = API_URL + '/events='; | |
const apiKey = 'b4ee0d16abbf4b73af1193cac08f4e04'; | |
const MAX_PER_PAGE = 30; | |
console.log(ENDPOINT_EVENTS + MAX_PER_PAGE); | |
export const fetchEvents = async (dispatch, query) => { | |
try { | |
const response = await axios.get(ENDPOINT_EVENTS + MAX_PER_PAGE, {}); | |
/*console.log('Response =', response.data);*/ | |
dispatch(fetchEventsAction(response.data)); | |
} catch (e) { | |
console.log('error requete events', e); | |
} | |
}; | |
export const sendEvent = async (dispatch, query) => { | |
try { | |
console.log('Dans event : '); | |
const formData = new FormData(); | |
formData.append('title', 'test 12'); | |
formData.append('description', 'test 12'); | |
formData.append('postalCode', 'test 12'); | |
formData.append('city', 'test 12'); | |
formData.append('contact_mail', 'test 12'); | |
formData.append('contact_phone', 'test 12'); | |
formData.append('dateStart', '2021-04-01'); | |
formData.append('dateEnd', '2021-04-12'); | |
formData.append('timeStart', ''); | |
formData.append('timeEnd', ''); | |
formData.append('user_id', '1'); | |
const response = await axios.post(API_URL + '/events/store', formData, { | |
headers: { | |
'Content-Type': | |
'multipart/form-data; charset=utf-8; boundary="another cool boundary";', | |
}, | |
}); | |
console.log('Response =', response.data); | |
dispatch(fetchSelectedRecipeAction(response.data)); | |
} catch (e) { | |
console.log('error', e); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment