tweak imports
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -17,7 +17,7 @@
|
||||
},
|
||||
{
|
||||
"name": "Run npm nodemon (DEV)",
|
||||
"command": "npm run debug", // > _logs/debug.log
|
||||
"command": "npm run debug-npm-env", // > _logs/debug.log
|
||||
"request": "launch",
|
||||
"type": "node-terminal",
|
||||
"preLaunchTask": "killInspector", // <-- Add this line
|
||||
|
@ -57,7 +57,8 @@ export default function PublisherCard({ publisher }) {
|
||||
return isCardVisible ? (
|
||||
// className="block p-6 max-w-sm bg-white rounded-lg border border-gray-200 shadow-md hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700 mb-3"
|
||||
<div id={`publisher-card-${publisher.id}`} className={`relative block p-6 max-w-sm rounded-lg border border-gray-200 shadow-md hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700 mb-3
|
||||
${publisher.isImported ? "bg-orange-50" : (publisher.isTrained ? "bg-white" : "bg-red-50")}`}>
|
||||
${!publisher.isactive ? "opacity-50 bg-gray-200 border-gray-300 text-gray-400" : (publisher.isImported ? "bg-orange-50" : (publisher.isTrained ? "bg-white" : "bg-red-50"))}`}
|
||||
>
|
||||
<a
|
||||
href={`/cart/publishers/edit/${publisher.id}`}
|
||||
className=""
|
||||
|
@ -238,7 +238,7 @@ export default function PublisherForm({ item, me }) {
|
||||
<option value="Publisher">Вестител</option>
|
||||
<option value="Bethelite">Бетелит</option>
|
||||
<option value="RegularPioneer">Редовен Пионер</option>
|
||||
<option value="SpecialPioneer">Специален Пионер/Мисионер</option>
|
||||
<option value="SpecialPioneer_Missionary">Специален Пионер/Мисионер</option>
|
||||
{/* <option value="Missionary">Мисионер</option>
|
||||
<option value="CircuitOverseer">Пътуваща служба</option> */}
|
||||
</select>
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { toast } from 'react-toastify';
|
||||
import Layout from "../../../components/layout";
|
||||
import { Publisher, Availability, AvailabilityType, DayOfWeek, UserRole } from "@prisma/client";
|
||||
import { Publisher, Availability, AvailabilityType, DayOfWeek, UserRole, PublisherType } from "@prisma/client";
|
||||
import ProtectedRoute from '../../../components/protectedRoute';
|
||||
|
||||
import axiosInstance from '../../../src/axiosSecure';
|
||||
@ -144,7 +144,7 @@ export default function ImportPage() {
|
||||
await new Promise(r => setTimeout(r, 100));
|
||||
|
||||
const row = rawData[i];
|
||||
var email, phone, names, dateOfInput, oldAvDeleted = false, isTrained = false, desiredShiftsPerMonth = 4, isActive = false;
|
||||
var email, phone, names, dateOfInput, oldAvDeleted = false, isTrained = false, desiredShiftsPerMonth = 4, isActive = false, publisherType = PublisherType.Publisher;
|
||||
//const date = new Date(row[0]).toISOS{tring().slice(0, 10);
|
||||
if (mode.mainMode == MODE_PUBLISHERS1) {
|
||||
|
||||
@ -165,6 +165,7 @@ export default function ImportPage() {
|
||||
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];
|
||||
}
|
||||
else {
|
||||
dateOfInput = common.excelSerialDateToDate(row[0]);
|
||||
@ -179,10 +180,17 @@ export default function ImportPage() {
|
||||
let personId = '';
|
||||
try {
|
||||
try {
|
||||
const select = "&select=id,firstName,lastName,phone,isTrained,desiredShiftsPerMonth,isactive,availabilities";
|
||||
const select = "&select=id,firstName,lastName,phone,isTrained,desiredShiftsPerMonth,isactive,type,availabilities";
|
||||
const responseByName = await axiosInstance.get(`/api/?action=findPublisher&filter=${names.join(' ')}${select}`);
|
||||
let existingPublisher = responseByName.data[0];
|
||||
if (!existingPublisher) {
|
||||
// Check if email is empty and generate a system one if needed
|
||||
if (!email) {
|
||||
const fullName = names.join(' ').toLowerCase(); // Assuming names is an array of [firstName, lastName]
|
||||
email = fullName.replace(/\s+/g, '.'); // Replace spaces with dots
|
||||
email += "";//@gmail.com? // Append a domain to make it a valid email format
|
||||
}
|
||||
|
||||
// If no match by name, check by email
|
||||
const responseByEmail = await axiosInstance.get(`/api/?action=findPublisher&email=${email}${select}`);
|
||||
if (responseByEmail.data.length > 0) {
|
||||
@ -199,7 +207,8 @@ export default function ImportPage() {
|
||||
// Create a flag to check if update is needed
|
||||
const updatedData = {};
|
||||
personId = existingPublisher?.id;
|
||||
let updateNeeded = false;
|
||||
let fieldsToUpdateString = '';
|
||||
|
||||
|
||||
// Check for name update
|
||||
const fullName = names.join(' ');
|
||||
@ -209,7 +218,7 @@ export default function ImportPage() {
|
||||
updatedData.firstName = names[0];
|
||||
updatedData.lastName = names.slice(1).join(' ');
|
||||
data[i - mode.headerRow][4] = "name updated!";
|
||||
updateNeeded = true;
|
||||
fieldsToUpdateString += `name, `;
|
||||
} else {
|
||||
data[i - mode.headerRow][4] = "existing";
|
||||
}
|
||||
@ -220,27 +229,33 @@ export default function ImportPage() {
|
||||
|
||||
// Check for other updates
|
||||
const fieldsToUpdate = [
|
||||
{ key: 'email', value: email },
|
||||
{ key: 'phone', value: phone },
|
||||
{ key: 'desiredShiftsPerMonth', value: desiredShiftsPerMonth, parse: parseInt },
|
||||
{ key: 'isTrained', value: isTrained },
|
||||
{ key: 'isactive', value: isActive }
|
||||
{ key: 'isactive', value: isActive },
|
||||
{ key: 'type', value: publisherType, parse: common.getPubTypeEnum }
|
||||
];
|
||||
|
||||
fieldsToUpdate.forEach(({ key, value, parse }) => {
|
||||
if (!existingPublisher[key] && value !== '' && value !== undefined) {
|
||||
const newValue = parse ? parse(value) : value;
|
||||
// Check if an update is needed: if the existing value is different or not set, and the new value is not empty/undefined
|
||||
if ((existingPublisher[key] !== newValue && value !== '' && value !== undefined)
|
||||
|| (!existingPublisher.hasOwnProperty(key) && value !== '' && value !== undefined)) {
|
||||
updatedData[key] = parse ? parse(value) : value;
|
||||
updateNeeded = true;
|
||||
fieldsToUpdateString += `${key}, `;
|
||||
}
|
||||
});
|
||||
|
||||
// Update the record if needed and if MODE_PUBLISHERS1 (Import from List of Participants)
|
||||
if (updateNeeded && (mode.publishers2Import || mode.mainMode == MODE_PUBLISHERS1)) {
|
||||
if (fieldsToUpdateString.length > 0 && (mode.publishers2Import || mode.mainMode == MODE_PUBLISHERS1)) {
|
||||
try {
|
||||
await axiosInstance.put(`/api/data/publishers/${personId}`, updatedData);
|
||||
common.logger.debug(`Updated publisher ${personId}`);
|
||||
data[i - mode.headerRow][4] = "updated";
|
||||
common.logger.debug(`Updated publisher ${personId} - Fields Updated: ${fieldsToUpdateString}`);
|
||||
data[i - mode.headerRow][4] = fieldsToUpdateString.substring(0, fieldsToUpdateString.length - 2)
|
||||
+ " updated";
|
||||
} catch (error) {
|
||||
console.error(`Failed to update publisher ${personId}`, error);
|
||||
console.error(`Failed to update publisher ${personId} - Fields Attempted: ${fieldsToUpdateString}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user