Remove conf values

This commit is contained in:
Yang Luo
2023-06-30 01:38:48 +08:00
parent eee9b8b9fe
commit d31077a510
6 changed files with 15 additions and 25 deletions

View File

@ -18,8 +18,6 @@ import {SearchOutlined} from "@ant-design/icons";
import Highlighter from "react-highlight-words"; import Highlighter from "react-highlight-words";
import i18next from "i18next"; import i18next from "i18next";
import * as Setting from "./Setting"; import * as Setting from "./Setting";
import * as Conf from "./Conf";
import {DefaultOrganization} from "./Conf";
class BaseListPage extends React.Component { class BaseListPage extends React.Component {
constructor(props) { constructor(props) {
@ -44,14 +42,14 @@ class BaseListPage extends React.Component {
}; };
componentDidMount() { componentDidMount() {
window.addEventListener(Conf.StorageOrganizationChangedEvent, this.handleOrganizationChange); window.addEventListener("storageOrganizationChanged", this.handleOrganizationChange);
if (!Setting.isAdminUser(this.props.account)) { if (!Setting.isAdminUser(this.props.account)) {
Setting.setOrganization(DefaultOrganization); Setting.setOrganization("All");
} }
} }
componentWillUnmount() { componentWillUnmount() {
window.removeEventListener(Conf.StorageOrganizationChangedEvent, this.handleOrganizationChange); window.removeEventListener("storageOrganizationChanged", this.handleOrganizationChange);
} }
UNSAFE_componentWillMount() { UNSAFE_componentWillMount() {

View File

@ -32,8 +32,3 @@ export const ThemeDefault = {
}; };
export const CustomFooter = null; export const CustomFooter = null;
export const DefaultOrganization = "All"; // i18next.t("organization:All")
export const StorageOrganizationChangedEvent = "storageOrganizationChanged";
export const StorageOrganizationsChangedEvent = "storageOrganizationsChanged";

View File

@ -427,7 +427,7 @@ class OrganizationEditPage extends React.Component {
this.setState({ this.setState({
organizationName: this.state.organization.name, organizationName: this.state.organization.name,
}); });
window.dispatchEvent(new Event(Conf.StorageOrganizationsChangedEvent)); window.dispatchEvent(new Event("storageOrganizationsChanged"));
if (willExist) { if (willExist) {
this.props.history.push("/organizations"); this.props.history.push("/organizations");
@ -449,7 +449,7 @@ class OrganizationEditPage extends React.Component {
.then((res) => { .then((res) => {
if (res.status === "ok") { if (res.status === "ok") {
this.props.history.push("/organizations"); this.props.history.push("/organizations");
window.dispatchEvent(new Event(Conf.StorageOrganizationsChangedEvent)); window.dispatchEvent(new Event("storageOrganizationsChanged"));
} else { } else {
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`); Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
} }

View File

@ -21,7 +21,6 @@ import * as OrganizationBackend from "./backend/OrganizationBackend";
import i18next from "i18next"; import i18next from "i18next";
import BaseListPage from "./BaseListPage"; import BaseListPage from "./BaseListPage";
import PopconfirmModal from "./common/modal/PopconfirmModal"; import PopconfirmModal from "./common/modal/PopconfirmModal";
import * as Conf from "./Conf";
class OrganizationListPage extends BaseListPage { class OrganizationListPage extends BaseListPage {
newOrganization() { newOrganization() {
@ -84,7 +83,7 @@ class OrganizationListPage extends BaseListPage {
if (res.status === "ok") { if (res.status === "ok") {
this.props.history.push({pathname: `/organizations/${newOrganization.name}`, mode: "add"}); this.props.history.push({pathname: `/organizations/${newOrganization.name}`, mode: "add"});
Setting.showMessage("success", i18next.t("general:Successfully added")); Setting.showMessage("success", i18next.t("general:Successfully added"));
window.dispatchEvent(new Event(Conf.StorageOrganizationsChangedEvent)); window.dispatchEvent(new Event("storageOrganizationsChanged"));
} else { } else {
Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`); Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`);
} }
@ -105,7 +104,7 @@ class OrganizationListPage extends BaseListPage {
...this.state.pagination, ...this.state.pagination,
total: this.state.pagination.total - 1}, total: this.state.pagination.total - 1},
}); });
window.dispatchEvent(new Event(Conf.StorageOrganizationsChangedEvent)); window.dispatchEvent(new Event("storageOrganizationsChanged"));
} else { } else {
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`); Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
} }

View File

@ -25,7 +25,6 @@ import {Helmet} from "react-helmet";
import * as Conf from "./Conf"; import * as Conf from "./Conf";
import * as phoneNumber from "libphonenumber-js"; import * as phoneNumber from "libphonenumber-js";
import moment from "moment"; import moment from "moment";
import {DefaultOrganization} from "./Conf";
const {Option} = Select; const {Option} = Select;
@ -1168,24 +1167,24 @@ export function inIframe() {
export function getOrganization() { export function getOrganization() {
const organization = localStorage.getItem("organization"); const organization = localStorage.getItem("organization");
return organization !== null ? organization : DefaultOrganization; return organization !== null ? organization : "All";
} }
export function setOrganization(organization) { export function setOrganization(organization) {
localStorage.setItem("organization", organization); localStorage.setItem("organization", organization);
window.dispatchEvent(new Event(Conf.StorageOrganizationChangedEvent)); window.dispatchEvent(new Event("storageOrganizationChanged"));
} }
export function getRequestOrganization(account) { export function getRequestOrganization(account) {
if (isAdminUser(account)) { if (isAdminUser(account)) {
return getOrganization() === DefaultOrganization ? account.owner : getOrganization(); return getOrganization() === "All" ? account.owner : getOrganization();
} }
return account.owner; return account.owner;
} }
export function isDefaultOrganizationSelected(account) { export function isDefaultOrganizationSelected(account) {
if (isAdminUser(account)) { if (isAdminUser(account)) {
return getOrganization() === DefaultOrganization; return getOrganization() === "All";
} }
return false; return false;
} }

View File

@ -17,7 +17,6 @@ import {Select} from "antd";
import i18next from "i18next"; import i18next from "i18next";
import * as OrganizationBackend from "../../backend/OrganizationBackend"; import * as OrganizationBackend from "../../backend/OrganizationBackend";
import * as Setting from "../../Setting"; import * as Setting from "../../Setting";
import * as Conf from "../../Conf";
function OrganizationSelect(props) { function OrganizationSelect(props) {
const {onChange, initValue, style, onSelect, withAll, className} = props; const {onChange, initValue, style, onSelect, withAll, className} = props;
@ -28,9 +27,9 @@ function OrganizationSelect(props) {
if (props.organizations === undefined) { if (props.organizations === undefined) {
getOrganizations(); getOrganizations();
} }
window.addEventListener(Conf.StorageOrganizationsChangedEvent, getOrganizations); window.addEventListener("storageOrganizationsChanged", getOrganizations);
return function() { return function() {
window.removeEventListener(Conf.StorageOrganizationsChangedEvent, getOrganizations); window.removeEventListener("storageOrganizationsChanged", getOrganizations);
}; };
}, [value]); }, [value]);
@ -59,8 +58,8 @@ function OrganizationSelect(props) {
if (withAll) { if (withAll) {
items.unshift({ items.unshift({
label: i18next.t(`organization:${Conf.DefaultOrganization}`), label: i18next.t("organization:All"),
value: Conf.DefaultOrganization, value: "All",
}); });
} }