Skip to content
Permalink
Browse files

add customer feedback option when unsubscribing

  • Loading branch information...
tj committed Feb 2, 2018
1 parent ac8bcae commit 391f474b1518eb3fa7127e8493553970e10217dd
Showing with 42 additions and 0 deletions.
  1. +17 −0 internal/account/account.go
  2. +25 −0 internal/cli/team/team.go
@@ -294,6 +294,23 @@ func (c *Client) RemovePlan(token, product, plan string) error {
return nil
}

// AddFeedback sends customer feedback.
func (c *Client) AddFeedback(token, message string) error {
in := struct {
Message string `json:"message"`
}{
Message: message,
}

res, err := c.requestJSON(token, "POST", "/feedback", in)
if err != nil {
return err
}
defer res.Body.Close()

return nil
}

// Login signs in the user.
func (c *Client) Login(email, team string) (code string, err error) {
in := struct {
@@ -15,6 +15,7 @@ import (
"github.com/tj/go/clipboard"
"github.com/tj/go/env"
"github.com/tj/go/http/request"
"github.com/tj/go/term"
"github.com/tj/kingpin"
"github.com/tj/survey"

@@ -506,6 +507,20 @@ func unsubscribe(cmd *kingpin.Cmd) {
return nil
}

term.MoveUp(1)
term.ClearLine()

msg, err := feedback()
if err != nil {
util.LogPad("Aborted")
return nil
}

if strings.TrimSpace(msg) != "" {
util.Log("Thanks for the feedback!")
_ = a.AddFeedback(config.Token, msg)
}

stats.Track("Unsubscribe", nil)

if err := a.RemovePlan(config.Token, "up", "pro"); err != nil {
@@ -672,3 +687,13 @@ func prompt(name string, s *string) error {
prompt := &survey.Input{Message: name}
return survey.AskOne(prompt, s, survey.Required)
}

// feedback prompt helper.
func feedback() (string, error) {
var s string
prompt := &survey.Input{Message: "Have any feedback? (optional)"}
if err := survey.AskOne(prompt, &s, nil); err != nil {
return "", err
}
return s, nil
}

0 comments on commit 391f474

Please sign in to comment.
You can’t perform that action at this time.