lbry-desktop/src/ui/modal/modalPhoneCollection/view.jsx

71 lines
1.6 KiB
React
Raw Normal View History

2018-09-26 19:48:07 +02:00
// @flow
2019-04-03 07:56:58 +02:00
import React, { Suspense } from 'react';
import { Modal } from 'modal/modal';
2018-03-26 23:32:43 +02:00
import Button from 'component/button';
import UserPhoneVerify from 'component/userPhoneVerify';
import { Redirect } from 'react-router';
2019-04-12 15:03:47 +02:00
const LazyUserPhoneNew = React.lazy(() =>
2019-09-26 18:07:11 +02:00
import(
/* webpackChunkName: "userPhoneNew" */
'component/userPhoneNew'
)
2019-04-12 15:03:47 +02:00
);
2019-04-03 07:56:58 +02:00
2018-09-26 19:48:07 +02:00
type Props = {
phone: ?number,
user: {
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> {
getTitle() {
const { user, phone } = this.props;
if (!user.is_identity_verified && !phone) {
return __('Enter Your Phone Number');
}
return __('Enter The Verification Code');
}
renderInner() {
const { closeModal, phone, user } = this.props;
const cancelButton = <Button button="link" onClick={closeModal} label={__('Not Now')} />;
if (!user.is_identity_verified && !phone) {
2019-04-03 07:56:58 +02:00
return (
2019-04-12 15:03:47 +02:00
<Suspense fallback={<div />}>
<LazyUserPhoneNew cancelButton={cancelButton} />
2019-04-03 07:56:58 +02:00
</Suspense>
);
} else if (!user.is_identity_verified) {
return <UserPhoneVerify cancelButton={cancelButton} />;
}
2019-04-04 23:05:23 +02:00
closeModal();
return <Redirect to="/$/rewards" />;
}
render() {
const { user } = this.props;
// this shouldn't happen
if (!user) {
return null;
}
return (
<Modal type="custom" isOpen contentLabel="Phone" title={this.getTitle()}>
2019-01-08 19:48:09 +01:00
{this.renderInner()}
</Modal>
);
}
}
export default ModalPhoneCollection;