Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLPAB-397: How should the attorneys make decisions #192

Merged
merged 17 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions app/internal/page/how_should_attorneys_make_decisions.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package page

import (
"fmt"
"net/http"

"github.com/ministryofjustice/opg-go-common/template"
)

type howShouldAttorneysMakeDecisionsData struct {
App AppData
DecisionsType string
DecisionsDetails string
Errors map[string]string
App AppData
Errors map[string]string
Form *howShouldAttorneysMakeDecisionsForm
}

type howShouldAttorneysMakeDecisionsForm struct {
Expand All @@ -23,27 +21,28 @@ func HowShouldAttorneysMakeDecisions(tmpl template.Template, lpaStore LpaStore)
return func(appData AppData, w http.ResponseWriter, r *http.Request) error {
lpa, err := lpaStore.Get(r.Context(), appData.SessionID)
if err != nil {
fmt.Print(lpa.ID)
return err
}

data := &howShouldAttorneysMakeDecisionsData{
App: appData,
DecisionsType: lpa.DecisionsType,
DecisionsDetails: lpa.DecisionsDetails,
App: appData,
Form: &howShouldAttorneysMakeDecisionsForm{
DecisionsType: lpa.DecisionsType,
DecisionsDetails: lpa.DecisionsDetails,
},
}

if r.Method == http.MethodPost {
form := readHowShouldAttorneysMakeDecisionsForm(r)
data.Errors = form.Validate()
data.Form = readHowShouldAttorneysMakeDecisionsForm(r)
data.Errors = data.Form.Validate()

if len(data.Errors) == 0 {
lpa.DecisionsType = form.DecisionsType
lpa.DecisionsType = data.Form.DecisionsType

if form.DecisionsType != "mixed" {
if data.Form.DecisionsType != "mixed" {
lpa.DecisionsDetails = ""
} else {
lpa.DecisionsDetails = form.DecisionsDetails
lpa.DecisionsDetails = data.Form.DecisionsDetails
}

if err := lpaStore.Put(r.Context(), appData.SessionID, lpa); err != nil {
Expand Down
19 changes: 15 additions & 4 deletions app/internal/page/how_should_attorneys_make_decisions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func TestGetHowShouldAttorneysMakeDecisions(t *testing.T) {
template := &mockTemplate{}
template.
On("Func", w, &howShouldAttorneysMakeDecisionsData{
App: appData,
App: appData,
Form: &howShouldAttorneysMakeDecisionsForm{},
}).
Return(nil)

Expand All @@ -47,9 +48,11 @@ func TestGetHowShouldAttorneysMakeDecisionsFromStore(t *testing.T) {
template := &mockTemplate{}
template.
On("Func", w, &howShouldAttorneysMakeDecisionsData{
App: appData,
DecisionsType: "jointly",
DecisionsDetails: "some decisions",
App: appData,
Form: &howShouldAttorneysMakeDecisionsForm{
DecisionsType: "jointly",
DecisionsDetails: "some decisions",
},
}).
Return(nil)

Expand Down Expand Up @@ -93,6 +96,10 @@ func TestGetHowShouldAttorneysMakeDecisionsWhenTemplateErrors(t *testing.T) {
template.
On("Func", w, &howShouldAttorneysMakeDecisionsData{
App: appData,
Form: &howShouldAttorneysMakeDecisionsForm{
DecisionsType: "",
DecisionsDetails: "",
},
}).
Return(expectedError)

Expand Down Expand Up @@ -235,6 +242,10 @@ func TestPostHowShouldAttorneysMakeDecisionsWhenValidationErrors(t *testing.T) {
Errors: map[string]string{
"decision-type": "chooseADecisionType",
},
Form: &howShouldAttorneysMakeDecisionsForm{
DecisionsType: "",
DecisionsDetails: "",
},
}).
Return(nil)

Expand Down
1 change: 1 addition & 0 deletions app/lang/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
"jointlyHint": "Welsh",
"jointlyAndSeverallyMixed": "Welsh",
"jointlyAndSeverallyMixedHint": "Welsh",
"decisionDetailsHint": "Welsh",
"details": "Welsh",
"chooseADecisionType": "Welsh",
"provideDecisionDetails": "Welsh",
Expand Down
3 changes: 2 additions & 1 deletion app/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,10 @@
"jointlyAndSeverally": "Jointly and severally",
"jointlyAndSeverallyHint": "Attorneys can make decisions on their own or together. Most people choose this option because it's the most practical.",
"jointly": "Jointly",
"jointlyHint": "Attorneys must agree unanimously on every decision, however big or small. Be careful-if one of the attorneys can no longer act, none of the other attorneys will be able to act either, unless the donor states otherwise in their instructions.",
"jointlyHint": "Attorneys must agree unanimously on every decision, however big or small. Be careful - if one of the attorneys can no longer act, none of the other attorneys will be able to act either, unless the donor states otherwise in their instructions.",
"jointlyAndSeverallyMixed": "Jointly for some decisions, and jointly and severally for other decisions",
"jointlyAndSeverallyMixedHint": "Attorneys must agree unanimously on some decisions, but can make others on their own. The donor must state which decisions need to be agreed unanimously.",
"decisionDetailsHint": " Please tell us which decisions the donor wants to be made jointly. These decisions will be printed on a extra sheet that the donor will need to sign and date. Take a look at the guidance for examples of how the donor can make their wishes clear.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, extra sheets

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know 😂

"details": "Details",
"chooseADecisionType": "Select from the listed decision options",
"provideDecisionDetails": "Provide details on how your attorneys should act",
Expand Down
59 changes: 51 additions & 8 deletions app/web/template/how_should_attorneys_make_decisions.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,59 @@
<div class="govuk-form-group {{ if index .Errors "decision-type" }}govuk-form-group--error{{ end }}">
{{ template "error-message" (errorMessage . "decision-type") }}

{{ template "radios" (items . "decision-type" .DecisionsType
(item "jointly-and-severally" "jointlyAndSeverally" "hint" "jointlyAndSeverallyHint")
(item "jointly" "jointly" "hint" "jointlyHint")
(item "mixed" "jointlyAndSeverallyMixed" "hint" "jointlyAndSeverallyMixedHint" "conditionalLabel" "details" "conditionalValue" .DecisionsDetails "conditionalInputName" "mixed-details")
) }}
<div class="govuk-radios {{ if index .Errors "decision-type" }}govuk-radios--error{{ end }}" data-module="govuk-radios">
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="f-decision-type" name="decision-type" type="radio" value="jointly-and-severally" aria-describedby="decision-type-item-hint" {{ if eq "jointly-and-severally" .Form.DecisionsType }}checked{{ end }}>
<label class="govuk-label govuk-radios__label" for="f-decision-type">
{{ tr .App "jointlyAndSeverally" }}
</label>

<div id="decision-type-item-hint" class="govuk-hint govuk-radios__hint">
{{ tr .App "jointlyAndSeverallyHint" }}
</div>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="f-decision-type-2" name="decision-type" type="radio" value="jointly" aria-describedby="decision-type-2-item-hint" {{ if eq "jointly" .Form.DecisionsType }}checked{{ end }}>
<label class="govuk-label govuk-radios__label" for="f-decision-type-2">
{{ tr .App "jointly" }}
</label>

<div id="decision-type-2-item-hint" class="govuk-hint govuk-radios__hint">
{{ tr .App "jointlyHint" }}
</div>
</div>
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="f-decision-type-3" name="decision-type" type="radio" value="mixed" aria-describedby="decision-type-3-item-hint" aria-controls="decision-type-3-conditional-div" {{ if or (eq "mixed" .Form.DecisionsType) (index .Errors "mixed-details") }}checked{{ end }}>
<label class="govuk-label govuk-radios__label" for="f-decision-type-3">
{{ tr .App "jointlyAndSeverallyMixed" }}
</label>

<div id="decision-type-3-item-hint" class="govuk-hint govuk-radios__hint">
{{ tr .App "jointlyAndSeverallyMixedHint" }}
</div>

<div class="govuk-radios__conditional" id="decision-type-3-conditional-div">
<div class="govuk-form-group {{ if index .Errors "mixed-details" }}govuk-form-group--error{{ end }}">
<p class="goveuk--body">{{ tr .App "decisionDetailsHint" }}</p>
<label class="govuk-label" for="mixed-details">
{{ tr .App "details" }}
</label>
{{ if index .Errors "mixed-details" }}
<p id="decision-type-3-error" class="govuk-error-message">
{{ tr .App (index .Errors "mixed-details") }}
</p>
{{ end }}

<textarea class="govuk-textarea {{ if index .Errors "mixed-details" }}govuk-input--error{{ end }}" id="mixed-details" name="mixed-details" rows="10">{{ .Form.DecisionsDetails }}</textarea>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="govuk-button-group">
{{ template "continue-button" . }}
<div class="govuk-button-group">
{{ template "continue-button" . }}
</div>
</div>
</form>
</div>
Expand Down
16 changes: 0 additions & 16 deletions app/web/template/layout/radios.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
value="{{ $e.value }}"
{{ if eq $.value $e.value }}checked{{ end }}
{{ if $e.hint }}aria-describedby="{{ fieldID $.name $i }}-item-hint"{{ end }}
{{ if $e.conditionalLabel }}data-aria-controls="{{ fieldID $.name $i }}-conditional-div"{{ end }}
>
<label class="govuk-label govuk-radios__label" for="f-{{ $.name }}{{ if ne $i 0 }}-{{ inc $i }}{{ end }}">
{{ tr $.top.App $e.label }}
Expand All @@ -19,21 +18,6 @@
{{ tr $.top.App $e.hint }}
</div>
{{ end }}
{{ if $e.conditionalLabel }}
<div class="govuk-radios__conditional" id="{{ fieldID $.name $i }}-conditional-div">
<div class="govuk-form-group {{ if index $.top.Errors $.name }}govuk-form-group--error{{ end }}">
<label class="govuk-label" for="{{ $e.conditionalInputName }}">
{{ tr $.top.App $e.conditionalLabel }}
</label>
{{ if index $.top.Errors $e.conditionalInputName }}
<p id="{{ fieldID $.name $i }}-error" class="govuk-error-message">
{{ tr $.top.App (index $.top.Errors $e.conditionalInputName) }}
</p>
{{ end }}
<textarea class="govuk-textarea {{ if index $.top.Errors $.name }}govuk-input--error{{ end }}" id="{{ $e.conditionalInputName }}" name="{{ $e.conditionalInputName }}" rows="10">{{ $e.conditionalValue }}</textarea>
</div>
</div>
{{ end }}
</div>
{{ end }}
</div>
Expand Down