Skip to content

Commit

Permalink
Select section error (#346)
Browse files Browse the repository at this point in the history
* Check section selected

* Update EditForm.js and index.js in edit post

* Now section is checked before sending

Fix error message location

* Css position

* Notification Box

pop section not selected error

* Fixed version number problem

* Cleaner Message

* Fixed React and some code cleaning

* testing

* resolved multiple saves being executed

* syntax

* push failed

* Between sendnow and ready to publish validation of url

* Url Issue update

Enabled sendnow even if url is empty.
Flag a warning instead of error when url empty and ready publish is clicked.

Section error message now disappears when section is no longer null, more user-friendly?

* unused variable cleanup

* variable name change
  • Loading branch information
HarryZhang1224 authored May 16, 2021
1 parent d3b521d commit 76b35c0
Show file tree
Hide file tree
Showing 5 changed files with 2,504 additions and 2,359 deletions.
5 changes: 3 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ if [ "$DEBUG" = "False" ]; then
python meow/manage.py collectstatic --noinput

# Apply database migrations
echo "Apply database migrations"
python meow/manage.py migrate


fi
echo "Apply database migrations"
python meow/manage.py migrate

exec "$@"
8 changes: 8 additions & 0 deletions meow/frontend/src/components/EditPost/EditForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@
right: 0px;
color: red;
}
.no-section-error {
color: red;
font-size: small;
}
.no-url-warning {
color: #d4b106;
font-size: small;
}
24 changes: 24 additions & 0 deletions meow/frontend/src/components/EditPost/EditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,28 @@ class EditForm extends React.Component {
setFieldsValue({ tags });
};

handleClickpub = e => {
this.setState({
...this.state,
click_pubready: e.target.checked
});
};

render() {
const { getFieldDecorator, getFieldsValue } = this.props.form;

let no_urlwarning = null;
if (
getFieldsValue(["pub_ready_online"]).pub_ready_online &&
(this.props.story_url == null || this.props.story_url.trim() == "")
) {
no_urlwarning = (
<p className="no-url-warning">Warning: post can still be sent, but no url was entered</p>
);
} else if (!getFieldsValue(["pub_ready_online"]).pub_ready_online) {
no_urlwarning = null;
}

const CopyEdited = Copy(
() => (
<Form.Item className="checkable-items">
Expand All @@ -142,6 +162,7 @@ class EditForm extends React.Component {
valuePropName: "checked",
initialValue: true
})(<Checkbox style={{ fontSize: "1.2em" }}>Ready to publish</Checkbox>)}
{no_urlwarning}
</Form.Item>
),
null,
Expand Down Expand Up @@ -183,6 +204,9 @@ class EditForm extends React.Component {
))}
</RadioGroup>
)}
<p className="no-section-error">
{this.props.section == null ? this.props.sectionError : ""}
</p>
</Form.Item>
<Form.Item {...formItemLayout} label="tags">
{getFieldDecorator("tags", {
Expand Down
37 changes: 27 additions & 10 deletions meow/frontend/src/components/EditPost/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import moment from "moment";
import { Layout } from "antd";
import { Layout, notification, Icon } from "antd";

import EditSidebar from "./Sidebar";
import EditContent from "./Content";
Expand All @@ -26,7 +26,8 @@ const contentStyles = { position: "relative", transform: "translateY(-30px)" };

class EditPost extends React.Component {
state = {
sections: this.props.sections
sections: this.props.sections,
sectionerror: ""
};

componentDidMount() {
Expand Down Expand Up @@ -149,23 +150,38 @@ class EditPost extends React.Component {
});
};

sendNow = () => {
const { postId } = this.props.match.params;
popSectionerror = () => {
notification.open({
message: "Send Failed :(",
description: "No section was selected",
icon: <Icon type="close-circle" style={{ color: "#FF0000" }} />
});
};

this.savePostPromise(postId).then(data => {
if (data) {
sendNow = data => {
const { postId } = this.props.match.params;
if (data && this.state.section !== null) {
this.savePostPromise(postId).then(() => {
this.setState({
...this.state,
version_number: this.state.version_number + 1
});
this.props.sendPostNow(postId).then(response => {
console.log(response);
if (response.error) {
} else {
//using double == because status might be a string.
this.props.history.push("/");
}
});
}
});
});
} else if (this.state.section == null) {
this.setState({
...this.state,
sectionerror: "Please make sure to select a section "
});
this.popSectionerror();
}
};

/**
* This function is used by the HistoryBar compoenent
* to replace current posts with one of the historic edits.
Expand Down Expand Up @@ -198,6 +214,7 @@ class EditPost extends React.Component {
editPost={this.editField}
savePost={this.savePost.bind(this)}
user_groups={this.state.user_groups}
sectionError={this.state.sectionerror}
/>
</Content>
<div style={{ width: "25vw" }}>
Expand Down
Loading

0 comments on commit 76b35c0

Please sign in to comment.