satellite/marketing: Create New Offer (#2186)

* update UI to reflect final mockups

* implement create handler and render offers table data to UI

* fix line-height unit and remove important from selectors

* update file names and ids for clarity

* shorten 'label' in ids

* localize global vars, fix endpoint names, remove unnecessary receiver, fix comments

* fix unnecessary initialization of pointer

* correct file-naming conventions

* register timeConverter in an init func for safety and remove unnecessary important from css

* consolidate create endpoints and add comments

* register timeConverter in init func

* add copyright to files

* introduce require pkg

* add proper http server unit test

* update linting and create offers concurrently in unit test

* fix getOffers comment

* add copy-right to unit-test

* fix data-races

* fix linting

* remove converter in NewServer

* requested changes in progress

* add require for checking status code

* renamed template file

* fix 400 handler

* fix missing copyright and remove extra line

* fix build

* run goroutine for testing parallel

* evaluate reqType with switch stmt and promp for credit amount in cents

* fix lint issue

* add default case

* remove unnecessary var

* fix range scope error

* remove empty lines and use long form for struct field

* fix merge conflicts

* fix template reference

* fix modal id

* not delete package

* add currency formatting and requested changes

* markup formatting

* lean out currency logic and move wait outside loop

* pass ToDollars func to home template

* fix lint
This commit is contained in:
Faris Huskovic 2019-06-28 10:34:10 -04:00 committed by GitHub
parent 53e550f7d8
commit ebd976ec28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 465 additions and 161 deletions

1
go.mod
View File

@ -45,6 +45,7 @@ require (
github.com/gorilla/handlers v1.4.0 // indirect
github.com/gorilla/mux v1.7.0
github.com/gorilla/rpc v1.1.0 // indirect
github.com/gorilla/schema v1.1.0
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-msgpack v0.5.3 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect

2
go.sum
View File

@ -151,6 +151,8 @@ github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U=
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/rpc v1.1.0 h1:marKfvVP0Gpd/jHlVBKCQ8RAoUPdX7K1Nuh6l1BNh7A=
github.com/gorilla/rpc v1.1.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ=
github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY=
github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/graphql-go/graphql v0.7.9-0.20190403165646-199d20bbfed7 h1:E45QFM7IqRdFnuyFk8GSamb42EckUSyJ55rtVB/w8VQ=
github.com/graphql-go/graphql v0.7.9-0.20190403165646-199d20bbfed7/go.mod h1:k6yrAYQaSP59DC5UVxbgxESlmVyojThKdORUqGDGmrI=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=

View File

@ -9,15 +9,23 @@ import (
"net"
"net/http"
"path/filepath"
"reflect"
"time"
"github.com/gorilla/mux"
"github.com/gorilla/schema"
"github.com/zeebo/errs"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"storj.io/storj/satellite/rewards"
)
// Error is satellite marketing error type
var Error = errs.Class("satellite marketing error")
var (
// Error is satellite marketing error type
Error = errs.Class("satellite marketing error")
decoder = schema.NewDecoder()
)
// Config contains configuration for marketingweb server
type Config struct {
@ -25,24 +33,52 @@ type Config struct {
StaticDir string `help:"path to static resources" default:""`
}
// Server represents marketingweb server
// Server represents marketing offersweb server
type Server struct {
log *zap.Logger
config Config
listener net.Listener
server http.Server
log *zap.Logger
config Config
listener net.Listener
server http.Server
db rewards.DB
templateDir string
templates struct {
home *template.Template
pageNotFound *template.Template
internalError *template.Template
badRequest *template.Template
}
}
// commonPages returns templates that are required for everything.
// offerSet provides a separation of marketing offers by type.
type offerSet struct {
ReferralOffers rewards.Offers
FreeCredits rewards.Offers
}
// init safely registers convertStringToTime for the decoder.
func init() {
decoder.RegisterConverter(time.Time{}, convertStringToTime)
}
// organizeOffers organizes offers by type.
func organizeOffers(offers []rewards.Offer) offerSet {
var os offerSet
for _, offer := range offers {
switch offer.Type {
case rewards.FreeCredit:
os.FreeCredits.Set = append(os.FreeCredits.Set, offer)
case rewards.Referral:
os.ReferralOffers.Set = append(os.ReferralOffers.Set, offer)
default:
continue
}
}
return os
}
// commonPages returns templates that are required for all routes.
func (s *Server) commonPages() []string {
return []string{
filepath.Join(s.templateDir, "base.html"),
@ -52,21 +88,22 @@ func (s *Server) commonPages() []string {
}
}
// NewServer creates new instance of marketingweb server
func NewServer(logger *zap.Logger, config Config, listener net.Listener) (*Server, error) {
// NewServer creates new instance of offersweb server
func NewServer(logger *zap.Logger, config Config, db rewards.DB, listener net.Listener) (*Server, error) {
s := &Server{
log: logger,
config: config,
listener: listener,
db: db,
}
logger.Sugar().Debugf("Starting Marketing Admin UI on %s...", s.listener.Addr().String())
fs := http.StripPrefix("/static/", http.FileServer(http.Dir(s.config.StaticDir)))
mux := mux.NewRouter()
if s.config.StaticDir != "" {
mux.HandleFunc("/", s.GetOffers)
mux.PathPrefix("/static/").Handler(fs)
mux.Handle("/", s)
mux.HandleFunc("/create/{offer_type}", s.CreateOffer)
}
s.server.Handler = mux
@ -79,16 +116,23 @@ func NewServer(logger *zap.Logger, config Config, listener net.Listener) (*Serve
return s, nil
}
// ServeHTTP handles index request
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// GetOffers renders the tables for free credits and referral offers to the UI
func (s *Server) GetOffers(w http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/" {
s.serveNotFound(w, req)
return
}
err := s.templates.home.ExecuteTemplate(w, "base", nil)
offers, err := s.db.ListAll(req.Context())
if err != nil {
s.log.Error("failed to retrieve all offers", zap.Error(err))
s.serveInternalError(w, req, err)
return
}
if err := s.templates.home.ExecuteTemplate(w, "base", organizeOffers(offers)); err != nil {
s.log.Error("failed to execute template", zap.Error(err))
s.serveInternalError(w, req, err)
}
}
@ -102,32 +146,103 @@ func (s *Server) parseTemplates() (err error) {
filepath.Join(s.templateDir, "free-offers-modal.html"),
)
s.templates.home, err = template.New("landingPage").ParseFiles(homeFiles...)
if err != nil {
return Error.Wrap(err)
}
pageNotFoundFiles := append(s.commonPages(),
filepath.Join(s.templateDir, "page-not-found.html"),
)
internalErrorFiles := append(s.commonPages(),
filepath.Join(s.templateDir, "internal-server-error.html"),
)
badRequestFiles := append(s.commonPages(),
filepath.Join(s.templateDir, "err.html"),
)
s.templates.home, err = template.New("landingPage").Funcs(template.FuncMap{
"ToDollars": rewards.ToDollars,
}).ParseFiles(homeFiles...)
if err != nil {
return Error.Wrap(err)
}
s.templates.pageNotFound, err = template.New("page-not-found").ParseFiles(pageNotFoundFiles...)
if err != nil {
return Error.Wrap(err)
}
internalErrorFiles := append(s.commonPages(),
filepath.Join(s.templateDir, "internal-server-error.html"),
)
s.templates.internalError, err = template.New("internal-server-error").ParseFiles(internalErrorFiles...)
if err != nil {
return Error.Wrap(err)
}
s.templates.badRequest, err = template.New("bad-request-error").ParseFiles(badRequestFiles...)
if err != nil {
return Error.Wrap(err)
}
return nil
}
// convertStringToTime formats form time input as time.Time.
func convertStringToTime(value string) reflect.Value {
v, err := time.Parse("2006-01-02", value)
if err != nil {
// invalid decoder value
return reflect.Value{}
}
return reflect.ValueOf(v)
}
// parseOfferForm decodes POST form data into a new offer.
func parseOfferForm(w http.ResponseWriter, req *http.Request) (o rewards.NewOffer, e error) {
err := req.ParseForm()
if err != nil {
return o, err
}
if err := decoder.Decode(&o, req.PostForm); err != nil {
return o, err
}
o.InviteeCreditInCents = rewards.ToCents(o.InviteeCreditInCents)
o.AwardCreditInCents = rewards.ToCents(o.AwardCreditInCents)
return o, nil
}
// CreateOffer handles requests to create new offers.
func (s *Server) CreateOffer(w http.ResponseWriter, req *http.Request) {
offer, err := parseOfferForm(w, req)
if err != nil {
s.log.Error("failed to convert form to struct", zap.Error(err))
s.serveBadRequest(w, req, err)
return
}
offer.Status = rewards.Active
offerType := mux.Vars(req)["offer_type"]
switch offerType {
case "referral-offer":
offer.Type = rewards.Referral
case "free-credit":
offer.Type = rewards.FreeCredit
default:
err := errs.New("response status %d : invalid offer type", http.StatusBadRequest)
s.serveBadRequest(w, req, err)
return
}
if _, err := s.db.Create(req.Context(), &offer); err != nil {
s.log.Error("failed to insert new offer", zap.Error(err))
s.serveBadRequest(w, req, err)
return
}
http.Redirect(w, req, "/", http.StatusSeeOther)
}
// serveNotFound handles 404 errors and defaults to 500 if template parsing fails.
func (s *Server) serveNotFound(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusNotFound)
@ -137,11 +252,20 @@ func (s *Server) serveNotFound(w http.ResponseWriter, req *http.Request) {
}
}
func (s *Server) serveInternalError(w http.ResponseWriter, req *http.Request) {
// serveInternalError handles 500 errors and renders err to the internal-server-error template.
func (s *Server) serveInternalError(w http.ResponseWriter, req *http.Request, errMsg error) {
w.WriteHeader(http.StatusInternalServerError)
err := s.templates.internalError.ExecuteTemplate(w, "base", nil)
if err != nil {
if err := s.templates.internalError.ExecuteTemplate(w, "base", errMsg); err != nil {
s.log.Error("failed to execute template", zap.Error(err))
}
}
// serveBadRequest handles 400 errors and renders err to the bad-request template.
func (s *Server) serveBadRequest(w http.ResponseWriter, req *http.Request, errMsg error) {
w.WriteHeader(http.StatusBadRequest)
if err := s.templates.badRequest.ExecuteTemplate(w, "base", errMsg); err != nil {
s.log.Error("failed to execute template", zap.Error(err))
}
}
@ -152,7 +276,7 @@ func (s *Server) Run(ctx context.Context) error {
var group errgroup.Group
group.Go(func() error {
<-ctx.Done()
return Error.Wrap(s.server.Shutdown(nil))
return Error.Wrap(s.server.Shutdown(ctx))
})
group.Go(func() error {
defer cancel()

View File

@ -0,0 +1,78 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package marketingweb_test
import (
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testplanet"
)
type CreateRequest struct {
Path string
Values url.Values
}
func TestCreateOffer(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
requests := []CreateRequest{
{
Path: "/create/referral-offer",
Values: url.Values{
"Name": {"Referral Credit"},
"Description": {"desc"},
"ExpiresAt": {"2119-06-27"},
"InviteeCreditInCents": {"50"},
"InviteeCreditDurationDays": {"50"},
"AwardCreditInCents": {"50"},
"AwardCreditDurationDays": {"50"},
"RedeemableCap": {"150"},
},
}, {
Path: "/create/free-credit-offer",
Values: url.Values{
"Name": {"Free Credit Credit"},
"Description": {"desc"},
"ExpiresAt": {"2119-06-27"},
"InviteeCreditInCents": {"50"},
"InviteeCreditDurationDays": {"50"},
"RedeemableCap": {"150"},
},
},
}
addr := planet.Satellites[0].Marketing.Listener.Addr()
var group errgroup.Group
for _, offer := range requests {
o := offer
group.Go(func() error {
baseURL := "http://" + addr.String()
_, err := http.PostForm(baseURL+o.Path, o.Values)
if err != nil {
return err
}
_, err = http.Get(baseURL)
if err != nil {
return err
}
return nil
})
}
err := group.Wait()
require.NoError(t, err)
})
}

View File

@ -601,6 +601,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, config *Config, ve
peer.Marketing.Endpoint, err = marketingweb.NewServer(
peer.Log.Named("marketing:endpoint"),
marketingConfig,
peer.DB.Rewards(),
peer.Marketing.Listener,
)
if err != nil {

View File

@ -5,9 +5,21 @@ package rewards
import (
"context"
"fmt"
"time"
)
// ToCents converts USD credit amounts to cents.
func ToCents(dollars int) int {
return dollars * 100
}
// ToDollars converts credit amounts in cents to USD.
func ToDollars(cents int) string {
formattedAmount := fmt.Sprintf("%d.%d0", (cents / 100), (cents % 100))
return formattedAmount
}
// DB holds information about offer
type DB interface {
ListAll(ctx context.Context) ([]Offer, error)
@ -86,3 +98,54 @@ type Offer struct {
Status OfferStatus
Type OfferType
}
// IsDefault evaluates the default status of offers for templates.
func (o Offer) IsDefault() bool {
if o.Status == Default {
return true
}
return false
}
// IsCurrent evaluates the current status of offers for templates.
func (o Offer) IsCurrent() bool {
if o.Status == Active {
return true
}
return false
}
// IsDone evaluates the done status of offers for templates.
func (o Offer) IsDone() bool {
if o.Status == Done {
return true
}
return false
}
// Offers holds a set of organized offers.
type Offers struct {
Set []Offer
}
// GetCurrentFromSet returns the current offer from an organized set.
func (offers Offers) GetCurrentFromSet() Offer {
var o Offer
for _, offer := range offers.Set {
if offer.IsCurrent() {
o = offer
}
}
return o
}
// GetDefaultFromSet returns the current offer from an organized set.
func (offers Offers) GetDefaultFromSet() Offer {
var o Offer
for _, offer := range offers.Set {
if offer.IsDefault() {
o = offer
}
}
return o
}

View File

@ -61,9 +61,11 @@ hr{
.col-heading {
font-family: 'Roboto';
font-style: normal;
white-space: nowrap;
}
.data-row{
.data-row,
.data-row .col a{
font-weight: normal;
font-size: 14px;
line-height: 49px;
@ -168,6 +170,8 @@ input{
.offer-type{
margin-left:35px;
text-transform: uppercase;
white-space: nowrap;
}
.edit-offer{

View File

@ -0,0 +1,7 @@
<!-- Copyright (C) 2019 Storj Labs, Inc.
See LICENSE for copying information. -->
{{define "main"}}
<h1 class="m-5 text-center">Bad Request</h1>
<h2 class="m-5 text-center">{{.}}</h2>
{{end}}

View File

@ -0,0 +1,6 @@
<!-- Copyright (C) 2019 Storj Labs, Inc.
See LICENSE for copying information. -->
{{define "main"}}
<h1 class="m-5 text-center">{{.}}</h1>
{{end}}

View File

@ -12,33 +12,33 @@ See LICENSE for copying information. -->
</button>
</div>
<div class="modal-body">
<form>
<form action="/create/free-credit" method="POST" enctype="application/x-www-form-urlencoded">
<div class="form-row">
<div class="form-group col-md-4">
<label for="offer-name">Offer Name</label>
<input type="text" class="form-control" id="offer-name" placeholder="May Referral" required>
<label for="Name">Offer Name</label>
<input type="text" class="form-control" name="Name" id="Name" placeholder="May Referral" required>
</div>
<div class="form-group col-md-4">
<label for="description">Description</label>
<input type="text" class="form-control" id="description" placeholder="Our test with $50 for May" required>
<label for="Description">Description</label>
<input type="text" class="form-control" name="Description" id="Description" placeholder="Our test with $50 for May" required>
</div>
<div class="form-group col-md-4">
<label for="expiration">Credit Exp Date</label>
<input type="date" class="form-control" id="expiration" placeholder="06/01/19" required>
<label for="ExpiresAt">Credit Exp Date</label>
<input type="date" class="form-control" name="ExpiresAt" id="ExpiresAt" placeholder="06/01/19" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="give-credit">Give Credit</label>
<input type="number" class="form-control" id="give-credit" placeholder="$50" min="1" required>
<label for="AwardCreditInCents">Award Credit</label>
<input type="number" class="form-control" name="AwardCreditInCents" id="AwardCreditInCents" placeholder="$50" min="1" required>
</div>
<div class="form-group col-md-4">
<label for="give-credit-exp">Give Credit Exp</label>
<input type="number" class="form-control" id="give-credit-exp" placeholder="14 days" min="1" required>
<label for="AwardCreditDurationDays">Award Credit Exp</label>
<input type="number" class="form-control" name="AwardCreditDurationDays" id="AwardCreditDurationDays" placeholder="14 days" min="1" required>
</div>
<div class="form-group col-md-4">
<label for="redeemable-capacity">Redeemable Capacity</label>
<input type="number" class="form-control" id="redeemable-capacity" placeholder="150 users" min="1" required>
<label for="RedeemableCap">Redeemable Capacity</label>
<input type="number" class="form-control" name="RedeemableCap" id="RedeemableCap" placeholder="150 users" min="1" required>
</div>
</div>
<div class="m-1 text-left">

View File

@ -3,59 +3,65 @@ See LICENSE for copying information. -->
{{define "freeOffers"}}
<div class="offers-table mt-2 mb-5 container">
<div class="row">
<div class="col col-heading">Name</div>
<div class="col col-heading">Give Credit</div>
<div class="col col-heading">Get Credit</div>
<div class="col col-heading">Referrals&nbsp;Used</div>
<div class="col col-heading">Redeemable&nbsp;Capacity</div>
<div class="col col-heading">Created</div>
<div class="col col-heading">Expiration</div>
<div class="col col-heading">Status</div>
<div class="col col-heading edit-offer"></div>
</div>
<hr>
<div class="row offer-heading ">
<p class="offer-type">DEFAULT&nbsp;OFFER</p>
</div>
<div class="row data-row">
<div class="col ml-3">May Referral</div>
<div class="col">$50</div>
<div class="col">$50</div>
<div class="col">48</div>
<div class="col">200</div>
<div class="col">05/01/19</div>
<div class="col">06/01/19</div>
<div class="col"><strong>Live</strong></div>
<div class="col col-heading edit-offer">EDIT</div>
</div>
<hr>
<div class="row offer-heading ">
<p class="offer-type">DEFAULT&nbsp;OFFER</p>
</div>
<div class="row data-row">
<div class="col ml-3">May Referral</div>
<div class="col">$50</div>
<div class="col">$50</div>
<div class="col">48</div>
<div class="col">200</div>
<div class="col">05/01/19</div>
<div class="col">06/01/19</div>
<div class="col">Off</div>
<div class="col col-heading edit-offer">EDIT</div>
</div>
<hr>
<div class="row data-row">
<div class="col ml-3">May Referral</div>
<div class="col">$50</div>
<div class="col">$50</div>
<div class="col">48</div>
<div class="col">200</div>
<div class="col">05/01/19</div>
<div class="col">06/01/19</div>
<div class="col">Off</div>
<div class="col col-heading edit-offer">EDIT</div>
</div>
<hr>
<div class="row">
<div class="col col-heading">Name</div>
<div class="col col-heading">Award Credit</div>
<div class="col col-heading">Referrals Used</div>
<div class="col col-heading">Redeemable Capacity</div>
<div class="col col-heading">Created</div>
<div class="col col-heading">Expiration</div>
<div class="col col-heading">Status</div>
</div><hr>
<div class="row offer-heading ">
<p class="offer-type">default offer</p>
</div>
{{$defaultOffer := .FreeCredits.GetDefaultFromSet}}
<div class="row data-row">
<div class="col ml-3">{{$defaultOffer.Name}}</div>
<div class="col">${{ToDollars $defaultOffer.AwardCreditInCents}}</div>
<div class="col">{{$defaultOffer.NumRedeemed}}</div>
<div class="col">{{$defaultOffer.RedeemableCap}}</div>
<div class="col">{{printf "%.10s" $defaultOffer.CreatedAt}}</div>
<div class="col">{{printf "%.10s" $defaultOffer.ExpiresAt}}</div>
<div class="col"></div>
</div><hr>
<div class="row offer-heading ">
<p class="offer-type">current offer</p>
</div>
{{if gt (len .FreeCredits.Set) 0}}
{{$currentOffer := .FreeCredits.GetCurrentFromSet}}
<div class="row data-row">
<div class="col ml-3">{{$currentOffer.Name}}</div>
<div class="col">${{ToDollars $currentOffer.AwardCreditInCents}}</div>
<div class="col">{{$currentOffer.NumRedeemed}}</div>
<div class="col">{{$currentOffer.RedeemableCap}}</div>
<div class="col">{{printf "%.10s" $currentOffer.CreatedAt}}</div>
<div class="col">{{printf "%.10s" $currentOffer.ExpiresAt}}</div>
<div class="col stop-offer">
<span data-toggle="modal" data-target=".stop-referral-offer-modal">
<strong>Live &#183;</strong>
</span>
</div>
</div><hr>
{{end}}
<div class="row offer-heading ">
<p class="offer-type">other offers</p>
</div>
{{if gt (len .FreeCredits.Set) 0}}
{{range .FreeCredits.Set}}
{{$offer := .}}
{{if $offer.IsDone}}
<div class="row data-row">
<div class="col ml-3">{{$offer.Name}}</div>
<div class="col">${{ToDollars $offer.AwardCreditInCents}}</div>
<div class="col">{{$offer.NumRedeemed}}</div>
<div class="col">{{$offer.RedeemableCap}}</div>
<div class="col">{{printf "%.10s" $offer.CreatedAt}}</div>
<div class="col">{{printf "%.10s" $offer.ExpiresAt}}</div>
<div class="col">off</div>
</div><hr>
{{end}}
{{end}}
{{end}}
</div>
{{end}}

View File

@ -2,5 +2,6 @@
See LICENSE for copying information. -->
{{define "main"}}
<h1>Internal Server Error</h1>
<h1 class="m-5 text-center">Internal Server Error</h1>
<h2 class="m-5 text-center">{{.}}</h2>
{{end}}

View File

@ -2,51 +2,51 @@
See LICENSE for copying information. -->
{{define "referralOffersModal"}}
<div class="modal fade p-5" id="referral-offers-modal" tabindex="-1" role="dialog" aria-labelledby="referral-offers-modal-lbl" aria-hidden="true">
<div class="modal fade p-5" id="referral-offers-modal" tabindex="-1" role="dialog" aria-labelledby="ref-offers-modal-lbl" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="referral-offers-modal-lbl">Create Referral Credit</h5>
<h5 class="modal-title" id="ref-offers-modal-lbl">Create Referral Credit</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form>
<form action="/create/referral-offer" method="POST" enctype="application/x-www-form-urlencoded">
<div class="form-row">
<div class="form-group col-md-4">
<label for="offer-name">Offer Name</label>
<input type="text" class="form-control" id="offer-name" placeholder="May Referral" required>
<label for="Name">Offer Name</label>
<input type="text" class="form-control" name="Name" id="Name" placeholder="May Referral" required>
</div>
<div class="form-group col-md-4">
<label for="description">Description</label>
<input type="text" class="form-control" id="description" placeholder="Our test with $50 for May" required>
<label for="Description">Description</label>
<input type="text" class="form-control" name="Description" id="Description" placeholder="Our test with $50 for May" required>
</div>
<div class="form-group col-md-4">
<label for="expiration">Credit Exp Date</label>
<input type="date" class="form-control" id="expiration" placeholder="06/01/19" required>
<label for="ExpiresAt">Credit Exp Date</label>
<input type="date" class="form-control" id="ExpiresAt" name="ExpiresAt" placeholder="06/01/19" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-2">
<label for="give-credit">Give Credit</label>
<input type="number" class="form-control" id="give-credit" placeholder="$50" required>
<label for="InviteeCreditInCents">Give Credit</label>
<input type="number" class="form-control" name="InviteeCreditInCents" id="InviteeCreditInCents" placeholder="$50" required>
</div>
<div class="form-group col-md-2">
<label for="give-credit-exp">Give Credit Exp.</label>
<input type="number" class="form-control" id="give-credit-exp" min="1" placeholder="14 days" required>
<label for="InviteeCreditDurationDays">Give Credit Exp.</label>
<input type="number" class="form-control" name="InviteeCreditDurationDays" id="InviteeCreditDurationDays" min="1" placeholder="14 days" required>
</div>
<div class="form-group col-md-2">
<label for="get-credit">Get Credit</label>
<input type="number" class="form-control" id="get-credit" placeholder="$50" min="1" required>
<label for="AwardCreditInCents">Award Credit</label>
<input type="number" class="form-control" name="AwardCreditInCents" id="AwardCreditInCents" placeholder="$50" min="1" required>
</div>
<div class="form-group col-md-3">
<label for="get-credit-exp">Get Credit Exp.</label>
<input type="number" class="form-control" id="get-credit-exp" placeholder="12 months" min="1" required>
<label for="AwardCreditDurationDays">Award Credit Exp.</label>
<input type="number" class="form-control" name="AwardCreditDurationDays" id="AwardCreditDurationDays" placeholder="12 months" min="1" required>
</div>
<div class="form-group col-md-3">
<label for="redeemable-capacity">Redeemable Capacity</label>
<input type="number" class="form-control" id="redeemable-capacity" min="1" placeholder="150 users" required>
<label for="RedeemableCap">Redeemable Capacity</label>
<input type="number" class="form-control" name="RedeemableCap" id="RedeemableCap" min="1" placeholder="150 users" required>
</div>
</div>
<div class="m-1 text-left">

View File

@ -6,55 +6,66 @@ See LICENSE for copying information. -->
<div class="row">
<div class="col col-heading">Name</div>
<div class="col col-heading">Give Credit</div>
<div class="col col-heading">Get Credit</div>
<div class="col col-heading">Referrals&nbsp;Used</div>
<div class="col col-heading">Redeemable&nbsp;Capacity</div>
<div class="col col-heading">Award Credit</div>
<div class="col col-heading">Referrals Used</div>
<div class="col col-heading">Redeemable Capacity</div>
<div class="col col-heading">Created</div>
<div class="col col-heading">Expiration</div>
<div class="col col-heading"></div>
</div>
<hr>
<div class="col col-heading">Status</div>
</div><hr>
<div class="row offer-heading ">
<p class="offer-type">DEFAULT&nbsp;OFFER</p>
<p class="offer-type">default offer</p>
</div>
{{$defaultOffer := .ReferralOffers.GetDefaultFromSet}}
<div class="row data-row">
<div class="col ml-3">May Referral</div>
<div class="col">$50</div>
<div class="col">$50</div>
<div class="col">48</div>
<div class="col">200</div>
<div class="col">05/01/19</div>
<div class="col">06/01/19</div>
<div class="col"><strong>Live</strong></div>
<div class="col col-heading edit-offer">EDIT</div>
</div>
<hr>
<div class="col ml-3">{{$defaultOffer.Name}}</div>
<div class="col">${{ToDollars $defaultOffer.InviteeCreditInCents}}</div>
<div class="col">${{ToDollars $defaultOffer.AwardCreditInCents}}</div>
<div class="col">{{$defaultOffer.NumRedeemed}}</div>
<div class="col">&#8734;</div>
<div class="col">{{printf "%.10s" $defaultOffer.CreatedAt}}</div>
<div class="col">&#8734;</div>
<div class="col"></div>
</div><hr>
<div class="row offer-heading ">
<p class="offer-type">DEFAULT&nbsp;OFFER</p>
<p class="offer-type">current offer</p>
</div>
<div class="row data-row">
<div class="col ml-3">May Referral</div>
<div class="col">$50</div>
<div class="col">$50</div>
<div class="col">48</div>
<div class="col">200</div>
<div class="col">05/01/19</div>
<div class="col">06/01/19</div>
<div class="col">Off</div>
<div class="col col-heading edit-offer">EDIT</div>
{{if gt (len .ReferralOffers.Set) 0}}
{{$currentOffer := .ReferralOffers.GetCurrentFromSet}}
<div class="row data-row">
<div class="col ml-3">{{$currentOffer.Name}}</div>
<div class="col">${{ToDollars $currentOffer.InviteeCreditInCents}}</div>
<div class="col">${{ToDollars $currentOffer.AwardCreditInCents}}</div>
<div class="col">{{$currentOffer.NumRedeemed}}</div>
<div class="col">{{$currentOffer.RedeemableCap}}</div>
<div class="col">{{printf "%.10s" $currentOffer.CreatedAt}}</div>
<div class="col">{{printf "%.10s" $currentOffer.ExpiresAt}}</div>
<div class="col stop-offer">
<span data-toggle="modal" data-target=".stop-referral-offer-modal">
<strong>Live &#183;</strong>
</span>
</div>
</div><hr>
{{end}}
<div class="row offer-heading ">
<p class="offer-type">other offers</p>
</div>
<hr>
<div class="row data-row">
<div class="col ml-3">May Referral</div>
<div class="col">$50</div>
<div class="col">$50</div>
<div class="col">48</div>
<div class="col">200</div>
<div class="col">05/01/19</div>
<div class="col">06/01/19</div>
<div class="col">Off</div>
<div class="col col-heading edit-offer">EDIT</div>
</div>
<hr>
{{if gt (len .ReferralOffers.Set) 0}}
{{range .ReferralOffers.Set}}
{{$offer := .}}
{{if $offer.IsDone}}
<div class="row data-row">
<div class="col ml-3">{{$offer.Name}}</div>
<div class="col">${{ToDollars $offer.InviteeCreditInCents}}</div>
<div class="col">${{ToDollars $offer.AwardCreditInCents}}</div>
<div class="col">{{.NumRedeemed}}</div>
<div class="col">{{.RedeemableCap}}</div>
<div class="col">{{printf "%.10s" .CreatedAt}}</div>
<div class="col">{{printf "%.10s" .ExpiresAt}}</div>
<div class="col">off</div>
</div><hr>
{{end}}
{{end}}
{{end}}
</div>
{{end}}