-
Notifications
You must be signed in to change notification settings - Fork 2
/
task_list.go
175 lines (159 loc) · 4.82 KB
/
task_list.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package donor
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/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)
type taskListData struct {
App page.AppData
Errors validation.List
Donor *actor.DonorProvidedDetails
Sections []taskListSection
EvidenceReceived bool
}
type taskListItem struct {
Name string
Path string
State actor.TaskState
PaymentState actor.PaymentTask
Count int
Hidden bool
}
type taskListSection struct {
Heading string
Items []taskListItem
}
func TaskList(tmpl template.Template, evidenceReceivedStore EvidenceReceivedStore) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error {
evidenceReceived, err := evidenceReceivedStore.Get(r.Context())
if err != nil {
return err
}
section1 := taskListSection{
Heading: "fillInTheLpa",
Items: []taskListItem{
{
Name: "provideYourDetails",
Path: page.Paths.YourDetails.Format(donor.LpaID),
State: donor.Tasks.YourDetails,
},
{
Name: "chooseYourAttorneys",
Path: page.Paths.ChooseAttorneysGuidance.Format(donor.LpaID),
State: donor.Tasks.ChooseAttorneys,
Count: donor.Attorneys.Len(),
},
{
Name: "chooseYourReplacementAttorneys",
Path: page.Paths.DoYouWantReplacementAttorneys.Format(donor.LpaID),
State: donor.Tasks.ChooseReplacementAttorneys,
Count: donor.ReplacementAttorneys.Len(),
},
taskListTypeSpecificStep(donor),
{
Name: "addRestrictionsToTheLpa",
Path: page.Paths.Restrictions.Format(donor.LpaID),
State: donor.Tasks.Restrictions,
},
{
Name: "chooseYourCertificateProvider",
Path: page.Paths.WhatACertificateProviderDoes.Format(donor.LpaID),
State: donor.Tasks.CertificateProvider,
},
{
Name: "peopleToNotifyAboutYourLpa",
Path: page.Paths.DoYouWantToNotifyPeople.Format(donor.LpaID),
State: donor.Tasks.PeopleToNotify,
Count: len(donor.PeopleToNotify),
},
{
Name: "chooseYourSignatoryAndIndependentWitness",
Path: page.Paths.GettingHelpSigning.Format(donor.LpaID),
State: donor.Tasks.ChooseYourSignatory,
Hidden: !donor.Donor.CanSign.IsNo(),
},
{
Name: "checkAndSendToYourCertificateProvider",
Path: taskListCheckLpaPath(donor).Format(donor.LpaID),
State: donor.Tasks.CheckYourLpa,
},
},
}
var sections []taskListSection
if appData.IsSupporter {
sections = []taskListSection{section1}
} else {
sections = []taskListSection{section1, taskListPaymentSection(donor), taskListSignSection(donor)}
}
return tmpl(w, &taskListData{
App: appData,
Donor: donor,
EvidenceReceived: evidenceReceived,
Sections: sections,
})
}
}
func taskListTypeSpecificStep(donor *actor.DonorProvidedDetails) taskListItem {
if donor.Type == actor.LpaTypePersonalWelfare {
return taskListItem{
Name: "lifeSustainingTreatment",
Path: page.Paths.LifeSustainingTreatment.Format(donor.LpaID),
State: donor.Tasks.LifeSustainingTreatment,
}
}
return taskListItem{
Name: "chooseWhenTheLpaCanBeUsed",
Path: page.Paths.WhenCanTheLpaBeUsed.Format(donor.LpaID),
State: donor.Tasks.WhenCanTheLpaBeUsed,
}
}
func taskListCheckLpaPath(donor *actor.DonorProvidedDetails) page.LpaPath {
if len(donor.Under18ActorDetails()) > 0 {
return page.Paths.YouCannotSignYourLpaYet
} else if donor.CertificateProviderSharesDetails() {
return page.Paths.ConfirmYourCertificateProviderIsNotRelated
} else {
return page.Paths.CheckYourLpa
}
}
func taskListPaymentSection(donor *actor.DonorProvidedDetails) taskListSection {
var paymentPath page.LpaPath
switch donor.Tasks.PayForLpa {
case actor.PaymentTaskDenied:
paymentPath = page.Paths.FeeDenied
case actor.PaymentTaskMoreEvidenceRequired:
paymentPath = page.Paths.UploadEvidence
default:
paymentPath = page.Paths.AboutPayment
}
return taskListSection{
Heading: "payForTheLpa",
Items: []taskListItem{
{
Name: "payForTheLpa",
Path: paymentPath.Format(donor.LpaID),
PaymentState: donor.Tasks.PayForLpa,
},
},
}
}
func taskListSignSection(donor *actor.DonorProvidedDetails) taskListSection {
var signPath page.LpaPath
if donor.DonorIdentityConfirmed() {
signPath = page.Paths.ReadYourLpa
} else {
signPath = page.Paths.HowToConfirmYourIdentityAndSign
}
return taskListSection{
Heading: "confirmYourIdentityAndSign",
Items: []taskListItem{
{
Name: "confirmYourIdentityAndSign",
Path: signPath.Format(donor.LpaID),
State: donor.Tasks.ConfirmYourIdentityAndSign,
},
},
}
}