Commit 6a8e5bdb authored by dungtnguyen's avatar dungtnguyen

change user info

parent 49289102
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.anawork_mobile",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"outputFile": "app-release.apk"
}
],
"elementType": "File",
"baselineProfiles": [
{
"minApi": 28,
"maxApi": 30,
"baselineProfiles": [
"baselineProfiles/1/app-release.dm"
]
},
{
"minApi": 31,
"maxApi": 2147483647,
"baselineProfiles": [
"baselineProfiles/0/app-release.dm"
]
}
],
"minSdkVersionForDexing": 23
}
\ No newline at end of file
...@@ -14,7 +14,7 @@ const authAPI = { ...@@ -14,7 +14,7 @@ const authAPI = {
`authenticate/authenticate?username=${username}&password=${password}`, `authenticate/authenticate?username=${username}&password=${password}`,
), ),
requestLogout: ({token}) => axiosClient.post('authenticate/logout', {token}), requestLogout: () => axiosClient.post('authenticate/logout'),
requestGetMyInfo: () => axiosClient.get('authenticate/getMyInfo'), requestGetMyInfo: () => axiosClient.get('authenticate/getMyInfo'),
requestGetCompanyLogo: () => axiosClient.get('companyInfo'), requestGetCompanyLogo: () => axiosClient.get('companyInfo'),
......
import axiosClient from '../axios'; import axiosClient from '../network/axios';
export default { export default {
requestGetLeavesDay: ({filter, sort, page, pageSize}) => requestGetLeavesDay: ({filter, sort, page, pageSize}) =>
axiosClient.get( axiosClient.get(
......
import axiosClient from '../network/axios';
export default {
requestChangeUserInfo: ({id, body}) => axiosClient.put(`users/${id}`, body),
};
...@@ -2,7 +2,10 @@ const storageKey = { ...@@ -2,7 +2,10 @@ const storageKey = {
AUTH: 'auth', AUTH: 'auth',
LANGUAGE: 'language', LANGUAGE: 'language',
}; };
const profileField = {
PERSONAL_INFO: 'Personal Information',
DETAIL_INFO: 'Detail Information',
};
export default { export default {
apiEndpoint: 'https://gateway.dev.meu-solutions.com/staginganawork/api/', apiEndpoint: 'https://gateway.dev.meu-solutions.com/staginganawork/api/',
//apiEndpoint: 'https://gateway.dev.meu-solutions.com/techport/api/', //apiEndpoint: 'https://gateway.dev.meu-solutions.com/techport/api/',
...@@ -11,4 +14,5 @@ export default { ...@@ -11,4 +14,5 @@ export default {
ONE_SIGNAL_KEY: '6f4f8bd1-9b43-4067-8175-c0052140e891', ONE_SIGNAL_KEY: '6f4f8bd1-9b43-4067-8175-c0052140e891',
axiosTimeout: 10000, axiosTimeout: 10000,
storageKey, storageKey,
profileField,
}; };
...@@ -52,6 +52,19 @@ export const getCompanyInfo = createAsyncThunk( ...@@ -52,6 +52,19 @@ export const getCompanyInfo = createAsyncThunk(
}); });
}, },
); );
export const logout = createAsyncThunk(
'auth/logout',
async (data, thunkAPI) => {
return serviceRequest({
dispatch: thunkAPI.dispatch,
serviceMethod: authAPI.requestLogout,
payload: data,
options: {
skipLoader: false,
},
});
},
);
const authSlice = createSlice({ const authSlice = createSlice({
name: 'auth', name: 'auth',
initialState: initialState, initialState: initialState,
...@@ -71,6 +84,12 @@ const authSlice = createSlice({ ...@@ -71,6 +84,12 @@ const authSlice = createSlice({
state.userInfo = user; state.userInfo = user;
} }
}); });
builder.addCase(logout.fulfilled, (state, action) => {
const {success} = Utils.getValues(action, 'payload', false);
if (success) {
Utils.removeData(config.storageKey.AUTH);
}
});
}, },
}); });
......
/* eslint-disable prettier/prettier */
import React, {useState} from 'react'; import React, {useState} from 'react';
import RootNavigation from '../../../navigation/RootNavigation'; import RootNavigation from '../../../navigation/RootNavigation';
import LoginScreen from './LoginScreen'; import LoginScreen from './LoginScreen';
...@@ -7,11 +6,10 @@ import {useTranslation} from 'react-i18next'; ...@@ -7,11 +6,10 @@ import {useTranslation} from 'react-i18next';
import OneSignal from 'react-native-onesignal'; import OneSignal from 'react-native-onesignal';
import {useDispatch, useSelector} from 'react-redux'; import {useDispatch, useSelector} from 'react-redux';
import {loaderSelector} from '../../../app/selectors'; import {loaderSelector} from '../../../app/selectors';
import {getMyInfo} from '../../../store/actions/CommonAction';
import Utils from '../../../utils'; import Utils from '../../../utils';
import {APP_NAVIGATE_SCREEN} from '../../../utils/constant'; import {APP_NAVIGATE_SCREEN} from '../../../utils/constant';
import {ToastMessage} from '../../../utils/MessageUtil'; import {ToastMessage} from '../../../utils/MessageUtil';
import {authenticate} from '../authSlice'; import {authenticate, getMyInfo} from '../authSlice';
const LoginContainer = props => { const LoginContainer = props => {
// console.log("props: ", props) // console.log("props: ", props)
const dispatch = useDispatch(); const dispatch = useDispatch();
...@@ -66,6 +64,7 @@ const LoginContainer = props => { ...@@ -66,6 +64,7 @@ const LoginContainer = props => {
}), }),
).then(response => { ).then(response => {
const {success} = Utils.getValues(response, 'payload', false); const {success} = Utils.getValues(response, 'payload', false);
dispatch(getMyInfo());
if (success) { if (success) {
ToastMessage({ ToastMessage({
title: 'Hệ thống', title: 'Hệ thống',
......
...@@ -380,6 +380,11 @@ const ConfirmDateContainer = props => { ...@@ -380,6 +380,11 @@ const ConfirmDateContainer = props => {
}; };
const handleSubmitConfirmWorkingDayRequest = () => { const handleSubmitConfirmWorkingDayRequest = () => {
if (directManagersList?.length === 0) { if (directManagersList?.length === 0) {
ToastMessage({
title: 'Hệ thống',
message: 'Bạn đã là cấp trên không thể gửi yêu cầu !!!',
type: 'error',
});
return false; return false;
} }
const isSelectedManager = directManagersList.filter(item => item.isChecked); const isSelectedManager = directManagersList.filter(item => item.isChecked);
......
...@@ -334,6 +334,12 @@ const OnLeaveContainer = props => { ...@@ -334,6 +334,12 @@ const OnLeaveContainer = props => {
}; };
const handleSubmitLeaveRequest = () => { const handleSubmitLeaveRequest = () => {
if (directManagersList?.length === 0) { if (directManagersList?.length === 0) {
ToastMessage({
title: 'Hệ thống',
message: 'Bạn đã là cấp trên không thể gửi yêu cầu !!!',
type: 'info',
timeVisible: 5000,
});
return false; return false;
} }
const isSelectedManager = directManagersList.filter(item => item.isChecked); const isSelectedManager = directManagersList.filter(item => item.isChecked);
......
...@@ -2,7 +2,7 @@ import {createAsyncThunk, createSlice} from '@reduxjs/toolkit'; ...@@ -2,7 +2,7 @@ import {createAsyncThunk, createSlice} from '@reduxjs/toolkit';
import serviceRequest from '../../app/serviceRequest'; import serviceRequest from '../../app/serviceRequest';
import onLeaveApi from '../../network/api/onLeaveApi'; import onLeaveApi from '../../api/onLeaveApi';
import Utils from '../../utils'; import Utils from '../../utils';
const initialHome = { const initialHome = {
......
...@@ -428,9 +428,9 @@ export const leavesModalStyles = StyleSheet.create({ ...@@ -428,9 +428,9 @@ export const leavesModalStyles = StyleSheet.create({
shadowOpacity: 0.25, shadowOpacity: 0.25,
shadowRadius: 4, shadowRadius: 4,
elevation: 5, elevation: 5,
marginTop: 80, marginTop: 100,
height: windowHeight,
width: '100%', width: '100%',
height: windowHeight,
}, },
button: { button: {
......
...@@ -4,67 +4,38 @@ import {launchImageLibrary} from 'react-native-image-picker'; ...@@ -4,67 +4,38 @@ import {launchImageLibrary} from 'react-native-image-picker';
import Toast from 'react-native-toast-message'; import Toast from 'react-native-toast-message';
import {useDispatch} from 'react-redux'; import {useDispatch} from 'react-redux';
import RootNavigation from '../../navigation/RootNavigation'; import RootNavigation from '../../navigation/RootNavigation';
import {logoutApp} from '../../store/actions/CommonAction'; import {changeAvatar, changeCoverAvatar} from '../../store/actions/UserAction';
import { import Utils from '../../utils';
addContactUser,
changeAvatar,
changeContactUser,
changeCoverAvatar,
changeUserInfo,
deleteContactUser,
getContactUser,
} from '../../store/actions/UserAction';
import {APP_NAVIGATE_SCREEN} from '../../utils/constant'; import {APP_NAVIGATE_SCREEN} from '../../utils/constant';
import {logout} from '../authentication/authSlice';
import profilePropsProvider from './profilePropsProvider'; import profilePropsProvider from './profilePropsProvider';
import ProfileMainView from './template/ProfileMainView'; import ProfileMainView from './template/ProfileMainView';
import {ToastMessage} from '../../utils/MessageUtil';
import config from '../../config';
import {changeUserInfo} from './profileSlice';
const ProfileContainer = props => { const ProfileContainer = props => {
const {userInfo} = props; const {userInfo} = props;
const dispatch = useDispatch(); const dispatch = useDispatch();
const [modalVisible, setModalVisible] = useState(false);
const [isEditField, setEditField] = useState({ const [isEditField, setEditField] = useState({
detail_info: false, detail_info: false,
contact_info: false, contact_info: false,
personal_info: false, personal_info: false,
avatar: false, avatar: false,
}); });
const [btnAvailable, setBtnAvailable] = useState({
personalBtn: false,
contactBtn: false,
detailBtn: false,
});
const [infoUser, setInfoUser] = useState(userInfo);
const [contactUser, setContactUser] = useState([]); const [editUserInfo, setEditUserInfo] = useState({
const [defaultContact, setDefaultContact] = useState([]); personalInfo: false,
const [userInputContact, setUserInputContact] = useState({ detailInfo: false,
type: '',
text: '',
}); });
const [avatar, setAvatar] = useState(); const [avatar, setAvatar] = useState();
const [visibleMenu, setVisibleMenu] = useState(false); const [visibleMenu, setVisibleMenu] = useState(false);
const [isSlideShow, setSlideShow] = useState(false);
const [dateTimePicker, setDateTimePicker] = useState({
birthday: false,
id_card_issue_date: false,
});
const [showAlert, setShowAlert] = useState({
isError: false,
title: '',
message: '',
});
const [deleteItem, setDelItem] = useState([]);
const hideMenu = () => setVisibleMenu(false); const hideMenu = () => setVisibleMenu(false);
const showMenu = () => setVisibleMenu(true); const showMenu = () => setVisibleMenu(true);
const hideDateTimePicker = () => {
setDateTimePicker({
birthday: false,
id_card_issue_date: false,
});
};
const openGallery = () => { const openGallery = () => {
hideMenu(); hideMenu();
...@@ -113,30 +84,63 @@ const ProfileContainer = props => { ...@@ -113,30 +84,63 @@ const ProfileContainer = props => {
); );
}; };
const showFullScreen = () => { const onSubmitChangeInfo = async values => {
setSlideShow(true); console.log('values', values);
hideMenu();
}; if (userInfo) {
const hideFullScreen = () => { const {
//console.log("hide") first_name,
setSlideShow(false); middle_name,
last_name,
cell_phone,
gender,
birthday,
birthplace,
nationality,
id_card_number,
id_card_issue_date,
id_card_issue_palce,
ethnic,
religion,
domicile,
personal_tax_code,
address,
permanent_address,
} = values;
const payload = {
first_name: first_name || userInfo?.first_name,
middle_name: middle_name || userInfo?.middle_name,
last_name: last_name || userInfo?.last_name,
cell_phone: cell_phone || userInfo?.cell_phone,
gender: gender === 'Nam',
birthday: birthday || userInfo?.birthday,
birthplace: birthplace || userInfo?.birthplace,
nationality: nationality || userInfo?.nationality,
id_card_number: id_card_number || userInfo?.id_card_number,
id_card_issue_date: id_card_issue_date || userInfo?.id_card_issue_date,
id_card_issue_palce:
id_card_issue_palce || userInfo?.id_card_issue_palce,
ethnic: ethnic || userInfo?.ethnic,
religion: religion || userInfo?.religion,
domicile: domicile || userInfo?.domicile,
personal_tax_code: personal_tax_code || userInfo?.personal_tax_code,
address: address || userInfo?.address,
permanent_address: permanent_address || userInfo?.permanent_address,
}; };
const onSaveInfo = async () => {
if (!!compareInfoUser) { dispatch(changeUserInfo({id: userInfo.id, body: payload})).then(
const res = await dispatch(changeUserInfo(userInfo.id, infoUser)); response => {
if (res) { const {success} = Utils.getValues(response, 'payload', false);
Toast.show({ success && onEditUserInfo();
type: 'success', ToastMessage({
text1: 'Hệ thống', title: 'Hệ thống',
text2: 'Thay đổi thông tin thành công 💖', message: `Thay đổi thông tin ${
}); success ? 'thành công 💖' : 'thất bại 💔'
} else { } `,
Toast.show({ type: success ? 'success' : 'error',
type: 'error',
text1: 'Hệ thống',
text2: 'Thay đổi thông tin thất bại 💔',
}); });
} },
);
} }
}; };
const onDeniedAvatar = () => { const onDeniedAvatar = () => {
...@@ -154,246 +158,38 @@ const ProfileContainer = props => { ...@@ -154,246 +158,38 @@ const ProfileContainer = props => {
}); });
} }
}; };
const navigateMain = () => {
RootNavigation.navigate(APP_NAVIGATE_SCREEN.MAIN);
};
const compareInfoUser = () => {
// check user have change info
if (JSON.stringify(infoUser) == JSON.stringify(userInfo)) return true;
return false;
};
const compareContactUser = () => {
// check user have change info
// console.log("defaultContact", defaultContact)
if (JSON.stringify(defaultContact) === JSON.stringify(contactUser))
return false;
return true;
};
const getContactSocialUser = async () => {
const res = await dispatch(getContactUser(userInfo.id));
//console.log(res)
if (res.length > 0) {
let arrContact = [];
res.map((item, index) => {
arrContact.push(item);
});
setContactUser(arrContact);
setDefaultContact(JSON.parse(JSON.stringify(arrContact)));
}
};
const onChangeDropDownContactUser = (selectedItem, index) => {
const clone = [...contactUser];
clone[index].type = selectedItem;
setContactUser(clone);
//console.log("clone", clone)
};
const onChangeInputContactUser = (selectedItem, index) => {
const clone = [...contactUser];
clone[index].contact_unique_id = selectedItem;
setContactUser(clone);
//console.log("clone", clone)
};
const checkValidDropdown = () => {
var isValid = contactUser.map(a => a.type);
//console.log(isValid.some((a, index) => isValid.indexOf(a) !== index))
return isValid.some((a, index) => isValid.indexOf(a) !== index);
};
const onSubmitChangeContactUser = async (contact_unique_id, type) => {
const isChange = compareContactUser();
//console.log("defaultContact", defaultContact)
const isValid = checkValidDropdown();
if (!isValid) {
if (isChange) {
//console.log("compareEmailContactUser", isChange)
const resultsChange = contactUser.filter(
({type: t1, contact_unique_id: cui_1}) =>
!defaultContact.some(
({type: t2, contact_unique_id: cui_2}) =>
t2 === t1 && cui_1 === cui_2,
),
);
//console.log("results", resultsChange)
const res = await dispatch(
changeContactUser(
resultsChange[0].id,
resultsChange[0].contact_unique_id,
resultsChange[0].type,
),
);
if (res.success) {
Toast.show({
type: 'success',
text1: 'Hệ thống',
text2: 'Thay đổi liên lạc thành công 💖',
});
setEditField(prev => ({...prev, contact_info: false}));
setBtnAvailable(prev => ({...prev, contactBtn: false}));
} else {
Toast.show({
type: 'error',
text1: 'Hệ thống',
text2: 'Thay đổi liên lạc thất bại 💔',
});
}
} else {
setEditField(prev => ({...prev, contact_info: false}));
setBtnAvailable(prev => ({...prev, contactBtn: false}));
}
} else {
Toast.show({
type: 'error',
text1: 'Hệ thống',
text2: 'Vui lòng chọn social khác nhau',
});
}
};
const onPressDeleteItem = item => {
// console.log("item", item)
setShowAlert({
isError: true,
title: 'Hệ thống',
message: 'Bạn có chắc chắn muốn xóa dòng dữ liệu này?',
});
setDelItem(item);
};
const onPressAddItem = () => {
setModalVisible(true);
};
const onConfirmDeleteAlert = async () => {
const clone = contactUser.filter(i => i !== deleteItem);
const res = await dispatch(deleteContactUser(deleteItem.id)); const navigateToLogout = () => {
if (res) { dispatch(logout()).then(response => {
Toast.show({ const {success} = Utils.getValues(response, 'payload', false);
type: 'success', if (success) {
text1: 'Hệ thống', RootNavigation.replace(APP_NAVIGATE_SCREEN.LOGIN);
text2: 'Xoá thành công ',
});
setContactUser(clone);
setDefaultContact(clone);
setShowAlert({
isError: false,
title: '',
message: '',
});
} else {
Toast.show({
type: 'error',
text1: 'Hệ thống',
text2: 'Xoá thất bại',
});
setShowAlert({
isError: false,
title: '',
message: '',
});
} }
// console.log("clone", clone)
};
const onCancelAlert = () => {
setShowAlert({
isError: false,
title: '',
message: '',
}); });
}; };
// submit add new contact const onEditUserInfo = field => {
const onSubmitCreateNew = async () => { setEditUserInfo({
if (userInputContact.text.length > 0 && userInputContact.type.length > 0) { personalInfo: field === config.profileField.PERSONAL_INFO,
// had social network type detailInfo: field === config.profileField.DETAIL_INFO,
const duplicateSocial = contactUser.find(
item => item.type === userInputContact.type,
);
//console.log("duplicateSocial", duplicateSocial)
if (duplicateSocial === undefined) {
const res = await dispatch(
addContactUser(
userInfo.id,
userInputContact.text,
userInputContact.type,
),
);
if (res.success) {
Toast.show({
type: 'success',
text1: 'Hệ thống',
text2: 'Thêm contact thành công',
}); });
setEditField(prev => ({...prev, contact_info: false}));
setBtnAvailable(prev => ({...prev, contactBtn: false}));
setModalVisible(false);
setUserInputContact({
type: '',
text: '',
});
getContactSocialUser();
} else {
Toast.show({
type: 'error',
text1: 'Hệ thống',
text2: 'Thêm contact thất bại',
});
}
} else {
Toast.show({
type: 'error',
text1: 'Hệ thống',
text2: 'Đã social này đã tổn tài',
});
}
}
};
const navigateToLogout = () => {
dispatch(logoutApp());
}; };
useEffect(() => {
getContactSocialUser();
}, []);
const profileProps = { const profileProps = {
userInfo, userInfo,
isEditField, isEditField,
btnAvailable,
infoUser,
avatar, avatar,
visibleMenu, visibleMenu,
isSlideShow, editUserInfo,
dateTimePicker,
contactUser,
showAlert,
modalVisible,
userInputContact,
setAvatar,
setInfoUser,
navigateMain,
setEditField,
setBtnAvailable,
onSaveInfo,
onDeniedAvatar, onDeniedAvatar,
onConfirmAvatar, onConfirmAvatar,
showMenu, showMenu,
openGallery, openGallery,
showFullScreen,
hideFullScreen,
hideMenu, hideMenu,
hideDateTimePicker,
setDateTimePicker,
onSubmitChangeContactUser,
setContactUser,
onChangeDropDownContactUser,
onChangeInputContactUser,
onPressDeleteItem,
onPressAddItem,
onConfirmDeleteAlert,
onCancelAlert,
setUserInputContact,
onSubmitCreateNew,
setModalVisible,
navigateToLogout, navigateToLogout,
onChangeCoverAvatar, onChangeCoverAvatar,
onEditUserInfo,
onSubmitChangeInfo,
}; };
return <ProfileMainView {...profilePropsProvider(profileProps)} />; return <ProfileMainView {...profilePropsProvider(profileProps)} />;
......
...@@ -2,86 +2,24 @@ export default function profilePropsProvider(props) { ...@@ -2,86 +2,24 @@ export default function profilePropsProvider(props) {
const { const {
userInfo, userInfo,
isEditField, isEditField,
btnAvailable,
infoUser,
avatar, avatar,
visibleMenu, visibleMenu,
isSlideShow,
dateTimePicker,
contactUser,
showAlert,
modalVisible,
userInputContact,
setAvatar,
setInfoUser,
navigateMain,
setEditField,
setBtnAvailable,
onSaveInfo,
onDeniedAvatar, onDeniedAvatar,
onConfirmAvatar, onConfirmAvatar,
showMenu, showMenu,
openGallery, openGallery,
showFullScreen,
hideFullScreen,
hideMenu, hideMenu,
hideDateTimePicker,
setDateTimePicker,
onSubmitChangeContactUser,
setContactUser,
onChangeDropDownContactUser,
onChangeInputContactUser,
onPressDeleteItem,
onPressAddItem,
onConfirmDeleteAlert,
onCancelAlert,
setUserInputContact,
onSubmitCreateNew,
setModalVisible,
navigateToLogout, navigateToLogout,
onChangeCoverAvatar, onChangeCoverAvatar,
onEditUserInfo,
editUserInfo,
onSubmitChangeInfo,
} = props; } = props;
return { return {
userInfo, userInfo,
isEditField,
btnAvailable,
infoUser,
avatar,
visibleMenu,
isSlideShow,
dateTimePicker,
contactUser,
showAlert,
modalVisible,
userInputContact,
setAvatar,
setInfoUser,
navigateMain,
setEditField,
setBtnAvailable,
onSaveInfo,
onDeniedAvatar,
onConfirmAvatar,
showMenu,
openGallery,
showFullScreen,
hideFullScreen,
hideMenu,
hideDateTimePicker,
setDateTimePicker,
onSubmitChangeContactUser,
setContactUser,
onChangeDropDownContactUser,
onChangeInputContactUser,
onPressDeleteItem,
onPressAddItem,
onConfirmDeleteAlert,
onCancelAlert,
setUserInputContact,
onSubmitCreateNew,
setModalVisible,
navigateToLogout, navigateToLogout,
onChangeCoverAvatar, onEditUserInfo,
editUserInfo,
introduceUserProps: { introduceUserProps: {
userInfo, userInfo,
isEditField, isEditField,
...@@ -94,5 +32,6 @@ export default function profilePropsProvider(props) { ...@@ -94,5 +32,6 @@ export default function profilePropsProvider(props) {
openGallery, openGallery,
onChangeCoverAvatar, onChangeCoverAvatar,
}, },
onSubmitChangeInfo,
}; };
} }
import {createAsyncThunk, createSlice} from '@reduxjs/toolkit';
import serviceRequest from '../../app/serviceRequest';
import Utils from '../../utils';
import profileAPI from '../../api/profileAPI';
const initialState = {};
export const changeUserInfo = createAsyncThunk(
'profile/changeUserInfo',
async (data, thunkAPI) => {
return serviceRequest({
dispatch: thunkAPI.dispatch,
serviceMethod: profileAPI.requestChangeUserInfo,
payload: data,
options: {
skipLoader: false,
},
});
},
);
const profileSlice = createSlice({
name: 'profile',
initialState: initialState,
reducers: {},
extraReducers: builder => {
builder.addCase(changeUserInfo.fulfilled, (state, action) => {
const {success} = Utils.getValues(action, 'payload', false);
});
},
});
const {reducer} = profileSlice;
export default reducer;
import Moment from 'moment';
import React from 'react'; import React from 'react';
import { import {SafeAreaView, ScrollView, View} from 'react-native';
Animated,
Image,
ImageBackground,
Modal,
SafeAreaView,
ScrollView,
TextInput,
TouchableOpacity,
View,
} from 'react-native';
import Alert from 'react-native-awesome-alerts';
import {GestureHandlerRootView, Swipeable} from 'react-native-gesture-handler';
import {Menu, MenuItem} from 'react-native-material-menu';
import DateTimePickerModal from 'react-native-modal-datetime-picker';
import SelectDropdown from 'react-native-select-dropdown';
import Swiper from 'react-native-swiper';
import AppText from '../../../components/AppText';
import ButtonComponent from '../../../components/ButtonComponent'; import ButtonComponent from '../../../components/ButtonComponent';
import TextInputComponent from '../../../components/TextInputComponent'; import {IMAGES} from '../../../values/images';
import {
IMAGES,
IcNotificationList,
IconProfile,
IconSocial,
} from '../../../values/images';
import {default as string, default as strings} from '../../../values/string';
import styles from '../style'; import styles from '../style';
import colors from '../../../values/colors'; import DetailInformation from './components/DetailInformation';
import config from '../../../config';
import IntroduceUser from './components/IntroduceUser';
import GeneralInformation from './components/GeneralInformation'; import GeneralInformation from './components/GeneralInformation';
import IntroduceUser from './components/IntroduceUser';
import PersonalInformation from './components/PersonalInformation'; import PersonalInformation from './components/PersonalInformation';
import DetailInformation from './components/DetailInformation';
const Socials = [
'FACEBOOK',
'EMAIL',
'SKYPE',
'LINKEDIN',
'TWITTER',
'INSTAGRAM',
'WHATSAPP',
'VIPER',
'SNAPCHAT',
'TELEGRAM',
'APPLE',
'YOUTUBE',
'PINTEREST',
];
const gender = ['Nam', 'Nữ'];
const ProfileMainView = ({ const ProfileMainView = ({
userInfo, userInfo,
contactUser,
btnAvailable,
isEditField,
navigateMain,
setEditField,
setBtnAvailable,
infoUser,
setInfoUser,
onSaveInfo,
avatar = [],
onDeniedAvatar,
onConfirmAvatar,
showMenu,
hideMenu,
visibleMenu,
openGallery,
isSlideShow,
showFullScreen,
hideFullScreen,
dateTimePicker,
hideDateTimePicker,
setDateTimePicker,
showAlert,
onSubmitChangeContactUser,
onChangeDropDownContactUser,
onChangeInputContactUser,
onPressDeleteItem,
onPressAddItem,
onCancelAlert,
modalVisible,
setModalVisible,
setUserInputContact,
userInputContact,
onSubmitCreateNew,
onConfirmDeleteAlert,
navigateToLogout, navigateToLogout,
onChangeCoverAvatar,
introduceUserProps, introduceUserProps,
onEditUserInfo,
editUserInfo,
onSubmitChangeInfo,
}) => { }) => {
return ( return (
<SafeAreaView style={styles.container}> <SafeAreaView style={styles.container}>
...@@ -100,9 +24,19 @@ const ProfileMainView = ({ ...@@ -100,9 +24,19 @@ const ProfileMainView = ({
{/* General information */} {/* General information */}
<GeneralInformation userInfo={userInfo} /> <GeneralInformation userInfo={userInfo} />
{/* personal information */} {/* personal information */}
<PersonalInformation userInfo={userInfo} /> <PersonalInformation
userInfo={userInfo}
onEditUserInfo={onEditUserInfo}
editUserInfo={editUserInfo}
handleSubmitChangeInfo={onSubmitChangeInfo}
/>
{/* detail information */} {/* detail information */}
<DetailInformation userInfo={userInfo} /> <DetailInformation
userInfo={userInfo}
onEditUserInfo={onEditUserInfo}
editUserInfo={editUserInfo}
handleSubmitChangeInfo={onSubmitChangeInfo}
/>
{/* Logout Btn */} {/* Logout Btn */}
<View <View
style={{ style={{
...@@ -118,96 +52,6 @@ const ProfileMainView = ({ ...@@ -118,96 +52,6 @@ const ProfileMainView = ({
onPress={navigateToLogout} onPress={navigateToLogout}
/> />
</View> </View>
{/* <View style={styles.centeredView}>
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
setModalVisible(!modalVisible);
}}>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<View style={{flexDirection: 'row'}}>
<View style={{flex: 1}}>
<SelectDropdown
data={Socials}
dropdownIconPosition={'right'}
defaultButtonText={'Loại liên hệ'}
buttonStyle={styles.dropdown1BtnStyle}
onSelect={(selectedItem, item_index) =>
setUserInputContact(prev => ({
...prev,
type: selectedItem,
}))
}
dropdownStyle={styles.dropdown1DropdownStyle}
rowStyle={styles.dropdown1RowStyle}
rowTextStyle={styles.dropdown1RowTxtStyle}
buttonTextStyle={styles.dropdown1BtnTxtStyle}
renderDropdownIcon={isOpened => {
return (
<Image
source={
isOpened ? IMAGES.IcUpArrow : IMAGES.IcDownArrow
}
style={{width: 20, height: 20}}
/>
);
}}
/>
{userInputContact.type.length <= 0 && (
<AppText style={{fontSize: 12, color: 'red'}}>
{' '}
Vui lòng chọn liên hệ
</AppText>
)}
</View>
<View style={{flex: 1}}>
<TextInput
style={{borderBottomWidth: 0.2}}
placeholder={'Nhập F'}
keyboardType={'email-address'}
autoCapitalize="none"
value={userInputContact.text}
onChangeText={text =>
setUserInputContact(prev => ({
...prev,
text: text,
}))
}
/>
{userInputContact.text.length <= 0 && (
<AppText style={{fontSize: 12, color: 'red'}}>
{' '}
Vui lòng nhập liên hệ
</AppText>
)}
</View>
</View>
<View style={{flexDirection: 'row', marginTop: 20}}>
<ButtonComponent
text={'Đóng'}
textStyle={styles.textStyle}
style={[
styles.button,
styles.buttonClose,
{marginRight: 15},
]}
onPress={() => setModalVisible(!modalVisible)}
/>
<ButtonComponent
text={'Thêm mới'}
textStyle={styles.textStyle}
style={[styles.button, styles.buttonClose]}
onPress={onSubmitCreateNew}
/>
</View>
</View>
</View>
</Modal>
</View> */}
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
); );
......
...@@ -6,9 +6,14 @@ import string from '../../../../values/string'; ...@@ -6,9 +6,14 @@ import string from '../../../../values/string';
import styles from '../../style'; import styles from '../../style';
import commonStyles from '../../../../styles/commonStyles'; import commonStyles from '../../../../styles/commonStyles';
import moment from 'moment'; import moment from 'moment';
import config from '../../../../config';
import {Formik} from 'formik';
import TextInputComponent from '../../../../components/TextInputComponent';
import ButtonComponent from '../../../../components/ButtonComponent';
import colors from '../../../../values/colors';
const DetailInformation = React.memo( const DetailInformation = React.memo(
({userInfo}) => { ({userInfo, editUserInfo, onEditUserInfo, handleSubmitChangeInfo}) => {
const personalInfo = [ const personalInfo = [
{ {
name: 'Số CMND', name: 'Số CMND',
...@@ -74,7 +79,7 @@ const DetailInformation = React.memo( ...@@ -74,7 +79,7 @@ const DetailInformation = React.memo(
name: 'Địa chỉ liên hệ', name: 'Địa chỉ liên hệ',
value: userInfo?.address || '', value: userInfo?.address || '',
icon: IMAGES.IcLocationGray, icon: IMAGES.IcLocationGray,
width: '50%', width: '100%',
}, },
{ {
name: 'Địa chỉ thường trú', name: 'Địa chỉ thường trú',
...@@ -90,13 +95,21 @@ const DetailInformation = React.memo( ...@@ -90,13 +95,21 @@ const DetailInformation = React.memo(
{string.PERSONAL_INFORMATION} {string.PERSONAL_INFORMATION}
</AppText> </AppText>
<View> <View>
<TouchableOpacity> {!editUserInfo?.detailInfo ? (
<TouchableOpacity
onPress={() => onEditUserInfo(config.profileField.DETAIL_INFO)}>
<Image source={IMAGES.IcEdit} style={{height: 30, width: 30}} /> <Image source={IMAGES.IcEdit} style={{height: 30, width: 30}} />
</TouchableOpacity> </TouchableOpacity>
) : (
<TouchableOpacity onPress={() => onEditUserInfo()}>
<Image source={IMAGES.IcReject} />
</TouchableOpacity>
)}
</View> </View>
</View> </View>
<View style={[commonStyles.row, {flexWrap: 'wrap'}]}> <View style={[commonStyles.row, {flexWrap: 'wrap'}]}>
{personalInfo.map(item => ( {!editUserInfo?.detailInfo ? (
personalInfo.map(item => (
<View <View
key={item.name} key={item.name}
style={[styles.infoView, {width: item.width}]}> style={[styles.infoView, {width: item.width}]}>
...@@ -106,14 +119,69 @@ const DetailInformation = React.memo( ...@@ -106,14 +119,69 @@ const DetailInformation = React.memo(
<AppText isSubText>{item?.value}</AppText> <AppText isSubText>{item?.value}</AppText>
</View> </View>
</View> </View>
))} ))
) : (
<Formik
initialValues={{
id_card_number: userInfo?.id_card_number || '',
id_card_issue_date: userInfo?.id_card_issue_date || '',
id_card_issue_palce: userInfo?.id_card_issue_palce || '',
birthday: userInfo?.birthday ? 'Nam' : 'Nữ',
domicile: userInfo?.domicile || '',
birthplace: userInfo?.birthplace || '',
religion: userInfo?.religion || '',
ethnic: userInfo?.ethnic || '',
personal_tax_code: userInfo?.personal_tax_code || '',
nationality: userInfo?.personal_tax_code || '',
address: userInfo?.address || '',
permanent_address: userInfo?.permanent_address || '',
}}
onSubmit={values => handleSubmitChangeInfo(values)}>
{({handleChange, handleBlur, handleSubmit, values}) => (
<View style={[commonStyles.row, {flexWrap: 'wrap'}]}>
{personalInfo.map((item, index) => {
return (
<View
key={item.name}
style={{
width: item.width,
paddingHorizontal: 5,
}}>
<TextInputComponent
value={Object.values(values)[index]}
label={item.name}
placeholder={`Vui lòng nhập ${item.name} của bạn`}
styleAreaInput={{
backgroundColor: colors.white,
width: '100%',
}}
autoCompleteType={'postal-address'}
keyboardType={'email'}
onChangeText={handleChange(
Object.keys(values)[index],
)}
/>
</View>
);
})}
<ButtonComponent
style={[styles.btnSubmit]}
text={'Đồng ý'}
textStyle={{color: colors.white}}
onPress={handleSubmit}
/>
</View>
)}
</Formik>
)}
</View> </View>
</View> </View>
); );
}, },
function (prevProps, nextProps) { // function (prevProps, nextProps) {
return prevProps.userInfo === nextProps.userInfo; // return prevProps.userInfo === nextProps.userInfo;
}, // },
); );
export default memo(DetailInformation); export default memo(DetailInformation);
import {Formik} from 'formik';
import React, {memo} from 'react'; import React, {memo} from 'react';
import {Image, TouchableOpacity, View} from 'react-native'; import {Image, TouchableOpacity, View} from 'react-native';
import AppText from '../../../../components/AppText'; import AppText from '../../../../components/AppText';
import ButtonComponent from '../../../../components/ButtonComponent';
import TextInputComponent from '../../../../components/TextInputComponent';
import config from '../../../../config';
import commonStyles from '../../../../styles/commonStyles';
import {IMAGES} from '../../../../values/images'; import {IMAGES} from '../../../../values/images';
import string from '../../../../values/string'; import string from '../../../../values/string';
import styles from '../../style'; import styles from '../../style';
import commonStyles from '../../../../styles/commonStyles'; import colors from '../../../../values/colors';
const PersonalInformation = React.memo( const PersonalInformation = React.memo(
({userInfo}) => { ({userInfo, onEditUserInfo, editUserInfo, handleSubmitChangeInfo}) => {
const personalInfo = [ const personalInfo = [
{ {
name: 'Họ', name: 'Họ',
...@@ -53,13 +58,23 @@ const PersonalInformation = React.memo( ...@@ -53,13 +58,23 @@ const PersonalInformation = React.memo(
{string.PERSONAL_INFORMATION} {string.PERSONAL_INFORMATION}
</AppText> </AppText>
<View> <View>
<TouchableOpacity> {!editUserInfo?.personalInfo ? (
<TouchableOpacity
onPress={() =>
onEditUserInfo(config.profileField.PERSONAL_INFO)
}>
<Image source={IMAGES.IcEdit} style={{height: 30, width: 30}} /> <Image source={IMAGES.IcEdit} style={{height: 30, width: 30}} />
</TouchableOpacity> </TouchableOpacity>
) : (
<TouchableOpacity onPress={() => onEditUserInfo()}>
<Image source={IMAGES.IcReject} />
</TouchableOpacity>
)}
</View> </View>
</View> </View>
<View style={[commonStyles.row, {flexWrap: 'wrap'}]}> <View style={[commonStyles.row, {flexWrap: 'wrap'}]}>
{personalInfo.map(item => ( {!editUserInfo?.personalInfo ? (
personalInfo.map(item => (
<View <View
key={item.name} key={item.name}
style={[styles.infoView, {width: item.width}]}> style={[styles.infoView, {width: item.width}]}>
...@@ -69,14 +84,68 @@ const PersonalInformation = React.memo( ...@@ -69,14 +84,68 @@ const PersonalInformation = React.memo(
<AppText isSubText>{item?.value}</AppText> <AppText isSubText>{item?.value}</AppText>
</View> </View>
</View> </View>
))} ))
) : (
<Formik
initialValues={{
first_name: userInfo?.first_name || '',
middle_name: userInfo?.middle_name || '',
last_name: userInfo?.last_name || '',
gender: userInfo?.gender ? 'Nam' : 'Nữ',
cell_phone: userInfo?.cell_phone || '',
}}
onSubmit={values => handleSubmitChangeInfo(values)}>
{({handleChange, handleBlur, handleSubmit, values}) => (
<View style={[commonStyles.row, {flexWrap: 'wrap'}]}>
{personalInfo.map((item, index) => {
if (index === personalInfo.length - 1) {
return null;
}
return (
<View
key={item.name}
style={{
width: item.width,
paddingHorizontal: 5,
}}>
<TextInputComponent
value={Object.values(values)[index]}
label={item.name}
placeholder={`Vui lòng nhập ${item.name} của bạn`}
styleAreaInput={{
backgroundColor: colors.white,
width: '100%',
}}
autoCompleteType={'postal-address'}
keyboardType={'email'}
onChangeText={handleChange(
Object.keys(values)[index],
)}
/>
</View>
);
})}
<ButtonComponent
style={[styles.btnSubmit]}
text={'Đồng ý'}
textStyle={{color: colors.white}}
onPress={handleSubmit}
/>
</View>
)}
</Formik>
)}
</View> </View>
</View> </View>
); );
}, },
function (prevProps, nextProps) { // function (prevProps, nextProps) {
return prevProps.userInfo === nextProps.userInfo; // return (
}, // prevProps.userInfo === nextProps.userInfo ||
// prevProps.editUserInfo === nextProps.editUserInfo ||
// prevProps.onEditUserInfo() === nextProps.onEditUserInfo()
// );
// },
); );
export default memo(PersonalInformation); export default memo(PersonalInformation);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment