fix(dashboard): correct birthday validation on member creation
This commit is contained in:
parent
937867b047
commit
1a0a9e4ef3
@ -59,17 +59,28 @@
|
||||
}
|
||||
|
||||
if (data.birthday) {
|
||||
if (!moment(data.birthday, 'YYYY-MM-DD').isValid()) {
|
||||
if (moment(data.birthday, 'MM-DD').isValid()) {
|
||||
let allowedFormats = ['YYYY-MM-DD','YYYY-M-D', 'YYYY-MM-D', 'YYYY-M-DD'];
|
||||
|
||||
// replace all brackets with dashes
|
||||
if (data.birthday.includes('/')) {
|
||||
data.birthday = data.birthday.replaceAll('/', '-');
|
||||
}
|
||||
|
||||
// add a generic year if there's no year included
|
||||
// NOTE: for some reason moment parses a date with only a month and day as a YEAR and a month
|
||||
// so I'm just checking by the amount of dashes in the string
|
||||
if (data.birthday.split('-').length - 1 === 1) {
|
||||
data.birthday = '0004-' + data.birthday;
|
||||
}
|
||||
|
||||
// try matching the birthday to the YYYY-MM-DD format
|
||||
if (moment(data.birthday, allowedFormats, true).isValid()) {
|
||||
// convert the format to have months and days as double digits.
|
||||
data.birthday = moment(data.birthday, 'YYYY-MM-DD').format('YYYY-MM-DD');
|
||||
} else {
|
||||
err.push(`${data.birthday} is not a valid date, please use the following format: YYYY-MM-DD. (example: 2019-07-21)`);
|
||||
}
|
||||
}
|
||||
if (data.birthday.includes('/')) {
|
||||
data.birthday.replace('/', '-');
|
||||
}
|
||||
}
|
||||
|
||||
err = err;
|
||||
if (err.length > 0) return;
|
||||
|
Loading…
Reference in New Issue
Block a user