-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,484 additions
and
5 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/components/EditListingAvailabilityPanel/EditListingAvailabilityPanel.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@import '../../marketplace.css'; | ||
|
||
.root { | ||
flex-grow: 1; | ||
width: 100%; | ||
height: auto; | ||
display: flex; | ||
flex-direction: column; | ||
padding: 11px 24px 0 24px; | ||
} | ||
|
||
.form { | ||
flex-grow: 1; | ||
} | ||
|
||
.title { | ||
margin-bottom: 19px; | ||
|
||
@media (--viewportLarge) { | ||
margin-bottom: 44px; | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/components/EditListingAvailabilityPanel/EditListingAvailabilityPanel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React from 'react'; | ||
import { bool, func, object, shape, string } from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { ensureOwnListing } from '../../util/data'; | ||
import { LISTING_STATE_DRAFT } from '../../util/types'; | ||
import { ListingLink } from '../../components'; | ||
import { EditListingAvailabilityForm } from '../../forms'; | ||
|
||
import css from './EditListingAvailabilityPanel.css'; | ||
|
||
const EditListingAvailabilityPanel = props => { | ||
const { | ||
className, | ||
rootClassName, | ||
listing, | ||
availability, | ||
onSubmit, | ||
onChange, | ||
submitButtonText, | ||
panelUpdated, | ||
updateInProgress, | ||
errors, | ||
} = props; | ||
|
||
const classes = classNames(rootClassName || css.root, className); | ||
const currentListing = ensureOwnListing(listing); | ||
const isPublished = currentListing.id && currentListing.attributes.state !== LISTING_STATE_DRAFT; | ||
const defaultAvailabilityPlan = { | ||
type: 'availability-plan/day', | ||
entries: [ | ||
{ dayOfWeek: 'mon', seats: 1 }, | ||
{ dayOfWeek: 'tue', seats: 1 }, | ||
{ dayOfWeek: 'wed', seats: 1 }, | ||
{ dayOfWeek: 'thu', seats: 1 }, | ||
{ dayOfWeek: 'fri', seats: 1 }, | ||
{ dayOfWeek: 'sat', seats: 1 }, | ||
{ dayOfWeek: 'sun', seats: 1 }, | ||
], | ||
}; | ||
const availabilityPlan = defaultAvailabilityPlan; //currentListing.attributes.availabilityPlan || defaultAvailabilityPlan; | ||
|
||
const panelTitle = isPublished ? ( | ||
<FormattedMessage | ||
id="EditListingAvailabilityPanel.title" | ||
values={{ listingTitle: <ListingLink listing={listing} /> }} | ||
/> | ||
) : ( | ||
<FormattedMessage id="EditListingAvailabilityPanel.createListingTitle" /> | ||
); | ||
|
||
return ( | ||
<div className={classes}> | ||
<h1 className={css.title}>{panelTitle}</h1> | ||
<EditListingAvailabilityForm | ||
className={css.form} | ||
listingId={currentListing.id} | ||
initialValues={{ availabilityPlan }} | ||
availability={availability} | ||
availabilityPlan={availabilityPlan} | ||
onSubmit={() => { | ||
// We save default availability plan | ||
// I.e. every night this listing is available | ||
// (exceptions handled with live edit through calendar) | ||
onSubmit({ availabilityPlan }); | ||
}} | ||
onChange={onChange} | ||
saveActionMsg={submitButtonText} | ||
updated={panelUpdated} | ||
updateError={errors.updateListingError} | ||
updateInProgress={updateInProgress} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
EditListingAvailabilityPanel.defaultProps = { | ||
className: null, | ||
rootClassName: null, | ||
listing: null, | ||
}; | ||
|
||
EditListingAvailabilityPanel.propTypes = { | ||
className: string, | ||
rootClassName: string, | ||
|
||
// We cannot use propTypes.listing since the listing might be a draft. | ||
listing: object, | ||
|
||
availability: shape({ | ||
calendar: object.isRequired, | ||
onFetchAvailabilityExceptions: func.isRequired, | ||
onCreateAvailabilityException: func.isRequired, | ||
onDeleteAvailabilityException: func.isRequired, | ||
}).isRequired, | ||
onSubmit: func.isRequired, | ||
onChange: func.isRequired, | ||
submitButtonText: string.isRequired, | ||
panelUpdated: bool.isRequired, | ||
updateInProgress: bool.isRequired, | ||
errors: object.isRequired, | ||
}; | ||
|
||
export default EditListingAvailabilityPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.