|
@@ -1,35 +1,133 @@
|
|
-import React from 'react';
|
|
|
|
|
|
+import React, { useState } from 'react';
|
|
import { View, ScrollView } from 'react-native';
|
|
import { View, ScrollView } from 'react-native';
|
|
|
|
+import { Formik } from 'formik';
|
|
|
|
+import * as yup from 'yup';
|
|
|
|
+
|
|
import { AvatarPicker, BigText, Button, Header, Input, PageWrapper } from '../../../components';
|
|
import { AvatarPicker, BigText, Button, Header, Input, PageWrapper } from '../../../components';
|
|
import { InputDatePicker } from '../../../components/Calendar/InputDatePicker';
|
|
import { InputDatePicker } from '../../../components/Calendar/InputDatePicker';
|
|
import { ModalFlatList } from '../../../components/FlatList/modal-flatlist';
|
|
import { ModalFlatList } from '../../../components/FlatList/modal-flatlist';
|
|
|
|
+import store from '../../../storage/zustand';
|
|
|
|
+import {
|
|
|
|
+ usePostRegister,
|
|
|
|
+ UserRegistrationData
|
|
|
|
+} from '../../../modules/auth/api/queries/use-post-register';
|
|
|
|
+
|
|
|
|
+const SignUpSchema = yup.object({
|
|
|
|
+ first_name: yup.string().required(),
|
|
|
|
+ last_name: yup.string().required(),
|
|
|
|
+ date_of_birth: yup.date().required(),
|
|
|
|
+ homebase: yup.number().required()
|
|
|
|
+});
|
|
|
|
|
|
-//TODO: connect with API + simple refactor
|
|
|
|
|
|
+//TODO: formik avatar | date and flatlist error shown
|
|
|
|
|
|
const EditAccount = () => {
|
|
const EditAccount = () => {
|
|
|
|
+ const [requestData, setRequestData] = useState<UserRegistrationData>({
|
|
|
|
+ user: {
|
|
|
|
+ username: '',
|
|
|
|
+ last_name: '',
|
|
|
|
+ first_name: '',
|
|
|
|
+ homebase: 1,
|
|
|
|
+ date_of_birth: new Date(),
|
|
|
|
+ email: '',
|
|
|
|
+ password: ''
|
|
|
|
+ },
|
|
|
|
+ photo: {
|
|
|
|
+ type: '',
|
|
|
|
+ name: '',
|
|
|
|
+ uri: ''
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const [user] = store((state) => [state.registration.user]);
|
|
|
|
+
|
|
|
|
+ const { data, error, refetch } = usePostRegister(
|
|
|
|
+ {
|
|
|
|
+ user: requestData.user,
|
|
|
|
+ photo: requestData.photo
|
|
|
|
+ },
|
|
|
|
+ false
|
|
|
|
+ );
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<PageWrapper>
|
|
<PageWrapper>
|
|
<ScrollView showsVerticalScrollIndicator={false}>
|
|
<ScrollView showsVerticalScrollIndicator={false}>
|
|
<View style={{ gap: 10 }}>
|
|
<View style={{ gap: 10 }}>
|
|
<Header label={'Sign Up'} />
|
|
<Header label={'Sign Up'} />
|
|
<BigText>Edit account data</BigText>
|
|
<BigText>Edit account data</BigText>
|
|
- <View style={{ display: 'flex', alignItems: 'center' }}>
|
|
|
|
- <AvatarPicker />
|
|
|
|
- </View>
|
|
|
|
- <Input placeholder={'Text'} onChange={() => {}} header={'First name'} />
|
|
|
|
- <Input placeholder={'Text'} onChange={() => {}} header={'Last name'} />
|
|
|
|
- <InputDatePicker selectedDate={(date) => console.log(date)} />
|
|
|
|
- <ModalFlatList
|
|
|
|
- headerTitle={'Region of origin'}
|
|
|
|
- selectedObject={(data) => console.log(data)}
|
|
|
|
- />
|
|
|
|
- <ModalFlatList
|
|
|
|
- headerTitle={'Second region'}
|
|
|
|
- selectedObject={(data) => console.log(data)}
|
|
|
|
- />
|
|
|
|
- <View style={{ marginTop: 10 }}>
|
|
|
|
- <Button>Sign up</Button>
|
|
|
|
- </View>
|
|
|
|
|
|
+ <Formik
|
|
|
|
+ initialValues={{
|
|
|
|
+ photo: {
|
|
|
|
+ type: '',
|
|
|
|
+ uri: '',
|
|
|
|
+ name: ''
|
|
|
|
+ },
|
|
|
|
+ first_name: '',
|
|
|
|
+ last_name: '',
|
|
|
|
+ date_of_birth: new Date(),
|
|
|
|
+ homebase: 0
|
|
|
|
+ }}
|
|
|
|
+ validationSchema={SignUpSchema}
|
|
|
|
+ onSubmit={(values) => {
|
|
|
|
+ const data = {
|
|
|
|
+ user: {
|
|
|
|
+ ...user,
|
|
|
|
+ first_name: values.first_name,
|
|
|
|
+ last_name: values.last_name,
|
|
|
|
+ date_of_birth: values.date_of_birth,
|
|
|
|
+ homebase: values.homebase
|
|
|
|
+ },
|
|
|
|
+ photo: {
|
|
|
|
+ type: values.photo.type,
|
|
|
|
+ uri: values.photo.uri,
|
|
|
|
+ name: values.photo.uri.split('/').pop()!
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ setRequestData(data);
|
|
|
|
+
|
|
|
|
+ refetch();
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ {(props) => (
|
|
|
|
+ <View>
|
|
|
|
+ <View style={{ display: 'flex', alignItems: 'center' }}>
|
|
|
|
+ <AvatarPicker selectedAvatar={(asset) => props.setFieldValue('photo', asset)} />
|
|
|
|
+ </View>
|
|
|
|
+ <Input
|
|
|
|
+ onChange={props.handleChange('first_name')}
|
|
|
|
+ value={props.values.first_name}
|
|
|
|
+ onBlur={props.handleBlur('first_name')}
|
|
|
|
+ placeholder={'Enter your first name'}
|
|
|
|
+ header={'First name'}
|
|
|
|
+ formikError={props.touched.first_name && props.errors.first_name}
|
|
|
|
+ />
|
|
|
|
+ <Input
|
|
|
|
+ onChange={props.handleChange('last_name')}
|
|
|
|
+ value={props.values.last_name}
|
|
|
|
+ onBlur={props.handleBlur('last_name')}
|
|
|
|
+ placeholder={'Enter your last name'}
|
|
|
|
+ header={'Last name'}
|
|
|
|
+ formikError={props.touched.last_name && props.errors.last_name}
|
|
|
|
+ />
|
|
|
|
+ <InputDatePicker
|
|
|
|
+ selectedDate={(date) => props.setFieldValue('date_of_birth', date)}
|
|
|
|
+ formikError={props.touched.date_of_birth && props.errors.date_of_birth}
|
|
|
|
+ />
|
|
|
|
+ <ModalFlatList
|
|
|
|
+ headerTitle={'Region of origin'}
|
|
|
|
+ selectedObject={(data) => props.setFieldValue('homebase', data.id)}
|
|
|
|
+ />
|
|
|
|
+ <ModalFlatList
|
|
|
|
+ headerTitle={'Second region'}
|
|
|
|
+ selectedObject={(data) => console.log(data)}
|
|
|
|
+ />
|
|
|
|
+ <View style={{ marginTop: 10 }}>
|
|
|
|
+ <Button onPress={props.handleSubmit}>Sign up</Button>
|
|
|
|
+ </View>
|
|
|
|
+ </View>
|
|
|
|
+ )}
|
|
|
|
+ </Formik>
|
|
</View>
|
|
</View>
|
|
</ScrollView>
|
|
</ScrollView>
|
|
</PageWrapper>
|
|
</PageWrapper>
|