diff --git a/framework/core/js/src/admin/components/LoadingModal.tsx b/framework/core/js/src/admin/components/LoadingModal.tsx index 5594cb278..082efd002 100644 --- a/framework/core/js/src/admin/components/LoadingModal.tsx +++ b/framework/core/js/src/admin/components/LoadingModal.tsx @@ -1,7 +1,9 @@ import app from '../../admin/app'; import Modal, { IInternalModalAttrs } from '../../common/components/Modal'; -export default class LoadingModal extends Modal { +export interface ILoadingModalAttrs extends IInternalModalAttrs {} + +export default class LoadingModal extends Modal { /** * @inheritdoc */ diff --git a/framework/core/js/src/admin/components/ReadmeModal.js b/framework/core/js/src/admin/components/ReadmeModal.tsx similarity index 70% rename from framework/core/js/src/admin/components/ReadmeModal.js rename to framework/core/js/src/admin/components/ReadmeModal.tsx index 425e5aac2..f932de229 100644 --- a/framework/core/js/src/admin/components/ReadmeModal.js +++ b/framework/core/js/src/admin/components/ReadmeModal.tsx @@ -1,11 +1,21 @@ import app from '../../admin/app'; -import Modal from '../../common/components/Modal'; +import Modal, { IInternalModalAttrs } from '../../common/components/Modal'; import LoadingIndicator from '../../common/components/LoadingIndicator'; import Placeholder from '../../common/components/Placeholder'; import ExtensionReadme from '../models/ExtensionReadme'; +import type Mithril from 'mithril'; +import { Extension } from '../AdminApplication'; -export default class ReadmeModal extends Modal { - oninit(vnode) { +export interface IReadmeModalAttrs extends IInternalModalAttrs { + extension: Extension; +} + +export default class ReadmeModal extends Modal { + protected name!: string; + protected extName!: string; + protected readme!: ExtensionReadme; + + oninit(vnode: Mithril.Vnode) { super.oninit(vnode); app.store.models['extension-readmes'] = ExtensionReadme; diff --git a/framework/core/js/src/common/Model.ts b/framework/core/js/src/common/Model.ts index 1bc29431e..9fce10624 100644 --- a/framework/core/js/src/common/Model.ts +++ b/framework/core/js/src/common/Model.ts @@ -32,11 +32,11 @@ export interface SavedModelData { export type ModelData = UnsavedModelData | SavedModelData; -interface SaveRelationships { +export interface SaveRelationships { [relationship: string]: Model | Model[]; } -interface SaveAttributes { +export interface SaveAttributes { [key: string]: unknown; relationships?: SaveRelationships; } diff --git a/framework/core/js/src/common/Session.ts b/framework/core/js/src/common/Session.ts index 0997bf99f..e4e15a6dc 100644 --- a/framework/core/js/src/common/Session.ts +++ b/framework/core/js/src/common/Session.ts @@ -7,11 +7,8 @@ export type LoginParams = { * The username/email */ identification: string; - - /** - * Password - */ password: string; + remember: boolean; }; /** diff --git a/framework/core/js/src/common/components/EditUserModal.js b/framework/core/js/src/common/components/EditUserModal.tsx similarity index 67% rename from framework/core/js/src/common/components/EditUserModal.js rename to framework/core/js/src/common/components/EditUserModal.tsx index 70b3ca9c5..01083ec76 100644 --- a/framework/core/js/src/common/components/EditUserModal.js +++ b/framework/core/js/src/common/components/EditUserModal.tsx @@ -1,17 +1,28 @@ import app from '../../common/app'; -import Modal from './Modal'; +import Modal, { IInternalModalAttrs } from './Modal'; import Button from './Button'; import GroupBadge from './GroupBadge'; import Group from '../models/Group'; import extractText from '../utils/extractText'; import ItemList from '../utils/ItemList'; import Stream from '../utils/Stream'; +import Mithril from 'mithril'; +import User from '../models/User'; +import { SaveAttributes, SaveRelationships } from '../Model'; -/** - * The `EditUserModal` component displays a modal dialog with a login form. - */ -export default class EditUserModal extends Modal { - oninit(vnode) { +export interface IEditUserModalAttrs extends IInternalModalAttrs { + user: User; +} + +export default class EditUserModal extends Modal { + protected username!: Stream; + protected email!: Stream; + protected isEmailConfirmed!: Stream; + protected setPassword!: Stream; + protected password!: Stream; + protected groups: Record> = {}; + + oninit(vnode: Mithril.Vnode) { super.oninit(vnode); const user = this.attrs.user; @@ -19,14 +30,15 @@ export default class EditUserModal extends Modal { this.username = Stream(user.username() || ''); this.email = Stream(user.email() || ''); this.isEmailConfirmed = Stream(user.isEmailConfirmed() || false); - this.setPassword = Stream(false); + this.setPassword = Stream(false as boolean); this.password = Stream(user.password() || ''); - this.groups = {}; + + const userGroups = user.groups() || []; app.store - .all('groups') - .filter((group) => [Group.GUEST_ID, Group.MEMBER_ID].indexOf(group.id()) === -1) - .forEach((group) => (this.groups[group.id()] = Stream(user.groups().indexOf(group) !== -1))); + .all('groups') + .filter((group) => ![Group.GUEST_ID, Group.MEMBER_ID].includes(group.id()!)) + .forEach((group) => (this.groups[group.id()!] = Stream(userGroups.includes(group)))); } className() { @@ -49,7 +61,7 @@ export default class EditUserModal extends Modal { fields() { const items = new ItemList(); - if (app.session.user.canEditCredentials()) { + if (app.session.user?.canEditCredentials()) { items.add( 'username',
@@ -103,10 +115,11 @@ export default class EditUserModal extends Modal {