import now imports gender
This commit is contained in:
@ -51,7 +51,8 @@ export default function ImportPage() {
|
||||
desiredShiftsIndex: -1,
|
||||
dataStartIndex: -1,
|
||||
isActiveIndex: -1,
|
||||
pubTypeIndex: -1
|
||||
pubTypeIndex: -1,
|
||||
gender: -1
|
||||
});
|
||||
|
||||
const handleFile = (e) => {
|
||||
@ -111,6 +112,7 @@ export default function ImportPage() {
|
||||
headerRef.current.desiredShiftsIndex = header.indexOf('Желан брой участия');
|
||||
headerRef.current.isActiveIndex = header.indexOf("Неактивен");
|
||||
headerRef.current.pubTypeIndex = header.indexOf("Назначение");
|
||||
headerRef.current.gender = header.indexOf("Пол");
|
||||
|
||||
const filteredData = sheetData.slice(headerRef.current.dataStartIndex).map((row) => {
|
||||
let date;
|
||||
@ -147,12 +149,16 @@ export default function ImportPage() {
|
||||
|
||||
let isOld = false;
|
||||
const row = rawData[i];
|
||||
let email, phone, names, dateOfInput, oldAvDeleted = false, isTrained = false, desiredShiftsPerMonth = 4, isActive = true, publisherType = PublisherType.Publisher;
|
||||
//const date = new Date(row[0]).toISOS{tring().slice(0, 10);
|
||||
let email, phone, names, dateOfInput, oldAvDeleted = false,
|
||||
isTrained = false, desiredShiftsPerMonth = 4, isActive = true,
|
||||
publisherType = PublisherType.Publisher,
|
||||
isMale = 0
|
||||
;
|
||||
//ToDo: structure all vars above as single object:
|
||||
|
||||
if (mode.mainMode == MODE_PUBLISHERS1) {
|
||||
|
||||
email = row[headerRef.current.emailIndex];
|
||||
|
||||
phone = row[headerRef.current.phoneIndex].toString().trim(); // Trim whitespace
|
||||
// Remove any non-digit characters, except for the leading +
|
||||
//phone = phone.replace(/(?!^\+)\D/g, '');
|
||||
@ -165,11 +171,11 @@ export default function ImportPage() {
|
||||
names = row[headerRef.current.nameIndex].normalize('NFC').split(/[ ]+/);
|
||||
dateOfInput = importDate.value || new Date().toISOString();
|
||||
// not empty == true
|
||||
|
||||
isTrained = row[headerRef.current.isTrainedIndex] !== '';
|
||||
isActive = row[headerRef.current.isActiveIndex] == '';
|
||||
desiredShiftsPerMonth = row[headerRef.current.desiredShiftsIndex] !== '' ? row[headerRef.current.desiredShiftsIndex] : 4;
|
||||
publisherType = row[headerRef.current.pubTypeIndex];
|
||||
isMale = row[headerRef.current.gender].trim().toLowerCase() === 'брат';
|
||||
}
|
||||
else {
|
||||
dateOfInput = common.excelSerialDateToDate(row[0]);
|
||||
@ -201,7 +207,7 @@ export default function ImportPage() {
|
||||
let personNames = names.join(' ');
|
||||
try {
|
||||
try {
|
||||
const select = "&select=id,firstName,lastName,email,phone,isTrained,desiredShiftsPerMonth,isActive,type,availabilities";
|
||||
const select = "&select=id,firstName,lastName,email,phone,isTrained,desiredShiftsPerMonth,isActive,isMale,type,availabilities";
|
||||
const responseByName = await axiosInstance.get(`/api/?action=findPublisher&filter=${names.join(' ')}${select}`);
|
||||
let existingPublisher = responseByName.data[0];
|
||||
if (!existingPublisher) {
|
||||
@ -244,11 +250,8 @@ export default function ImportPage() {
|
||||
} else {
|
||||
data[i - mode.headerRow][4] = "existing";
|
||||
}
|
||||
|
||||
// Log existing publisher
|
||||
common.logger.debug(`Existing publisher '${[existingPublisher.firstName, existingPublisher.lastName].join(' ')}' found for ${email} (ID:${personId})`);
|
||||
|
||||
|
||||
// Check for other updates
|
||||
const fieldsToUpdate = [
|
||||
{ key: 'email', value: email },
|
||||
@ -256,6 +259,7 @@ export default function ImportPage() {
|
||||
{ key: 'desiredShiftsPerMonth', value: desiredShiftsPerMonth, parse: parseInt },
|
||||
{ key: 'isTrained', value: isTrained },
|
||||
{ key: 'isActive', value: isActive },
|
||||
{ key: "isMale", value: isMale },
|
||||
{ key: 'type', value: publisherType, parse: common.getPubTypeEnum }
|
||||
];
|
||||
|
||||
@ -277,6 +281,7 @@ export default function ImportPage() {
|
||||
data[i - mode.headerRow][4] = fieldsToUpdateString.substring(0, fieldsToUpdateString.length - 2)
|
||||
+ " updated";
|
||||
} catch (error) {
|
||||
data[i - mode.headerRow][4] = "error updating!";
|
||||
console.error(`Failed to update publisher ${personId} - Fields Attempted: ${fieldsToUpdateString}`, error);
|
||||
}
|
||||
}
|
||||
@ -309,6 +314,7 @@ export default function ImportPage() {
|
||||
firstName: firstname,
|
||||
lastName: names[names.length - 1],
|
||||
isActive: isActive,
|
||||
isMale: isMale,
|
||||
isTrained,
|
||||
desiredShiftsPerMonth
|
||||
});
|
||||
|
Reference in New Issue
Block a user