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

Feat/contact us page #260

Merged
merged 22 commits into from
Dec 4, 2020
Merged

Feat/contact us page #260

merged 22 commits into from
Dec 4, 2020

Conversation

gweiying
Copy link
Contributor

@gweiying gweiying commented Nov 24, 2020

Addresses #217. PR is continued in #266.

This PR is still a work in progress, but seeking feedback for the stuff here so far. The remaining tasks are more modular/ cleanup-focused, and is unlikely to affect functionality significantly. Please have a look and give your feedback, especially if it's not covered in the scope of the tasks mentioned below or it's a bug I've not discovered:

Remaining tasks:

  • Initialize contact-us.md if file does not exist (P1) Hide/ Show Contact Us card on Workspace depending on whether contact-us.md exists (P1)
  • Validation and Error Checking (P1)
    - [ ] Add CSP checking on Contact Description field as html elements are accepted (P1)
  • Clean up implementation/ modification of POST update for Settings on backend (P1) (see link)
  • Auto format phone numbers with spacing, prefixes when a user enters the number (how to support both toll-free and local numbers?) (P1)
  • Remove empty object from the operatingHours array , either through validation or through filtering (P2)
  • Change color of Agency Name on Edit Contact Us preview to use Site theme color (P2)
  • Clean up PropTypes and setting default PropType values (P2)
    - [ ] Contact Us image ? (see link)
    - [ ] Data sanitiser should return indicator for whether values are removed e.g. Customs has more Address fields than we support, so we automatically truncate it to the first 3 fields. Warning should be returned when fields are removed. (to be discussed)
  • Clean up this.state.displaySections, intended structure: { contact: [], location: [], sectionsDisplay: {} } as this should simplify displayHandler, createHandler, deleteHandler (P3)
  • Code formatting (P3)

Additional tasks (updated 11/26/2020):

  • Remove dropdown options from Contact Us card on Workspace
  • Fix operating hours validation error
  • Snap to individual fields rather than the section head
  • Explore snap to options: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
  • Remove empty contacts array if no contacts.length
  • Stylistic consistency changes: dangerouslySetHtml, View Map (padding), feedback form, Emails and phone numbers under contacts
  • Fix size of fields (should not be dependent on error length)
  • Set background to white
  • Check for any edited data and give a warning if the user is navigating away with unsaved changes, similar to editHomepage
  • Fix email validation
  • Test Edit Contact Us page across multiple sites to bug find
    - [ ] Fix memory leaks with API call on Workspace

Additional tasks (updated 12/1/2020):

  • Fix title overflow on card
  • Add note to Map Url about automated link generation
  • Make links open in new page (consistent behavior w template)
  • Red border on error cards
  • Keep delete confirmation modal
  • Validation title: Length 1 and above

For FUTURE PR (updated 12/1/2020):

  • Validation on mount
  • Providing overview of removed data
  • Fix memory leaks with API call on Workspace
  • Contact Us script python
  • Filter out contact-us page from /pages in Workspace
  • Option to delete all location/ contact cards at once
  • Allow deletion of contact us page

Considerations to discuss with Lisa/ designers - Updated summary of discussion on 12/1 linked here

  • Should links on preview pages work?
  • View Map url generation (how to tell users that we will generate the url automatically)?
  • How to deal with already erroneous data on mount? (sanitise, validation) How to feedback this to users?
  • How to highlight which cards have errors?
  • Feedback field position - when you type how to correlate positions?
  • Limit on # of contact cards/ location cards
  • Contact us page image?
  • Do we need the Delete confirmation modal if all we are deleting is just one Contact/ one Location card? Tradeoff between extra click + flow-interruption vs having to retype card if accidentally deleted.
  • Option to delete all Location/ Card cards at once? Otherwise a user has to individually open each card to delete it.
  • Allow deletion of page if they don't want a contact-us.md page?

Copy link
Contributor

@alexanderleegs alexanderleegs left a comment

Choose a reason for hiding this comment

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

Left a few comments. In addition, there were some other things we could possibly consider modifying:

  • Editing a field automatically shifts the editor view back to the start of a section (e.g. editing a location will bring you to the very first location), which is problematic for long sections - the viewer should only snap back to the item being edited
  • We might want to provide a way to add and delete sections - there's no way to remove or add a new section entirely currently
  • We could implement a check for any edited data and give a warning if the user is navigating away with unsaved changes, similar to editHomepage
  • One other thing is that on a site with no contact-us to begin with, there's no way to add a contact-us page. We could possible consider giving the option to create a new contact-us page, which gives default values? This could also be used in the case that the contact-us page is empty. Am open to suggestions on this

src/components/FolderCard.jsx Outdated Show resolved Hide resolved
src/utils/validators.js Outdated Show resolved Hide resolved
Copy link
Contributor

@kwajiehao kwajiehao left a comment

Choose a reason for hiding this comment

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

Left a couple of comments - other comments to be discussed offline

setCollections(collectionsResp.data?.collections)
const fetchData = async () => {
try {
await axios.get(`${BACKEND_URL}/sites/${siteName}/pages/contact-us.md`);
Copy link
Contributor

Choose a reason for hiding this comment

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

For this part, you might want to rebase to the latest staging branch. To avoid memory leaks with this API call (refer to #242), we use a local variable _isMounted and only update state when _isMounted === true, so in this case it would be

if (_isMounted) setContactUsCard(true)

default: { // others
return (
/* TODO: CSP validation should be done on html elements before rendering */
<div dangerouslySetInnerHTML={{__html: d[key]}} key={i}/>
Copy link
Contributor

Choose a reason for hiding this comment

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

I forgot what the use case was here - why is this not also a <p> like the others? Reference from the customs website for this portion:

<p class="margin--top--none margin--bottom--none">For queries and appeals pertaining to a Notice of Customs Offence by Singapore Customs Special Investigation Branch</p>

Copy link
Contributor Author

@gweiying gweiying Nov 26, 2020

Choose a reason for hiding this comment

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

We support html tags here, such for A-star NRP raw file:

  - title: Feedback
    content:
    - other: We would love to hear what you have to say! Fill in a feedback form <a href="https://form.gov.sg/#!/5fab84f4ec6c950011f3e8ba">here</a>!

Copy link
Contributor

Choose a reason for hiding this comment

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

I forgot what the conclusion was here - the problem is that in practice the html tags are wrapped inside the <p> tag, but we're unable to dangerously set inner html for p tags right?

@kwajiehao
Copy link
Contributor

Left a few comments. In addition, there were some other things we could possibly consider modifying:

  • Editing a field automatically shifts the editor view back to the start of a section (e.g. editing a location will bring you to the very first location), which is problematic for long sections - the viewer should only snap back to the item being edited
  • We might want to provide a way to add and delete sections - there's no way to remove or add a new section entirely currently
  • We could implement a check for any edited data and give a warning if the user is navigating away with unsaved changes, similar to editHomepage
  • One other thing is that on a site with no contact-us to begin with, there's no way to add a contact-us page. We could possible consider giving the option to create a new contact-us page, which gives default values? This could also be used in the case that the contact-us page is empty. Am open to suggestions on this

@alexanderleegs RE: the last point on no Contact Us page, Alexis and I had discussed this separately and since most repositories have a Contact Us page, we'll first go off the assumption that repos have a contact us page, and if they don't, then just don't display the Contact Us card for now.

@isomerpages isomerpages deleted a comment from kwajiehao Nov 26, 2020
@gweiying
Copy link
Contributor Author

^ Deleted @kwajiehao's comment accidentally, comment was about multi-line form field validation vs single-line form field validation (can't find option to undo delete)

Copy link
Contributor

@kwajiehao kwajiehao left a comment

Choose a reason for hiding this comment

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

Left comments

const URL_REGEX_PART_2 = '.com/)([a-zA-Z0-9_-]+(/)?)+$';
const PHONE_REGEX = '^\\+65(6|8|9)[0-9]{7}$'
const TOLLFREE_PHONE_REGEX = '^1800[0-9]{7}$'
const EMAIL_REGEX = '^[a-z0-9-_\.]+@[a-z0-9-]+\.[a-z]{2,4}$';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we consider using a more established email regex (like https://emailregex.com/)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, will change this

default: { // others
return (
/* TODO: CSP validation should be done on html elements before rendering */
<div dangerouslySetInnerHTML={{__html: d[key]}} key={i}/>
Copy link
Contributor

Choose a reason for hiding this comment

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

I forgot what the conclusion was here - the problem is that in practice the html tags are wrapped inside the <p> tag, but we're unable to dangerously set inner html for p tags right?

break;
}
case 'location': {
const { locations } = state.frontMatter;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused line of code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (value && !alphanumericRegexTest.test(value)) {
errorMessage += `Field should only contain alphanumeric characters. `
}
if (value && !value.length < LOCATION_OPERATING_HOURS_MIN_LENGTH) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a bug here, it should be value.length < LOCATION_OPERATING_HOURS_MIN_LENGTH instead of !value.length < LOCATION_OPERATING_HOURS_MIN_LENGTH

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (value && !value.length < LOCATION_OPERATING_HOURS_MIN_LENGTH) {
errorMessage += `Field should be longer than ${LOCATION_OPERATING_HOURS_MIN_LENGTH} characters.`
}
if (value && !value.length > LOCATION_OPERATING_HOURS_MAX_LENGTH) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same bug as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gweiying gweiying linked an issue Dec 1, 2020 that may be closed by this pull request
Copy link
Contributor

@kwajiehao kwajiehao left a comment

Choose a reason for hiding this comment

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

lgtm, remaining changes will be reviewed in #266

Copy link
Contributor

@alexanderleegs alexanderleegs left a comment

Choose a reason for hiding this comment

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

lgtm

…tact-us template page, renames old Breadcrumb as PageHeader and updates Breadcrumb references in LeftNavPage and SimplePage as well as isomer-template.scss
… isHomepage and isCollection to a single page type string as there are 4 different page types to consider now, updates references to isHomepage and isCollection in Workspace, FolderCard and Resources, adds contact-us route to App
…lly intended for reuse in contact contents; updates NewSectionCreator to use Dropdown component
…used as a series of fields without each having a title such as the address fields in Contact Us
gweiying and others added 6 commits December 4, 2020 08:53
* fix: suppresses dropdown for Contact Us Folder Card dropdown options

* fix: removes hardcoded sectionId, passing sectionId as argument

* fix: updates displaySections to use locations, contacts as key values, simplifies indexing updates for OnDragEnd, createHandler, deleteHandler, displayHandler

* fix: adds check if frontMatter.contacts or frontMatter.locations array is empty, if empty the key-value pair is removed and not saved

* fix: updates templates to use forwarded react references

* fix: updates scrollRefs to use React.createRef() and forward references to templates, also updates scroll behavior for onFieldChange, onDragEnd, deleteHandler, createHandler and displayHandler

* fix: fixes error in operatingHours validation, adds case for validating map links

* fix: clean up comments, whitespace

* fix: checks whether content has been edited and shows navigate away warning accordingly

* fix: uses deep cloning to sanitise frontMatter

* fix: sets background color for contactUs edit preview

* fix: buffs up email validation

* fix: add packages for DOMPurify

* fix: uses DOMPurify to prevent XSS scripts from rendering on Contacts descriptions

* fix: fixes paragraph stylistic formatting on Contacts description

* fix: fixes form field width for operating hours to not resize with error length

* fix: resolves stylistic differences in links and span text

* fix: adds parent style around links in ContactSection Templates

* fix: cleans up scrollIntoView

* fix: adds key to dropdown options to resolve unique id warning

* install: adds packages for react-input-mask

* feat: creates InputMaskFormField using react-input-mask for FormFields that can use masked input styling, for example dates, phone numbers and so on

* feat: adds state hook to Contact Fields to support masked input styling for the Phone Number field, uses Dropdown to set state

* fix: simplifies validation for Contact Fields phone number as masked input provides user cues for length of phone number already

* fix: rectifies relative imports

* fix: cleans up warning errors in validation

* fix: fix initialized state in state hook

* fix: filters dropdown before mapping to remove arrow function warning

* fix: sets font size for error and info messages since span has been set by default to inherit parent font-size

* fix: uses info message style for notes

* fix: removes extraneous terms from automated url generation and sets View Map link to open in a new page

* fix: adds Delete modal for each Location and Contact

* feat: add styling for error cards

* feat: uses red border to highlight sections and cards that contain errors, border is only highlighted when section/card is minimized

* fix: fix title overflow bug

* fix: removes default value if user does not select phone number field

* fix: clean up dataSanitisers and add initial values for maps_links and titles

* fix: removes min length for title

* fix: sets min length of titles to 1

* fix: change Add button to singular form instead of plural as in Contact and Location not contacts and locations
@gweiying gweiying force-pushed the feat/contact-us-page branch from c432942 to 9548a83 Compare December 4, 2020 08:24
@gweiying gweiying merged commit aefeae3 into staging Dec 4, 2020
@gweiying gweiying deleted the feat/contact-us-page branch December 4, 2020 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EditContactUsPage layout
3 participants