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 (
); } getDisplayComponent = () => { const { appointmentId, appointmentDetails, scheduleId, siteSlug, signupForm, translate } = this.props; switch ( signupForm.status ) { case CONCIERGE_STATUS_CANCELLED: return ( ); 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 (
{ scheduleId && ( ) } { translate( 'Reschedule or cancel' ) } { ! appointmentDetails && this.renderBtnPlaceholder() } { appointmentDetails && ( <> ) }
); } } }; render() { const { analyticsPath, analyticsTitle, site } = this.props; const siteId = site && site.ID; return (
{ siteId && } { this.getDisplayComponent() }
); } } 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 ) );