Import UI crashes when configuring date-field in non-Scandinavian country
Closed this issue · 0 comments
Description
The recent addition of date format parsing in the importer UI assumes that all countries have equivalents of the Swedish/Norwegian/Danish concept of "personnummer" that consist of dates. When used in an organization with a different country code than SE/NO/DK, it crashes.
Steps to reproduce
- On the dev server, modify org 1 (using a PATCH request to https://app.dev.zetkin.org/api/orgs/1) to have country code
UK
- Go to https://app.dev.zetkin.org/organize/1/people
- Click "Create"
- Click "import people"
- Drop any CSV
- For any column, pick "Extra date" as the field to import into
Expected Behaviour
You should be allowed to configure the parsing.
Actual Behaviour
Crash
Screenshots (if you have any)
Proposed solution
The root of the issue seems to be this logic:
app.zetkin.org/src/features/import/hooks/useDateConfig.ts
Lines 53 to 63 in 13a6320
Note how the type cast on line 59 claims that any string will be 'se' | 'dk' | 'no'
. Typecasts are dangerous. Removing the typecast will reveal the error, and force an if statement to make sure that the string is actually what this logic assumes it is (which it isn't when the org country is Germany or UK, for example).