-
Notifications
You must be signed in to change notification settings - Fork 2
/
confirm_donor_can_interact_online.go
44 lines (36 loc) · 1.34 KB
/
confirm_donor_can_interact_online.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package supporter
import (
"net/http"
"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)
type confirmDonorCanInteractOnlineData struct {
App page.AppData
Errors validation.List
Form *form.YesNoForm
}
func ConfirmDonorCanInteractOnline(tmpl template.Template, organisationStore OrganisationStore) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error {
data := &confirmDonorCanInteractOnlineData{
App: appData,
Form: form.NewYesNoForm(form.YesNoUnknown),
}
if r.Method == http.MethodPost {
data.Form = form.ReadYesNoForm(r, "ifYouWouldLikeToContinueMakingAnOnlineLPA")
data.Errors = data.Form.Validate()
if data.Form.YesNo.IsYes() {
donorProvided, err := organisationStore.CreateLPA(r.Context())
if err != nil {
return err
}
return page.Paths.YourDetails.Redirect(w, r, appData, donorProvided)
} else if data.Form.YesNo.IsNo() {
return page.Paths.Supporter.ContactOPGForPaperForms.Redirect(w, r, appData)
}
}
return tmpl(w, data)
}
}