-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(branding): add new placeholder pages * style(branding): add info icon * feat(branding): add new routes/logic for branding * feat(branding): add feature flag to allow branding settings link to flow to new feature * feat(branding): add new form for GOC branding selection * chore(branding): re-gen index.css * chore: formatting * feat(back navigation): add js helper to make back links all work without keeping track * feat(branding form model): simplify model so it can be used in both the GOC and pool pages * feat(branding preview): add flexibility to preview current branding or arbitrary branding * feat(preview): add a partial using shadow dom to isolate and display email template preview * feat(branding): move display of branding into its own partial * feat(view branding): add preview option to settings page * feat(goc branding): use branding partial * feat(pool): add ability to select from other branding in org; add empty state; * feat(preview): add preview page * feat(branding request): get the page structure ready * feat(view branding): add preview to settings * chore: formatting * chore: formatting * chore: regen css * chore(branding request): add WTF form for branding request page * feat(branding request): add form to page * feat(branding request): experiment with building a better file upload component * chore: regen css * feat(branding_request): make a proper js component; refactor page to suit * feat(request_branding): add backend code i missed * a11y(branding_request): focus on preview after file upload * feat(branding_request): make request post work * chore(css/forms): update css and use form macros * chore: formatting * style(radio image): update padding * feat(request submit): fix up confirmation page/forms * chore: regen css * chore: formatting * test(branding): add tests for `/edit-branding` and `/review-pool` * chore: remove unused component * feat(test-ids): update some macros to accept testid param * feat(branding): add testids to ui elements * chore: formatting * secure(request_branding): encode URI before using it * fix(pool): clean up forms; implement latest content/design * a11y(select-input): divs arent allowed inside labels * style(branding-settings): update/simplify as per latest design * style(preview): update per latest design * style(branding): update as per latest design * chore: regen css * chore: formatting * test(test_headers): update test with new CSP * chore: formatting * fix(branding): update failing tests * fix: add placeholder for missing translations * fix(a11y): fix floating quotation mark that breaks html validation * style(branding preview): show placeholder rectangles instead of content for a11y, provide useful content! * chore: formatting * chore: update tranlsations * fix:(request branding): update screen per figma * chore: update validation message in test * chore: add missing translation * feat(request branding): update screen/behaviour as per figma * chore: formatting * chore: add translation * chore: remove unsused variable; remove commented out code * chore: remove dupe translation * chore: adding docstrings * fix: enable new branding features for all platform admins * chore: formatting/regen js * chore: docs * chore: regen css/js * chore: formatting * fix: remove testing FF from staging config
- Loading branch information
1 parent
b3b2920
commit f14446b
Showing
33 changed files
with
1,100 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/** | ||
* This script handles the functionality for the branding request form. | ||
* It initializes the UI, updates the email template preview based on the selected file, | ||
* and validates the form inputs (brand name and logo). | ||
* | ||
* Client-side validation: | ||
* ---------------------- | ||
* Normally with file uploads, when you post a file it doesnt get returned back with the form, so if we want to display | ||
* errors, we would have to either save the file temporarily (i.e. in s3) which is complex or force the user | ||
* to upload it twice, which isn't great UX. | ||
* | ||
* Instead, we do client-side validation so that the user can upload the file only once. | ||
* | ||
* Localisation: | ||
* ------------ | ||
* This module uses the window.APP_PHRASES object to get the strings for the error messages, following the pattern of other | ||
* existing components. | ||
* | ||
*/ | ||
(function () { | ||
"use strict"; | ||
const input_img = document.querySelector("input.file-upload-field"); | ||
const input_brandname = document.querySelector("#name"); | ||
const submit_button = document.querySelector("button[type=submit]"); | ||
const message = document.querySelector(".preview .message"); | ||
const image_slot = document.querySelector(".preview .img"); | ||
const preview_heading = document.querySelector("#preview_heading"); | ||
const brand_name_group = document | ||
.querySelector("#name") | ||
.closest(".form-group"); | ||
const image_label = document.getElementById("file-upload-label"); | ||
|
||
// init UI | ||
input_img.style.opacity = 0; | ||
input_img.addEventListener("change", updateImageDisplay); | ||
submit_button.addEventListener("click", validateForm); | ||
input_brandname.addEventListener("change", validateBrand); | ||
// strings | ||
let file_name = window.APP_PHRASES.branding_request_file_name; | ||
let file_size = window.APP_PHRASES.branding_request_file_size; | ||
let display_size = window.APP_PHRASES.branding_request_display_size; | ||
let brand_error = window.APP_PHRASES.branding_request_brand_error; | ||
let logo_error = window.APP_PHRASES.branding_request_logo_error; | ||
|
||
// error message html | ||
let brand_error_html = `<span id="name-error-message" data-testid="brand-error" class="error-message" data-module="track-error" data-error-type="${brand_error}" data-error-label="name">${brand_error}</span>`; | ||
let image_error_html = `<span id="logo-error-message" data-testid="logo-error" class="error-message">${logo_error}</span>`; | ||
|
||
/** | ||
* Update email template preview based on the selected file | ||
*/ | ||
function updateImageDisplay() { | ||
// remove the last image | ||
while (image_slot.firstChild) { | ||
image_slot.removeChild(image_slot.firstChild); | ||
} | ||
|
||
const curFiles = input_img.files; | ||
if (curFiles.length === 0) { | ||
const message = document.createElement("p"); | ||
message.textContent = "No files currently selected for upload"; | ||
} else { | ||
for (const file of curFiles) { | ||
if (validFileType(file)) { | ||
const img_src = URL.createObjectURL(file); | ||
const img = document | ||
.getElementById("template_preview") | ||
.shadowRoot.querySelector("img"); | ||
img.src = encodeURI(img_src); | ||
|
||
img.onload = () => { | ||
message.textContent = `${file_name} ${ | ||
file.name | ||
}, ${file_size} ${returnFileSize(file.size)}, ${display_size} ${ | ||
img.naturalWidth | ||
} x ${img.naturalHeight}`; | ||
document | ||
.querySelector(".template_preview") | ||
.classList.remove("hidden"); | ||
preview_heading.focus(); | ||
}; | ||
validateLogo(); | ||
} else { | ||
//remove file from input | ||
input_img.value = ""; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Utilities | ||
*/ | ||
const fileTypes = ["image/png"]; | ||
|
||
function validFileType(file) { | ||
return fileTypes.includes(file.type); | ||
} | ||
|
||
function returnFileSize(number) { | ||
if (number < 1024) { | ||
return `${number} bytes`; | ||
} else if (number >= 1024 && number < 1048576) { | ||
return `${(number / 1024).toFixed(1)} KB`; | ||
} else if (number >= 1048576) { | ||
return `${(number / 1048576).toFixed(1)} MB`; | ||
} | ||
} | ||
|
||
function validateForm(event) { | ||
const brandName = input_brandname.value.trim(); | ||
const image = input_img.value.length > 0; | ||
|
||
validateBrand(); | ||
validateLogo(); | ||
|
||
if (!brandName || !image) { | ||
// set focus on the first input with an error | ||
if (!brandName) { | ||
input_brandname.focus(); | ||
} else { | ||
input_img.focus(); | ||
} | ||
if (event) { | ||
event.preventDefault(); | ||
} | ||
} | ||
} | ||
|
||
function validateBrand() { | ||
const brandName = input_brandname.value.trim(); | ||
|
||
if (!brandName) { | ||
if (!brand_name_group.classList.contains("form-group-error")) { | ||
// dont display the error more than once | ||
brand_name_group.classList.add("form-group-error"); | ||
input_brandname.insertAdjacentHTML("beforebegin", brand_error_html); | ||
} | ||
} else { | ||
if (brand_name_group.classList.contains("form-group-error")) { | ||
brand_name_group.classList.remove("form-group-error"); | ||
document.getElementById("name-error-message").remove(); | ||
} | ||
} | ||
} | ||
|
||
function validateLogo() { | ||
const image = input_img.value.length > 0; | ||
|
||
if (!image) { | ||
if (!image_label.classList.contains("form-group-error")) { | ||
// dont display the error more than once | ||
image_label.classList.add("form-group-error"); | ||
image_label.insertAdjacentHTML("beforebegin", image_error_html); | ||
} | ||
} else { | ||
if (image_label.classList.contains("form-group-error")) { | ||
image_label.classList.remove("form-group-error"); | ||
document.getElementById("logo-error-message").remove(); | ||
} | ||
} | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.