From 30d740e2bbe254069487bccb4a37089f275ad38a Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Sun, 10 Jul 2022 14:58:57 +0100 Subject: [PATCH 1/3] refactor: convert core modals to TypeScript Signed-off-by: Sami Mazouz --- .../js/src/admin/components/AdminPage.tsx | 5 +- ...stomCssModal.js => EditCustomCssModal.tsx} | 0 ...oterModal.js => EditCustomFooterModal.tsx} | 0 ...aderModal.js => EditCustomHeaderModal.tsx} | 0 .../{EditGroupModal.js => EditGroupModal.tsx} | 23 ++++++-- .../{SettingsModal.js => SettingsModal.tsx} | 24 ++++---- ...angeEmailModal.js => ChangeEmailModal.tsx} | 55 +++++++++---------- ...sswordModal.js => ChangePasswordModal.tsx} | 8 +-- ...sionModal.js => RenameDiscussionModal.tsx} | 24 ++++++-- 9 files changed, 83 insertions(+), 56 deletions(-) rename framework/core/js/src/admin/components/{EditCustomCssModal.js => EditCustomCssModal.tsx} (100%) rename framework/core/js/src/admin/components/{EditCustomFooterModal.js => EditCustomFooterModal.tsx} (100%) rename framework/core/js/src/admin/components/{EditCustomHeaderModal.js => EditCustomHeaderModal.tsx} (100%) rename framework/core/js/src/admin/components/{EditGroupModal.js => EditGroupModal.tsx} (85%) rename framework/core/js/src/admin/components/{SettingsModal.js => SettingsModal.tsx} (65%) rename framework/core/js/src/forum/components/{ChangeEmailModal.js => ChangeEmailModal.tsx} (76%) rename framework/core/js/src/forum/components/{ChangePasswordModal.js => ChangePasswordModal.tsx} (80%) rename framework/core/js/src/forum/components/{RenameDiscussionModal.js => RenameDiscussionModal.tsx} (75%) diff --git a/framework/core/js/src/admin/components/AdminPage.tsx b/framework/core/js/src/admin/components/AdminPage.tsx index 71517bd461..658fd53f39 100644 --- a/framework/core/js/src/admin/components/AdminPage.tsx +++ b/framework/core/js/src/admin/components/AdminPage.tsx @@ -134,8 +134,11 @@ export type SettingsComponentOptions = */ export type AdminHeaderAttrs = AdminHeaderOptions & Partial>; +export type SettingValue = string; +export type MutableSettings = Record>; + export default abstract class AdminPage extends Page { - settings: Record> = {}; + settings: MutableSettings = {}; loading: boolean = false; view(vnode: Mithril.Vnode): Mithril.Children { diff --git a/framework/core/js/src/admin/components/EditCustomCssModal.js b/framework/core/js/src/admin/components/EditCustomCssModal.tsx similarity index 100% rename from framework/core/js/src/admin/components/EditCustomCssModal.js rename to framework/core/js/src/admin/components/EditCustomCssModal.tsx diff --git a/framework/core/js/src/admin/components/EditCustomFooterModal.js b/framework/core/js/src/admin/components/EditCustomFooterModal.tsx similarity index 100% rename from framework/core/js/src/admin/components/EditCustomFooterModal.js rename to framework/core/js/src/admin/components/EditCustomFooterModal.tsx diff --git a/framework/core/js/src/admin/components/EditCustomHeaderModal.js b/framework/core/js/src/admin/components/EditCustomHeaderModal.tsx similarity index 100% rename from framework/core/js/src/admin/components/EditCustomHeaderModal.js rename to framework/core/js/src/admin/components/EditCustomHeaderModal.tsx diff --git a/framework/core/js/src/admin/components/EditGroupModal.js b/framework/core/js/src/admin/components/EditGroupModal.tsx similarity index 85% rename from framework/core/js/src/admin/components/EditGroupModal.js rename to framework/core/js/src/admin/components/EditGroupModal.tsx index d89182f9f9..d1b6293834 100644 --- a/framework/core/js/src/admin/components/EditGroupModal.js +++ b/framework/core/js/src/admin/components/EditGroupModal.tsx @@ -1,18 +1,31 @@ import app from '../../admin/app'; -import Modal from '../../common/components/Modal'; +import Modal, { IInternalModalAttrs } from '../../common/components/Modal'; import Button from '../../common/components/Button'; import Badge from '../../common/components/Badge'; import Group from '../../common/models/Group'; import ItemList from '../../common/utils/ItemList'; import Switch from '../../common/components/Switch'; import Stream from '../../common/utils/Stream'; +import Mithril from 'mithril'; +import extractText from '../../common/utils/extractText'; + +export interface IEditGroupModalAttrs extends IInternalModalAttrs { + group?: Group; +} /** * The `EditGroupModal` component shows a modal dialog which allows the user * to create or edit a group. */ -export default class EditGroupModal extends Modal { - oninit(vnode) { +export default class EditGroupModal extends Modal { + group!: Group; + nameSingular!: Stream; + namePlural!: Stream; + icon!: Stream; + color!: Stream; + isHidden!: Stream; + + oninit(vnode: Mithril.Vnode) { super.oninit(vnode); this.group = this.attrs.group || app.store.createRecord('groups'); @@ -134,7 +147,7 @@ export default class EditGroupModal extends Modal { }; } - onsubmit(e) { + onsubmit(e: SubmitEvent) { e.preventDefault(); this.loading = true; @@ -149,7 +162,7 @@ export default class EditGroupModal extends Modal { } deleteGroup() { - if (confirm(app.translator.trans('core.admin.edit_group.delete_confirmation'))) { + if (confirm(extractText(app.translator.trans('core.admin.edit_group.delete_confirmation')))) { this.group.delete().then(() => m.redraw()); this.hide(); } diff --git a/framework/core/js/src/admin/components/SettingsModal.js b/framework/core/js/src/admin/components/SettingsModal.tsx similarity index 65% rename from framework/core/js/src/admin/components/SettingsModal.js rename to framework/core/js/src/admin/components/SettingsModal.tsx index e108c78ae8..bc167fed5c 100644 --- a/framework/core/js/src/admin/components/SettingsModal.js +++ b/framework/core/js/src/admin/components/SettingsModal.tsx @@ -1,18 +1,18 @@ import app from '../../admin/app'; -import Modal from '../../common/components/Modal'; +import Modal, { IInternalModalAttrs } from '../../common/components/Modal'; import Button from '../../common/components/Button'; import Stream from '../../common/utils/Stream'; import saveSettings from '../utils/saveSettings'; +import Mithril from 'mithril'; +import { MutableSettings, SettingValue } from './AdminPage'; -export default class SettingsModal extends Modal { - oninit(vnode) { - super.oninit(vnode); +export interface ISettingsModalAttrs extends IInternalModalAttrs {} - this.settings = {}; - this.loading = false; - } +export default abstract class SettingsModal extends Modal { + settings: MutableSettings = {}; + loading: boolean = false; - form() { + form(): Mithril.Children { return ''; } @@ -28,7 +28,7 @@ export default class SettingsModal extends Modal { ); } - submitButton() { + submitButton(): Mithril.Children { return (