import { ipcRenderer } from 'electron'; import BaseSection from './base-section'; import * as DomainUtil from '../../utils/domain-util'; import ServerInfoForm from './server-info-form'; import AddCertificate from './add-certificate'; import FindAccounts from './find-accounts'; import * as t from '../../utils/translation-util'; export default class ConnectedOrgSection extends BaseSection { // TODO: TypeScript - Here props should be object type props: any; $serverInfoContainer: Element | null; $existingServers: Element | null; $newOrgButton: HTMLButtonElement | null; $addCertificateContainer: Element | null; $findAccountsContainer: Element | null; constructor(props: any) { super(); this.props = props; } template(): string { return `
${t.__('Connected organizations')}
${t.__('All the connected orgnizations will appear here.')}
${t.__('Add Custom Certificates')}
${t.__('Find accounts by email')}
`; } init(): void { this.initServers(); } initServers(): void { this.props.$root.innerHTML = ''; const servers = DomainUtil.getDomains(); this.props.$root.innerHTML = this.template(); this.$serverInfoContainer = document.querySelector('#server-info-container'); this.$existingServers = document.querySelector('#existing-servers'); this.$newOrgButton = document.querySelector('#new-org-button'); this.$addCertificateContainer = document.querySelector('#add-certificate-container'); this.$findAccountsContainer = document.querySelector('#find-accounts-container'); const noServerText = t.__('All the connected orgnizations will appear here'); // Show noServerText if no servers are there otherwise hide it this.$existingServers.innerHTML = servers.length === 0 ? noServerText : ''; for (const [i, server] of servers.entries()) { new ServerInfoForm({ $root: this.$serverInfoContainer, server, index: i, onChange: this.reloadApp }).init(); } this.$newOrgButton.addEventListener('click', () => { ipcRenderer.send('forward-message', 'open-org-tab'); }); this.initAddCertificate(); this.initFindAccounts(); } initAddCertificate(): void { new AddCertificate({ $root: this.$addCertificateContainer }).init(); } initFindAccounts(): void { new FindAccounts({ $root: this.$findAccountsContainer }).init(); } }