fix: phone collection layout
This commit is contained in:
parent
bae0534d99
commit
7b0ab43bfa
6 changed files with 100 additions and 71 deletions
|
@ -23,6 +23,7 @@ class CreditAmount extends React.PureComponent<Props> {
|
|||
showFullPrice: false,
|
||||
showPlus: false,
|
||||
showLBC: true,
|
||||
badge: true,
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
|
@ -53,12 +53,12 @@ class TransactionListItem extends React.PureComponent<Props> {
|
|||
return (
|
||||
<tr>
|
||||
<td>
|
||||
<CreditAmount showPlus amount={amount} precision={8} />
|
||||
<CreditAmount badge={false} showPlus amount={amount} precision={8} />
|
||||
<br />
|
||||
|
||||
{fee !== 0 && (
|
||||
<span className="table__item-label">
|
||||
<CreditAmount fee amount={fee} precision={8} />
|
||||
<CreditAmount badge={false} fee amount={fee} precision={8} />
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// I'll come back to this
|
||||
/* eslint-disable */
|
||||
import React from 'react';
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import { Form, FormRow, FormField, Submit } from 'component/common/form';
|
||||
|
||||
const os = require('os').type();
|
||||
|
@ -20,67 +19,86 @@ const countryCodes = require('country-data')
|
|||
return 0;
|
||||
});
|
||||
|
||||
class UserPhoneNew extends React.PureComponent {
|
||||
constructor(props) {
|
||||
type Props = {
|
||||
addUserPhone: (string, string) => void,
|
||||
cancelButton: React.Node,
|
||||
phoneErrorMessage: ?string,
|
||||
isPending: boolean,
|
||||
};
|
||||
|
||||
type State = {
|
||||
phone: string,
|
||||
countryCode: string,
|
||||
};
|
||||
|
||||
class UserPhoneNew extends React.PureComponent<Props, State> {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
phone: '',
|
||||
country_code: '+1',
|
||||
countryCode: '+1',
|
||||
};
|
||||
|
||||
this.formatPhone = this.formatPhone.bind(this);
|
||||
(this: any).formatPhone = this.formatPhone.bind(this);
|
||||
(this: any).handleSubmit = this.handleSubmit.bind(this);
|
||||
(this: any).handleSelect = this.handleSelect.bind(this);
|
||||
}
|
||||
|
||||
formatPhone(value) {
|
||||
const { country_code } = this.state;
|
||||
value = value.replace(/\D/g, '');
|
||||
if (country_code === '+1') {
|
||||
if (!value) {
|
||||
formatPhone(value: string) {
|
||||
const { countryCode } = this.state;
|
||||
const formattedNumber = value.replace(/\D/g, '');
|
||||
|
||||
if (countryCode === '+1') {
|
||||
if (!formattedNumber) {
|
||||
return '';
|
||||
} else if (value.length < 4) {
|
||||
return value;
|
||||
} else if (value.length < 7) {
|
||||
return `(${value.substring(0, 3)}) ${value.substring(3)}`;
|
||||
} else if (formattedNumber.length < 4) {
|
||||
return formattedNumber;
|
||||
} else if (formattedNumber.length < 7) {
|
||||
return `(${formattedNumber.substring(0, 3)}) ${formattedNumber.substring(3)}`;
|
||||
}
|
||||
const fullNumber = `(${value.substring(0, 3)}) ${value.substring(3, 6)}-${value.substring(
|
||||
const fullNumber = `(${formattedNumber.substring(0, 3)}) ${formattedNumber.substring(
|
||||
3,
|
||||
6
|
||||
)}`;
|
||||
)}-${formattedNumber.substring(6)}`;
|
||||
return fullNumber.length <= 14 ? fullNumber : fullNumber.substring(0, 14);
|
||||
}
|
||||
return value;
|
||||
return formattedNumber;
|
||||
}
|
||||
|
||||
handleChanged(event) {
|
||||
handleChanged(event: SyntheticInputEvent<*>) {
|
||||
this.setState({
|
||||
phone: this.formatPhone(event.target.value),
|
||||
});
|
||||
}
|
||||
|
||||
handleSelect(event) {
|
||||
this.setState({ country_code: event.target.value });
|
||||
handleSelect(event: SyntheticInputEvent<*>) {
|
||||
this.setState({ countryCode: event.target.value });
|
||||
}
|
||||
|
||||
handleSubmit() {
|
||||
const { phone, country_code } = this.state;
|
||||
this.props.addUserPhone(phone.replace(/\D/g, ''), country_code.substring(1));
|
||||
const { phone, countryCode } = this.state;
|
||||
this.props.addUserPhone(phone.replace(/\D/g, ''), countryCode.substring(1));
|
||||
}
|
||||
|
||||
render() {
|
||||
const { cancelButton, phoneErrorMessage, isPending } = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p>
|
||||
{__(
|
||||
'Enter your phone number and we will send you a verification code. We will not share your phone number with third parties.'
|
||||
)}
|
||||
</p>
|
||||
<Form onSubmit={this.handleSubmit.bind(this)}>
|
||||
<FormRow>
|
||||
<FormField type="select" name="country-codes" onChange={this.handleSelect.bind(this)}>
|
||||
{countryCodes.map((country, index) => (
|
||||
<option key={index} value={country.countryCallingCode}>
|
||||
<React.Fragment>
|
||||
<header className="card__header">
|
||||
<h2 className="card__title">{__('Enter The Verification Code')}</h2>
|
||||
<p className="card__subtitle">
|
||||
{__(
|
||||
'Enter your phone number and we will send you a verification code. We will not share your phone number with third parties.'
|
||||
)}
|
||||
</p>
|
||||
</header>
|
||||
<Form onSubmit={this.handleSubmit}>
|
||||
<FormRow padded verticallyCentered>
|
||||
<FormField type="select" name="country-codes" onChange={this.handleSelect}>
|
||||
{countryCodes.map(country => (
|
||||
<option key={country.countryCallingCode} value={country.countryCallingCode}>
|
||||
{os === 'Darwin' ? country.emoji : `(${country.alpha2})`}{' '}
|
||||
{country.countryCallingCode}
|
||||
</option>
|
||||
|
@ -88,7 +106,7 @@ class UserPhoneNew extends React.PureComponent {
|
|||
</FormField>
|
||||
<FormField
|
||||
type="text"
|
||||
placeholder={this.state.country_code === '+1' ? '(555) 555-5555' : '5555555555'}
|
||||
placeholder={this.state.countryCode === '+1' ? '(555) 555-5555' : '5555555555'}
|
||||
name="phone"
|
||||
value={this.state.phone}
|
||||
error={phoneErrorMessage}
|
||||
|
@ -102,10 +120,9 @@ class UserPhoneNew extends React.PureComponent {
|
|||
{cancelButton}
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default UserPhoneNew;
|
||||
/* eslint-enable */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/* eslint-disable */
|
||||
import React from 'react';
|
||||
import Button from 'component/button';
|
||||
import { Form, FormField, Submit } from 'component/common/form';
|
||||
import { Form, FormField, Submit, FormRow } from 'component/common/form';
|
||||
|
||||
class UserPhoneVerify extends React.PureComponent {
|
||||
constructor(props) {
|
||||
|
@ -32,35 +32,44 @@ class UserPhoneVerify extends React.PureComponent {
|
|||
render() {
|
||||
const { cancelButton, phoneErrorMessage, phone, countryCode } = this.props;
|
||||
return (
|
||||
<Form onSubmit={this.handleSubmit.bind(this)}>
|
||||
<p>
|
||||
{__(
|
||||
`Please enter the verification code sent to +${countryCode}${phone}. Didn't receive it? `
|
||||
)}
|
||||
<Button button="link" onClick={this.reset.bind(this)} label="Go back." />
|
||||
</p>
|
||||
<FormField
|
||||
type="text"
|
||||
name="code"
|
||||
value={this.state.code}
|
||||
onChange={event => {
|
||||
this.handleCodeChanged(event);
|
||||
}}
|
||||
label={__('Verification Code')}
|
||||
error={phoneErrorMessage}
|
||||
/>
|
||||
{/* render help separately so it always shows */}
|
||||
<div className="card__actions card__actions--center">
|
||||
<Submit label={__('Verify')} />
|
||||
{cancelButton}
|
||||
</div>
|
||||
<React.Fragment>
|
||||
<header className="card__header">
|
||||
<h2 className="card__title">{__('Enter The Verification Code')}</h2>
|
||||
<p className="card__subtitle">
|
||||
{' '}
|
||||
{__(
|
||||
`Please enter the verification code sent to +${countryCode}${phone}. Didn't receive it? `
|
||||
)}
|
||||
<Button button="link" onClick={this.reset.bind(this)} label="Go back." />
|
||||
</p>
|
||||
</header>
|
||||
<Form className="card__content" onSubmit={this.handleSubmit.bind(this)}>
|
||||
<FormRow padded>
|
||||
<FormField
|
||||
type="text"
|
||||
name="code"
|
||||
placeholder="1234"
|
||||
value={this.state.code}
|
||||
onChange={event => {
|
||||
this.handleCodeChanged(event);
|
||||
}}
|
||||
label={__('Verification Code')}
|
||||
error={phoneErrorMessage}
|
||||
/>
|
||||
</FormRow>
|
||||
|
||||
<div className="card__actions">
|
||||
<Submit label={__('Verify')} />
|
||||
{cancelButton}
|
||||
</div>
|
||||
</Form>
|
||||
|
||||
<p className="help">
|
||||
{__('Email')} <Button button="link" href="mailto:help@lbry.io" label="help@lbry.io" />{' '}
|
||||
or join our <Button button="link" href="https://chat.lbry.io" label="chat" />{' '}
|
||||
{__('Email')} <Button button="link" href="mailto:help@lbry.io" label="help@lbry.io" /> or
|
||||
join our <Button button="link" href="https://chat.lbry.io" label="chat" />{' '}
|
||||
{__('if you encounter any trouble with your code.')}
|
||||
</p>
|
||||
</Form>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,9 +67,11 @@ export class Modal extends React.PureComponent<ModalProps> {
|
|||
![null, undefined, ''].includes(overlayClassName) ? overlayClassName : 'modal-overlay'
|
||||
}
|
||||
>
|
||||
<header className="card__header">
|
||||
<h2 className="card__title">{title}</h2>
|
||||
</header>
|
||||
{title && (
|
||||
<header className="card__header">
|
||||
<h1 className="card__title">{title}</h1>
|
||||
</header>
|
||||
)}
|
||||
<div className="card__content">{children}</div>
|
||||
{type === 'custom' ? null : ( // custom modals define their own buttons
|
||||
<div className="card__actions">
|
||||
|
|
|
@ -36,8 +36,8 @@ class ModalPhoneCollection extends React.PureComponent<Props> {
|
|||
}
|
||||
|
||||
return (
|
||||
<Modal type="custom" isOpen contentLabel="Phone" title={__('Verify Your Phone')}>
|
||||
<section className="card__content">{this.renderInner()}</section>
|
||||
<Modal type="custom" isOpen contentLabel="Phone">
|
||||
{this.renderInner()}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue