Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

allow change status input

goenningcf37a0f4e2b5
diff --git a/app/handlers/feedback.go b/app/handlers/feedback.go
index bf3ea5ba3..530a5e003 100644
--- a/app/handlers/feedback.go
+++ b/app/handlers/feedback.go
@@ -135,6 +135,41 @@ func (h AllHandlers) PostComment() web.HandlerFunc {
}
}
+type setResponseInput struct {
+ Status int `json:"status"`
+ Text string `json:"text"`
+}
+
+// SetResponse changes current idea staff response
+func (h AllHandlers) SetResponse() web.HandlerFunc {
+ return func(c web.Context) error {
+ input := new(setResponseInput)
+ if err := c.Bind(input); err != nil {
+ return c.Failure(err)
+ }
+
+ ideaNumber, err := c.ParamAsInt("number")
+ if err != nil {
+ return c.Failure(err)
+ }
+
+ idea, err := h.ideas.GetByNumber(c.Tenant().ID, ideaNumber)
+ if err != nil {
+ if err == app.ErrNotFound {
+ return c.NotFound()
+ }
+ return c.Failure(err)
+ }
+
+ err = h.ideas.SetResponse(c.Tenant().ID, idea.ID, input.Text, c.User().ID, input.Status)
+ if err != nil {
+ return c.Failure(err)
+ }
+
+ return c.JSON(200, echo.Map{})
+ }
+}
+
// AddSupporter adds current user to given idea list of supporters
func (h AllHandlers) AddSupporter() web.HandlerFunc {
return func(c web.Context) error {
diff --git a/public/shared/Common.tsx b/public/shared/Common.tsx
index de9453299..b08a2b6c6 100644
--- a/public/shared/Common.tsx
+++ b/public/shared/Common.tsx
@@ -57,7 +57,9 @@ interface IdeaResponseProps {
}
export const ShowIdeaResponse = (props: IdeaResponseProps): JSX.Element => {
- if (props.response) {
+ const metadata = IdeaStatusMetadata[props.status];
+
+ if (props.response && metadata.showStatus) {
return <div className="fdr-response item ui raised segment">
<IdeaStatusRibbon status={props.status} />
<div className="info">
diff --git a/public/shared/Header.tsx b/public/shared/Header.tsx
index 98f4c80ef..1aa2a8455 100644
--- a/public/shared/Header.tsx
+++ b/public/shared/Header.tsx
@@ -32,7 +32,7 @@ export class Header extends React.Component<{}, {}> {
<div className="item">
<b>{ this.user.email }</b>
</div>
- { this.isMember() &&
+ { this.isStaff() &&
<div className="item">
<a href="/admin">
Administration
@@ -67,7 +67,7 @@ export class Header extends React.Component<{}, {}> {
</div>;
}
- private isMember() {
+ private isStaff() {
return this.user.role >= 2;
}
}
diff --git a/public/shared/RespondForm.tsx b/public/shared/RespondForm.tsx
new file mode 100644
index 000000000..af4db6ac5
--- /dev/null
+++ b/public/shared/RespondForm.tsx
@@ -0,0 +1,84 @@
+import axios from "axios";
+import * as React from "react";
+import * as storage from "../storage";
+import { User, Comment, Idea } from "../models";
+
+interface RespondFormProps {
+ idea: Idea;
+}
+
+interface RespondFormState {
+ active: boolean;
+}
+
+export class RespondForm extends React.Component<RespondFormProps, RespondFormState> {
+ private user: User;
+ private text: HTMLTextAreaElement;
+ private status: HTMLSelectElement;
+
+ constructor(props: RespondFormProps) {
+ super(props);
+
+ this.user = storage.getCurrentUser();
+ this.state = {
+ active: false
+ };
+ }
+
+ private async submit() {
+ try {
+ await axios.post(`/api/ideas/${this.props.idea.number}/status`, {
+ status: parseInt(this.status.value, 10),
+ text: this.text.value
+ });
+ location.reload();
+ } catch (ex) {
+ // TODO: handle this
+ }
+ }
+
+ private activate() {
+ this.setState({ active: true });
+ }
+
+ private deactivate() {
+ this.setState({ active: false });
+ }
+
+ public render() {
+ const respond = <div className="ui blue labeled submit icon button false"
+ onClick={() => this.activate()}>
+ <i className="icon announcement"></i>Respond
+ </div>;
+ const form = <form className="ui reply form">
+ <div className="two fields">
+ <div className="field">
+ <label>Status</label>
+ <select className="ui dropdown"
+ ref={(input) => this.status = input}>
+ <option selected={this.props.idea.status === 0} value="0">New</option>
+ <option selected={this.props.idea.status === 1} value="1">Started</option>
+ <option selected={this.props.idea.status === 2} value="2">Completed</option>
+ <option selected={this.props.idea.status === 3} value="3">Declined</option>
+ </select>
+ </div>
+ </div>
+ <div className="field">
+ <textarea
+ ref={(input) => this.text = input}
+ defaultValue={this.props.idea.response && this.props.idea.response.text}
+ placeholder="What's going on with this idea? Let your users know what are your plans...">
+ </textarea>
+ </div>
+ <div className="ui blue labeled submit icon button false"
+ onClick={() => this.submit()}>
+ <i className="icon checkmark box"></i>Submit
+ </div>
+ <div className="ui submit button false"
+ onClick={() => this.deactivate()}>
+ Cancel
+ </div>
+ </form>;
+ return this.state.active ? form : respond;
+ }
+}
diff --git a/public/site/ShowIdeaPage.tsx b/public/site/ShowIdeaPage.tsx
index 94bb226cd..065b45794 100644
--- a/public/site/ShowIdeaPage.tsx
+++ b/public/site/ShowIdeaPage.tsx
@@ -7,6 +7,7 @@ import { CommentInput } from "../shared/CommentInput";
import { Gravatar, MultiLineText, ShowIdeaResponse } from "../shared/Common";
import { SocialSignInButton } from "../shared/SocialSignInButton";
import { SupportCounter } from "../shared/SupportCounter";
+import { RespondForm } from "../shared/RespondForm";
import { Footer } from "../shared/Footer";
import { Header } from "../shared/Header";
@@ -44,6 +45,10 @@ export class ShowIdeaPage extends React.Component<{}, {}> {
</div>
) : <p>No comments yet.</p>;
+ const respond = <div className="ui blue labeled submit icon button false">
+ <i className="icon announcement"></i>Respond
+ </div>;
+
return <div>
<Header />
<div className="ui container">
@@ -67,6 +72,8 @@ export class ShowIdeaPage extends React.Component<{}, {}> {
<MultiLineText text={ this.idea.description } />
<ShowIdeaResponse status={ this.idea.status } response={ this.idea.response } />
+ <div className="ui hidden divider"></div>
+ <RespondForm idea={ this.idea } />
<div className="ui comments">
<h3 className="ui dividing header">Comments</h3>
@@ -77,4 +84,8 @@ export class ShowIdeaPage extends React.Component<{}, {}> {
<Footer />
</div>;
}
+
+ private isStaff() {
+ return this.user.role >= 2;
+ }
}
diff --git a/router.go b/router.go
index e69567041..2a1f7e340 100644
--- a/router.go
+++ b/router.go
@@ -51,6 +51,7 @@ func GetMainEngine(ctx *AppServices) *web.Engine {
private.Post("/api/ideas", handlers.Handlers(ctx.Idea).PostIdea())
private.Post("/api/ideas/:number/comments", handlers.Handlers(ctx.Idea).PostComment())
+ private.Post("/api/ideas/:number/status", handlers.Handlers(ctx.Idea).SetResponse())
private.Post("/api/ideas/:number/support", handlers.Handlers(ctx.Idea).AddSupporter())
private.Post("/api/ideas/:number/unsupport", handlers.Handlers(ctx.Idea).RemoveSupporter())
}
diff --git a/tslint.json b/tslint.json
index e9caf970c..c4ee74f24 100644
--- a/tslint.json
+++ b/tslint.json
@@ -11,6 +11,9 @@
"ordered-imports": [
false
],
- "no-var-requires": false
+ "no-var-requires": false,
+ "member-ordering": [
+ false
+ ]
}
}
\ No newline at end of file