business logic, customer communication.
This commit is contained in:
28
lib/app/communications/customer.d.ts
vendored
Normal file
28
lib/app/communications/customer.d.ts
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
interface CheckboxConfig {
|
||||
checked: boolean
|
||||
onchanged: (flag: boolean) => void
|
||||
}
|
||||
|
||||
interface InitConfig {
|
||||
autoUpdates?: CheckboxConfig;
|
||||
statusLink?: CheckboxConfig;
|
||||
readonly?: boolean;
|
||||
}
|
||||
|
||||
export class CustomerCommunication {
|
||||
get autoUpdatesEnabled(): boolean;
|
||||
set autoUpdatesEnabled(enabled: boolean);
|
||||
get autoUpdates(): boolean;
|
||||
set autoUpdates(checked: boolean);
|
||||
|
||||
get statusLinkEnabled(): boolean;
|
||||
set statusLinkEnabled(enabled: boolean);
|
||||
get statusLink(): boolean;
|
||||
set statusLink(checked: boolean);
|
||||
|
||||
create(): HTMLElement;
|
||||
}
|
||||
|
||||
declare var CustomerCommunication: {
|
||||
new(opt: InitConfig): CustomerCommunication
|
||||
}
|
226
lib/app/communications/customer.js
Normal file
226
lib/app/communications/customer.js
Normal file
@ -0,0 +1,226 @@
|
||||
import "./style.scss";
|
||||
import { createElement, createElementInit } from "../../functions";
|
||||
import { r } from "../../utility/lgres";
|
||||
import { isEmail, isPhone } from "../../utility";
|
||||
import { setTooltip } from "../../ui/tooltip";
|
||||
import { createIcon } from "../../ui/icon";
|
||||
import { createCheckbox } from "../../ui/checkbox";
|
||||
import { createBox } from "./lib";
|
||||
|
||||
class CustomerCommunication {
|
||||
#container;
|
||||
#option;
|
||||
#contacts;
|
||||
#followers;
|
||||
#enter;
|
||||
#message;
|
||||
|
||||
constructor(opt) {
|
||||
this.#option = opt ?? {};
|
||||
}
|
||||
|
||||
get #autoUpdates() { return this.#container.querySelector('.check-auto-update>input') }
|
||||
get autoUpdatesEnabled() { return this.#autoUpdates?.disabled !== true }
|
||||
set autoUpdatesEnabled(flag) {
|
||||
const element = this.#autoUpdates;
|
||||
element != null && (element.disabled = flag === false);
|
||||
}
|
||||
get autoUpdates() { return this.#autoUpdates?.checked }
|
||||
set autoUpdates(flag) {
|
||||
const element = this.#autoUpdates;
|
||||
element != null && (element.checked = flag);
|
||||
}
|
||||
|
||||
get #statusLink() { return this.#container.querySelector('.check-status-link') }
|
||||
get statusLinkEnabled() { return this.#statusLink?.disabled !== true }
|
||||
set statusLinkEnabled(flag) {
|
||||
const element = this.#statusLink;
|
||||
element != null && (element.disabled = flag === false);
|
||||
}
|
||||
get statusLink() { return this.#statusLink?.checked }
|
||||
set statusLink(flag) {
|
||||
const element = this.#statusLink;
|
||||
element != null && (element.checked = flag);
|
||||
}
|
||||
|
||||
get text() { return this.#enter?.value }
|
||||
set text(s) {
|
||||
const element = this.#enter;
|
||||
element != null && (element.value = s);
|
||||
}
|
||||
|
||||
get contacts() {
|
||||
return [...this.#contacts.children].map(el => {
|
||||
const span = el.querySelector('span');
|
||||
return { 'Key': span.innerText, 'Value': span.dataset.name };
|
||||
});
|
||||
}
|
||||
set contacts(contacts) {
|
||||
this.#contacts.replaceChildren();
|
||||
if (contacts?.length > 0) {
|
||||
for (let c of contacts) {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
continue;
|
||||
}
|
||||
const mp = String(c.MobilePhone).trim();
|
||||
const email = String(c.Email).trim();
|
||||
if (c.ContactPreference === '0' && !isPhone(mp) ||
|
||||
c.ContactPreference === '1' && !isEmail(email)) {
|
||||
continue;
|
||||
}
|
||||
const to = c.ContactPreference === '0' ? mp : email;
|
||||
this.#contacts.appendChild(
|
||||
createElement('div', 'contact-item',
|
||||
createIcon('fa-light', c.ContactPreference === '0' ? 'comment-lines' : 'envelope'),
|
||||
createElementInit('span', span => {
|
||||
span.dataset.name = c.Name;
|
||||
span.innerText = to;
|
||||
})
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
create() {
|
||||
// functions
|
||||
const checkAutoUpdate = createCheckbox({
|
||||
className: 'check-auto-update',
|
||||
checked: this.#option.autoUpdates?.checked,
|
||||
enabled: this.#option.autoUpdates?.enabled,
|
||||
checkedNode: createIcon('fa-regular', 'redo-alt'),
|
||||
uncheckedNode: createIcon('fa-regular', 'ban'),
|
||||
onchange: () => {
|
||||
setTooltip(checkAutoUpdate, this.checked ?
|
||||
r('autoUpdateEnabled', 'Auto Updates Enabled') :
|
||||
r('autoUpdateDisabled', 'Auto Updates Disabled'));
|
||||
if (typeof this.#option.autoUpdates?.onchanged === 'function') {
|
||||
this.#option.autoUpdates.onchanged(this.checked);
|
||||
}
|
||||
}
|
||||
});
|
||||
const checkLink = createCheckbox({
|
||||
className: 'check-status-link',
|
||||
checked: this.#option.statusLink?.checked,
|
||||
enabled: this.#option.statusLink?.enabled,
|
||||
checkedNode: createIcon('fa-regular', 'link'),
|
||||
uncheckedNode: createIcon('fa-regular', 'unlink'),
|
||||
onchange: () => {
|
||||
setTooltip(checkLink, this.checked ?
|
||||
r('statusLinkIncluded', 'Status Link Included') :
|
||||
r('statusLinkExcluded', 'Status Link Excluded'));
|
||||
if (typeof this.#option.statusLink?.onchanged === 'function') {
|
||||
this.#option.statusLink.onchanged(this.checked);
|
||||
}
|
||||
}
|
||||
});
|
||||
const container = createBox(
|
||||
createElement('div', null,
|
||||
createElementInit('div', div => div.innerText = r('messages', 'Customer Communication')),
|
||||
createElementInit('div', div => div.innerText = consts.user?.companyName)),
|
||||
[
|
||||
setTooltip(checkAutoUpdate, r('autoUpdateDisabled', 'Auto Updates Disabled')),
|
||||
setTooltip(checkLink, r('statusLinkExcluded', 'Status Link Excluded'))
|
||||
]
|
||||
);
|
||||
// contacts
|
||||
const contacts = createElement('div');
|
||||
container.append(
|
||||
createElement('div', 'contact-bar',
|
||||
createIcon('fa-solid', 'user-circle', {
|
||||
'fill': 'lightgray',
|
||||
'flex': '0 0 auto'
|
||||
}),
|
||||
createElementInit('div', div => div.style.flex = '1 1 auto',
|
||||
contacts,
|
||||
createElementInit('button', button => {
|
||||
button.className = 'roundbtn';
|
||||
button.style.backgroundColor = 'rgb(1, 199, 172)';
|
||||
button.appendChild(createIcon('fa-solid', 'user-edit'));
|
||||
setTooltip(button, r('editContacts', 'Edit Contacts'));
|
||||
button.addEventListener('click', () => {
|
||||
// TODO:
|
||||
});
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
this.#contacts = contacts;
|
||||
// followers
|
||||
const followers = createElement('div');
|
||||
container.append(
|
||||
createElement('div', 'contact-bar follower-bar',
|
||||
createIcon('fa-solid', 'user-tag', {
|
||||
'fill': '#fff',
|
||||
'background-color': 'lightgray',
|
||||
'box-sizing': 'border-box',
|
||||
'border-radius': '15px',
|
||||
'padding': '4px',
|
||||
'flex': '0 0 auto'
|
||||
}),
|
||||
createElementInit('div', div => div.style.flex = '1 1 auto',
|
||||
followers,
|
||||
createElementInit('button', button => {
|
||||
button.className = 'roundbtn';
|
||||
button.style.backgroundColor = 'rgb(48, 107, 255)';
|
||||
button.appendChild(createIcon('fa-solid', 'pen'));
|
||||
setTooltip(button, r('editFollower', 'Edit Followers'));
|
||||
button.addEventListener('click', () => {
|
||||
// TODO:
|
||||
});
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
this.#followers = followers;
|
||||
// enter box
|
||||
const enter = createElement('textarea');
|
||||
enter.placeholder = r('typeComment', 'Enter Message Here');
|
||||
enter.maxLength = 3000;
|
||||
this.#enter = enter;
|
||||
container.appendChild(
|
||||
createElement('div', 'message-bar',
|
||||
enter,
|
||||
createElementInit('div', div => div.style.textAlign = 'right',
|
||||
createElementInit('button', button => {
|
||||
button.className = 'roundbtn';
|
||||
button.style.backgroundColor = 'rgb(19, 150, 204)';
|
||||
button.appendChild(createIcon('fa-solid', 'paper-plane'));
|
||||
setTooltip(button, r('sendMessage', 'Send Message'));
|
||||
button.addEventListener('click', () => {
|
||||
// TODO: Add text
|
||||
})
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
const message = createElement('div');
|
||||
this.#message = message;
|
||||
container.appendChild(message);
|
||||
return this.#container = container;
|
||||
}
|
||||
|
||||
load(data, contacts) {
|
||||
const children = [];
|
||||
if (data?.length > 0) {
|
||||
for (let comm of data) {
|
||||
const div = document.createElement('div', 'txtdiv');
|
||||
let name;
|
||||
if (comm.IsReply) {
|
||||
const email = isEmail(comm.Sender);
|
||||
const c = contacts.find(c => email ?
|
||||
c.Email === comm.Sender :
|
||||
c.MobilePhone === comm.Sender);
|
||||
if (c != null) {
|
||||
name = c.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
children[0].style.marginTop = '0';
|
||||
this.#message.append(...children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default CustomerCommunication;
|
1
lib/app/communications/lib.d.ts
vendored
Normal file
1
lib/app/communications/lib.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export function createBox(title: HTMLElement, functions: HTMLElement[]): HTMLElement
|
15
lib/app/communications/lib.js
Normal file
15
lib/app/communications/lib.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { createElement, createElementInit } from "../../functions";
|
||||
|
||||
function createBox(title, functions) {
|
||||
const container = createElement('div', 'comm');
|
||||
const header = createElement('div', 'title-bar',
|
||||
title,
|
||||
createElement('div', 'title-functions', ...functions)
|
||||
);
|
||||
container.appendChild(header);
|
||||
return container;
|
||||
}
|
||||
|
||||
export {
|
||||
createBox
|
||||
}
|
242
lib/app/communications/style.scss
Normal file
242
lib/app/communications/style.scss
Normal file
@ -0,0 +1,242 @@
|
||||
:root {
|
||||
--dark-fore-color: #fff;
|
||||
--dark-fore-opacity-color: rgba(255, 255, 255, .6);
|
||||
--title-color: #fff;
|
||||
--title-bg-color: rgb(68, 114, 196);
|
||||
--strong-color: #333;
|
||||
--medium-font-size: .875rem;
|
||||
}
|
||||
|
||||
.comm {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 320px;
|
||||
background-color: var(--dark-fore-color);
|
||||
border: 1px solid var(--title-bg-color);
|
||||
|
||||
.roundbtn {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
display: inline-block;
|
||||
box-sizing: border-box;
|
||||
cursor: pointer;
|
||||
padding: 7px;
|
||||
margin-left: 10px;
|
||||
fill: var(--dark-fore-color);
|
||||
border-radius: 15px;
|
||||
border: none;
|
||||
outline: none;
|
||||
transition: background-color .2s;
|
||||
user-select: none;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--dark-fore-opacity-color);
|
||||
|
||||
>svg {
|
||||
opacity: .6;
|
||||
}
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
fill: lightgray;
|
||||
background-color: transparent !important;
|
||||
|
||||
&:hover {
|
||||
opacity: unset;
|
||||
}
|
||||
}
|
||||
|
||||
>svg {
|
||||
width: 13px;
|
||||
height: 14px;
|
||||
display: block;
|
||||
transition: opacity .2s;
|
||||
}
|
||||
}
|
||||
|
||||
.image-check-box {
|
||||
user-select: none;
|
||||
|
||||
>input[type="checkbox"] {
|
||||
display: none;
|
||||
|
||||
&:checked~.unchecked {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&:checked~.checked {
|
||||
display: unset;
|
||||
}
|
||||
}
|
||||
|
||||
>.unchecked {
|
||||
opacity: .5;
|
||||
}
|
||||
|
||||
>.checked {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.title-bar {
|
||||
flex: 0 0 auto;
|
||||
padding: 5px 0 5px 10px;
|
||||
color: var(--title-color);
|
||||
background-color: var(--title-bg-color);
|
||||
line-height: 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
>div {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
>.title-functions {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
|
||||
>label {
|
||||
margin: 0 4px;
|
||||
box-sizing: border-box;
|
||||
cursor: pointer;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background-color: var(--dark-fore-color);
|
||||
border-radius: 15px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background-color .2s;
|
||||
|
||||
>svg {
|
||||
fill: var(--strong-color);
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
transition: opacity .2s;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: var(--dark-fore-opacity-color);
|
||||
|
||||
>svg {
|
||||
opacity: .6;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.contact-bar {
|
||||
flex: 0 0 auto;
|
||||
padding: 4px 0;
|
||||
display: flex;
|
||||
border-bottom: 1px solid var(--title-bg-color);
|
||||
|
||||
>svg {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
margin: 0 8px;
|
||||
}
|
||||
|
||||
.contact-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
line-height: 22px;
|
||||
|
||||
>svg {
|
||||
flex: 0 0 auto;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin-right: 6px;
|
||||
fill: var(--strong-color);
|
||||
}
|
||||
|
||||
>span {
|
||||
flex: 1 1 auto;
|
||||
color: var(--strong-color);
|
||||
font-size: var(--medium-font-size);
|
||||
}
|
||||
}
|
||||
|
||||
.roundbtn {
|
||||
float: right;
|
||||
margin: 4px 10px 10px;
|
||||
|
||||
>svg {
|
||||
width: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.message-bar {
|
||||
flex: 0 0 auto;
|
||||
border-bottom: 1px solid var(--title-bg-color);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
>textarea {
|
||||
padding: 10px 10px 0;
|
||||
border: none;
|
||||
height: 70px;
|
||||
}
|
||||
|
||||
>div {
|
||||
padding: 0 10px 10px;
|
||||
}
|
||||
|
||||
&+div {
|
||||
flex: 1 1 auto;
|
||||
overflow: auto;
|
||||
margin-top: 8px;
|
||||
|
||||
.msgdiv {
|
||||
margin-top: 5px;
|
||||
border-bottom: solid 1px lightgray;
|
||||
padding: 3px 10px 5px;
|
||||
line-height: 1.5rem;
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
overflow: hidden;
|
||||
font-size: .8125rem;
|
||||
color: #333;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.msgposter {
|
||||
font-weight: bold;
|
||||
|
||||
&+div {
|
||||
line-height: 1.2rem;
|
||||
padding: 8px 20px;
|
||||
background-color: rgb(244, 244, 244);
|
||||
border-radius: 5px;
|
||||
white-space: pre-wrap;
|
||||
text-align: left;
|
||||
word-break: break-word;
|
||||
|
||||
&.txtself {
|
||||
max-width: 240px;
|
||||
margin-right: 10px;
|
||||
background-color: #9eea6a;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
&.txtother {
|
||||
max-width: 240px;
|
||||
margin-left: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.msgtime {
|
||||
text-align: right;
|
||||
color: #aaa;
|
||||
font-size: .7rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user