import * as utils from "@helpers"; import { msg } from "@lit/localize"; import { Task } from "@lit/task"; import type { PropertiesPicker } from "@src/tems"; import { html, nothing, unsafeCSS, css } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import type { RegisterOrganisation } from "@src/tems"; import "~icons/heroicons-outline/arrow-down"; import OrganisationApprovalStyle from "@styles/orbit/organisation/tems-organisation-approval.scss?inline"; @customElement("solid-tems-organisation-approval") export class OrganisationApproval extends utils.OrbitComponent { @property({ attribute: "header", type: String }) header?: string = "Organisation approval"; @state() sortBy = ""; @state() sortDir?: "asc" | "desc"; cherryPickedProperties: PropertiesPicker[] = [ { key: "@id", value: "@id" }, { key: "organisation", value: "organisation" }, { key: "organisationAddress", value: "organisationAddress" }, { key: "organisationRegistrationNumber", value: "organisationRegistrationNumber", }, { key: "firstname", value: "firstname" }, { key: "lastname", value: "lastname" }, { key: "status", value: "status" }, ]; static styles = css` ${unsafeCSS(OrganisationApprovalStyle)} `; _getResource = new Task(this, { task: async ([dataSrc]) => { if ( !dataSrc || !this.orbit || (!this.noRouter && this.route && !this.route.startsWith(this.currentRoute)) ) return; if (!this.hasCachedDatas || this.oldDataSrc !== dataSrc) { this.datas = await this._getProxyValue(dataSrc); this.hasCachedDatas = true; } if (this.oldDataSrc !== dataSrc) { this.oldDataSrc = dataSrc; } return this.datas; }, args: () => [this.dataSrc, this.caching, this.currentRoute], }); _rotateSort(prop: string) { if (this.sortBy === prop) { if (this.sortDir === "asc") { this.sortDir = "desc"; } else if (this.sortDir === "desc") { this.sortBy = ""; this.sortDir = undefined; } else { this.sortDir = "asc"; } } else { this.sortBy = prop; this.sortDir = "asc"; } } async _updateOrganisationStatus(org: RegisterOrganisation, status: string) { org.status = status; await window.sibStore.patch(org, org["@id"]); this.requestUpdate(); } _renderRows(sortedData: RegisterOrganisation[]) { return sortedData.map( (d) => html`
| this._rotateSort("organisation")}
class="${this.sortBy === "organisation"
? `sort-${this.sortDir}`
: nothing}"
>
${msg("Organisation")}
|
this._rotateSort("organisationAddress")}
class="${this.sortBy === "organisationAddress"
? `sort-${this.sortDir}`
: nothing}"
>
${msg("Address")}
|
this._rotateSort("organisationRegistrationNumber")}
class="${this.sortBy === "organisationRegistrationNumber"
? `sort-${this.sortDir}`
: nothing}"
>
${msg("Registration number")}
|
this._rotateSort("firstname")}
class="${this.sortBy === "firstname"
? `sort-${this.sortDir}`
: nothing}"
>
${msg("First name")}
|
this._rotateSort("lastname")}
class="${this.sortBy === "lastname"
? `sort-${this.sortDir}`
: nothing}"
>
${msg("Last name")}
|
this._rotateSort("status")}
class="${this.sortBy === "status"
? `sort-${this.sortDir}`
: nothing}"
>
${msg("Current status")}
|
${msg("Set status")} |
|---|