2018-09-26 19:48:07 +02:00
|
|
|
// @flow
|
2019-04-03 07:56:58 +02:00
|
|
|
import React, { Suspense } from 'react';
|
2017-12-21 22:08:54 +01:00
|
|
|
import { Modal } from 'modal/modal';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
2018-01-22 08:09:11 +01:00
|
|
|
import UserPhoneVerify from 'component/userPhoneVerify';
|
2019-11-07 20:39:22 +01:00
|
|
|
import UserPhoneNew from 'component/userPhoneNew';
|
2019-05-10 07:08:48 +02:00
|
|
|
import { Redirect } from 'react-router';
|
2017-12-07 19:07:30 +01:00
|
|
|
|
2018-09-26 19:48:07 +02:00
|
|
|
type Props = {
|
|
|
|
phone: ?number,
|
|
|
|
user: {
|
2019-05-10 07:08:48 +02:00
|
|
|
is_identity_verified: boolean,
|
2018-09-26 19:48:07 +02:00
|
|
|
},
|
|
|
|
closeModal: () => void,
|
2019-04-04 23:05:23 +02:00
|
|
|
history: { push: string => void },
|
2018-09-26 19:48:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ModalPhoneCollection extends React.PureComponent<Props> {
|
2019-01-14 19:40:06 +01:00
|
|
|
getTitle() {
|
|
|
|
const { user, phone } = this.props;
|
|
|
|
|
2019-05-10 07:08:48 +02:00
|
|
|
if (!user.is_identity_verified && !phone) {
|
2019-01-14 19:40:06 +01:00
|
|
|
return __('Enter Your Phone Number');
|
|
|
|
}
|
2019-05-10 07:08:48 +02:00
|
|
|
|
2019-01-14 19:40:06 +01:00
|
|
|
return __('Enter The Verification Code');
|
|
|
|
}
|
|
|
|
|
2017-12-07 19:07:30 +01:00
|
|
|
renderInner() {
|
2019-05-10 07:08:48 +02:00
|
|
|
const { closeModal, phone, user } = this.props;
|
2017-12-07 19:07:30 +01:00
|
|
|
|
2018-04-05 23:26:20 +02:00
|
|
|
const cancelButton = <Button button="link" onClick={closeModal} label={__('Not Now')} />;
|
2017-12-07 19:07:30 +01:00
|
|
|
|
2019-05-10 07:08:48 +02:00
|
|
|
if (!user.is_identity_verified && !phone) {
|
2019-11-07 20:39:22 +01:00
|
|
|
return <UserPhoneNew cancelButton={cancelButton} />;
|
2019-05-10 07:08:48 +02:00
|
|
|
} else if (!user.is_identity_verified) {
|
2018-01-22 08:09:11 +01:00
|
|
|
return <UserPhoneVerify cancelButton={cancelButton} />;
|
2017-12-07 19:07:30 +01:00
|
|
|
}
|
2019-04-04 23:05:23 +02:00
|
|
|
|
2019-05-10 07:08:48 +02:00
|
|
|
closeModal();
|
|
|
|
return <Redirect to="/$/rewards" />;
|
2017-12-07 19:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { user } = this.props;
|
|
|
|
|
2017-12-21 22:08:54 +01:00
|
|
|
// this shouldn't happen
|
2017-12-07 19:07:30 +01:00
|
|
|
if (!user) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-01-14 19:40:06 +01:00
|
|
|
<Modal type="custom" isOpen contentLabel="Phone" title={this.getTitle()}>
|
2019-01-08 19:48:09 +01:00
|
|
|
{this.renderInner()}
|
2017-12-07 19:07:30 +01:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 07:08:48 +02:00
|
|
|
export default ModalPhoneCollection;
|