docbrown/app/javascript/listings/listingForm.jsx
Mario See fda048dc12 Listing Drafts and Deletion (#3540)
* wip init handle draft class and styling

* add draft button

* start splitting up listing row into multile files

* separate tag links

* split location

* fix location

* separate listing row action buttons

* update listing row proptypes to describe listing object

* contact via connect to jsx

* fix default checked

* init draft creation and first publish charge

* fix first publish logic and credit charging

* handle drafts in dashboard filtering

* adjust isDraft bool statement

* hide drafts from main listings feed

* fix expired and draft bools in listing row

* adjust create listing org credits

* internally handle drafts

* adjust listing row

* break down update method

* remove unnecessary logic and shorten lines

* fix logic again woops

* convert input hidden value + submit into one form button submit with corresponding name and value

also adds clear message that drafts do not cost credits

* handle insufficient org credits on first publish

- uses user credits to publish
- similar to bump implementation

* fix sorting for personal and all orgs

* space out some elements

* don't spend original users credit for them

* add delete buttons and delete_confirm and destroy methods

* remove notification removal since listings dont trigger notifications

* move draft message and add draft_params to tests

* Update classified_listings_controller.rb

* update tests

* update snapshot

* add del tests

* add guard preventing free draft publish

* fix draft filter

* update from master and resolve merge conflict in listing preact

* Revert "update from master and resolve merge conflict in listing preact"

This reverts commit 0a34fccf334a2ca0902644b486cb26ead6bef664.

* update column spec

instead of setting and saving

* separate two expectations into their own tests

* split more tests into single expectations

* change to unless bumped_at? instead of if nil

* Fix listing draft edge cases and styling

* Add title tags to listings pages
2019-09-01 13:54:54 -04:00

87 lines
3.1 KiB
JavaScript

import { h, Component } from 'preact';
import linkState from 'linkstate';
import Title from './elements/title';
import BodyMarkdown from './elements/bodyMarkdown';
import Categories from './elements/categories';
import Tags from './elements/tags';
import OrgSettings from './elements/orgSettings';
import ContactViaConnect from './elements/contactViaConnect';
import ExpireDate from './elements/expireDate';
export default class ListingForm extends Component {
constructor(props) {
super(props);
this.listing = JSON.parse(this.props.listing);
this.categoriesForDetails = JSON.parse(this.props.categoriesForDetails);
this.categoriesForSelect = JSON.parse(this.props.categoriesForSelect);
const organizations = JSON.parse(this.props.organizations);
this.url = window.location.href;
this.state = {
id: this.listing.id || null,
title: this.listing.title || '',
category: this.listing.category || '',
tagList: this.listing.cached_tag_list || '',
bodyMarkdown: this.listing.body_markdown || '',
categoriesForSelect: this.categoriesForSelect,
categoriesForDetails: this.categoriesForDetails,
organizations,
organizationId: null, // change this for /edit later
contactViaConnect: this.listing.contact_via_connect || 'checked',
expireDate: this.listing.expires_at || '',
};
}
handleOrgIdChange = e => {
const organizationId = e.target.selectedOptions[0].value;
this.setState({ organizationId });
};
render() {
const {
id,
title,
bodyMarkdown,
tagList,
category,
categoriesForDetails,
categoriesForSelect,
organizations,
organizationId,
contactViaConnect,
expireDate,
} = this.state;
const selectOrg = ((organizations && organizations.length > 0) ? <OrgSettings organizations={organizations} organizationId={organizationId} onToggle={this.handleOrgIdChange} /> : '');
if (id === null) {
return (
<div>
<Title defaultValue={title} onChange={linkState(this, 'title')} />
<BodyMarkdown defaultValue={bodyMarkdown} onChange={linkState(this, 'bodyMarkdown')} />
<Categories categoriesForSelect={categoriesForSelect} categoriesForDetails={categoriesForDetails} onChange={linkState(this, 'category')} category={category} />
<Tags defaultValue={tagList} category={category} onInput={linkState(this, 'tagList')} />
<ExpireDate defaultValue={expireDate} onChange={linkState(this, 'expireDate')} />
{selectOrg}
<ContactViaConnect defaultValue={contactViaConnect} onChange={linkState(this, 'contactViaConnect')} />
</div>
);
}
// WIP code for edit
return (
<div>
<Title defaultValue={title} onChange={linkState(this, 'title')} />
<BodyMarkdown
defaultValue={bodyMarkdown}
onChange={linkState(this, 'bodyMarkdown')}
/>
<Tags defaultValue={tagList} onInput={linkState(this, 'tagList')} />
{selectOrg}
<ContactViaConnect checked={contactViaConnect} onChange={linkState(this, 'contactViaConnect')} />
</div>
);
}
}