File size: 4,941 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 135 136 137 138 139 140 141 142 143 144 145 146 147 | import { CompactCard, FormLabel } from '@automattic/components';
import { localize } from 'i18n-calypso';
import { without } from 'lodash';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import QueryConciergeAppointmentDetails from 'calypso/components/data/query-concierge-appointment-details';
import FormFieldset from 'calypso/components/forms/form-fieldset';
import FormSettingExplanation from 'calypso/components/forms/form-setting-explanation';
import Timezone from 'calypso/components/timezone';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import {
rescheduleConciergeAppointment,
updateConciergeAppointmentDetails,
} from 'calypso/state/concierge/actions';
import { getCurrentUserLocale } from 'calypso/state/current-user/selectors';
import getConciergeAppointmentDetails from 'calypso/state/selectors/get-concierge-appointment-details';
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_BOOKING, CONCIERGE_STATUS_BOOKED } from '../constants';
import AvailableTimePicker from '../shared/available-time-picker';
import { renderDisallowed } from '../shared/utils';
class CalendarStep extends Component {
static propTypes = {
appointmentDetails: PropTypes.object,
appointmentId: PropTypes.string.isRequired,
availableTimes: PropTypes.array.isRequired,
currentUserLocale: PropTypes.string.isRequired,
onComplete: PropTypes.func.isRequired,
site: PropTypes.object.isRequired,
signupForm: PropTypes.object.isRequired,
scheduleId: PropTypes.number,
};
onSubmit = ( timestamp ) => {
const { appointmentDetails, appointmentId, scheduleId } = this.props;
this.props.rescheduleConciergeAppointment(
scheduleId,
appointmentId,
timestamp,
appointmentDetails
);
};
setTimezone = ( timezone ) => {
const { appointmentDetails, appointmentId } = this.props;
this.props.updateConciergeAppointmentDetails( appointmentId, {
...appointmentDetails,
meta: { ...appointmentDetails.meta, timezone },
} );
};
getFilteredTimeSlots = () => {
// filter out current timeslot
const { appointmentDetails, availableTimes } = this.props;
return without( availableTimes, appointmentDetails.beginTimestamp );
};
componentDidMount() {
this.props.recordTracksEvent( 'calypso_concierge_reschedule_calendar_step' );
}
componentDidUpdate() {
if ( this.props.signupForm.status === CONCIERGE_STATUS_BOOKED ) {
// go to confirmation page if booking was successful
this.props.onComplete();
}
}
render() {
const {
appointmentDetails,
appointmentId,
appointmentTimespan,
currentUserLocale,
signupForm,
site,
scheduleId,
translate,
} = this.props;
const canChangeAppointment = appointmentDetails?.meta.canChangeAppointment;
if ( appointmentDetails && ! canChangeAppointment ) {
return renderDisallowed( translate, site.slug );
}
return (
<div>
<QueryConciergeAppointmentDetails
appointmentId={ appointmentId }
scheduleId={ scheduleId }
/>
<CompactCard>
{ translate(
'To reschedule your session, let us know your timezone and preferred day.'
) }
</CompactCard>
{ appointmentDetails && (
<div>
<CompactCard>
<FormFieldset>
<FormLabel>{ translate( "What's your timezone?" ) }</FormLabel>
<Timezone
includeManualOffsets={ false }
name="timezone"
onSelect={ this.setTimezone }
selectedZone={ appointmentDetails.meta.timezone }
/>
<FormSettingExplanation>
{ translate( 'Choose a city in your timezone.' ) }
</FormSettingExplanation>
</FormFieldset>
</CompactCard>
<AvailableTimePicker
actionText={ translate( 'Reschedule to this date' ) }
availableTimes={ this.getFilteredTimeSlots() }
appointmentTimespan={ appointmentTimespan }
currentUserLocale={ currentUserLocale }
disabled={ signupForm.status === CONCIERGE_STATUS_BOOKING || ! appointmentDetails }
onBack={ null }
onSubmit={ this.onSubmit }
site={ site }
timezone={ appointmentDetails.meta.timezone }
/>
</div>
) }
</div>
);
}
}
export default connect(
( state, props ) => ( {
appointmentDetails: getConciergeAppointmentDetails( state, props.appointmentId ),
appointmentTimespan: getConciergeAppointmentTimespan( state ),
currentUserLocale: getCurrentUserLocale( state ),
signupForm: getConciergeSignupForm( state ),
scheduleId: getConciergeScheduleId( state ),
} ),
{ recordTracksEvent, rescheduleConciergeAppointment, updateConciergeAppointmentDetails }
)( localize( CalendarStep ) );
|