Skip to content

Commit

Permalink
Cleaned up page controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
ziggy-cyb committed Nov 27, 2023
1 parent 6a0ab30 commit a72660a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ export class PageControllerBase {

await cacheService.mergeState(request, { progress });

viewModel.backLink = progress[progress.length - 2];
viewModel.backLink =
progress[progress.length - 2] ?? this.backLinkFallback;
return h.view(this.viewName, viewModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,44 @@ import { FormModel } from "server/plugins/engine/models";
import { Page } from "@xgovformbuilder/model";
import { FormComponent } from "server/plugins/engine/components";
import { HapiRequest, HapiResponseToolkit } from "server/types";

export class PlaybackUploadPageController extends PageController {
inputComponent: FormComponent;
standardViewModel = {
name: "retryUpload",
fieldset: {
legend: {
text: "Would you like to upload a new image?",
isPageHeading: false,
classes: "govuk-fieldset__legend--s",
},
},
items: [
{
value: "true",
text: "Yes - I would like to upload a new image",
},
{
value: "false",
text: "No - I am happy with the image",
},
],
};

constructor(model: FormModel, pageDef: Page, inputComponent: FormComponent) {
super(model, pageDef);
this.inputComponent = inputComponent;
}

buildRadioViewModel(error?: string) {
const standardViewModel = {
name: "retryUpload",
fieldset: {
legend: {
text: "Would you like to upload a new image?",
isPageHeading: false,
classes: "govuk-fieldset__legend--s",
},
},
items: [
{
value: "true",
text: "Yes - I would like to upload a new image",
},
{
value: "false",
text: "No - I am happy with the image",
},
],
};
getRetryUploadViewModel(error?: string) {
if (error) {
return {
errorMessage: {
text: error,
},
...standardViewModel,
...this.standardViewModel,
};
}
return standardViewModel;
return this.standardViewModel;
}

makeGetRouteHandler() {
Expand All @@ -56,7 +55,7 @@ export class PlaybackUploadPageController extends PageController {
showTitle: true,
pageTitle: "Check your image",
backLink: progress[progress.length - 1] ?? this.backLinkFallback,
radios: this.buildRadioViewModel(),
radios: this.getRetryUploadViewModel(),
});
};
}
Expand Down Expand Up @@ -86,7 +85,7 @@ export class PlaybackUploadPageController extends PageController {
pageTitle: "Check your image",
uploadErrors: errors,
backLink: progress[progress.length - 2] ?? this.backLinkFallback,
radios: this.buildRadioViewModel(errorText),
radios: this.getRetryUploadViewModel(errorText),
});
}

Expand Down

0 comments on commit a72660a

Please sign in to comment.