EMed

Customer website for an at-home telehealth test kit company

Project setup and tooling, product and cart pages, identity-document upload for sign-up, and over half of the test code

  • web
  • e-commerce
  • front-end
  • Typescript
  • React
  • Gatsby
  • Styled Components
  • Contentful
  • Moltin
  • GraphQL
  • AWS
  • static
  • Apply

This is the first version of the customer-facing website for eMed, a digital health company selling at-home telehealth test kits (at the time, COVID-19 tests). I built it with Apply Digital in 2020, as part of a team which grew to around seven developers.

Tech

It’s a Gatsby and React app written in TypeScript. Product data comes from Moltin (now Elastic Path Commerce Cloud), editorial content from Contentful, and authentication from AWS Amplify. The public pages are built to static files and deployed to S3, and the account pages (sign-up, profile, orders, a symptom checker) render in the browser.

Starting the project

I created the repository on 17 July and for the first four weeks was its only committer. That meant setting up everything the team would lean on: type checking, with the starter’s components converted to TypeScript, ESLint and Prettier with a pre-commit hook, styled-components with themeable components, and Jest for unit tests, with a first test for the product grid. I also wired up the Moltin source so that products appeared in a list and each had a page. I tried a monorepo with yarn workspaces for a week or so before dropping it for a single package.

The cart

Moltin keeps the cart on the server, so the front end’s job is to ask for operations and show what’s happening. I built the cart as a React context with a reducer, and typed its actions as a discriminated union: loading, adding, updating, and removing each have start, success, and error actions, so every operation has proper loading and error states. The functions which talk to Moltin live in a separate hook file, which keeps them easy to mock in tests. The cart ID is persisted in localStorage so a returning visitor gets their cart back.

On top of that I built the pieces customers touch: a quantity stepper, the add-to-cart button, the cart page with a contents table and an order summary, and a stock check which caps the quantity at what’s available once the number already in the cart is counted.

Identity documents

Signing up involves verifying identity with a selfie and a photo of an ID document, front and back. I built an image field for the sign-up forms which previews the chosen file, asks the back end for a pre-signed S3 POST, and uploads straight to S3. It reports its state to the form’s validation, and cancels in-flight requests if the user navigates away.

The field listens for drags over the whole window, so every image field on the page lights up its “drop here” state as soon as a file is dragged in, and puts it back when the file is dropped somewhere else. I also learnt that Chrome and Safari don’t offer the photo gallery on a file input when the capture hint is set, whereas Firefox does follow the spec, so I removed the hint.

Tests

I wrote around half of the project’s test code: the cart context and utilities, the stock hook, the product detail page, the stepper, the accordion, and the form fields.