File size: 4,562 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | import { CompactCard } from '@automattic/components';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import ExternalLinkWithTracking from 'calypso/components/external-link-with-tracking';
import FormattedHeader from 'calypso/components/formatted-header';
import HeaderCake from 'calypso/components/header-cake';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import { bookConciergeAppointment, requestConciergeInitial } from 'calypso/state/concierge/actions';
import { getCurrentUserId, getCurrentUserLocale } from 'calypso/state/current-user/selectors';
import getConciergeAppointmentTimespan from 'calypso/state/selectors/get-concierge-appointment-timespan';
import getConciergeScheduleId from 'calypso/state/selectors/get-concierge-schedule-id';
import getConciergeSignupForm from 'calypso/state/selectors/get-concierge-signup-form';
import {
CONCIERGE_STATUS_BOOKED,
CONCIERGE_STATUS_BOOKING,
CONCIERGE_STATUS_BOOKING_ERROR,
} from '../constants';
import AvailableTimePicker from '../shared/available-time-picker';
class CalendarStep extends Component {
static propTypes = {
availableTimes: PropTypes.array.isRequired,
appointmentTimespan: PropTypes.number.isRequired,
currentUserId: PropTypes.number.isRequired,
currentUserLocale: PropTypes.string.isRequired,
onBack: PropTypes.func.isRequired,
onComplete: PropTypes.func.isRequired,
site: PropTypes.object.isRequired,
signupForm: PropTypes.object.isRequired,
scheduleId: PropTypes.number.isRequired,
};
onSubmit = ( timestamp ) => {
const { currentUserId, signupForm, site, scheduleId } = this.props;
const meta = {
firstname: signupForm.firstname,
lastname: signupForm.lastname,
message: signupForm.message,
timezone: signupForm.timezone,
phoneNumber: signupForm.phoneNumber,
};
this.props.bookConciergeAppointment( scheduleId, timestamp, currentUserId, site.ID, meta );
};
componentDidMount() {
this.props.recordTracksEvent( 'calypso_concierge_book_calendar_step' );
}
componentDidUpdate() {
if ( this.props.signupForm.status === CONCIERGE_STATUS_BOOKED ) {
// go to confirmation page if booking was successful
this.props.onComplete();
} else if ( this.props.signupForm.status === CONCIERGE_STATUS_BOOKING_ERROR ) {
// request new available times
this.props.requestConciergeInitial( this.props.scheduleId );
}
}
render() {
const {
availableTimes,
appointmentTimespan,
currentUserLocale,
onBack,
signupForm,
site,
translate,
} = this.props;
return (
<div>
<HeaderCake onClick={ onBack }>{ translate( 'Choose Session' ) }</HeaderCake>
<CompactCard>
<FormattedHeader
headerText={ translate( 'Select a time that works for you' ) }
align="left"
isSecondary
/>
<div className="calendar-step__explanation">
<div>
{ translate(
'Our sessions are available 24 hours a day. If you don’t see a day or time that works for you, please check back soon for more options! '
) }
</div>
<div className="calendar-step__webinars">
{ translate(
'In the meantime, consider attending one of our expert webinars on a wide variety of topics designed to help you build and grow your site. {{u}}{{externalLink}}View webinars{{/externalLink}}{{/u}}.',
{
components: {
u: <u />,
externalLink: (
<ExternalLinkWithTracking
href="/webinars"
target="_blank"
tracksEventName="calypso_concierge_book_view_webinars"
/>
),
},
}
) }
</div>
</div>
</CompactCard>
<AvailableTimePicker
actionText={ translate( 'Book this session' ) }
availableTimes={ availableTimes }
appointmentTimespan={ appointmentTimespan }
currentUserLocale={ currentUserLocale }
disabled={ signupForm.status === CONCIERGE_STATUS_BOOKING }
onSubmit={ this.onSubmit }
site={ site }
timezone={ signupForm.timezone }
/>
</div>
);
}
}
export default connect(
( state ) => ( {
appointmentTimespan: getConciergeAppointmentTimespan( state ),
signupForm: getConciergeSignupForm( state ),
scheduleId: getConciergeScheduleId( state ),
currentUserId: getCurrentUserId( state ),
currentUserLocale: getCurrentUserLocale( state ),
} ),
{ bookConciergeAppointment, recordTracksEvent, requestConciergeInitial }
)( localize( CalendarStep ) );
|