2019-12-23 12:16:33 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import Badge from "./Badge";
|
|
|
|
|
import { Directions } from "utils/helpers";
|
|
|
|
|
import { ReduxActionTypes } from "constants/ReduxActionConstants";
|
|
|
|
|
import { getOnSelectAction, DropdownOnSelectActions } from "./dropdownHelpers";
|
2020-02-03 10:37:03 +00:00
|
|
|
import DropdownComponent, { CustomizedDropdownProps } from "./index";
|
2019-12-23 12:16:33 +00:00
|
|
|
import { Org } from "constants/orgConstants";
|
|
|
|
|
import { User } from "constants/userConstants";
|
2020-02-03 10:37:03 +00:00
|
|
|
import FormDialogComponent from "components/editorComponents/form/FormDialogComponent";
|
|
|
|
|
import CreateOrganizationForm from "pages/organization/CreateOrganizationForm";
|
2019-12-23 12:16:33 +00:00
|
|
|
|
2020-02-03 10:37:03 +00:00
|
|
|
const switchdropdown = (
|
|
|
|
|
orgs: Org[],
|
|
|
|
|
currentOrg: Org,
|
|
|
|
|
): CustomizedDropdownProps => ({
|
|
|
|
|
sections: [
|
|
|
|
|
{
|
|
|
|
|
isSticky: true,
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
content: (
|
|
|
|
|
<FormDialogComponent
|
|
|
|
|
trigger="Create Organization"
|
|
|
|
|
Form={CreateOrganizationForm}
|
|
|
|
|
title="Create Organization"
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
shouldCloseDropdown: false,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
options: orgs
|
|
|
|
|
.filter(org => org.id !== currentOrg.id)
|
|
|
|
|
.map(org => ({
|
|
|
|
|
content: org.name,
|
|
|
|
|
onSelect: () =>
|
|
|
|
|
getOnSelectAction(DropdownOnSelectActions.DISPATCH, {
|
|
|
|
|
type: ReduxActionTypes.SWITCH_ORGANIZATION_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
orgId: org.id,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
})),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
trigger: {
|
|
|
|
|
text: "Switch Organization",
|
|
|
|
|
},
|
|
|
|
|
openDirection: Directions.RIGHT,
|
|
|
|
|
openOnHover: true,
|
|
|
|
|
});
|
2019-12-23 12:16:33 +00:00
|
|
|
|
|
|
|
|
export const options = (
|
|
|
|
|
orgs: Org[],
|
|
|
|
|
currentOrg: Org,
|
|
|
|
|
user: User,
|
|
|
|
|
): CustomizedDropdownProps => ({
|
|
|
|
|
sections: [
|
|
|
|
|
{
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
content: (
|
|
|
|
|
<Badge
|
|
|
|
|
text={currentOrg.name}
|
|
|
|
|
imageURL="https://via.placeholder.com/32"
|
|
|
|
|
/>
|
|
|
|
|
),
|
2020-01-27 08:24:58 +00:00
|
|
|
disabled: true,
|
|
|
|
|
shouldCloseDropdown: false,
|
2019-12-23 12:16:33 +00:00
|
|
|
},
|
|
|
|
|
{
|
2020-01-27 08:24:58 +00:00
|
|
|
content: "Organization Settings",
|
|
|
|
|
onSelect: () =>
|
|
|
|
|
getOnSelectAction(DropdownOnSelectActions.REDIRECT, {
|
|
|
|
|
path: "/org/settings",
|
|
|
|
|
}),
|
2019-12-23 12:16:33 +00:00
|
|
|
},
|
|
|
|
|
{
|
2020-01-27 08:24:58 +00:00
|
|
|
content: "Applications",
|
|
|
|
|
onSelect: () =>
|
|
|
|
|
getOnSelectAction(DropdownOnSelectActions.REDIRECT, {
|
|
|
|
|
path: "/applications",
|
|
|
|
|
}),
|
2019-12-23 12:16:33 +00:00
|
|
|
},
|
|
|
|
|
{
|
2020-01-27 08:24:58 +00:00
|
|
|
content: "Members",
|
2019-12-23 12:16:33 +00:00
|
|
|
onSelect: () =>
|
2020-01-27 08:24:58 +00:00
|
|
|
getOnSelectAction(DropdownOnSelectActions.REDIRECT, {
|
2020-01-31 10:46:43 +00:00
|
|
|
path: "/users",
|
2019-12-23 12:16:33 +00:00
|
|
|
}),
|
|
|
|
|
},
|
2020-02-03 10:37:03 +00:00
|
|
|
{
|
|
|
|
|
content: <DropdownComponent {...switchdropdown(orgs, currentOrg)} />,
|
|
|
|
|
shouldCloseDropdown: false,
|
|
|
|
|
},
|
2019-12-23 12:16:33 +00:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
content: (
|
|
|
|
|
<Badge
|
|
|
|
|
text={user.email}
|
|
|
|
|
subtext={user.email}
|
|
|
|
|
imageURL="https://via.placeholder.com/32"
|
|
|
|
|
/>
|
|
|
|
|
),
|
2020-01-27 08:24:58 +00:00
|
|
|
disabled: true,
|
|
|
|
|
shouldCloseDropdown: false,
|
2019-12-23 12:16:33 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
content: "Sign Out",
|
|
|
|
|
onSelect: () =>
|
|
|
|
|
getOnSelectAction(DropdownOnSelectActions.DISPATCH, {
|
|
|
|
|
type: ReduxActionTypes.LOGOUT_USER_INIT,
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
trigger: {
|
|
|
|
|
icon: "ORG_ICON",
|
|
|
|
|
text: currentOrg.name,
|
|
|
|
|
outline: false,
|
|
|
|
|
},
|
|
|
|
|
openDirection: Directions.DOWN,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default options;
|