Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create admin orgs #2217

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const OrgDetails = () => {
});
};
const [updateOrg, { data: updateOrgData, loading: updateLoading }] = useMutation(UPDATE_ORG, {
refetchQueries: ["getUserOrgs"],
refetchQueries: ["getLoggedInUserFullAccessOrgs"],
onCompleted: () => {
setSnackbarSuccess();
},
Expand Down
50 changes: 48 additions & 2 deletions wondrous-bot-admin/src/components/WorkspaceSwitch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import { SidebarLabel, WorkspaceContainer, WorkspaceImageWrapper, WorkspaceWrapp
import AddImage from "components/Icons/Add.svg";
import { WorkspaceDAOIcon } from "components/Icons/DAOIcon";
import MoreVertIcon from "@mui/icons-material/MoreVert";
import { logout } from "components/Auth";
import { logout, useMe, withAuth } from "components/Auth";
import { LogoutRounded } from "@mui/icons-material";
import { ButtonIconWrapper } from "components/Shared/styles";
import { useMutation } from "@apollo/client";
import { CREATE_ORG } from "graphql/mutations";
import { generateRandomString } from "utils/discord";
import { ALLOWLIST_ADMIN_IDS } from "utils/constants";

interface GearIconProps {
onClick?: () => void;
Expand Down Expand Up @@ -45,6 +49,8 @@ const WorkspaceSwitch = ({ isCollapsed = false }) => {
const { userOrgs, activeOrg, setActiveOrg } = useContext(GlobalContext);
const navigate = useNavigate();

const { user } = useMe() || {};

const handleClickAway = () => {
if (anchorEl) setAnchorEl(null);
};
Expand All @@ -58,6 +64,30 @@ const WorkspaceSwitch = ({ isCollapsed = false }) => {
return setAnchorEl((prev) => (prev ? null : e.currentTarget));
};

const [adminCreateOrg, { loading }] = useMutation(CREATE_ORG, {
refetchQueries: ["getLoggedInUserFullAccessOrgs"],
onCompleted: (data) => {
setActiveOrg(data?.createOrg);
},
});
const _adminCreateOrg = async () => {
const randomStr = generateRandomString(8);
try {
await adminCreateOrg({
variables: {
input: {
name: `New Workspace - ${randomStr}`,
username: `workspace-${randomStr}`,
cmtyEnabled: true,
},
},
});
} catch (error) {
alert("Error creating workspace, check console for more details");
console.log(error, "some error");
}
};

return (
<ClickAwayListener onClickAway={handleClickAway} mouseEvent="onMouseDown">
<Box>
Expand Down Expand Up @@ -194,6 +224,22 @@ const WorkspaceSwitch = ({ isCollapsed = false }) => {
</Label>
</Box>
</WorkspaceWrapper>
{ALLOWLIST_ADMIN_IDS.includes(user?.id) && (
<WorkspaceWrapper onClick={_adminCreateOrg} disabled={loading}>
<Box display="flex" gap="10px" alignItems="center">
<img
style={{
width: "30px",
height: "30px",
}}
src={AddImage}
/>
<Label color="#1D1D1D" fontWeight={500} fontSize="15px">
ADMIN - create org
</Label>
</Box>
</WorkspaceWrapper>
)}
<Divider />
<WorkspaceWrapper onClick={() => logout()}>
<Box display="flex" gap="10px" alignItems="center">
Expand All @@ -219,4 +265,4 @@ const WorkspaceSwitch = ({ isCollapsed = false }) => {
);
};

export default WorkspaceSwitch;
export default withAuth(WorkspaceSwitch);
2 changes: 2 additions & 0 deletions wondrous-bot-admin/src/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,5 @@ export const QUALIFYING_ACTION_TYPES = {
export const LOCKED_PATHS = ["/store", "/store/items/create", "/store/items/:id", "/analytics"];

export const LOCAL_STORAGE_ORG_ID_KEY = "default-org-id";

export const ALLOWLIST_ADMIN_IDS = ["46108748309069853", "54694658413953389"];
Loading