diff --git a/force-app/main/default/lwc/crmStoMessaging/crmStoMessaging.js b/force-app/main/default/lwc/crmStoMessaging/crmStoMessaging.js index e1c6f7d9..acc0928c 100644 --- a/force-app/main/default/lwc/crmStoMessaging/crmStoMessaging.js +++ b/force-app/main/default/lwc/crmStoMessaging/crmStoMessaging.js @@ -16,23 +16,23 @@ import oldDesignTemplate from './oldDesignTemplate.html'; import { resolve } from 'c/nksComponentsUtils'; const englishCompanyTranslations = { - 'DIR Ytelsesavdelingen': 'Benefits department, Directorate of Labour and Welfare', - 'NAV Arbeid og ytelser styringsenhet': 'NAV Work and Benefits Management Unit', - 'NAV Familie- og pensjonsytelser': 'NAV Family Benefits and Pensions Management Unit', - 'NAV Kontroll Øst': 'NAV Control Eastern Norway', - 'NAV Kontroll Vest': 'NAV Control Western Norway', - 'NAV Kontroll Nord': 'NAV Control Northern Norway', - 'NAV Kontroll Styringsenhet': 'NAV Control Management Unit', - 'NAV Medlemskap og avgift': 'NAV Social insurance and Contributions', - 'NAV Oppfølging utland': 'Norwegian Labour and rehabilitation unit', - 'NAV Registerforvaltning': 'NAV Registry Management', - 'NAV Styringsenhet Kontaktsenter': 'NAV Call and Service Centre Management Unit', + 'DIR ytelsesavdelingen': 'Benefits department, Directorate of Labour and Welfare', + 'Nav arbeid og ytelser styringsenhet': 'Nav Work and Benefits Management Unit', + 'Nav familie- og pensjonsytelser': 'Nav Family Benefits and Pensions Management Unit', + 'Nav kontroll Øst': 'Nav Control Eastern Norway', + 'Nav kontroll Vest': 'Nav Control Western Norway', + 'Nav kontroll Nord': 'Nav Control Northern Norway', + 'Nav kontroll styringsenhet': 'Nav Control Management Unit', + 'Nav medlemskap og avgift': 'Nav Social insurance and Contributions', + 'Nav oppfølging utland': 'Norwegian Labour and rehabilitation unit', + 'Nav registerforvaltning': 'Nav Registry Management', + 'Nav styringsenhet kontaktsenter': 'Nav Call and Service Centre Management Unit', 'Seksjon fag- og ytelsesutvikling': 'Pensions and benefits - Legislation and development', 'Seksjon informasjonsforvaltning': 'Information Management', 'Seksjon juridisk': 'Legal affairs', 'Seksjon kompetanseutvikling': 'Professional Development', 'Seksjon styring': 'Governance', - Ytelseslinjen: 'NAV Benefits Administration' + Ytelseslinjen: 'Nav Benefits Administration' }; export default class CrmStoMessaging extends LightningElement { @@ -127,189 +127,6 @@ export default class CrmStoMessaging extends LightningElement { this.dispatchEvent(toolbarActionEvent); } - getNorwegianCompanyName() { - try { - // Return all "Kontaktsenter"-units as "NAV Kontaktsenter" - if ( - this.companyName.toLowerCase().includes('kontaktsenter') && - !this.companyName.toLowerCase().toLowerCase().includes('styringsenhet') - ) { - return 'NAV Kontaktsenter'; - } - const startWords = ['DIR', 'HJELPEMIDDEL', 'NAV', 'SEKSJON', 'YTELSE']; - const words = [ - 'Analyse', - 'Avgift', - 'Helse', - 'Pensjonsytelser', - 'Styringsavdelingen', - 'Styringsenhet', - 'Tjenesteavdelingen', - 'Ytelser', - 'Ytelsesutvikling' - ]; - // Check for related units - if (startWords.some((str) => this.companyName.startsWith(str))) { - let listString = this.companyName.toLowerCase().split(' '); - for (let i = 0; i < listString.length; i++) { - if (listString[i].length > 1) { - listString[i] = listString[i].charAt(0).toUpperCase() + listString[i].slice(1).toLowerCase(); - if (listString[i].toUpperCase() === 'NAV' || listString[i].toUpperCase() === 'DIR') { - listString[i] = listString[i].toUpperCase(); - } else if ( - (i > 0 && listString[i - 1].toUpperCase() === 'SEKSJON') || - listString[i].toUpperCase() === 'OG' || - (((i > 0 && listString[i - 1].toUpperCase() === 'OG') || - (i > 1 && listString[i - 2].toUpperCase() === 'OG')) && - words.includes(listString[i])) - ) { - listString[i] = listString[i].toLowerCase(); - } else if (listString[i].includes('-') || listString[i].includes('/')) { - listString[i] = listString[i].replaceAll(/[-/][a-z]/g, (match) => match.toUpperCase()); - } - } - } - return listString.join(' '); - } - return this.companyName; - } catch (error) { - console.error('Problem getting Norwegian company name: ' + error); - return ''; - } - } - - getEnglishCompanyName() { - try { - // English translation for management units - if (this.norwegianCompanyName in englishCompanyTranslations) { - return englishCompanyTranslations[this.norwegianCompanyName]; - } - let ecn = ''; - let hasEnglishTranslation = true; - const mapObj = { - og: 'and', - i: 'in' - }; - const unitsWithPrepositions = [ - 'NAV Eiganes og Tasta', - 'NAV Evje og Hornnes', - 'NAV Herøy og Vanylven', - 'NAV Hillevåg og Hinna', - 'NAV Hundvåg og Storhaug', - 'NAV Møre og Romsdal', - 'NAV Nes i Akershus', - 'NAV Oppdal og Rennebu', - 'NAV Rennesøy og Finnøy', - 'NAV Røros, Os og Holtålen', - 'NAV Troms og Finnmark', - 'NAV Vestfold og Telemark', - 'NAV Våler i Hedmark' - //'NAV Øst i Agder' - ]; - - if (this.norwegianCompanyName.includes('Arbeid og ytelser')) { - ecn = this.norwegianCompanyName.replace('Arbeid og ytelser', 'Work and Benefits'); - } else if (this.norwegianCompanyName.includes('Familie- og pensjonsytelser')) { - ecn = this.norwegianCompanyName.replace('Familie- og pensjonsytelser', 'Family Benefits and Pensions'); - } else if (this.norwegianCompanyName.includes('Hjelpemiddelsentral')) { - ecn = this.norwegianCompanyName.replace('Hjelpemiddelsentral', 'Department of assistive technology'); - } else if (this.norwegianCompanyName.includes('Klageinstans')) { - ecn = this.norwegianCompanyName.replace('Klageinstans', 'Appeals'); - } else if (this.norwegianCompanyName.includes('Kontaktsenter')) { - ecn = this.norwegianCompanyName.replace('Kontaktsenter', 'Call and Service Center'); - } else if (this.norwegianCompanyName.includes('Kontroll Analyse')) { - ecn = this.norwegianCompanyName.replace('Kontroll Analyse', 'Control Analysis'); - } else if (this.norwegianCompanyName.includes('Kontroll')) { - ecn = this.norwegianCompanyName.replace('Kontroll', 'Control'); - } else if (this.norwegianCompanyName.includes('Tiltak')) { - ecn = this.norwegianCompanyName.replace('Tiltak', 'Department for employment measures'); - } else if (this.norwegianCompanyName.includes('Ytelseslinjen')) { - ecn = this.norwegianCompanyName.replace('Ytelseslinjen', 'Benefits Administration'); - } else { - if (unitsWithPrepositions.includes(this.norwegianCompanyName)) { - ecn = this.norwegianCompanyName.replace(/\b(?:og|i)\b/gi, (matched) => mapObj[matched]); - return ecn; - } - hasEnglishTranslation = false; - console.error('There is no translation for this CompanyName.'); - return this.norwegianCompanyName; - } - if (hasEnglishTranslation) { - ecn = ecn.replace(/\b(?:og|i)\b/gi, (matched) => mapObj[matched]); - } - return ecn; - } catch (error) { - console.error('Problem getting English company name: ' + error); - return ''; - } - } - - get textTemplate() { - let salutation = this.userName == null ? 'Hei,' : 'Hei, ' + this.userName; - let regards = 'Med vennlig hilsen'; - - if (this.englishTextTemplate === true) { - salutation = this.userName == null ? 'Hi,' : 'Hi ' + this.userName + ','; - regards = 'Kind regards'; - } - - return `${salutation}\n\n\n\n${regards}\n${this.supervisorName}\n${ - this.englishTextTemplate === true ? this.englishCompanyName : this.norwegianCompanyName - }`; - } - - get computeClasses() { - return this.threadType === 'BTO' ? 'greenHeader' : ''; - } - - get actualCardTitle() { - if (this.objectApiName === 'Case' && ['BTO', 'STO'].includes(this.threadType)) - return this.threadType === 'STO' ? 'Skriv til oss' : 'Beskjed til oss'; - - return this.cardTitle; - } - - get showMedskrivBlocker() { - return this.checkMedskriv === true && this.acceptedMedskriv === false && this.medskriv === false; - } - - getAccountApiName() { - if (this.objectApiName === 'Case') { - return 'AccountId'; - } else if (this.objectApiName === 'Thread__c') { - return 'CRM_Account__c'; - } - return null; - } - - getAccountId() { - getRelatedRecord({ - parentId: this.recordId, - relationshipField: this.accountApiName, - objectApiName: this.objectApiName - }) - .then((record) => { - this.accountId = resolve(this.accountApiName, record); - }) - .catch((error) => { - console.error(error); - }); - } - - getPersonId() { - getRelatedRecord({ - parentId: this.accountId, - relationshipField: 'CRM_Person__c', - objectApiName: 'Account' - }) - .then((record) => { - this.personId = resolve('CRM_Person__c', record); - }) - .catch((error) => { - console.error('Problem getting person id: ', error); - }); - } - @wire(getRecord, { recordId: '$recordId', fields: '$wireField' @@ -396,6 +213,7 @@ export default class CrmStoMessaging extends LightningElement { } } + // Event Handlers handleEnglishEventTwo(event) { this.englishTextTemplate = event.detail; } @@ -414,4 +232,220 @@ export default class CrmStoMessaging extends LightningElement { forwardEvent(event) { this.dispatchEvent(new CustomEvent(event.type)); } + + // Getters + get textTemplate() { + let salutation = this.userName == null ? 'Hei,' : 'Hei, ' + this.userName; + let regards = 'Med vennlig hilsen'; + + if (this.englishTextTemplate === true) { + salutation = this.userName == null ? 'Hi,' : 'Hi ' + this.userName + ','; + regards = 'Kind regards'; + } + + return `${salutation}\n\n\n\n${regards}\n${this.supervisorName}\n${ + this.englishTextTemplate === true ? this.englishCompanyName : this.norwegianCompanyName + }`; + } + + get computeClasses() { + return this.threadType === 'BTO' ? 'greenHeader' : ''; + } + + get actualCardTitle() { + if (this.objectApiName === 'Case' && ['BTO', 'STO'].includes(this.threadType)) + return this.threadType === 'STO' ? 'Skriv til oss' : 'Beskjed til oss'; + + return this.cardTitle; + } + + get showMedskrivBlocker() { + return this.checkMedskriv === true && this.acceptedMedskriv === false && this.medskriv === false; + } + + getAccountApiName() { + if (this.objectApiName === 'Case') { + return 'AccountId'; + } else if (this.objectApiName === 'Thread__c') { + return 'CRM_Account__c'; + } + return null; + } + + getAccountId() { + getRelatedRecord({ + parentId: this.recordId, + relationshipField: this.accountApiName, + objectApiName: this.objectApiName + }) + .then((record) => { + this.accountId = resolve(this.accountApiName, record); + }) + .catch((error) => { + console.error(error); + }); + } + + getPersonId() { + getRelatedRecord({ + parentId: this.accountId, + relationshipField: 'CRM_Person__c', + objectApiName: 'Account' + }) + .then((record) => { + this.personId = resolve('CRM_Person__c', record); + }) + .catch((error) => { + console.error('Problem getting person id: ', error); + }); + } + + getNorwegianCompanyName() { + try { + const phraseMap = { + 'NAV ARBEID OG YTELSER': 'Nav arbeid og ytelser', + 'NAV FAMILIE- OG PENSJONSYTELSER': 'Nav familie- og pensjonsytelser', + 'NAV HJELPEMIDDELSENTRAL': 'Nav hjelpemiddelsentral', + 'NAV KONTROLL': 'Nav kontroll', + 'NAV OPPFØLGING UTLAND': 'Nav oppfølging utland', + 'NAV STYRINGSENHET KONTAKTSENTER': 'Nav styringsenhet kontaktsenter', + 'NAV ØKONOMI STØNAD': 'Nav økonomi stønad', + 'NAV UTLAND OG FELLESTJENESTER': 'Nav utland og fellestjenester', + 'NAV KONTROLL ANALYSE': 'Nav kontroll analyse', + 'NAV KONTROLL STYRINGSENHET': 'Nav kontroll styringsenhet', + 'NAV REGISTERFORVALTNING': 'Nav registerforvaltning', + 'NAV TILTAK': 'Nav tiltak', + 'NAV KLAGEINSTANS': 'Nav klageinstans', + 'SEKSJON FAG- OG YTELSESUTVIKLING': 'Seksjon fag- og ytelsesutvikling', + 'SEKSJON INFORMASJONSFORVALTNING': 'Seksjon informasjonsforvaltning', + 'SEKSJON JURIDISK': 'Seksjon juridisk', + 'SEKSJON KOMPETANSEUTVIKLING': 'Seksjon kompetanseutvikling', + 'SEKSJON STYRING': 'Seksjon styring' + }; + + const formatWord = (word) => + word + .split('-') + .map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()) + .join('-'); + + const formatRemainingWords = (name) => name.split(/\s+/).map(formatWord).join(' '); + + const formatCompanyName = (key, formattedName) => { + const mappedPhrase = phraseMap[key]; + const remainingName = formattedName.replace(key, '').trim(); + return `${mappedPhrase} ${formatRemainingWords(remainingName)}`; + }; + + if (this.companyName === 'IT-AVDELINGEN') { + return 'IT-avdelingen'; + } + + if (this.companyName.startsWith('DIR')) { + const remainingName = this.companyName.slice(4).trim(); + const formattedName = remainingName + .toLowerCase() + .split(/\s+/) + .map((part) => { + if (part.includes('-')) { + return part + .split('-') + .map((subPart) => { + return subPart.charAt(0).toLowerCase() + subPart.slice(1); + }) + .join('-'); + } + return part.toLowerCase(); + }) + .join(' '); + return `DIR ${formattedName}`; + } + + if ( + this.companyName.toLowerCase().includes('kontaktsenter') && + !this.companyName.toLowerCase().includes('styringsenhet') + ) { + return 'Nav kontaktsenter'; + } + + const formattedName = this.companyName.toUpperCase(); + for (const key in phraseMap) { + if (formattedName.includes(key)) { + return formatCompanyName(key, formattedName); + } + } + + return formatRemainingWords(this.companyName); + } catch (error) { + console.error('Problem getting Norwegian company name:', error); + return ''; + } + } + + getEnglishCompanyName() { + try { + const normalizedCompanyName = this.norwegianCompanyName.trim(); + + if (normalizedCompanyName in englishCompanyTranslations) { + return englishCompanyTranslations[normalizedCompanyName]; + } + + let ecn = ''; + let hasEnglishTranslation = true; + const mapObj = { + og: 'and', + i: 'in' + }; + const unitsWithPrepositions = [ + 'Nav Eiganes og Tasta', + 'Nav Evje og Hornnes', + 'Nav Herøy og Vanylven', + 'Nav Hillevåg og Hinna', + 'Nav Hundvåg og Storhaug', + 'Nav Møre og Romsdal', + 'Nav Nes i Akershus', + 'Nav Oppdal og Rennebu', + 'Nav Rennesøy og Finnøy', + 'Nav Røros, Os og Holtålen', + 'Nav Troms og Finnmark', + 'Nav Vestfold og Telemark', + 'Nav Våler i Hedmark' + ]; + + if (this.norwegianCompanyName.includes('arbeid og ytelser')) { + ecn = this.norwegianCompanyName.replace('arbeid og ytelser', 'Work and Benefits'); + } else if (this.norwegianCompanyName.includes('familie- og pensjonsytelser')) { + ecn = this.norwegianCompanyName.replace('familie- og pensjonsytelser', 'Family Benefits and Pensions'); + } else if (this.norwegianCompanyName.includes('hjelpemiddelsentral')) { + ecn = this.norwegianCompanyName.replace('hjelpemiddelsentral', 'Department of assistive technology'); + } else if (this.norwegianCompanyName.includes('klageinstans')) { + ecn = this.norwegianCompanyName.replace('klageinstans', 'Appeals'); + } else if (this.norwegianCompanyName.includes('kontaktsenter')) { + ecn = this.norwegianCompanyName.replace('kontaktsenter', 'Call and Service Center'); + } else if (this.norwegianCompanyName.includes('kontroll analyse')) { + ecn = this.norwegianCompanyName.replace('kontroll analyse', 'Control Analysis'); + } else if (this.norwegianCompanyName.includes('kontroll')) { + ecn = this.norwegianCompanyName.replace('kontroll', 'Control'); + } else if (this.norwegianCompanyName.includes('tiltak')) { + ecn = this.norwegianCompanyName.replace('tiltak', 'Department for employment measures'); + } else if (this.norwegianCompanyName.includes('Ytelseslinjen')) { + ecn = this.norwegianCompanyName.replace('Ytelseslinjen', 'Benefits Administration'); + } else { + if (unitsWithPrepositions.includes(this.norwegianCompanyName)) { + ecn = this.norwegianCompanyName.replace(/\b(?:og|i)\b/gi, (matched) => mapObj[matched]); + return ecn; + } + hasEnglishTranslation = false; + console.error('There is no translation for this CompanyName.'); + return this.norwegianCompanyName; + } + if (hasEnglishTranslation) { + ecn = ecn.replace(/\b(?:og|i)\b/gi, (matched) => mapObj[matched]); + } + return ecn; + } catch (error) { + console.error('Problem getting English company name: ' + error); + return ''; + } + } }