Simplelease
Web app for drafting, negotiating, and signing commercial leases
Most front-end development, and some API fixes
Simplelease was a platform for putting a commercial lease through its whole life: drafting it, negotiating it, signing it, and then paying against it. I joined the front-end work in September 2019, a couple of weeks after the repository was created, and stayed until March 2020. I don’t believe it ever had a successful public launch.
What it did
A landlord adds properties and builds a lease from a template (office was the main one; retail and industrial were stubs while I was there). The lease is versioned as it’s edited, and team members can comment on any section of it. The finished lease is sent to a tenant as an offer. The tenant verifies a bank account, signs electronically, and the landlord countersigns. After that, both sides can see the payment schedule and the transactions.
Landlords and tenants each have their own teams, roles, and permissions, and see different views of the same lease.
Tech
The front end is React with hooks throughout, and deliberately no Redux. It talks to a GraphQL API through Apollo Client, uses Formik and Yup for forms, react-intl for strings, react-table for the many lists, and a customized Bootstrap theme written in Sass. The lease itself is edited through forms generated from Json schemas. Bank verification uses Plaid. Tests were Jest for components and Cypress (with Cucumber-style features) end to end.
The back end is Rails 6 serving GraphQL, with Devise and JWTs for authentication, Postgres, and Heroku for hosting. That side was mostly owned by another developer, and I only made small changes there.
What I worked on
After the Create React App scaffold, I wrote the first real application code: the API client, the authentication layer, and the login and password-reset forms. After that I worked on most areas of the front end, and ended up as its largest contributor by commit count. The parts I’m most connected to are authentication, team and permission management, the lease comment threads, and the tenant-facing pages for offers, transactions, and payments.
Authentication
The API issues a short-lived JWT, and a refresh token in a cookie. I made the cookie inaccessible to Javascript and scoped it to the refresh endpoint alone, so the browser doesn’t send it along with every other request. The front end schedules a refresh shortly before the token expires, and if that fails, logs the user out.
A few details took some care. User data arrives from two places, REST on login and refresh and GraphQL afterwards, with different fields, so the two are merged. Logging out has to reset the Apollo cache, skip the API call if the token is already dead, and ignore any user-details response that arrives after the user has gone. And on the API side, a failed authentication on the GraphQL endpoint was being returned as a 200, which Apollo handled badly, so I changed it to a proper 401.
Permissions
Permissions work in two layers:
what a team member may do (keys such as landlord-sign or tenant-comment),
and which properties they may do it on.
The front end has a hasPermission check to hide or disable things,
though of course the API remains the authority.
While testing the “add property” flow I found that the API wasn’t filtering team permissions by whether they were actually allowed, which meant every team member was being given access to every new property. The fix was a few lines, but the bug was a good reminder to test authorization from the other side: not “can the right person do this?” but “can everyone else?”
Comments and autosave
Comment threads attach to individual sections of a lease, per version. They come in two kinds: internal, visible to your own team only, and public, visible to the other party. Threads can be resolved, the navigation shows counts of unresolved ones, and the list defaults to unresolved only.
For autosave, the editor saves ten seconds after the user stops typing, and again every two minutes as a backstop. It sits alongside the document locking and inactivity timeout that teammates built, so a lease can’t be silently edited from two places.
A moving target
The API changed underneath the front end throughout, with fields renamed and statuses added.
Much of the work was keeping queries, GraphQL fragments, and the Apollo cache consistent,
and avoiding refetches that made the interface feel slow.
Around a dozen people committed to the front end alone,
so conventions mattered: a README describing the architecture, Prettier and Eslint with a pre-commit hook,
and data-testid attributes so that QA wasn’t relying on fragile selectors.