One optional phone number, eleven files, five kinds of empty, and no migration
Yesterday I added an optional phone number to Nakodo. When a creator or a business says yes to a brand, the app introduces them by email, and the brand can now add a number to go with the address. One field, one afternoon, eleven files in the commit, and a good example of where the work in a small feature actually goes. The database part: nothing A campaign's outreach settings are a jsonb column…
Nakodo, an app that introduces creators and businesses to brands, now allows the addition of an optional phone number alongside an address. This feature is introduced through an email, with the brand having the option to include a phone number when they provide an address. The phone number field is made up of eleven files in the commit, with no migration or ALTER TABLE required. The database schema change is a single line in a TypeScript type, as the field is optional and can be null.
The validation of phone numbers is a crucial aspect of this feature, as it helps ensure that the entered numbers are plausible. The validation process involves two regexes: one for checking the characters (like digits, spaces, brackets, dots, and hyphens) and another for counting the digits to ensure the number falls within the valid range.
The rules for accepting a phone number are that it should be plausible and left as written by the brand. Thus, accepted formats include +44 7700 900123, (020) 7946 0018, and 02079460018, while rejecting invalid representations like call the office or ext 4.
The empty field has five different representations: an empty string in the editor, an empty string in the stored jsonb, null in the thread context, a sentence in the read view, and a required prop on the summary card. Each representation of empty serves a specific purpose, with the aim of maintaining clarity and ensuring the absence of a phone number is handled appropriately.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.