futurice/masifunde-fe

Name: masifunde-fe

Owner: Futurice

Description: Website for masifunde

Created: 2017-07-14 09:34:00.0

Updated: 2018-05-09 10:04:32.0

Pushed: 2018-05-17 15:08:19.0

Homepage: https://www.masifunde.de

Size: 4337

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Masifunde

Frontend for the Masifunde website. https://masifunde.netlify.com

Installing / Getting started
install
run dev

This will run nodemon with server.js which will run next.js development environment on port 3000.

Developing
Built With

Next.js, React, Styled-components, Bootstrap 4, Contentful, Fundraisingbox.

Prerequisites

Node 8 is required with NPM.

Building

To generate:

run build-static

It will run next.js next build && next export commands which will generate static files in the out folder. It will ONLY export and statically generate routes which are defined in next.config.js file.

Deploying / Publishing

The site is hosted on Netlify, which requires static files. Netlify will automatically run npm run build-static whenever anything is pushed to the master branch since it is connected to this GitHub repository. After that the changes should be reachable on https://masifunde.netlify.com.

When creating a Pull Request (PR) to master, Netlify will build and publish the merge result as a preview under deploy-preview-[preview-number]--masifunde.netlify.com.

Note that most Netlify build and deploy settings are defined in netlify.toml in this repository, which override those seen in the Netlify dashboard! See the Netlify “Deploy Contexts” documentation. (Hopefully in the future, Netlify will hide the settings that we define in netlify.toml to reduce confusion.)

Configuration
Feature Flags

We have a feature flags mechanism for decoupling the release of features from deployment. The currently existing flags can be seen in featureFlags.js.

By default, all feature flags are enabled during development and disabled for production. You can override this default by setting an environment variable called ENABLED_FEATURES, like this:

able exactly feature1 and feature2
LED_FEATURES=feature1,feature2 npm run dev

able all features (the default during development)
LED_FEATURES=all npm run dev

sable all features (the default in production)
LED_FEATURES= npm run dev

The special all value always enables all feature flags.

Remember that feature flags are always temporary. Once a feature behind a flag goes to production, simply remove the flag altogether.

Occasionally, you might experience that the site doesn't update properly after restarting the development server with a different ENABLED_FEATURES setting. In that case, try removing the node_modules/.cache folder.

Bootstrap + styled-components

We use Bootstrap 4 for two purposes.

  1. Responsive grid system
  2. Style consistency across browsers (reboot.css)

Our components are given custom styling using styled-components - a CSS-in-JS library.

Fundraisingbox

The service used to accept user donations is called Fundraisingbox, which Masifunde has previous experience with.

Masifunde's Fundraisingbox plan doesn't allow for using the API, but we get access to an iframe we embed on our site. We can embed 4 different iframe forms at a time. To configure the iframe, sign in to Masifunde's Fundraisingbox admin interface and go to Einstellungen > Spendenformular and select the relevant Spendenformular in the dropdown.

To fully customize the form, we hide most of the inputs in iframe, while rendering our own form fields outside of the iframe. We then populate the iframe with these custom form field values. This forces a reload and rerender of the iframe, which causes flickering. So we only do this when all custom form fields have values.

Einbettungsadresse (form embed url)

The Einbettungsadresse should specify the full url of the page this form is used (e.g https://www.masifunde.de/wie-sie-helfen/spenden), and not just the host https://www.masifunde.de. On a successful (or failed) donation attempt, the user gets redirected to the exact url in Einbettungsadresse with a status query param. Then a success or error message is displayed in the iframe. If the page doesn't have the Fundraisingbox iframe, no success or error message will be displayed.

iframe styling
  1. Sign in to Masifunde's Fundraisingbox admin interface.
  2. Then go to Einstellungen > Spendenformular and select the relevant Spendenformular in the dropdown.
  3. Scroll to the bottom of the textarea at the bottom of the page in the section Design.

By checking the box for Keine Standard-Stylesheets laden the Fundraisingbox iframe will use the css written in the textarea.

Note: This has to be standard css, no scss or less.

For version control and backup purposes we also store this css in the file Fundraisingbox_custom_css.css in this repo.

Testing Fundraisingbox locally

Fundraisingbox only displays the form in the iframe if you load the iframe from a specified domain, e.g. masifunde.netlify.com. In order to test it locally you need to expose your localhost. You can use ngrok for this. Install ngrok and run the command `ngrok http 3000 --region eu`. You will then see the address to which ngrok exposes your localhost.

  1. Log into Masifunde's Fundraisingbox.
  2. In the top right go to Einstellungen > Spendenformular.
  3. In the “Welches Formular wollen Sie bearbeiten” dropdown select the relevant Fundraising form.
  4. Paste your ngrok address into the field “Einbettungsadresse”.
  5. Save.
  6. If you go to your ngrok address you should now be able to see the Fundraising form.
Contentful CMS

The project uses Contentful as a CMS, which has its own JavaScript package. To better understand the API structure you should sign in to Contentful and have a look at Content models to see how they are structured. The credentials can be found in the Futurice password safe.

Content model naming convention

Meta data:

Hero (hero image not through Contentful):

Page intro:

Banner:

Page section: For each section of the page, we prefix the fields with “section“:

Tests

No tests for now.

Style guide

Project uses ESLint Airbnb style guide with some tweaks (like no semicolons). The precommit git hook will automatically run ESLint to check if the code complies with the rules. If it fails then it will not push to the repo.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.