File size: 5,272 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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
import { Button } from '@automattic/components';
import { localize } from 'i18n-calypso';
import { includes } 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 QueryConciergeInitial from 'calypso/components/data/query-concierge-initial';
import QuerySites from 'calypso/components/data/query-sites';
import HeaderCake from 'calypso/components/header-cake';
import Main from 'calypso/components/main';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import { cancelConciergeAppointment } from 'calypso/state/concierge/actions';
import getConciergeAppointmentDetails from 'calypso/state/selectors/get-concierge-appointment-details';
import getConciergeScheduleId from 'calypso/state/selectors/get-concierge-schedule-id';
import getConciergeSignupForm from 'calypso/state/selectors/get-concierge-signup-form';
import { getSite } from 'calypso/state/sites/selectors';
import { CONCIERGE_STATUS_CANCELLED, CONCIERGE_STATUS_CANCELLING } from '../constants';
import Confirmation from '../shared/confirmation';
import { renderDisallowed } from '../shared/utils';
class ConciergeCancel extends Component {
static propTypes = {
analyticsPath: PropTypes.string,
analyticsTitle: PropTypes.string,
appointmentId: PropTypes.string.isRequired,
siteSlug: PropTypes.string.isRequired,
scheduleId: PropTypes.number,
};
componentDidMount() {
this.props.recordTracksEvent( 'calypso_concierge_cancel_step' );
}
cancelAppointment = () => {
const { appointmentId, scheduleId } = this.props;
this.props.cancelConciergeAppointment( scheduleId, appointmentId );
};
renderBtnPlaceholder() {
return (
<div className="cancel__placeholders">
<div className="cancel__placeholder-button-container">
<div className="cancel__placeholder-button is-placeholder" />
<div className="cancel__placeholder-button is-placeholder" />
</div>
</div>
);
}
getDisplayComponent = () => {
const { appointmentId, appointmentDetails, scheduleId, siteSlug, signupForm, translate } =
this.props;
switch ( signupForm.status ) {
case CONCIERGE_STATUS_CANCELLED:
return (
<Confirmation
description={ translate( 'Would you like to schedule a new session?' ) }
title={ translate( 'Your session has been cancelled.' ) }
>
<Button
className="cancel__schedule-button"
href={ `/me/quickstart/${ siteSlug }/book` }
primary
>
{ translate( 'Schedule', {
context: 'Concierge session',
} ) }
</Button>
</Confirmation>
);
default: {
const disabledCancelling =
includes(
[ CONCIERGE_STATUS_CANCELLED, CONCIERGE_STATUS_CANCELLING ],
signupForm.status
) ||
! appointmentDetails ||
! scheduleId;
const disabledRescheduling =
signupForm.status === CONCIERGE_STATUS_CANCELLING || ! appointmentDetails || ! scheduleId;
const canChangeAppointment = appointmentDetails?.meta.canChangeAppointment;
if ( appointmentDetails && ! canChangeAppointment ) {
return renderDisallowed( translate, siteSlug );
}
return (
<div>
{ scheduleId && (
<QueryConciergeAppointmentDetails
appointmentId={ appointmentId }
scheduleId={ scheduleId }
/>
) }
<HeaderCake backHref={ `/me/quickstart/${ siteSlug }/book` }>
{ translate( 'Reschedule or cancel' ) }
</HeaderCake>
<Confirmation
description={ translate(
'You can also reschedule your session. What would you like to do?'
) }
title={ translate( 'Cancel your session' ) }
>
{ ! appointmentDetails && this.renderBtnPlaceholder() }
{ appointmentDetails && (
<>
<Button
className="cancel__reschedule-button"
disabled={ disabledRescheduling }
href={ `/me/quickstart/${ siteSlug }/${ appointmentId }/reschedule` }
>
{ translate( 'Reschedule session' ) }
</Button>
<Button
className="cancel__confirmation-button"
disabled={ disabledCancelling }
onClick={ this.cancelAppointment }
primary
scary
>
{ translate( 'Cancel session' ) }
</Button>
</>
) }
</Confirmation>
</div>
);
}
}
};
render() {
const { analyticsPath, analyticsTitle, site } = this.props;
const siteId = site && site.ID;
return (
<Main>
<QuerySites />
{ siteId && <QueryConciergeInitial siteId={ siteId } /> }
<PageViewTracker path={ analyticsPath } title={ analyticsTitle } />
{ this.getDisplayComponent() }
</Main>
);
}
}
export default connect(
( state, props ) => ( {
appointmentDetails: getConciergeAppointmentDetails( state, props.appointmentId ),
signupForm: getConciergeSignupForm( state ),
site: getSite( state, props.siteSlug ),
scheduleId: getConciergeScheduleId( state ),
} ),
{ cancelConciergeAppointment, recordTracksEvent }
)( localize( ConciergeCancel ) );
|