Created
April 27, 2018 10:49
-
-
Save vhuytdt/d51bb58cfd9374f2b14302de0625cc42 to your computer and use it in GitHub Desktop.
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 from 'react'; | |
import {Text,View, TouchableOpacity,FlatList, StatusBar, ImageBackground, ActivityIndicator, Alert} from 'react-native'; | |
import JobItem from "../../components/Items/ComJobItem"; | |
import firebase from 'react-native-firebase'; | |
import { companiesRef,jobRef } from '../../api/index'; | |
import IonicIcon from 'react-native-vector-icons/Ionicons'; | |
import {Button,Card,Content, Container} from 'native-base'; | |
import { getAllJob,getCloseJob } from "../../api/JobsApi"; | |
import { withNavigationFocus, } from 'react-navigation'; | |
import HeaderDefault from "../../components/Header/HeaderDefault"; | |
import { IndicatorCenter } from "../../components/LazyLoading"; | |
import { connect } from "react-redux"; | |
import { chanelDoc, notificationDoc,jobDoc } from "../../api/rootRef"; | |
import { valueProfileById } from "../../api/CompanyApi"; | |
class MyJobs extends React.Component { | |
constructor(props){ | |
super(props); | |
this.state={ | |
myJobs:[], | |
refreshing : false, | |
closeJob:[], | |
loading:true | |
} | |
this.handlePostJob = this.handlePostJob.bind(this); | |
this.getItem = this.getItem.bind(this); | |
this.requestData = this.requestData.bind(this); | |
this.loadJobs = this.loadJobs.bind(this); | |
this.hideJob = this.hideJob.bind(this); | |
} | |
static navigationOptions = ({navigation})=> { | |
return { | |
tabBarIcon: ({tinColor})=>{ | |
return <IonicIcon | |
name={"md-person"} | |
size={25} | |
style={{width:22,height:22}} | |
/> | |
}, | |
title : `Tuyển dụng`, | |
tabBarLabel: "Tuyển dụng", | |
header:null | |
} | |
}; | |
hideJob(jobId,isClosed) { | |
let myThis = this; | |
Alert.alert( | |
'Ẩn tin.', | |
` ${isClosed? "Công việc sẽ được xuất hiện":"Công việc sẽ được ẩn đi"}`, | |
[ | |
{text: 'Đồng ý', onPress: () => { | |
jobDoc.doc(jobId).update({isClosed : !isClosed }).then(sucess=> { | |
myThis.loadJobs(); | |
}).catch(err=>{ | |
console.log("hide job faile",err); | |
}) | |
}}, | |
{text: 'Hủy', onPress: () => {}}, | |
], | |
) | |
} | |
handlePostJob(){ | |
this.props.navigation.navigate("JobCategory",{kind:"post"}) | |
} | |
requestData(){ | |
this.loadJobs(); | |
} | |
getItem({item}){ | |
const jobId = item.jobId; | |
let myThis = this; | |
const title = item.title; | |
const { navigation } = this.props; | |
return <TouchableOpacity onPress={()=>navigation.navigate("CandidatesJobs",{ jobId,title })} > | |
<View style={{marginTop:2,marginLeft:"2%",marginRight:"2%"}}> | |
<JobItem hideJob={this.hideJob} parent = {myThis} navigation={this.props.navigation} {...item}/> | |
</View> | |
</TouchableOpacity> | |
} | |
render() { | |
const { closeJob, myJobs, loading } = this.state; | |
if(loading) { | |
return <IndicatorCenter /> | |
} | |
if(myJobs.length < 1 && closeJob.length < 1) { | |
return ( | |
<ImageBackground source={require("../../assets/images/app_post_job.png")} style={{flex:1}}> | |
<StatusBar | |
backgroundColor={"#fff"} | |
barStyle="dark-content"/> | |
<HeaderDefault title="Tuyển dụng"/> | |
<Button style={{backgroundColor:"#e74c3c",position:"absolute",left:"30%",right:"30%",bottom:"30%"}} | |
small | |
onPress={()=>this.handlePostJob()} > | |
<Text style={{color:"#fff",padding:3,width:"100%",textAlign:"center"}}><IonicIcon color={"#fff"} name={"md-add"}/> Đăng tuyển ngay</Text> | |
</Button> | |
</ImageBackground> ) | |
} | |
return ( | |
<Container> | |
<StatusBar | |
backgroundColor={"#fff"} | |
barStyle="dark-content"/> | |
<HeaderDefault title={"Công việc"}> | |
<Button style={{backgroundColor:"#e74c3c",minWidth:100,justifyContent:"center",alignItems:"center"}} | |
small | |
onPress={()=>this.handlePostJob()} > | |
<Text style={{color:"#fff",padding:3}}><IonicIcon color={"#fff"} name={"md-add"}/> Đăng việc</Text> | |
</Button> | |
</HeaderDefault> | |
<Content > | |
<View > | |
<FlatList | |
data={this.state.myJobs} | |
keyExtractor={(item)=>item.jobId} | |
renderItem={this.getItem} | |
onEndReachedThreshold={1} | |
refreshing={this.state.refreshing} | |
onRefresh={this.requestData} | |
/> | |
</View> | |
{ | |
closeJob.length > 0 && | |
<View > | |
<Text style={{paddingLeft:"6%",marginTop:20,marginBottom:20}}>Việc đã đóng</Text> | |
<FlatList | |
data={this.state.closeJob} | |
keyExtractor={(item)=>item.jobId} | |
renderItem={this.getItem} | |
onEndReachedThreshold={1} | |
refreshing={this.state.refreshing} | |
onRefresh={this.requestData} | |
/> | |
</View> | |
} | |
</Content> | |
</Container> | |
) | |
} | |
loadJobs(){ | |
getAllJob().then(snapJobs=>{ | |
let myJobs = []; | |
snapJobs.forEach(job=>{ | |
const value = job.data(); | |
value.jobId = job.id; | |
myJobs.push(value); | |
}) | |
this.setState({myJobs,loading : false}); | |
}) | |
getCloseJob().then(snapJobs => { | |
let closeJob = []; | |
snapJobs.forEach(job=>{ | |
const value = job.data(); | |
value.jobId = job.id; | |
closeJob.push(value); | |
}) | |
this.setState({closeJob}); | |
}) | |
} | |
async componentWillMount(){ | |
} | |
async componentDidMount(){ | |
this.loadJobs(); | |
let myThis = this; | |
const currentUser = firebase.auth().currentUser; | |
const valueProfile = await valueProfileById(currentUser.uid); | |
if(valueProfile){ | |
if(!valueProfile.isVerified){ | |
if(valueProfile.verifyReason!=="") | |
Alert.alert( | |
'Cảnh báo', | |
`Thông tin của công ty bạn chưa được DUYỆT. Lý do: ${valueProfile.verifyReason}. Cám ơn`, | |
[ | |
{text: 'Đã hiểu', onPress: () => {}}, | |
], | |
) | |
} | |
chanelDoc.where("company.id","==",currentUser.uid).onSnapshot(channels =>{ | |
let count = 0; | |
channels.forEach( item => { | |
const value = item.data(); | |
if(value.isCompanyRead===false) { | |
count++; | |
} | |
}) | |
myThis.props.dispatch({type:"CHAT_COUNT",count }); | |
}) | |
notificationDoc.where("receiverId","==",`${currentUser.uid}`).where("isRead","==",false).onSnapshot ( notifications => { | |
let count = 0; | |
notifications.forEach( item => { | |
const value = item.data(); | |
if(value.isRead===false) { | |
count++; | |
} | |
}) | |
myThis.props.dispatch({type:"NOTIFICATION_COUNT",count }); | |
}) | |
} | |
} | |
componentDidUpdate(prevProps) { | |
if( this.props.reload ) { | |
setTimeout( () => this.loadJobs(),3000); | |
this.props.dispatch({type :"TOGGLE_RELOAD_COMPANY"}); | |
} | |
if ( prevProps.isFocused != this.props.isFocused ) { | |
this.loadJobs(); | |
} | |
} | |
} | |
const mapStateToProps = ({ companyJob : { reload } }) => { | |
return { | |
reload | |
} | |
} | |
export default connect(mapStateToProps) (withNavigationFocus(MyJobs)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment