fix(dashboard): correct birthday validation on member creation

This commit is contained in:
Jake/Rads 2022-06-07 19:05:40 +02:00
parent 937867b047
commit 1a0a9e4ef3

View File

@ -59,17 +59,28 @@
} }
if (data.birthday) { if (data.birthday) {
if (!moment(data.birthday, 'YYYY-MM-DD').isValid()) { let allowedFormats = ['YYYY-MM-DD','YYYY-M-D', 'YYYY-MM-D', 'YYYY-M-DD'];
if (moment(data.birthday, 'MM-DD').isValid()) {
// 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; 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 { } else {
err.push(`${data.birthday} is not a valid date, please use the following format: YYYY-MM-DD. (example: 2019-07-21)`); 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; err = err;
if (err.length > 0) return; if (err.length > 0) return;