Add a new business unit
There are several places which need to be changed when adding a business unit with a new locale. Which will be described in this How To.
Adding a locale to the Business Unit
Once the business unit is added to the company-table you’ll need to add the locale. It’s best to add this to the company-seed-table-with-locale.js file found within the company/ folder in cli-scripts-legacy. Run it through the Luna CLI: luna -e production script run cli-scripts-legacy/company/index.js --modules cli-scripts-legacy -- company-seed-table-with-locale -e production. Here are a list of examples:
| Unit | Locale |
|---|---|
| Club Turing | en-GB-ENG |
| Club Newton | en-GB-ENG |
| Club Somerville | en-GB-SCT |
| Club Aletta | nl-NL |
| Club Germany ??? | de-DE |
| Club America ??? | en-US |
These locales were sourced from RFC 5646 Language tags
In general, the structure of the locale follows the format of language-country-(region). Although en-GB is an edge case because the region part of the locale is actually a country within the UK! The way how it will work is that en-GB-SCT will extend any values or options for the en-GB locale within the config-table (which we will explain in the next step)
Populating the config table for the locale
We are using the config table to store information that the user should see. It does not contain any validation rules. The validation rules will need to be added to both the front end and back end code.
The config-table used to contain a locale-type-GSI which allowed us to query for locale and the type of config we want. This has since been refactored into a table with a domain-key primary key in order to be used for more general config, not just those related to specific locales. In the case of locale config, it is possible to query for it by looking for records with domain=ANDI and key beginning with locale.replaceAll("-", "_").toUppercase() e.g. EN_GB. The config API has been refactored to ensure the existing getConfig thunk in the Luna FE still returns the expected config structure for a locale.
There are 2 types of locale:
options: Static sets of values used for drop-down lists or fields with multiple values. For example:workingHours: [22.5,30,37.5]
values: Static names / values that are used to display the same data differently on the page depending on localisation. For example:currency: 'GBP'identityName: 'National Insurance Number'bankDetails: ['accountName', 'accountNumber', 'sortCode']This one might seem strange because it’s an array of strings even though I mentioned above thatoptionscontains a list of options. However, the main difference is thatbankDetailsis composed of multiple individual fields which will come in useful when we write the validation rules. The user will never be able to selectaccountName,accountNumberorsortCodefrom some sort of dropdown.
Below is a snapshot of the old config table:
| locale (PK) | type (SK) | identityName | workingHours | publicHolidays |
|---|---|---|---|---|
| en-GB | values | National Insurance Number | 8 | |
| en-GB | options | [22.5, 30, 37.5] | ||
| en-GB-SCT | values | 11 | ||
| nl-NL | values | Citizen Service Number (BSN) | ||
| nl-NL | options | [40] |
In the new table structure, this has become:
|domain (PK)|key (SK)|data| |---|---|---|---|---| |ANDI|EN_GB#IDENTITY_NAME_VALUE|National Insurance Number| |ANDI|EN_GB#WORKING_HOURS_OPTIONS|[22.5, 30, 37.5]| |ANDI|EN_GB_SCT#PUBLIC_HOLIDAYS_NUMBER|11| |ANDI|NL_NL#IDENTITY_NAME_VALUE|Citizen Service Number (BSN)| |ANDI|NL_NL#WORKING_HOURS_OPTIONS|[40]|
Note: Although, no config specific to the Scotland locale (en-GB-SCT) is actually present in the current config table (as of time of writing).
Seeding the config table
To add config for a new locale, a query should be performed to identify the config records for an existing locale e.g. domain=ANDI and key beginning with EN_GB. For each record in this set, an equivalent record should be created with the corresponding data for the new locale being added.
Creating a pipeline for the new business unit
The Win Opportunities app assumes that each Club, Cloud or Consulting (3C’s) business unit e.g Club Turing, Cloud Engineering - North and AND Consulting have their own pipeline. We have a table called opportunities-pipelines which stores all the pipelines. Each pipeline has a type which is one of:
CLIENT_PARTNERSHIPCLUB_CLOUD_CONSULTING
Once the business unit is created in the company-table it might also be worth adding their pipeline. There exists a command which can be run through the Luna CLI like: luna -e production script run cli-scripts-legacy/index.js --modules cli-scripts-legacy -- pipeline-add-new-pipeline -e production -p {BUSINESS_UNIT_NAME} where BUSINESS_UNIT_NAME matches the name used in the company-table. Once you enter the command, you’ll be prompted to answer the following question:
Is this for a Club/Cloud/Consulting pipeline? (Y/n)
Entering Y will set the type to CLUB_CLOUD_CONSULTING. Entering N will set the type to CLIENT_PARTNERSHIP.
The config endpoint
There shouldn’t need to be any major changes here but this is to give some context as to what it will return for different parameters.
GET /config
| Parameter | Required? | Type | Description |
|---|---|---|---|
| locale | Yes | String | The locale (partial or full) relevant to the business unit to lookup config for |
| type | No | String | The type of config to return. One of: values or options |
GET /config?locale=en-GB- This would lookup the relevant config set for the en-GB locale and return all config values + options.
javascript{ values: { identityName: 'National Insurance Number', publicHolidays: 8 }, options: { workingHours: [22.5, 30, 37.5] } }GET /config?locale=en-GBtype=options- This would lookup the relevant config set for the en-GB locale and return only the “options” set of config.
javascript{ options: { workingHours: [22.5, 30, 37.5] } }GET /config?locale=en-GB&type=values- This would lookup the relevant config set for the en-GB locale and return only the “values” set of config.
javascript{ values: { identityName: 'National Insurance Number', publicHolidays: 8 }, }GET /config?locale=en-GB-SCT&type=values- This would lookup the relevant config set for the en-GB locale, as well as the
en-GB-SCTlocale and return only the “values” set of config. Theen-GB-SCTlocale will override any of theen-GBlocale config.
javascript{ values: { identityName: 'National Insurance Number', publicHolidays: 11 }, }- This would lookup the relevant config set for the en-GB locale, as well as the
Onboarding form
Front end changes
Bank Details:
- All the differences for the validation of the bank details e.g
accountName,sortCode,accountNumberandibanare defined in the fields list within theBankDetailsStepfolder.src/pages/onboarding/components/OnboardingForms/OnboardingForm/OnboardingFormSteps/BankDetailsStep/fields.js. Take note that each field name is prefixed withbankDetails. e.gbankDetails.accountNumber. If in the future, we require different bank details, we will need to add the validation here.
- All the differences for the validation of the bank details e.g
Identification Details:
- There weren’t any changes made here other than rendering the correct label by using the
identityNamestored for the locale.
- There weren’t any changes made here other than rendering the correct label by using the
Starter Checklist:
- Currently, only Business Units in GB require onboarding andis to submit information about their student loans (which are defined as starter checklist).
- Here is a code snippet in
OnboardingForm.jsxwhich filters out this step if the BU is not inen-GB. If in the future a locale requires this, changes will need to be made in this condition.
javascriptif (!andi.locale.includes('en-GB')) { setSteps(steps.filter((step) => step.label !== 'Starter Checklist')); }- Similarly, within
SummaryStep.jsxwe conditionally render the Starter Checklist accordion depending on whether the locale requires this to be filled in or not.
Back end changes
Bank Details:
- Within the relevant per-operation schema under
services/onboarding/schemas/(e.g.createOnboardingProfile.schema.ts,updateOnboardingProfile.schema.ts), you’ll need to define the bank details schema for the locale and define it as a new object within the switch statement for thebankDetailsfield.
- Within the relevant per-operation schema under
Starter Checklist:
- Within the relevant per-operation schema under
services/onboarding/schemas/, you’ll need to define the starter checklist schema for the locale and define it as a new object within the switch statement for thestarterChecklistfield. Currently, we define whether it is optional or required.
- Within the relevant per-operation schema under
Update Andi Details Form:
The only difference we need to consider in the form is the Bank Details Section.
Front end changes
The config will dynamically render the fields for the bank details section. However, you will need to add the Yup schema for any new locales for this section. Within clients/luna-front-end/src/pages/newProfile/PayrollDetails/Sections/BankDetails/FormModel/validationSchema.js, there is an exported object called localeBankDetailsSchema where the key is the locale of the user. The value of the key is the Yup schema validation for that locale. As a result, you will need to set the key to the new locale and define it’s schema.
localeBankDetailsSchema is used in the UpdateAndiDetails component by getting the bank details schema for that locale and concatenating it onto the schema which defines the rest of the form.
NOTE: If the bank details schema cannot be found in localeBankDetailsSchema, it will default to gbBankDetailsSchema which defines: accountName, accountNumber and sortCode.
Back end changes
- Bank Details:
- Within
andi.schema.ts, you’ll need to define the bank details schema for the locale and define it as a new object within the switch statement for thebankDetailsfield.
- Within
Payments and deductions form:
The only things we need to consider for this form is when a new config is added, we need to make sure we’re maintaining the currencySymbols list within the front end code otherwise it will not render the currency symbol against any payments/deductions.
Front end changes
In the front end, navigate to the utils/constants/currencySymbols.js and add the new currency symbol for the new config that you’re adding. For example, if you’re adding Australian dollar, you would add a
currencySymbols.set('AUD', '$');
